-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplayer.php
More file actions
69 lines (52 loc) · 1.56 KB
/
Copy pathplayer.php
File metadata and controls
69 lines (52 loc) · 1.56 KB
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
<?php
class Player {
private $pieces;
private $color;
private $direction;
public function __construct($color, $direction) {
$this->color = $color; // White OR Red
$this->direction = $direction; // 1 or -1
$this->pieces = array();
if($color=='White'){
$xCoord = array(0,2,4,6,1,3,5,7,0,2,4,6);
$yCoord = array(7,7,7,7,6,6,6,6,5,5,5,5);
}elseif($color=='Red'){
$xCoord = array(1,3,5,7,0,2,4,6,1,3,5,7);
$yCoord = array(0,0,0,0,1,1,1,1,2,2,2,2);
}
for ($i=0; $i<12; $i++) {
$y = $xCoord[$i];
$x = $yCoord[$i];
$this->pieces[] = new Piece($x,$y,$direction,$i);
}
} // End constructor
public function &getPieces() {
return $this->pieces;
}
public function &getPiece($id) {
return $this->pieces[$id];
}
public function countPieces() {
$count = 0;
foreach($this->pieces as $piece) {
if(!is_null($piece)) {
$count++;
}
}
return $count;
}
public function &deletePiece($id) {
$this->pieces[$id] = null;
return $this->pieces;
}
public function move($piece,$x,$y) {
$pieceObj = $this->pieces[$piece];
$pieceObj->setPos($x,$y);
if($this->color=='White' && $x==0) {
$pieceObj->king();
}elseif($this->color=='Red' && $x==7) {
$pieceObj->king();
}
//$this->pieces[$piece] = $pieceObj;
}
} // End class definition