Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.45 KB | None | 0 0
  1. #element2 {
  2. width: 100px;
  3. height: 100px;
  4. background: red;
  5. position: absolute;
  6. right : 0 px;
  7. top : 0 px;
  8. }
  9.  
  10. .shiphover{
  11. -webkit-transition-duration: 0.4s; /* Safari */
  12. transition-duration: 0.4s;
  13. cursor: pointer;
  14. position:relative;
  15. }
  16.  
  17. ????????
  18.  
  19. // These can be modified by the user...
  20. var startingContraband = 10;
  21. var startingShips = 10;
  22. var shipCapacity = 5;
  23. var startingInspectionPoints = 10;
  24.  
  25. var basicCost = 1;
  26. var betterCost = 3;
  27. var totalCost = 5;
  28. // ######################################
  29.  
  30. // ########Database Purposes#############
  31. var uniqueID = null;
  32. var gameID = null;
  33.  
  34. var badShips = 0;
  35. var basicSearches = 0;
  36. var betterSearches = 0;
  37. var totalSearches = 0;
  38. var accuracy = 0;
  39.  
  40. var j = startingShips;
  41.  
  42. var redTurnCounterNumber = 1;
  43. var blueTurnCounterNumber = 1;
  44.  
  45. var allocatedContraband = 0;
  46. var activeContraband = allocatedContraband;
  47. var successfulContraband = 0;
  48.  
  49. var drugsFound = 0;
  50. var interceptedContraband = 0;
  51.  
  52. var contrabandCounter = document.getElementById("counterNumberContraband");
  53. var inspectionPointsCounter = document.getElementById("inspectionPointsCounter");
  54.  
  55. var successfulContrabandCounter = document.getElementById("counterNumberSuccessfulContraband");
  56. var interceptContrabandCounter = document.getElementById("interceptedContrabandCounter");
  57.  
  58. var successfulContrabandCounterNumber = 0;
  59. var interceptContrabandCounterNumber = 0;
  60.  
  61. var shipCargos = [
  62. [],
  63. [false, false, false, false, false],
  64. [false, false, false, false, false],
  65. [false, false, false, false, false],
  66. [false, false, false, false, false],
  67. [false, false, false, false, false],
  68. [false, false, false, false, false],
  69. [false, false, false, false, false],
  70. [false, false, false, false, false],
  71. [false, false, false, false, false],
  72. [false, false, false, false, false]
  73. ];
  74.  
  75. var shipCounters = [
  76. [],
  77. 0,
  78. 0,
  79. 0,
  80. 0,
  81. 0,
  82. 0,
  83. 0,
  84. 0,
  85. 0,
  86. 0
  87. ];
  88.  
  89.  
  90. // ########################Settings##################################
  91. var settingsContrabandCounter = document.getElementById("contrabandDisplay");
  92. settingsContrabandCounter.innerHTML = startingContraband;
  93.  
  94.  
  95. // #########################Red Team's Turn#################################
  96. function allocateContraband(determiner, shipNumber) {
  97. //Subtracts or adds contraband to the selected ship based on the determiner's value (0 for subtraction, 1 for addition).
  98. var shipID = String("ship counter " + shipNumber);
  99. var shipContrabandCounter = document.getElementById(shipID);
  100.  
  101. //Subtraction
  102. if (determiner == 0) {
  103. if (shipCounters[shipNumber] <= 0) {
  104. alert("Error: ship can't hold negative contraband!");
  105. return;
  106. }
  107. shipCounters[shipNumber] -= 1;
  108. startingContraband += 1;
  109.  
  110. shipContrabandCounter.innerHTML = shipCounters[shipNumber];
  111. contrabandCounter.innerHTML = startingContraband;
  112.  
  113. for (var i = 0; i < shipCounters[shipNumber]; i++) {
  114. shipCargos[shipNumber][i] = false;
  115. }
  116.  
  117. allocatedContraband -= 1;
  118. }
  119. //Addition
  120. else if (determiner == 1) {
  121. if (startingContraband <= 0) {
  122. alert("Error: you are out of contraband!");
  123. return;
  124. } else if (shipCounters[shipNumber] >= shipCapacity) {
  125. alert("Error: ship capacity reached!");
  126. return;
  127. }
  128. shipCounters[shipNumber] += 1;
  129. startingContraband -= 1;
  130.  
  131. shipContrabandCounter.innerHTML = shipCounters[shipNumber];
  132. contrabandCounter.innerHTML = startingContraband;
  133.  
  134. for (var i = 0; i < shipCounters[shipNumber]; i++) {
  135. shipCargos[shipNumber][i] = true;
  136. }
  137. allocatedContraband += 1;
  138. }
  139. var shipDiv = document.getElementById("div"+shipNumber);
  140. shipDiv.innerHTML += "<div id='element2'>" + shipCounters[shipNumber] + "</div>";
  141. };
  142.  
  143. function redOn(clicked_id) {
  144. //Enables the red ship assignment overlay.
  145. document.getElementById("redOverlay").style.display = "block";
  146. j = clicked_id;
  147.  
  148. var x = shipCounters[j];
  149. var overlaytext = "";
  150.  
  151. overlaytext += "<div class=\"redshipCard\"><div class=\"allocate\"><div class=\"ship\" onclick=\"selectShip(" + j + ")\"><img id=\"ship " + j + "\" class=\"shipImg\" src=\"res\\ship_active.png\"><p class=\"shipLabel\">Ship " + j + "</p></div><div class=\"allocateCommands\"><img class=\"allocateImg\" src=\"res/contraband.png\"><button class=\"allocateMinus\" onclick=\"allocateContraband(0," + j + ")\">-</button><p class=\"allocateCounter\" id=\"ship counter " + j + "\">" + x + "</p><button class=\"allocateAdd\" onclick=\"allocateContraband(1," + j + ")\">+</button></div><button class=\" allocateRedConfirmBtn\" onclick=\"redOff()\">Confirm</button></div></div>"
  152. document.getElementById("redOverlay").innerHTML = overlaytext;
  153. };
  154.  
  155. function redOff() {
  156. //Disables the red ship assignment overlay.
  157. document.getElementById("redOverlay").style.display = "none";
  158. };
  159.  
  160. var text = "";
  161. for (var i = 1; i < 11; i++) {
  162. text += "<div class = \"shiphover\" id = \"div" + i + "\" onclick=\"redOn(" + i + ");\"><img src = \"res/ship_active.png\" class=\"shiplist\" id=\"ship"+i+"\"></div>";
  163. };
  164.  
  165. document.getElementById("redFlex").innerHTML = text;
  166.  
  167. // ##########################Blue Team's Turn################################
  168. function blueOn(clicked_id) {
  169. //Enables the blue ship assignment overlay.
  170. document.getElementById("blueOverlay").style.display = "block";
  171. j = clicked_id;
  172.  
  173. var x = shipCounters[j];
  174. var overlaytext = "";
  175. // for (j = 1; j < 11; j++) {
  176. overlaytext += "<div class=\"blueshipCard\"><div class=\"ship\" onclick=\"selectShip(" + j + ")\"><img id=\"ship " + j + " class=\"shipImg\" src=\"res/ship_active.png\"><p class=\"shipLabel\">Ship " + j + "</p></div><div class=\"inspection\"><div><span><img src=\"res/basic_search.png\" alt=\"\"><button class=\"searchButton\" onclick=\"inspection(0, " + j + ")\">Basic Search</button></span></div><div><span><img src=\"res/better_search.png\" alt=\"\"><button class=\"searchButton\" onclick=\"inspection(1, " + j + ")\">Better Search</button></span></div><span><img src=\"res/total_search.png\" alt=\"\"><button class=\"searchButton\" onclick=\"inspection(2, " + j + ")\">Total Search</button></span><button class=\" searchBlueConfirmBtn\" onclick=\"blueOff()\">Confirm</button></div></div>"
  177.  
  178. document.getElementById("blueOverlay").innerHTML = overlaytext;
  179. };
  180.  
  181. function blueOff() {
  182. //Disables the blue ship assignment overlay.
  183. document.getElementById("blueOverlay").style.display = "none";
  184. };
  185.  
  186. var text = "";
  187. for (var i = 1; i < 11; i++) {
  188. text += "<div class = \"shiphover\" id = \"div" + i + "\" onclick=\"blueOn(" + i + ");\"><img src = \"res/ship_active.png\" class=\"shiplist\" id=\"ship"+i+"\"></div>";
  189. };
  190.  
  191. document.getElementById("blueFlex").innerHTML = text;
  192.  
  193. function randomInteger(min, max) {
  194. //Generates a random integer between the minimum and maximum values for use in the inspection function.
  195. return Math.floor(Math.random() * (max - min + 1)) + min;
  196. };
  197.  
  198. function inspection(determiner, shipNumber) {
  199. //Performs inspection on the ship to see if it contains contraband.
  200. var arr = shipCargos[shipNumber];
  201.  
  202. //Basic Search
  203. if (determiner == 0) {
  204. if (startingInspectionPoints >= basicCost) {
  205. var index = randomInteger(0, shipCapacity - 1);
  206. if (arr[index] === true) {
  207. // ####DRUGS FOUND#####
  208. alert("Contraband Located! 1 unit seized!")
  209. drugsFound += 1;
  210. } else {
  211. // ####NO DRUGS FOUND####
  212. alert("No contraband was located.")
  213. }
  214. startingInspectionPoints -= basicCost;
  215. inspectionPointsCounter.innerHTML = startingInspectionPoints;
  216.  
  217. basicSearches += 1;
  218. } else {
  219. alert("Error: insufficient inspection points!")
  220. return;
  221. }
  222. activeContraband -= drugsFound;
  223. interceptedContraband += drugsFound;
  224. drugsFound = 0;
  225. }
  226.  
  227. //Better Search
  228. else if (determiner == 1) {
  229. if (startingInspectionPoints >= betterCost) {
  230. var indexList = [randomInteger(0, shipCapacity - 1), randomInteger(0, shipCapacity - 1), randomInteger(0, shipCapacity - 1)];
  231. for (var i = 0; i <= indexList.length; i++) {
  232. var checker = indexList[i];
  233. if (arr[checker] === true) {
  234. // ####DRUGS FOUND#####
  235. alert("Contraband Located! 1 unit seized!")
  236. drugsFound += 1;
  237. } else if (arr[checker] == false) {
  238. // ####NO DRUGS FOUND####
  239. alert("No contraband was located.")
  240. } else {
  241. alert("End of inspection.")
  242. }
  243. }
  244. startingInspectionPoints -= betterCost;
  245. inspectionPointsCounter.innerHTML = startingInspectionPoints;
  246.  
  247. betterSearches += 1;
  248. } else {
  249. alert("Error: insufficient inspection points!")
  250. return;
  251. }
  252. activeContraband -= drugsFound;
  253. interceptedContraband += drugsFound;
  254. drugsFound = 0;
  255. }
  256.  
  257. //Total Search
  258. else if (determiner == 2) {
  259. if (startingInspectionPoints >= totalCost) {
  260. var contains = arr.includes(true);
  261. if (contains === true) {
  262. drugsFound += 1;
  263. for (x = 1; arr.length >= x; x++) {
  264. if (arr[x] === true) {
  265. drugsFound += 1;
  266. }
  267. }
  268. alert("Contraband Located! " + drugsFound + " units seized!")
  269. } else {
  270. // ####NO DRUGS FOUND####
  271. alert("No contraband was located.");
  272. }
  273. startingInspectionPoints -= totalCost;
  274. inspectionPointsCounter.innerHTML = startingInspectionPoints;
  275.  
  276. totalSearches += 1;
  277. } else {
  278. alert("Error: insufficient inspection points!")
  279. return;
  280. }
  281. activeContraband -= drugsFound;
  282. interceptedContraband += drugsFound;
  283. drugsFound = 0;
  284. }
  285. };
  286.  
  287. // #########################Navigation######################################
  288. function gameStart(){
  289. //Changes the view from the home to red turn screens.
  290. document.getElementById("homeScreen").style.display = "none";
  291. document.getElementById("redTurn").style.display = "block";
  292. };
  293.  
  294. function homeToSettings(){
  295. //Changes the view from the home to settings screens.
  296. document.getElementById("homeScreen").style.display = "none";
  297. document.getElementById("settingsScreen").style.display = "block";
  298. };
  299.  
  300. function settingsToHome(){
  301. //Changes the view from the settings to home screens.
  302. document.getElementById("settingsScreen").style.display = "none";
  303. document.getElementById("homeScreen").style.display = "block";
  304. };
  305.  
  306. function redToBlue() {
  307. //Switches from red to blue turns.
  308. if (blueTurnCounterNumber <= 10) {
  309.  
  310. activeContraband = allocatedContraband;
  311.  
  312. //Switch Turns
  313. redTurnCounterNumber += 1;
  314. document.getElementById("redTurnCounter").innerHTML = redTurnCounterNumber;
  315.  
  316. document.getElementById("redTurn").style.display = "none";
  317. document.getElementById("blueTurn").style.display = "block";
  318. }
  319.  
  320. };
  321.  
  322. function blueToRed() {
  323. if (redTurnCounterNumber == 11) {
  324. //Game Ends
  325. gameEnd();
  326. return;
  327. } else {
  328. //Database Purposes
  329. shipCounter();
  330. // Call # of searches here................
  331.  
  332. //Accuracy Calculation
  333. determineAccuracy();
  334.  
  335. //Updating Score
  336. successfulContraband += activeContraband;
  337. interceptedContraband += drugsFound;
  338.  
  339. successfulContrabandCounterNumber += successfulContraband;
  340. interceptContrabandCounterNumber += interceptedContraband;
  341.  
  342. successfulContrabandCounter.innerHTML = successfulContrabandCounterNumber;
  343. interceptContrabandCounter.innerHTML = interceptContrabandCounterNumber;
  344.  
  345. //Reset Board
  346. blueReset();
  347.  
  348. //Switch Turns
  349. blueTurnCounterNumber += 1;
  350. document.getElementById("blueTurnCounter").innerHTML = blueTurnCounterNumber;
  351.  
  352. document.getElementById("redTurn").style.display = "block";
  353. document.getElementById("blueTurn").style.display = "none";
  354. }
  355. };
  356.  
  357. function blueReset() {
  358. //Resets the board after blue finishes their turn (thereby ending the round).
  359. shipCargos = [
  360. [],
  361. [false, false, false, false, false],
  362. [false, false, false, false, false],
  363. [false, false, false, false, false],
  364. [false, false, false, false, false],
  365. [false, false, false, false, false],
  366. [false, false, false, false, false],
  367. [false, false, false, false, false],
  368. [false, false, false, false, false],
  369. [false, false, false, false, false],
  370. [false, false, false, false, false]
  371. ];
  372.  
  373. shipCounters = [
  374. [],
  375. 0,
  376. 0,
  377. 0,
  378. 0,
  379. 0,
  380. 0,
  381. 0,
  382. 0,
  383. 0,
  384. 0
  385. ];
  386.  
  387. uniqueID = null;
  388. gameID = null;
  389.  
  390. startingContraband = 10;
  391. allocatedContraband = 0;
  392.  
  393. drugsFound = 0;
  394. startingInspectionPoints = 10;
  395.  
  396. badShips = 0;
  397. basicSearches = 0;
  398. betterSearches = 0;
  399. totalSearches = 0;
  400. accuracy = 0;
  401.  
  402. successfulContrabandCounterNumber = 0;
  403. interceptContrabandCounterNumber = 0;
  404.  
  405. contrabandCounter.innerHTML = startingContraband;
  406. inspectionPointsCounter.innerHTML = startingInspectionPoints;
  407.  
  408. };
  409.  
  410. // ##########################Database Purposes##############################
  411. function createUniqueID() {
  412. //Generates a unique ID using date and time information for data storage.
  413. //Format is the following: YEAR-MONTH-DAY-HOUR-MINUTE-SECOND
  414.  
  415. var d = new Date();
  416.  
  417. var y = d.getFullYear();
  418. var mo = d.getMonth();
  419. var da = d.getDate();
  420. var h = d.getHours();
  421. var m = d.getMinutes();
  422. var s = d.getSeconds();
  423.  
  424. uniqueID = String(y + "-" + mo + "-" + da + "-" + h + "-" + m + "-" + s);
  425. alert("The unique ID for this game is: " + uniqueID);
  426. };
  427.  
  428. function shipCounter() {
  429. //Determines the number of ships containing contraband for every round.
  430. for (i = 0; i < shipCounters.length + 1; i++) {
  431. if (shipCounters[i] > 0) {
  432. badShips += 1;
  433. }
  434. }
  435. return badShips;
  436. };
  437.  
  438. function determineAccuracy() {
  439. //Determines the accuracy in terms of amount of contraband discovered per search.
  440. var searchCount = basicSearches + betterSearches + totalSearches;
  441. accuracy = activeContraband / drugsFound;
  442. };
  443.  
  444.  
  445.  
  446. // ##########################End of Game####################################
  447. function gameEnd() {
  448. //Ends the game.
  449. document.getElementById("blueTurn").style.display = "none";
  450. document.getElementById("endTurn").style.display = "block";
  451.  
  452.  
  453. var overlaytext = "";
  454. overlaytext += "<div class=\"endTurnDiv\"><h1 class=\"endTitle\">Results</h1><div class=\"itemsListEnd\"><div class =\"setTableEnd\"><div class=\"setRowsEnd\" id = \"redPoints\"><img class=\"settingsCounterEnd\" id=\"endSmuggled\" src=\"res/found contraband.png\"><div id=\"successCounter\"></div></div><div class=\"setRowsEnd\" id = \"bluePoints\"><img class=\"settingsCounterEnd\" id=\"endIntercepted\" src=\"res/contraband_not_found.png\"><div id=\"interceptCounter\">0</th></div></div></div><h1 id=\"redTeamEnd\"></h1><h1 id=\"blueTeamEnd\"></h1><h1 id=\"tieEnd\"></h1><button class=\"rePlay\" id=\"end\" onclick=\"restart()\">Play Again</button></div>"
  455.  
  456. document.getElementById("endTurn").innerHTML = overlaytext;
  457.  
  458. document.getElementById("successCounter").innerHTML = successfulContraband;
  459. document.getElementById("interceptCounter").innerHTML = interceptedContraband;
  460.  
  461. if (successfulContraband > interceptedContraband) {
  462. document.getElementById("redTeamEnd").innerHTML = "Red Wins!";
  463. } else if (successfulContraband < interceptedContraband) {
  464. document.getElementById("blueTeamEnd").innerHTML = "Blue Wins!";
  465. } else {
  466. document.getElementById("tieEnd").innerHTML = "Tie Game!";
  467. }
  468. };
  469.  
  470. function restart(){
  471. //Restarts the game.
  472. location.reload(true);
  473. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement