Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. var currentPlayer = 1;
  2. var randButtonID;
  3. setBoard();
  4. var p1Score = 0;
  5. var p2Score = 0;
  6. function setBoard() {
  7. var R = randomNumber(1, 255);
  8. var G = randomNumber(1, 255);
  9. var B = randomNumber(1, 255);
  10. var color = rgb(R,G,B);
  11. setProperty("button1", "background-color", color);
  12. setProperty("button2", "background-color", color);
  13. setProperty("button3", "background-color", color);
  14. setProperty("button4", "background-color", color);
  15. R = R+75;
  16. G = G+75;
  17. B = B+75;
  18. var diffColor = rgb (R,G,B) ;
  19. randButtonID = "button"+randomNumber(1,4);
  20. setProperty(randButtonID, "background-color", diffColor);
  21. console.log("correct one is: " + randButtonID);
  22. }
  23. function cheakCorrect(buttonId) {
  24. setBoard();
  25. switchPlayer();
  26. console.log("Cheaking: "+buttonId);
  27. if (buttonId == randButtonID) {
  28. console.log("DING!");
  29. updateScoreBy(1);
  30. } else {
  31. console.log("BOOP!");
  32. updateScoreBy(-3);
  33. }
  34. }
  35. function switchPlayer() {
  36. if (currentPlayer==1) {
  37. currentPlayer=2;
  38. showElement("player1_highlight");
  39. hideElement("player2_highlight");
  40. } else {
  41. currentPlayer=1;
  42. showElement("player2_highlight");
  43. hideElement("player1_highlight");
  44. }
  45. console.log("current player is: "+currentPlayer);
  46. }
  47. function updateScoreBy(amt) {
  48. if (currentPlayer == 1) {
  49. p1Score = p1Score +amt;
  50. } else {
  51. p2Score = p2Score +amt;
  52. }
  53. setText("score1_label", p1Score);
  54. setText("score2_label", p2Score);
  55. if (setTimeout(function() {
  56. setScreen("gameOver_screen");
  57. }, 60000)) {
  58. showElement("player1Win_label");
  59. hideElement("player2Win_label");
  60. } else {
  61. showElement("player2Win_label");
  62. hideElement("player1Win_label");
  63. }
  64. }
  65. onEvent("button1", "click", function() {
  66. cheakCorrect("button1");
  67. });
  68. onEvent("button2", "click", function() {
  69. cheakCorrect("button2");
  70. });
  71. onEvent("button3", "click", function() {
  72. cheakCorrect("button3");
  73. });
  74. onEvent("button4", "click", function() {
  75. cheakCorrect("button4");
  76. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement