-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery-war-o.js
66 lines (59 loc) · 2.57 KB
/
jquery-war-o.js
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
$(document).ready(function() {
var players = [];
var game = null;
var signalNextBidPlayer = function (kittyValue, setNextBidFunction, hand) {
$('#output').append('<br />Kitty Value is: ' + kittyValue + '<br />');
$.each(players, function () {
var name = this.getName();
var number = this.getNumber();
var playerPoints = game.getScoreForPlayer(number);
$('#output').append(name + ' has ' + playerPoints + ' points.<br />');
});
var bidSelection = $('#playerBid');
bidSelection.empty();
$.each(hand, function () {
bidSelection.append($('<option>').val(this).text(this));
});
$('#bidButton').unbind('click');
$('#bidButton').click(function () {
if (!game.isFinished()) {
var bidValue = parseInt($('#playerBid').val(), 10);
setNextBidFunction(humanPlayer.getNumber(), bidValue);
}
});
};
var humanPlayer = WARO.createPlayer("Human Player", signalNextBidPlayer);
players.push(humanPlayer);
players.push(WARO.createPlayer("Alice"));
players.push(WARO.createPlayer("Bob"));
players.push(WARO.createPlayer("Cassie"));
game = WARO.createGame(5, players, function () {
var winners = [];
var winningPoints = -1;
$('#output').append('<br />');
$.each(players, function () {
var name = this.getName();
var number = this.getNumber();
var playerPoints = game.getScoreForPlayer(number);
if (winningPoints < playerPoints) {
winners = []; // Reset
winners.push(this);
winningPoints = playerPoints;
} else if (winningPoints === playerPoints) {
winners.push(this);
winningPoints = playerPoints;
}
$('#output').append(name + ' has ' + playerPoints + ' points.<br />');
});
$('#output').append('<br />');
if (winners.length === 1) {
$('#output').append('With ' + winningPoints + ' points, ' + winners[0].getName() + ' won!<br />');
} else {
$('#output').append('With ' + winningPoints + ' points, the follwing:<br />');
$.each(winners, function () {
$('#output').append(this.getName() + '<br />');
});
}
});
game.startGame();
});