Created
June 4, 2014 21:44
-
-
Save seanreed1111/6c1f89d405e1b21c85ae to your computer and use it in GitHub Desktop.
Switch - Javascript Game - starting position
This file contains hidden or 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> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Switch!</title> | |
</head> | |
<body> | |
<div id="board"> | |
<canvas id="1" width=51 height=51 style="border-style:solid; border-width:2px;"></canvas> | |
<canvas id="2" width=51 height=51 style="border-style:solid; border-width:2px;"></canvas> | |
<canvas id="3" width=51 height=51 style="border-style:solid; border-width:2px;"></canvas> | |
<canvas id="4" width=51 height=51 style="border-style:solid; border-width:2px;"></canvas> | |
<canvas id="5" width=51 height=51 style="border-style:solid; border-width:2px;"></canvas> | |
<canvas id="6" width=51 height=51 style="border-style:solid; border-width:2px;"></canvas> | |
<canvas id="7" width=51 height=51 style="border-style:solid; border-width:2px;"></canvas> | |
<canvas id="8" width=51 height=51 style="border-style:solid; border-width:2px;"></canvas> | |
<canvas id="9" width=51 height=51 style="border-style:solid; border-width:2px;"></canvas> | |
</div> | |
<script src="switch.js"></script> | |
</body> | |
</html> |
This file contains hidden or 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
// This week's game is called SWITCH! (It is a one player game.) | |
// The game is played on a one-dimensional board 9 units long, placed either horizontally or vertically. | |
//(Let's assume it is horizontal for the rest of this description.) | |
// The game starts with four red tokens and four blue tokens grouped together on the left and right side of the board, respectively. | |
//The 9th space on the board (the middle space) starts off empty. | |
// Each turn, the player can move any one token to an unoccupied adjacent space or jump over exactly one token | |
//(of either color) to land on an unoccupied space. | |
// Game Objective: Switch the pieces so that the blue tokens are all on the left side of the board | |
// and the red tokens are on the right, in the shortest amount of time and shortest number of moves possible. | |
"use strict"; | |
window.onload = function(){ | |
//draw initial board configuration | |
for (var i = 1; i <= 9; i++) { | |
if (i == 5) continue; | |
var canvas = document.getElementById(i.toString()); | |
var context = canvas.getContext("2d"); | |
context.beginPath(); | |
context.arc(25,25,25,0,2*Math.PI,true); //draws circles | |
context.fillStyle = (i<5) ? "#f00" : "#00f"; //sets circle color to red or blue | |
context.fill(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment