-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCell.java
88 lines (79 loc) · 1.72 KB
/
Cell.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
public class Cell {
//Atribut
private String playersIn;
private String cellNo;
private boolean isTemporaryTrap = false;
//Konstantas
private final String clearCell = "99";
private final String trapCell = "88";
private final String noPlayerCell = "0";
//Methods
//konstruktor
public Cell()
{
cellNo = clearCell;
playersIn = clearCell;
}
// get nomor cell ini
public String getCellNo()
{
return cellNo;
}
// get player-player mana saja yang tokennya ada di cell ini
public String getPlayersIn()
{
return playersIn;
}
// get nomor cell ini
public void setCellNo(String No)
{
cellNo = No;
}
// mengeset cell menjadi trap temprorary
public boolean setTrap()
{
//bukan temporary trap dan bukan trap permanen
if(!playersIn.contains(trapCell))
{
setPlayersIn(trapCell); //letakkan mark trap 88
isTemporaryTrap = true;
return true;
}
else return false;
}
public boolean isTrap()
{
return playersIn.contains(trapCell);
}
// unset cell trap temporary menjadi cell biasa
public boolean unsetTrap()
{
if(isTemporaryTrap)
{
removePlayer(trapCell); //hapus mark trap 88
isTemporaryTrap = false;
return true;
}
else return false;
}
// menambahkan player P ke cell ini
public void setPlayersIn(String P)
{
if(playersIn.equals(clearCell) || playersIn.equals(noPlayerCell))
playersIn = P;
else if(!playersIn.contains(P))
playersIn = playersIn.concat(P);
}
// menghapus player P dari cell ini
public boolean removePlayer(String P)
{
if(playersIn.contains(P))
{
//System.out.println("hapus " + P + " di " + playersIn);
playersIn = playersIn.replaceAll(P, "");
//System.out.println("hasilnya : " + playersIn);
return true;
}
else return false;
}
}