Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Copyright (c) 2012 Nick "Static Fiend" Franklin
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source
- */
- //Java Bingo
- //By Nick "Static Fiend" Franklin
- //v1.0.3
- /*
- Changelog:
- v1.0.3
- Remade to put most of the init in a function
- Reset option made available
- v1.0.2
- Added 'static' local variable to markCell() for win condition
- Added win conditions and minor victory text.
- v1.0.1
- Minor fix so that "free" cell can't be unchecked.
- Added changelog.
- Added zlib license.
- v1.0.0
- Initial version.
- Debug "training wheels" removed!
- */
- //Got new suggestions for this? Send me an e-mail bingostuff@grimfiend.com
- //Stores all the text we can choose from.
- var textArray = new Array();
- var cellState = new Array();
- var cellText = new Array();
- //Used to store numbers so we don't have duplicate quotes.
- var tempNum = new Array();
- var gameWin = false;
- //FIXME: Send this all to a MySQL or text file to clean this up.
- textArray[0] = "";
- textArray[1] = "";
- textArray[2] = "";
- textArray[3] = "";
- textArray[4] = "";
- textArray[5] = "";
- textArray[6] = "";
- textArray[7] = "";
- textArray[8] = "";
- textArray[9] = "";
- textArray[10] = "";
- textArray[11] = "";
- textArray[12] = "";
- textArray[13] = "";
- textArray[14] = "";
- textArray[15] = "";
- textArray[16] = "";
- textArray[17] = "";
- textArray[18] = "";
- textArray[19] = "";
- textArray[20] = "";
- textArray[21] = "";
- textArray[22] = "";
- textArray[23] = "";
- textArray[24] = "";
- textArray[25] = "";
- textArray[26] = "";
- textArray[27] = "";
- textArray[28] = "";
- textArray[29] = "";
- textArray[30] = "";
- textArray[31] = "";
- textArray[32] = "";
- textArray[33] = "";
- textArray[34] = "";
- textArray[35] = "";
- textArray[36] = "";
- textArray[37] = "";
- textArray[38] = "";
- textArray[39] = "";
- textArray[40] = "";
- textArray[41] = "";
- textArray[42] = "";
- textArray[43] = "";
- textArray[44] = "";
- textArray[45] = "";
- textArray[46] = "";
- textArray[47] = "";
- textArray[48] = "";
- function reset() {
- var i = 0;
- var j = 0;
- for (i = 0; i < 25; i++) {
- if (i == 12) //Free square!
- cellState[i] = true;
- else
- cellState[i] = false;
- }
- gameWin = false;
- var temp = 0;
- var duplicate_found = 0;
- i = 0;
- document.getElementById("bingo_text").innerHTML = "/ovgt3/ B I N G O";
- document.getElementById("bingo_text").style.border = "3px solid black";
- document.getElementById("bingo_text").style.color = "black";
- while (tempNum.length < 25) {
- //This cell is special, contains the "Free" square.
- if (i == 12) {
- cellText[i] = "333";
- document.getElementById("cell12").style.color = "red";
- i++;
- continue;
- }
- temp = Math.floor(Math.random() * textArray.length);
- duplicate_found = 0;
- if (tempNum.length > 1) {
- for (j = 0; j < tempNum.length; j++) {
- if (tempNum[j] == temp) {
- duplicate_found = 1;
- break;
- }
- }
- if (duplicate_found != 1) {
- tempNum[i] = temp;
- cellText[i] = textArray[temp];
- i++;
- }
- }
- else {
- tempNum[i] = temp;
- cellText[i] = textArray[temp];
- i++;
- }
- }
- for (i = 0; i < cellText.length; i++) {
- document.getElementById("cell" + i).innerHTML = cellText[i];
- if (i == 12)
- document.getElementById("cell" + i).style.border = "3px solid blue";
- else
- document.getElementById("cell" + i).style.border = "3px solid black";
- }
- tempNum.splice(0, 25);
- }
- function markCell(cellNum) {
- if (cellState[cellNum] == false && gameWin == false) {
- cellState[cellNum] = true;
- document.getElementById("cell" + cellNum).style.border = "3px solid blue";
- //FIXME: Find a better way to do this? Dunno!
- if (
- //Diagonal:
- (cellState[0] == true && cellState[6] == true && cellState[12] == true && cellState[18] == true && cellState[24] == true) ||
- (cellState[4] == true && cellState[8] == true && cellState[12] == true && cellState[16] == true && cellState[20] == true) ||
- //Horizontal:
- (cellState[0] == true && cellState[1] == true && cellState[2] == true && cellState[3] == true && cellState[4] == true) ||
- (cellState[5] == true && cellState[6] == true && cellState[7] == true && cellState[8] == true && cellState[9] == true) ||
- (cellState[10] == true && cellState[11] == true && cellState[12] == true && cellState[13] == true && cellState[14] == true) ||
- (cellState[15] == true && cellState[16] == true && cellState[17] == true && cellState[18] == true && cellState[19] == true) ||
- (cellState[20] == true && cellState[21] == true && cellState[22] == true && cellState[23] == true && cellState[24] == true) ||
- //Veritcal:
- (cellState[0] == true && cellState[5] == true && cellState[10] == true && cellState[15] == true && cellState[20] == true) ||
- (cellState[1] == true && cellState[6] == true && cellState[11] == true && cellState[16] == true && cellState[21] == true) ||
- (cellState[2] == true && cellState[7] == true && cellState[12] == true && cellState[17] == true && cellState[22] == true) ||
- (cellState[3] == true && cellState[8] == true && cellState[13] == true && cellState[18] == true && cellState[23] == true) ||
- (cellState[4] == true && cellState[9] == true && cellState[14] == true && cellState[19] == true && cellState[24] == true)
- ) {
- gameWin = true;
- document.getElementById("bingo_text").style.color = "blue";
- document.getElementById("bingo_text").style.border = "3px solid blue";
- document.getElementById("bingo_text").innerHTML = "WINNER!!";
- for (i = 0; i < 25; i++)
- document.getElementById("cell" + i).style.border = "3px solid blue";
- }
- }
- else if (cellState[cellNum] == true && cellNum != 12 && gameWin == false) {
- cellState[cellNum] = false;
- document.getElementById("cell" + cellNum).style.border = "3px solid black";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement