Projects Inventory

Color Detection Gaming Project in C++

Explanation:

  1. Color Representation:
    • The Color struct represents a color with a name (e.g., “Red”) and an id
      (a unique integer corresponding to that color).
  2. Random Color Generation:
    • The generateRandomColor function selects a random color from a predefined list of colors. This color is the one that the player needs to guess.
  3. Player Guess:
    • The getPlayerGuess function prompts the player to enter their guess by choosing the ID corresponding to the color they think was generated.
  4. Color Display:
    • The displayColors function prints out the available colors and their corresponding IDs to the console. This helps the player know which colors they can guess.
  5. Game Loop:
    • The game allows the player up to 3 attempts to guess the correct color. After each guess, the program checks if the player’s guess matches the randomly selected color:
      • If correct, the game congratulates the player.
      • If incorrect and attempts remain, the game prompts the player to try again.
      • If all attempts are used without a correct guess, the game reveals the correct color.

Possible Enhancements:

Exit mobile version