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

Jessica's Tic-Tac-Toe #27

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a09e9bf
one working test on player, no work started on game yet
ellevargas Dec 12, 2016
a864e43
changed around player test to simplify it
ellevargas Dec 12, 2016
050ed34
good foundation for tests started yay
ellevargas Dec 13, 2016
84bf56d
added scorecard and basic tests
ellevargas Dec 13, 2016
edabea2
testing
ellevargas Dec 13, 2016
52fec63
wincheck function added
jchung722 Dec 13, 2016
13be2dc
added testing for error throwing, win check, and play
ellevargas Dec 13, 2016
6804ff8
okay now turnhandler function is working
ellevargas Dec 13, 2016
8c09895
still issues with winCheck showing up true when it should not
ellevargas Dec 14, 2016
0520ebd
draw function now working along with play and scoring functions
ellevargas Dec 14, 2016
9b3832c
changed play to have only one move parameter and updated tests to match
ellevargas Dec 14, 2016
6242369
added tests to check board after win, draw, and after creating new game
ellevargas Dec 14, 2016
cb9002c
wrote extra test to check turnHandler incrementing after first play o…
ellevargas Dec 14, 2016
daec13e
Merge pull request #1 from ellevargas/evwave1v2
ellevargas Dec 16, 2016
036daed
added some starter files
jchung722 Dec 16, 2016
36cfb1b
added html/css files
jchung722 Dec 19, 2016
b93ab9c
convert javascript to model for game
jchung722 Dec 19, 2016
f068825
changed game.js model to backbone model syntax
jchung722 Dec 19, 2016
cbaf173
moved app.js to src folder
jchung722 Dec 20, 2016
4f57398
gameview skeleton
jchung722 Dec 20, 2016
9e0bf3a
boardview skeleton
jchung722 Dec 20, 2016
5a0d4db
boardview render function
jchung722 Dec 20, 2016
717a101
spaceview skeleton
jchung722 Dec 20, 2016
953fde8
proper views rendering
jchung722 Dec 20, 2016
12e952a
can manipulate tiles as player
jchung722 Dec 20, 2016
6216579
fixed bug that lets players keep adding tiles after game over
jchung722 Dec 21, 2016
7aa9993
added functioning reset game button
jchung722 Dec 21, 2016
1d59569
vertical align in div keeps element from moving when text added
jchung722 Dec 21, 2016
c0e5d2c
added player scores and some css fix
jchung722 Dec 21, 2016
b8a41e5
added css
jchung722 Dec 21, 2016
28bda44
more css - changed space color and hover
jchung722 Dec 21, 2016
60f3e46
dried up css code
jchung722 Dec 21, 2016
beb5e18
some more css fun showing player turn
jchung722 Dec 21, 2016
0224709
fixed player spec
jchung722 Dec 21, 2016
9d6c094
fixed all tests
jchung722 Dec 21, 2016
2ea8f51
added rule and save buttons
jchung722 Dec 21, 2016
f81f1aa
added alert for winner and draw
jchung722 Dec 22, 2016
5747e76
makes post to API
jchung722 Dec 23, 2016
922c60d
refactor of model
jchung722 Dec 23, 2016
bb0553c
updated specs
jchung722 Dec 23, 2016
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
84 changes: 84 additions & 0 deletions build/css/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
body {
font-family: 'Mallanna', sans-serif;
}
main div {
background-color: #0abab5;
height: 140px;
width: 140px;
margin: 1% 1% 1% 1%;
padding: 1% 1% 1% 1%;
font-size: 75px;
display: inline-block;
vertical-align: top;
transition-duration: 0.4s;
}

main div:hover {
opacity: 0.5;
}

#game, #score, td, h1, main div {
text-align: center;
}

#score {
width: 100%;
}

#score div{
font-size: 15px;
display: inline-block;
margin: 0 30px 0 30px;
}

#board, h1, h3 {
margin: auto;
}

#board {
height: 500px;
width: 500px;
}

h1 {
font-size: 75px;
}

