Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var currentPlayer = 1;
- var randButtonID;
- setBoard();
- var p1Score = 0;
- var p2Score = 0;
- function setBoard() {
- var R = randomNumber(1, 255);
- var G = randomNumber(1, 255);
- var B = randomNumber(1, 255);
- var color = rgb(R,G,B);
- setProperty("button1", "background-color", color);
- setProperty("button2", "background-color", color);
- setProperty("button3", "background-color", color);
- setProperty("button4", "background-color", color);
- R = R+75;
- G = G+75;
- B = B+75;
- var diffColor = rgb (R,G,B) ;
- randButtonID = "button"+randomNumber(1,4);
- setProperty(randButtonID, "background-color", diffColor);
- console.log("correct one is: " + randButtonID);
- }
- function cheakCorrect(buttonId) {
- setBoard();
- switchPlayer();
- console.log("Cheaking: "+buttonId);
- if (buttonId == randButtonID) {
- console.log("DING!");
- updateScoreBy(1);
- } else {
- console.log("BOOP!");
- updateScoreBy(-3);
- }
- }
- function switchPlayer() {
- if (currentPlayer==1) {
- currentPlayer=2;
- showElement("player1_highlight");
- hideElement("player2_highlight");
- } else {
- currentPlayer=1;
- showElement("player2_highlight");
- hideElement("player1_highlight");
- }
- console.log("current player is: "+currentPlayer);
- }
- function updateScoreBy(amt) {
- if (currentPlayer == 1) {
- p1Score = p1Score +amt;
- } else {
- p2Score = p2Score +amt;
- }
- setText("score1_label", p1Score);
- setText("score2_label", p2Score);
- if (setTimeout(function() {
- setScreen("gameOver_screen");
- }, 60000)) {
- showElement("player1Win_label");
- hideElement("player2Win_label");
- } else {
- showElement("player2Win_label");
- hideElement("player1Win_label");
- }
- }
- onEvent("button1", "click", function() {
- cheakCorrect("button1");
- });
- onEvent("button2", "click", function() {
- cheakCorrect("button2");
- });
- onEvent("button3", "click", function() {
- cheakCorrect("button3");
- });
- onEvent("button4", "click", function() {
- cheakCorrect("button4");
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement