Interface 27

PHOTO EMBED

Sun Jan 07 2024 18:37:33 GMT+0000 (Coordinated Universal Time)

Saved by @马丽

void keyPressed() {
  if (gameStarted) {
    char keyPressed = Character.toUpperCase(key);
    for (int i = 0; i < colorKeys.length; i++) {
      if (keyPressed == colorKeys[i]) {
        if (keyPressed == getColorChar(circleFillColor)) {
          // If player presses the correct key corresponding to the displayed color
          points++;
          missedColors = 0; // Reset missed colors
          gameStarted = false; // Set to false to refresh the color
          pickRandomColor(); // Choose a new random color
        } else {
          missedColors++;
          if (missedColors >= 3) {
            gameOver();
          }
        }
        break; // Exit loop after handling input
      }
    }
  } else {
    // Start the game when the ENTER key is pressed
    if (keyCode == ENTER) {
      gameStarted = true;
      pickRandomColor(); // Choose a random color to start
    }
  }
}
content_copyCOPY