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

didn't have enough time to finish this. it's a mess. sorry in advance #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
30 changes: 15 additions & 15 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">

<!-- set viewport to device width to make site responsive -->
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- bootstrap css -->

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
<!-- custom styles -->

<link rel="stylesheet" type="text/css" href="main.css">
<title>Tic Tac Toe</title>
</head>
<body>
Expand All @@ -29,29 +27,31 @@ <h1>Tic Tac Toe</h1>
<!-- you can nest rows inside of columns! -->
<!-- our board has 3 rows, each with 3 columns inside -->
<div class="row">
<div class="col-xs-4 box"></div>
<div class="col-xs-4 box"></div>
<div class="col-xs-4 box"></div>
</div>

<div class="col-xs-4 box" id = "top-left"></div>
<div class="col-xs-4 box" id = "top-mid"></div>
<div class="col-xs-4 box" id = "top-right"></div>
</div>
<div class="row">
<div class="col-xs-4 box"></div>
<div class="col-xs-4 box"></div>
<div class="col-xs-4 box"></div>
<div class="col-xs-4 box" id = "mid-left"></div>
<div class="col-xs-4 box" id = "mid-mid"></div>
<div class="col-xs-4 box" id = "mid-right"></div>
</div>

<div class="row">
<div class="col-xs-4 box"></div>
<div class="col-xs-4 box"></div>
<div class="col-xs-4 box"></div>
<div class="col-xs-4 box" id = "bot-left"></div>
<div class="col-xs-4 box" id = "bot-mid"></div>
<div class="col-xs-4 box" id = "bot-right"></div>
</div>
</div>
</div>
</div>

<!-- jquery -->

<script src ="https://code.jquery.com/jquery-2.1.4.min.js"></script>

<!-- custom script -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" integrity="sha512-K1qjQ+NcF2TYO/eI3M6v8EiNYZfA95pQumfvcVrTHtwQVDG+aHRqLi/ETn2uB+1JqwYqVG3LIvdm9lj6imS/pQ==" crossorigin="anonymous"></script>

</body>
</html>
111 changes: 107 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,109 @@
// wait for DOM to load before running JS
$(function() {

// your code here
$(document).ready(function(){

var oldClick = 0;

function changeToX(box) {
var thisBox = box;
$("#" + thisBox).text('X');
thisBox = "";
}

function changeToO(box) {
var thisBox = box;
$("#" + thisBox).text('O');
thisBox = "";
}

function evalClickTime(newClick, specificBox) {
if(newClick - oldClick > 0 && newClick - oldClick < 2000) {
console.log('registered your timely second click');
console.log((newClick - oldClick));
changeToO(specificBox);
} else {
console.log('one click');
console.log((newClick - oldClick));
changeToX(specificBox);
}
oldClick = newClick;
}

$('.box').bind("click", function youClicked (event) {
//get the timestamp
var click = Date.now();
//get the box id
var boxId = event.toElement.id;
evalClickTime(click, boxId);
getCells();
//evaluate the cell patterns
var endGame = evalCells();
if(endGame) {
//get winner
//display winner
//reset the game
}


})

var cellValues = [[,,],[,,],[,,]];

function getCells() {
var cells = [["#top-left", "#top-mid", "#top-right"], ["#mid-left", "#mid-mid", "#mid-right"], ["#bot-left", "#bot-mid", "#bot-right"]];
for(var i = 0; i < 3; i++) {
for(j = 0; j < 3; j++) {
var cellVal = $(cells[i][j]).text();
cellValues[i][j] = cellVal;
}
}
}

function evalCells(cellValues) {
//rows
if(cellValues[0][0] === cellValues[0][1] && cellValues[0][1] === cellValues[0][2]) {
return true;
} else if(cellValues[1][0] === cellValues[1][1] && cellValues[1][1] === cellValues[1][2]) {
return true;
} else if(cellValues[2][0] === cellValues[2][1] && cellValues[2][1] === cellValues[2][2]) {
return true;
//columns
} else if(cellValues[0][0] === cellValues[1][0] && cellValues[1][0] === cellValues[2][0]) {
return true;
} else if(cellValues[0][1] === cellValues[1][1] && cellValues[1][1] === cellValues[2][1]) {
return true;
} else if(cellValues[0][2] === cellValues[1][2] && cellValues[1][2] === cellValues[2][2]) {
return true;
//diagonal
} else if(cellValues[0][1] === cellValues[1][1] && cellValues[1][1] === cellValues[2][2]) {
return true;
} else if(cellValues[0][0] === cellValues[1][1] && cellValues[1][1] === cellValues[0][2]) {
return true;
} else {
return false;
}

}

});






















});
96 changes: 96 additions & 0 deletions scrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@

var oldClick = 0;

function changeToX(box) {
var thisBox = box;
$("#" + thisBox).text('X');
thisBox = "";
}

function changeToO(box) {
var thisBox = box;
$("#" + thisBox).text('O');
thisBox = "";
}

function evalClickTime(newClick, specificBox) {
if(newClick - oldClick > 0 && newClick - oldClick < 2000) {
console.log('registered your timely second click');
console.log((newClick - oldClick));
changeToO(specificBox);
} else {
console.log('one click');
console.log((newClick - oldClick));
changeToX(specificBox);
}
oldClick = newClick;
}

$('.box').bind("click", function youClicked (event) {
//get the timestamp
var click = Date.now();
//get the box id
var boxId = event.toElement.id;
evalClickTime(click, boxId);
getCells();
//evaluate the cell patterns
var endGame = evalCells();
if(endGame) {
//get winner
//display winner
//reset the game
}


})

var cellValues = [[,,],[,,],[,,]];

function getCells() {
var cells = [["#top-left", "#top-mid", "#top-right"], ["#mid-left", "#mid-mid", "#mid-right"], ["#bot-left", "#bot-mid", "#bot-right"]];
for(var i = 0; i < 3; i++) {
for(j = 0; j < 3; j++) {
var cellVal = $(cells[i][j]).text();
cellValues[i][j] = cellVal;
}
}
}

function evalCells(cellValues) {
//rows
if(cellValues[0][0] === cellValues[0][1] && cellValues[0][1] === cellValues[0][2]) {
return true;
} else if(cellValues[1][0] === cellValues[1][1] && cellValues[1][1] === cellValues[1][2]) {
return true;
} else if(cellValues[2][0] === cellValues[2][1] && cellValues[2][1] === cellValues[2][2]) {
return true;
//columns
} else if(cellValues[0][0] === cellValues[1][0] && cellValues[1][0] === cellValues[2][0]) {
return true;
} else if(cellValues[0][1] === cellValues[1][1] && cellValues[1][1] === cellValues[2][1]) {
return true;
} else if(cellValues[0][2] === cellValues[1][2] && cellValues[1][2] === cellValues[2][2]) {
return true;
//diagonal
} else if(cellValues[0][1] === cellValues[1][1] && cellValues[1][1] === cellValues[2][2]) {
return true;
} else if(cellValues[0][0] === cellValues[1][1] && cellValues[1][1] === cellValues[0][2]) {
return true;
} else {
return false;

$(document).ready(function(){
}

});
}