Advertisement
Guest User

Untitled

a guest
Mar 17th, 2018
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.45 KB | None | 0 0
  1. /*Copyright (c) 2012 Nick "Static Fiend" Franklin
  2.  
  3. This software is provided 'as-is', without any express or implied
  4. warranty. In no event will the authors be held liable for any damages
  5. arising from the use of this software.
  6.  
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10.  
  11. 1. The origin of this software must not be misrepresented; you must not
  12. claim that you wrote the original software. If you use this software
  13. in a product, an acknowledgment in the product documentation would be
  14. appreciated but is not required.
  15.  
  16. 2. Altered source versions must be plainly marked as such, and must not be
  17. misrepresented as being the original software.
  18.  
  19. 3. This notice may not be removed or altered from any source
  20. */
  21.  
  22. //Java Bingo
  23. //By Nick "Static Fiend" Franklin
  24. //v1.0.3
  25.  
  26. /*
  27. Changelog:
  28.  
  29. v1.0.3
  30. Remade to put most of the init in a function
  31. Reset option made available
  32.  
  33. v1.0.2
  34. Added 'static' local variable to markCell() for win condition
  35. Added win conditions and minor victory text.
  36.  
  37. v1.0.1
  38. Minor fix so that "free" cell can't be unchecked.
  39. Added changelog.
  40. Added zlib license.
  41.  
  42. v1.0.0
  43. Initial version.
  44. Debug "training wheels" removed!
  45. */
  46.  
  47. //Got new suggestions for this? Send me an e-mail bingostuff@grimfiend.com
  48.  
  49. //Stores all the text we can choose from.
  50. var textArray = new Array();
  51.  
  52. var cellState = new Array();
  53. var cellText = new Array();
  54.  
  55. //Used to store numbers so we don't have duplicate quotes.
  56. var tempNum = new Array();
  57.  
  58. var gameWin = false;
  59.  
  60. //FIXME: Send this all to a MySQL or text file to clean this up.
  61. textArray[0] = "";
  62. textArray[1] = "";
  63. textArray[2] = "";
  64. textArray[3] = "";
  65. textArray[4] = "";
  66. textArray[5] = "";
  67. textArray[6] = "";
  68. textArray[7] = "";
  69. textArray[8] = "";
  70. textArray[9] = "";
  71. textArray[10] = "";
  72. textArray[11] = "";
  73. textArray[12] = "";
  74. textArray[13] = "";
  75. textArray[14] = "";
  76. textArray[15] = "";
  77. textArray[16] = "";
  78. textArray[17] = "";
  79. textArray[18] = "";
  80. textArray[19] = "";
  81. textArray[20] = "";
  82. textArray[21] = "";
  83. textArray[22] = "";
  84. textArray[23] = "";
  85. textArray[24] = "";
  86. textArray[25] = "";
  87. textArray[26] = "";
  88. textArray[27] = "";
  89. textArray[28] = "";
  90. textArray[29] = "";
  91. textArray[30] = "";
  92. textArray[31] = "";
  93. textArray[32] = "";
  94. textArray[33] = "";
  95. textArray[34] = "";
  96. textArray[35] = "";
  97. textArray[36] = "";
  98. textArray[37] = "";
  99. textArray[38] = "";
  100. textArray[39] = "";
  101. textArray[40] = "";
  102. textArray[41] = "";
  103. textArray[42] = "";
  104. textArray[43] = "";
  105. textArray[44] = "";
  106. textArray[45] = "";
  107. textArray[46] = "";
  108. textArray[47] = "";
  109. textArray[48] = "";
  110.  
  111. function reset() {
  112. var i = 0;
  113. var j = 0;
  114.  
  115. for (i = 0; i < 25; i++) {
  116. if (i == 12) //Free square!
  117. cellState[i] = true;
  118. else
  119. cellState[i] = false;
  120. }
  121.  
  122. gameWin = false;
  123.  
  124. var temp = 0;
  125. var duplicate_found = 0;
  126.  
  127. i = 0;
  128.  
  129. document.getElementById("bingo_text").innerHTML = "/ovgt3/ B I N G O";
  130. document.getElementById("bingo_text").style.border = "3px solid black";
  131. document.getElementById("bingo_text").style.color = "black";
  132.  
  133. while (tempNum.length < 25) {
  134. //This cell is special, contains the "Free" square.
  135. if (i == 12) {
  136. cellText[i] = "333";
  137. document.getElementById("cell12").style.color = "red";
  138. i++;
  139. continue;
  140. }
  141.  
  142. temp = Math.floor(Math.random() * textArray.length);
  143.  
  144. duplicate_found = 0;
  145.  
  146. if (tempNum.length > 1) {
  147. for (j = 0; j < tempNum.length; j++) {
  148. if (tempNum[j] == temp) {
  149. duplicate_found = 1;
  150. break;
  151. }
  152. }
  153.  
  154. if (duplicate_found != 1) {
  155. tempNum[i] = temp;
  156. cellText[i] = textArray[temp];
  157. i++;
  158. }
  159. }
  160. else {
  161. tempNum[i] = temp;
  162. cellText[i] = textArray[temp];
  163. i++;
  164. }
  165. }
  166.  
  167. for (i = 0; i < cellText.length; i++) {
  168. document.getElementById("cell" + i).innerHTML = cellText[i];
  169.  
  170. if (i == 12)
  171. document.getElementById("cell" + i).style.border = "3px solid blue";
  172. else
  173. document.getElementById("cell" + i).style.border = "3px solid black";
  174. }
  175.  
  176. tempNum.splice(0, 25);
  177. }
  178. function markCell(cellNum) {
  179.  
  180. if (cellState[cellNum] == false && gameWin == false) {
  181. cellState[cellNum] = true;
  182. document.getElementById("cell" + cellNum).style.border = "3px solid blue";
  183.  
  184. //FIXME: Find a better way to do this? Dunno!
  185. if (
  186. //Diagonal:
  187. (cellState[0] == true && cellState[6] == true && cellState[12] == true && cellState[18] == true && cellState[24] == true) ||
  188. (cellState[4] == true && cellState[8] == true && cellState[12] == true && cellState[16] == true && cellState[20] == true) ||
  189. //Horizontal:
  190. (cellState[0] == true && cellState[1] == true && cellState[2] == true && cellState[3] == true && cellState[4] == true) ||
  191. (cellState[5] == true && cellState[6] == true && cellState[7] == true && cellState[8] == true && cellState[9] == true) ||
  192. (cellState[10] == true && cellState[11] == true && cellState[12] == true && cellState[13] == true && cellState[14] == true) ||
  193. (cellState[15] == true && cellState[16] == true && cellState[17] == true && cellState[18] == true && cellState[19] == true) ||
  194. (cellState[20] == true && cellState[21] == true && cellState[22] == true && cellState[23] == true && cellState[24] == true) ||
  195. //Veritcal:
  196. (cellState[0] == true && cellState[5] == true && cellState[10] == true && cellState[15] == true && cellState[20] == true) ||
  197. (cellState[1] == true && cellState[6] == true && cellState[11] == true && cellState[16] == true && cellState[21] == true) ||
  198. (cellState[2] == true && cellState[7] == true && cellState[12] == true && cellState[17] == true && cellState[22] == true) ||
  199. (cellState[3] == true && cellState[8] == true && cellState[13] == true && cellState[18] == true && cellState[23] == true) ||
  200. (cellState[4] == true && cellState[9] == true && cellState[14] == true && cellState[19] == true && cellState[24] == true)
  201. ) {
  202. gameWin = true;
  203.  
  204. document.getElementById("bingo_text").style.color = "blue";
  205. document.getElementById("bingo_text").style.border = "3px solid blue";
  206. document.getElementById("bingo_text").innerHTML = "WINNER!!";
  207. for (i = 0; i < 25; i++)
  208. document.getElementById("cell" + i).style.border = "3px solid blue";
  209. }
  210.  
  211. }
  212. else if (cellState[cellNum] == true && cellNum != 12 && gameWin == false) {
  213. cellState[cellNum] = false;
  214. document.getElementById("cell" + cellNum).style.border = "3px solid black";
  215. }
  216. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement