-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtictactoe_scores.js
57 lines (49 loc) · 1.79 KB
/
tictactoe_scores.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
$( document ).ready(function() {
generate_footer();
settings_get();
setInterval( get_scores, 4000 );
get_scores();
});
function fill_data() {
//show player's current sign
$( '.player-sign' ).each(function() {
var playerId = $( this ).attr( 'data-player' );
var sign = game.players[playerId].sign;
$( this ).removeClass( 'sign-o sign-x' );
$( this ).addClass( 'sign-' + sign );
});
// show player's name
$( '.playername' ).each(function() {
var playerId = $( this ).attr( 'id' );
$( this ).val( game.players[playerId].name );
});
//Higlight active player's board
$( '.board.active' ).removeClass( 'active' );
$( '.board.' + game.activePlayer).addClass( 'active' );
//Show players throws
for (var i = 0; i <3; i++) {
var throww = game.players['player0'].throws[i];
throww = throww ? throww.val : ' ';
$( '.player0 .throws .tr' + i ).html( throww );
throww = game.players['player1'].throws[i];
throww = throww ? throww.val : ' ';
$( '.player1 .throws .tr' + i ).html( throww );
}
//Show players boards
render_player_board( 'player0' );
render_player_board( 'player1' );
//Show big board
$('.board.big td').each( function( index, td ) {
$( this ).removeClass();
if ( game.board[index] ) {
player = 'player' + ( game.board[index] - 1 );
$( this ).addClass( 'sign-' + game.players[player].sign );
}
} );
}
function render_player_board( player_name ) {
$( '.' + player_name + ' table td').each( function( index, td ) {
$( this ).removeClass();
$( this ).addClass( 'check-' + game.players[player_name].board[index] );
} );
}