-
Notifications
You must be signed in to change notification settings - Fork 0
/
Coordinate.java
72 lines (60 loc) · 2.07 KB
/
Coordinate.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
/**
* The Coordinate Class contains the placement of the sheep, dog, and wolf.
* At the start of the game, the animals are randomly assigned a tile.
* For the TAME WOLF (EASY) level, the wolf moves one position at a time when the player clicks a tile.
* For the SNEAKY WOLF (DIFFICULT) level, the wolf moves in random position
*
* @author Cherry Dominguez
* @version 1.0
* @since 2022-03-30
*/
public class Coordinate
{
/**
* Instance variables
*/
final int NUMBER_OF_GRIDS = 24;
int sheepPosition;
int dogPosition, wolfPosition;
int easyWolfTurn, difficultWolfTurn;
/**
* Constructor for Coordinate
*/
public Coordinate ()
{
//generating and assigning random position to sheep, dog, and wolf when the game loads.
sheepPosition = ((int)(Math.random() * 100) % NUMBER_OF_GRIDS);
dogPosition = ((int)(Math.random() * 100) % NUMBER_OF_GRIDS);
wolfPosition = ((int)(Math.random() * 100) % NUMBER_OF_GRIDS);
//To make sure characters doesn't go out of bounds
if (sheepPosition > 24)
{
sheepPosition = 0;
}
if (dogPosition > 24)
{
dogPosition = 0;
}
if (wolfPosition > 24)
{
wolfPosition = 0;
}
//To make sure that charcters are not in the same position at the start of the game
if (sheepPosition == dogPosition || sheepPosition == wolfPosition)
{
sheepPosition = sheepPosition + 1;
if (sheepPosition > 24)
sheepPosition = 0;
}
if (dogPosition == wolfPosition)
{
dogPosition = dogPosition + 1;
if (dogPosition > 24)
dogPosition = 0;
}
// Easy level wolf turn
easyWolfTurn = wolfPosition + 1;
//Difficult level wolf turn
difficultWolfTurn = ((int)(Math.random() * 100) % NUMBER_OF_GRIDS);
}// end of Coordinate Constructor
}//end of class Coordinate