h3 {
font-size: 25px;
}

th, td {
font-size: 20px;
}

button {
background-color: white;
font-family: 'Mallanna', sans-serif;
font-size: 20px;
border: 3px solid black;
margin: 0 5px 10px 5px;
transition-duration: 0.4s;
width: 125px;
}

button:hover {
background-color: black;
color: white;
}

#clear {
border: 3px solid #99ffcd;
}

#clear:hover {
background-color: #99ffcd;
}

.win {
color: green;
}

.lose {
color: red;
}
29 changes: 29 additions & 0 deletions build/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,37 @@
<head>
<title>Tic-Tac-Toe</title>
<meta charset="utf-8">
<link rel="stylesheet" href="css/app.css">
<link href="https://fonts.googleapis.com/css?family=Mallanna" rel="stylesheet">
</head>
<body>
<h1>Tic-Tac-Toe</h1>
<section id="game">
<div id="score"></div>
<button type="button" id="rules">Rules</button>
<button type="button" id="clear">New Round</button>
<button type="button" id="save">Save Game</button>
<main id="board"></main>
</section>

<script type="text/template" id="tmpl-player-details">
<h3><%- name %> : <%- letter %></h3>
<!-- <button class="edit button">Edit</button> -->
<table>
<tr>
<th>Win</th>
<th>Lose</th>
<th>Draw</th>
</tr>
<tr>
<td class="win"><%- scorecard.win %></td>
<td class="lose"><%- scorecard.lose %></td>
<td><%- scorecard.draw %></td>
</tr>
</table>
</script>

<script src="/app.bundle.js" charset="utf-8"></script>

</body>
</html>
149 changes: 149 additions & 0 deletions spec/game.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import Game from "app/models/game";

