Skip to content

Instantly share code, notes, and snippets.

@oravecz
Created January 29, 2011 20:25
Show Gist options
  • Save oravecz/802158 to your computer and use it in GitHub Desktop.
Save oravecz/802158 to your computer and use it in GitHub Desktop.
Javascript Game Challenge - Global Game Jam
<html>
<script type="text/javascript">
var nop = {};
var plA = {player: 'A'};
var solvedBoardA = [
[nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, nop ],
[nop, nop, nop, nop, nop, plA, nop, nop, nop, nop, nop, nop, nop ],
[nop, nop, nop, nop, plA, plA, plA, nop, nop, nop, nop, nop, nop ],
[nop, nop, nop, nop, nop, plA, nop, nop, nop, nop, nop, nop, nop ],
[nop, nop, nop, nop, nop, nop, nop, plA, nop, nop, nop, nop, nop ],
[nop, nop, nop, nop, nop, nop, nop, nop, plA, nop, nop, nop, nop ],
[nop, nop, nop, nop, nop, nop, nop, nop, nop, nop, plA, nop, nop ]
];
function QuizGame(boardSize, difficulty) {
var gameBoard = new HexBoard(boardSize, solvedBoardA);
var eleSolved = document.getElementById('solved');
eleSolved.innerHTML = gameBoard.isSolved() ? 'solved' : 'unsolved';
}
/**
* The quiz game board is a hex layout with hex "squares". The size of the board is adjustable. As
* an example, here is the layout of a 7x7 hex board with coordinates.
*
* | 3,3 | 5,4 | 7,5 | 9,6 |
*
* | 2,2 | 4,3 | 6,4 | 8,5 | A,6 |
*
* | 1,1 | 3,2 | 5,3 | 7,4 | 9,5 | B,6 |
*
* | 0,0 | 2,1 | 4,2 | 6,3 | 8,4 | A,5 | C,6 |
*
* | 1,0 | 3,1 | 5,2 | 7,3 | 9,4 | B,5 |
*
* | 2,0 | 4,1 | 6,2 | 8,3 | A,4 |
*
* | 3,0 | 5,1 | 7,2 | 9,3 |
*
*
* During gameplay, a board square will be unoccupied or occupied by at most one player at a time.
* It is also feasible that a square can also store powerups or additional properties, so a board
* square is a map. A player must start on any edge tile and the game is won when the player has
* formed a contiguous path to a non-adjacent side.
*
* A list of starting coordinates and valid ending coordinates follow:
* Start Valid ending coordinates
* ----- ----------------------------------------------------------------------------------------
* 0,0 9,3 A,4 B,5 C,6 B,6 A,6 9,6
* 1,0 9,3 A,4 B,5 C,6 B,6 A,6 9,6 7,5 5,4 3,3
* 2,0 9,3 A,4 B,5 C,6 B,6 A,6 9,6 7,5 5,4 3,3
* 3,0 C,6 B,6 A,6 9,6 7,5 5,4 3,3
* 5,1 0,0 C,6 B,6 A,6 9,6 7,5 5,4 3,3 2,2 1,1
* 7,2 0,0 C,6 B,6 A,6 9,6 7,5 5,4 3,3 2,2 1,1
* 9,3 0,0 9,6 7,5 5,4 3,3 2,2 1,1
* A,4 0,0 1,0 2,0 3,0 9,6 7,5 5,4 3,3 2,2 1,1
* B,5 0,0 1,0 2,0 3,0 9,6 7,5 5,4 3,3 2,2 1,1
* C,6 0,0 1,0 2,0 3,0 3,3 2,2 1,1
* B,6 0,0 1,0 2,0 3,0 5,1 7,2 9,3 3,3 2,2 1,1
* A,6 0,0 1,0 2,0 3,0 5,1 7,2 9,3 3,3 2,2 1,1
* 9,6 0,0 1,0 2,0 3,0 5,1 7,2 9,3
* 7,5 0,0 1,0 2,0 3,0 5,1 7,2 9,3 A,4 B,5 C,6
* 5,4 0,0 1,0 2,0 3,0 5,1 7,2 9,3 A,4 B,5 C,6
* 3,3 3,0 5,1 7,2 9,3 A,4 B,5 C,6
* 2,2 3,0 5,1 7,2 9,3 A,4 B,5 C,6 B,6 A,6 9,6
* 1,1 3,0 5,1 7,2 9,3 A,4 B,5 C,6 B,6 A,6 9,6
*
*
* Solved game using the sample solvedBoardA:
*
* | 3,3 | 5,4 | 7,5 | 9,6 |
*
* | 2,2 | 4,3 | 6,4 | A | A |
*
* | 1,1 | 3,2 | A | A | 9,5 | B,6 |
*
* | 0,0 | 2,1 | A | 6,3 | 8,4 | A,5 | C,6 |
*
* | 1,0 | 3,1 | A | 7,3 | 9,4 | B,5 |
*
* | 2,0 | 4,1 | A | 8,3 | A,4 |
*
* | 3,0 | A | 7,2 | 9,3 |
*
*/
function HexBoard(size, board) {
if (!board) {
board = new Array(size + size >> 1);
board.forEach(function(row) {
row = new Array(size);
});
}
function setSquare(x, y, contents) {
board[x][y] = contents;
}
function getSquare(x, y) {
return board[x][y] || {};
}
function isSolved() {
return false;
}
return {
// board: board,
get: getSquare,
set: setSquare,
isSolved: isSolved
}
}
window.onload = function() {
var quizGame = new QuizGame(7, 'easy');
}
</script>
<body>
<h2>Game board is <span id="solved">?</span></h2>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment