Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pequenos ajustes nas funções e add de template string #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 13 additions & 21 deletions js/tic-tac-toe.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ const tic_tac_toe = {

// ATTRIBUTES
board: ['','','','','','','','',''],
symbols: {
options: ['O','X'],
turn_index: 0,
change: function(){
this.turn_index = ( this.turn_index === 0 ? 1:0 );
}
},
symbols: false,
container_element: null,
gameover: false,
winning_sequences: [
Expand All @@ -30,20 +24,18 @@ const tic_tac_toe = {

make_play: function(position) {
if (this.gameover) return false;
if (this.board[position] === ''){
this.board[position] = this.symbols.options[this.symbols.turn_index];
this.draw();
let winning_sequences_index = this.check_winning_sequences( this.symbols.options[this.symbols.turn_index] );
if (winning_sequences_index >= 0){
this.game_is_over();
} else{
this.symbols.change();
}
return true;
}
else {
return false;
if (this.board[position] != '') return false;

this.board[position] = this.symbols ? 'X' : 'O'
this.draw()

let winning_sequences_index = this.check_winning_sequences( this.board[position] );
if (winning_sequences_index >= 0){
this.game_is_over();
} else{
this.symbols = !this.symbols
}
return true;
},

check_winning_sequences: function(simbol) {
Expand Down Expand Up @@ -74,7 +66,7 @@ const tic_tac_toe = {
let content = '';

for ( i in this.board ) {
content += '<div onclick="tic_tac_toe.make_play(' + i + ')">' + this.board[i] + '</div>';
content += `<div onclick="tic_tac_toe.make_play(${i})">${this.board[i]}</div>`;
};

this.container_element.innerHTML = content;
Expand Down