describe('Game', function() {

var testGame;
beforeEach(function() {
testGame = new Game("elle", "jessica");
});


describe('Game', function() {
it('should return player name', function() {
expect(testGame.player1.get("name")).toEqual("ELLE");
expect(testGame.player2.get("name")).toEqual("JESSICA");
});

it('should assign letter X to player 1 and letter O to player 2', function() {
expect(testGame.player1.get("letter")).toEqual("X");
expect(testGame.player2.get("letter")).toEqual("O");
expect(testGame.player1.get("letter")).not.toEqual("O");
expect(testGame.player2.get("letter")).not.toEqual("X");
});

});


describe('winCheck', function() {
it('should return true if there is a winner', function() {
expect(testGame.winCheck(["X", "X", "X", " ", " ", " ", " ", " ", " "])).toEqual(true);
});

it('should return false with an empty board', function() {
expect(testGame.winCheck([" ", " ", " ", " ", " ", " ", " ", " ", " "])).toEqual(false);
});

it('should return false if there is not a winner yet', function() {
expect(testGame.winCheck(["X", "X", " ", "O", "O", " ", " ", " ", " "])).toEqual(false);
});

it('should return false when the game ends in draw', function() {
expect(testGame.winCheck(["X", "X", "O", "O", "O", "X", "X", "O", "X"])).toEqual(false);
});
}); // describe winCheck end


describe('play', function() {
it('should return move in board', function() {
expect(testGame.play(2)).toEqual([" ", " ", "X", " ", " ", " ", " ", " ", " "]);
expect(testGame.play(1)).toEqual([" ", "O", "X", " ", " ", " ", " ", " ", " "]);
});

it('should throw an error if move made in spot that is taken', function() {
expect(testGame.play(2)).toEqual([" ", " ", "X", " ", " ", " ", " ", " ", " "]);
expect(function() { testGame.play(2)}).toThrow(TypeError("Please choose a valid move."));
});

it('should throw an error if move outside 0-8 are used', function() {
expect(function() { testGame.play(10)}).toThrow(TypeError("Please choose a valid move."));
});

it('should throw an error if move is a string', function() {
expect(function() { testGame.play("a")}).toThrow(TypeError("Please choose a valid move."));
});

it('should return the board after a win', function() {
testGame.play(6);
testGame.play(4);
testGame.play(7);
testGame.play(5);
expect(testGame.play(8)).toEqual([" ", " ", " ", " ", "O", "O", "X", "X", "X"])
});

it('should return the board after a draw', function() {
testGame.play(0);
testGame.play(2);
testGame.play(1);
testGame.play(3);
testGame.play(5);
testGame.play(4);
testGame.play(6);
testGame.play(7);
expect(testGame.play(8)).toEqual(["X", "X", "O", "O", "O", "X", "X", "O", "X"]);
});
}); //describe play end


describe('turnHandler', function() {
it('should increment turnCounter', function() {
expect(testGame.turnHandler()).toEqual(1);
expect(testGame.turnHandler()).toEqual(2);
});

it('should swap activePlayer', function() {
expect(testGame.activePlayer.get("name")).toEqual("ELLE");
expect(testGame.turnHandler()).toEqual(1);
expect(testGame.activePlayer.get("name")).toEqual("JESSICA");
expect(testGame.turnHandler()).toEqual(2);
expect(testGame.turnHandler()).toEqual(3);
});
});


describe('scoreKeeper', function() {
it('should increment scorecard when a player wins/player loses', function() {
// currentBoard = [" ", " ", " ", " ", "O", "O", "X", "X", "X"];
testGame.play(6);
testGame.play(4);
testGame.play(7);
testGame.play(5);
testGame.play(8);
expect(testGame.player1.get("scorecard").win).toEqual(1);
expect(testGame.player1.get("scorecard").lose).toEqual(0);
expect(testGame.player2.get("scorecard").lose).toEqual(1);
expect(testGame.player2.get("scorecard").win).toEqual(0);
});

it('should increment scorecards when game ends in draw', function() {
// currentBoard = ["X", "X", "O", "O", "O", "X", "X", "O", "X"]
testGame.play(0);
testGame.play(2);
testGame.play(1);
testGame.play(3);
testGame.play(5);
testGame.play(4);
testGame.play(6);
testGame.play(7);
testGame.play(8);
expect(testGame.player1.get("scorecard").draw).toEqual(1);
expect(testGame.player2.get("scorecard").draw).toEqual(1);
expect(testGame.player1.get("scorecard").draw).not.toEqual(0);
expect(testGame.player2.get("scorecard").draw).not.toEqual(0);
});
});


describe('newGame', function() {
it('should restart a new game with a clean board', function() {
testGame.play(6);
testGame.play(4);
testGame.play(7);
testGame.play(5);
expect(testGame.play(8)).toEqual([" ", " ", " ", " ", "O", "O", "X", "X", "X"]);
testGame.newGame();
expect(testGame.play(1)).toEqual([" ", "X", " ", " ", " ", " ", " ", " ", " "]);
expect(testGame.turnHandler()).toEqual(2);
});
});

});
28 changes: 28 additions & 0 deletions spec/player.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Player from "app/models/player";

describe('Player', function() {
var player1;
var player2;
beforeEach(function() {
player1 = new Player("elle", "X");
player2 = new Player("jessica", "O");
});

describe('get name assigned to player', function() {
it('should return the name of the player', function() {
expect(player1.get("name")).toEqual("ELLE");
expect(player1.get("letter")).toEqual("X");
expect(player2.get("name")).toEqual("JESSICA");
expect(player2.get("letter")).toEqual("O");
});
});

describe('get scorecard assigned to player with defaults of 0', function() {
it('should return the player scorecard', function() {
expect(player1.get("scorecard")).toEqual({ win:0, lose: 0, draw: 0});
expect(player1.get("scorecard").win).toEqual(0);
});
});


});
17 changes: 17 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import $ from 'jquery';
import Game from 'app/models/game';
import GameView from 'app/views/game_view';

$(document).ready(function() {

var game = new Game("player 1", "player 2");
game.fetch();

var gameView = new GameView({
el: '#game',
model: game
});

gameView.render();

});
Empty file added src/app/collections/board.js
Empty file.
Loading