-
Notifications
You must be signed in to change notification settings - Fork 6
/
testsuite.html
96 lines (72 loc) · 2.75 KB
/
testsuite.html
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
89
90
91
92
93
94
95
96
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="text/css" rel="stylesheet" media="all" href="domino.static.css" />
<link type="text/css" rel="stylesheet" media="all" href="stage.css" />
<script type="text/javascript" src="DominoGame.js"></script>
<script type="text/javascript" src="DominoClient.js"></script>
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript">
$( function() {
//test bed
//create a new game server and shuffle and deal
var gameServer = new Game();
gameServer.shuffle();
gameServer.deal();
var client = new DominoClient();
var a = gameServer.whichPlayer();
gameServer.makePlay(a, new Game.Domino(6,6));
var cc = 0;
var who = -1;
var canPlay = false;
who = gameServer.whoWon();
canPlay = gameServer.gameCanPlay();
while(who == -1 && canPlay == true)
{
a = gameServer.whichPlayer();
ends = gameServer.headsAndTails();
plays = gameServer.players[a].whatToPlay(ends.head, ends.tail);
whichOfPlays = Math.floor(Math.random() * plays.length);
first = plays[whichOfPlays];
var head = 0;
if(first.left() == ends.tails) head = 0;
else
if(first.right() == ends.tails) head = 0;
else
if(first.right() == ends.head) head = 1;
else
if(first.left() == ends.head) head = 1;
left = first.left();
right = first.right();
dom = new Game.Domino(left, right);
gameServer.makePlay(a, dom,head);
card = head == 1? gameServer.playstack[0] : gameServer.playstack[gameServer.playstack.length - 1];
domcard = client.createCard(card);
/*if(head > 0)
$("#players").prepend( domcard, $("#players").firstChild);
else
$("#players").append( domcard );*/
who = gameServer.whoWon();
canPlay = gameServer.gameCanPlay();
}
for(var ca = 0; ca < gameServer.playstack.length; ca++)
{
card = gameServer.playstack[ca];
domcard = client.createCard(card);
$("#players").append( domcard );
}
if(who >= 0)
console.log("player " + (who + 1) + " won");
else
console.log("game was drawn.");
} );
</script>
</head>
<body>
<div id="stage">
<div id="players">
</div>
</div>
</body>
</html>