Codementor Events

Guess my favorite color Game in Unix

Published Apr 17, 2025
Guess my favorite color Game in Unix

Overview
Create a bash or Unix Shell script that asks the user what their favorite color is. This is a game where the user guesses the script’s favorite color. The game will keep track of game stats and allow for repeated play.

Game Play and Requirements

  1. When the round starts, select a color at random and ask the user to guess the selected color.
  2. Read the guess and process.a. If they guess incorrectly, inform them that the color they selected is wrong and ask them to guess again.

b. If the user enters a color that is not a valid color, inform them and let them guess again.

  1. Provide a mechanism to list the valid colors to the user (either on-demand or as part of game play).
  2. When a user guesses incorrectly, provide a message and let them guess again.
  3. When a user guesses correctly let them know that they got it correct and end the round.
  4. For both correct and incorrect messages, include the color name in the message displayed in the color. For example “Correct, Blue is my favorite color.”
  5. Keep a record of the colors guessed and provide a mechanism to show the user what wrong colors they have guessed (either on-demand, or as part of game play).
  6. Provide a mechanism to give the user a hint. The hint will display the first letter of the correct color, if the correct color starts with dark include Dark before the letter. For example, if the correct answer is DarkGray, give the hint DarkG.
  7. Provide a mechanism for the user to quit a round.
  8. Keep a record of the guess attempts and let the user know how many guesses it took to guess the correct answer.
  9. Keep track of how long it takes the user to guess the correct answer and let them know how long it took to play the round.
  10. After the round is over, give the user an option to play again.

Demo :
https://youtu.be/Oygr9m277Mw

Discover and read more posts from Jigna N. Mer
get started