tictactoe.js
// utility function to check and handle game over
utility function to check and handle game over
utility function to check and handle game over
function checkGameOver() {
		let w = checkWin(board);
		if (w.result == 1) {
			p1_wins += 1;
			$('#p1_wins').text(p1_wins);
			$('#p1p1').addClass('slide');
			setTimeout(() => {
				$('#p1p1').removeClass('slide')
			}, 1000);
		} else if (w.result == -1) {
			p2_wins += 1;
			$('#p2_wins').text(p2_wins);
			$('#p2p1').addClass('slide');
			setTimeout(() => {
				$('#p2p1').removeClass('slide')
			}, 1000);
		}
		if (w.result != 0) {
			gameOver = true;	
			return;
		}
		if (!board.some((e) => e==0)) {
			ties += 1;
			$('#ties').text(ties);
			$('#tp1').addClass('slide');
			setTimeout(() => {
				$('#tp1').removeClass('slide')
			}, 1000);
			gameOver = true;
			return;
		}
	}
function checkGameOver ( ) { let w = checkWin ( board ) ; if ( w . result == 1 ) { p1_wins += 1 ; $ ( '#p1_wins' ) . text ( p1_wins ) ; $ ( '#p1p1' ) . addClass ( 'slide' ) ; setTimeout ( ( ) => { $ ( '#p1p1' ) . removeClass ( 'slide' ) } , 1000 ) ; } else if ( w . result == - 1 ) { p2_wins += 1 ; $ ( '#p2_wins' ) . text ( p2_wins ) ; $ ( '#p2p1' ) . addClass ( 'slide' ) ; setTimeout ( ( ) => { $ ( '#p2p1' ) . removeClass ( 'slide' ) } , 1000 ) ; } if ( w . result != 0 ) { gameOver = true ; return ; } if ( ! board . some ( ( e ) => e == 0 ) ) { ties += 1 ; $ ( '#ties' ) . text ( ties ) ; $ ( '#tp1' ) . addClass ( 'slide' ) ; setTimeout ( ( ) => { $ ( '#tp1' ) . removeClass ( 'slide' ) } , 1000 ) ; gameOver = true ; return ; } }
utility function to check and handle game over
utility function to check and handle game over
// check win // update text // +1 animation // update scoreboard // +1 animation // tictactoe animation // w.pattern // check cat's game // update scoreboard // +1 animation