-
Notifications
You must be signed in to change notification settings - Fork 0
/
Board.java
88 lines (77 loc) · 2.52 KB
/
Board.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.snakeandladder.snakeandladder;
import javafx.util.Pair;
import java.nio.channels.Pipe;
import java.util.ArrayList;
public class Board {
ArrayList<Pair<Integer, Integer>> posCoordinates;
ArrayList<Integer> snake_ladder;
public Board()
{
posCoordinates = new ArrayList<>();
populate_snakeLadder();
posCoordinates.add(new Pair<>(0,0));
for(int i = 0; i < SnakeAndLadder.height; i++)
{
for (int j = 0; j < SnakeAndLadder.width; j++)
{
int yCord = SnakeAndLadder.tile_size*SnakeAndLadder.height -(i * SnakeAndLadder.tile_size) - (SnakeAndLadder.tile_size/2);
int xCord = 0;
if((i & 1) == 0)
{
xCord = (j * SnakeAndLadder.tile_size) + SnakeAndLadder.tile_size/2;
}
else
{
xCord = SnakeAndLadder.tile_size*SnakeAndLadder.width - (j * SnakeAndLadder.tile_size) -(SnakeAndLadder.tile_size/2);
}
posCoordinates.add(new Pair<>(xCord, yCord));
}
}
}
public void populate_snakeLadder()
{
snake_ladder = new ArrayList<>();
for(int i = 0; i <101; i++)
{
snake_ladder.add(i);
}
snake_ladder.set(4, 25);
snake_ladder.set(13, 46);
snake_ladder.set(27, 5);
snake_ladder.set(33, 49);
snake_ladder.set(40, 3);
snake_ladder.set(42, 63);
snake_ladder.set(43, 18);
snake_ladder.set(50, 69);
snake_ladder.set(54, 31);
snake_ladder.set(62, 81);
snake_ladder.set(66, 45);
snake_ladder.set(74, 92);
snake_ladder.set(76, 58);
snake_ladder.set(89, 53);
snake_ladder.set(99, 41);
}
public int get_x(int pos)
{
if(pos >= 1 && pos <= 100)
{
return posCoordinates.get(pos).getKey();
}
return -1;
}
public int get_y(int pos)
{
if(pos >= 1 && pos <= 100)
{
return posCoordinates.get(pos).getValue();
}
return -1;
}
// public static void main(String[] args) {
// Board board = new Board();
// for(int i = 0; i < board.posCoordinates.size(); i++)
// {
// System.out.println(i + " $"+" x : "+ board.posCoordinates.get(i).getKey()+" y : "+board.posCoordinates.get(i).getValue());
// }
// }
}