//game base data
var numPlayers = 1;
var playerNames = { "X": "Ex", "O": "Oh" };
var gameOn = false; //use this to check all actions before executing
var computerTurn = false;
var computerHover = undefined;
//elements
var btnNewGame = document.getElementById("btn_new_game");
var players = document.getElementsByName("players");
var playerSelect = document.getElementsByName("player_select")[0];
var playerName = document.getElementsByName("player_name")[0];
var yourName = document.getElementsByName("your_name")[0];
var btnSaveName = document.getElementsByName("save_player_name")[0];
var btnSaveYourName = document.getElementsByName("save_your_name")[0];
var yourSymbol = document.getElementsByName("your_symbol");
var gameOptions = document.getElementById("game_options");
var singlePlayerOptions = document.getElementById("single_player_options");
var twoPlayerOptions = document.getElementById("two_player_options");
var btnShowOptions = document.getElementById("btn_show_options");
var board = document.getElementById("board");
var cells = [];
//game objects
//player object
function Player(name, symbol) {
this.name = name;
this.symbol = symbol;
}
//cell object
function Cell(cellIndex) {
//create graphic of cell
var tempCell = document.createElement('div');
var cellRef;
var value = "";
tempCell.id = "cell" + cellIndex;
tempCell.setAttribute("class", "cell");
board.appendChild(tempCell);
cellRef = document.getElementById("cell" + cellIndex);
cellRef.innerHTML = ""; //only using innerHTML for text on cells
//functions
this.getValue = function getValue() {
return value;
}
this.markCell = function markCell() {
cellRef.style.transition = "background 0.5s linear 0s";
cellRef.style.background = "#888";
}
//reset cell
this.reset = function reset() {
cellRef.innerHTML = "";
cellRef.style.background = "#fff";
value = "";
}
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.