Skip to content

Instantly share code, notes, and snippets.

@Brikky
Created August 28, 2016 18:40
Show Gist options
  • Save Brikky/9616180d463746ea5e2a062bac199cc3 to your computer and use it in GitHub Desktop.
Save Brikky/9616180d463746ea5e2a062bac199cc3 to your computer and use it in GitHub Desktop.
Tic Tac D'oh!
<div id = "popup"> Would you like to play as X or O? </div>
<div class = "board">
<div class = "loci" id = "1,1"></div>
<div class = "loci" id = "1,2"></div>
<div class = "loci" id = "1,3"></div>
<div class = "loci" id = "2,1"></div>
<div class = "loci" id = "2,2"></div>
<div class = "loci" id = "2,3"></div>
<div class = "loci" id = "3,1"></div>
<div class = "loci" id = "3,2"></div>
<div class = "loci" id = "3,3"></div>
</div>
var userMark;
var compMark;
var inPlayArray = [];
var loci = document.getElementsByClassName("loci");
//prompt user to select their mark
$(function() {
$("#popup").dialog({
resizable: false,
height: "auto",
width: 400,
modal: false,
buttons: {
X: function() {
userMark = "X";
$(this).dialog("close");
},
O: function() {
userMark = "O";
$(this).dialog("close");
}
}
});
})
//assign computer the unused mark
if (userMark = "X") {
compMark = "Y"
} else {
compMark = "X"
};
//function to add mark to the board then handle win check and computer's move via playRound
var addMark = function() {
this.innerHTML = "<p>" + userMark + "</p>";
inPlayArray.push(this.id.split(","));
playRound;
}
//function to handle one round of game logic by the computer
var playRound = function() {}
//add event listeners to all spaces on the board
for (i = 0; i < loci.length; i++) {
loci[i].addEventListener('click', addMark)
};
//checkWin function should take a mark and be called after that mark's move
//check if any 3 of the first array values are same
//check last
//check diagonals
var checkForWin = function() {
if (inPlayArray.length >= 5){
for(i=0;i<inPlayArray.length;i++){
}
}
}
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
.board {
background-color: rgb(100, 100, 100);
height: 80vh;
width: 80vh;
display: flex;
justify-content: space-around;
flex-wrap: wrap;
padding-top: 2.5vh;
margin: 10px auto;
}
.loci {
background-color: rgb(200, 200, 200);
height: 24vh;
width: 24vh;
display: flex;
justify-content: space-around;
align-items: center;
}
#popup {
background-color: rgba(200, 200, 200, .7);
border-radius: 10px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment