Last active
October 23, 2015 01:33
-
-
Save kevincolten/60782473278ae4349ef7 to your computer and use it in GitHub Desktop.
TicTacToe (GUI)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'); | |
var uglify = require('gulp-uglify'); | |
var minifyCss = require('gulp-minify-css'); | |
gulp.task('compress', function() { | |
return gulp.src('TicTacToe.js') | |
.pipe(uglify()) | |
.pipe(gulp.dest('dist/')); | |
}); | |
gulp.task('minify-css', function() { | |
return gulp.src('style.css') | |
.pipe(minifyCss()) | |
.pipe(gulp.dest('dist/')); | |
}); | |
gulp.task('watch', function () { | |
gulp.watch('./TicTacToe.js', ['compress']); | |
gulp.watch('./style.css', ['minify-css']); | |
}); | |
gulp.task('default', ['compress', 'minify-css', 'watch']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title></title> | |
<link rel="stylesheet" href="style.css" /> | |
</head> | |
<body> | |
<div class="row"> | |
<div data-cell="0"></div> | |
<div data-cell="1"></div> | |
<div data-cell="2"></div> | |
</div> | |
<div class="row"> | |
<div data-cell="3"></div> | |
<div data-cell="4"></div> | |
<div data-cell="5"></div> | |
</div> | |
<div class="row"> | |
<div data-cell="6"></div> | |
<div data-cell="7"></div> | |
<div data-cell="8"></div> | |
</div> | |
<div id="announce-winner"></div> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js"></script> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/fastclick/1.0.6/fastclick.min.js"></script> | |
<script type="text/javascript" src="./TicTacToe.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
div[data-cell] { | |
width: 100px; | |
height: 100px; | |
background-color: #f2f2f2; | |
float: left; | |
border: 1px solid #808080; | |
font-size: 100px; | |
text-align: center; | |
} | |
.row { | |
clear: both; | |
} | |
#announce-winner { | |
clear: both; | |
font-size: 50px; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
$(document).ready(function() { | |
var playerTurn = 'X'; | |
$('[data-cell]').on('click', function() { | |
$(this).text(playerTurn); | |
checkForWin(); | |
playerTurn = (playerTurn === 'X') ? 'O' : 'X'; | |
}); | |
function horizontalWin() { | |
return ($('[data-cell="0"]').text() === playerTurn && $('[data-cell="1"]').text() === playerTurn && $('[data-cell="2"]').text() === playerTurn) || | |
($('[data-cell="3"]').text() === playerTurn && $('[data-cell="4"]').text() === playerTurn && $('[data-cell="5"]').text() === playerTurn) || | |
($('[data-cell="6"]').text() === playerTurn && $('[data-cell="7"]').text() === playerTurn && $('[data-cell="8"]').text() === playerTurn); | |
} | |
function verticalWin() { | |
return ($('[data-cell="0"]').text() === playerTurn && $('[data-cell="3"]').text() === playerTurn && $('[data-cell="6"]').text() === playerTurn) || | |
($('[data-cell="1"]').text() === playerTurn && $('[data-cell="4"]').text() === playerTurn && $('[data-cell="7"]').text() === playerTurn) || | |
($('[data-cell="2"]').text() === playerTurn && $('[data-cell="5"]').text() === playerTurn && $('[data-cell="8"]').text() === playerTurn); | |
} | |
function diagonalWin() { | |
return ($('[data-cell="0"]').text() === playerTurn && $('[data-cell="4"]').text() === playerTurn && $('[data-cell="8"]').text() === playerTurn) || | |
($('[data-cell="2"]').text() === playerTurn && $('[data-cell="4"]').text() === playerTurn && $('[data-cell="6"]').text() === playerTurn); | |
} | |
function checkForWin() { | |
if ( horizontalWin() || verticalWin() || diagonalWin() ) { | |
$('#announce-winner').text('Player ' + playerTurn + ' Won!'); | |
} | |
} | |
FastClick.attach(document.body); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment