Bulls & Cows Game

A Java Gaming Experience

Overview

This project is a Java-based game that implements the classic Bulls and Cows guessing game. The game is played through the terminal, providing an interactive experience for the user.

Code: https://github.com/Esteban-Quevedo/BullsAndCows

The game begins by prompting the user to create a profile. Once a user is created, they are given the option to choose between two kinds of games:

1. CampaignMode: In this mode, the user starts at Level 1 and progresses through the levels, increasing in difficulty. The user has three lives to complete each level.

2. FreeMode: In this mode, the user can directly choose the desired level to play.

Each level presents a different challenge, with Level 1 having only 2 numbers to guess, and Level 5 requiring the player to guess a combination of 6 numbers.
Additionally, the player must select a game mode which determines the number of tries allowed for each level:

Amateur Mode:

  • Level 1: 6 tries per life.
  • Level 2: 8 tries per life.
  • Level 3: 10 tries per life.
  • Level 4: 12 tries per life.
  • Level 5: 14 tries per life.  

Normal Mode:

  • Level 1: 4 tries per life.
  • Level 2: 6 tries per life.
  • Level 3: 8 tries per life.
  • Level 4: 10 tries per life.
  • Level 5: 12 tries per life. 

Expert Mode:

  • Level 1: 2 tries per life.
  • Level 2: 4 tries per life.
  • Level 3: 6 tries per life.
  • Level 4: 8 tries per life.
  • Level 5: 10 tries per life.
     
Game Rules:

  • Each number in the combination is represented by a box, allowing the player to input their guesses.
  • After each guess, the program provides feedback in the form of "Bulls" and "Cows":
    • Bulls refer to the correct code in the correct position.
    • Cows refer to the correct code in the wrong position.
  • A visual dashboard is displayed throughout the game, showing the following information:
    •  Remaining lives.
    • Current score (determined by starting points for each level: Level 1 - 1000 points, Level 2 - 2000 points, Level 3 - 3000 points, Level 4 - 4000 points, Level 5 - 5000 points). The score decreases as the number of tries increases.
    • The player's current progress, including the level, number of attempts, and previous guesses.

The program is structured using three main classes, each equipped with its own getters, setters, and methods, along with the required conditionals, loops, and logic to guarantee the game's structure and operation:

  1. PlayerClass: This class defines the attributes and behaviours of a player, allowing for the creation and management of user profiles.

  2. LevelClass: This class encapsulates the various difficulty levels, handles points calculation, and generates random combinations for the player to guess.

  3. GameClass: This class orchestrates the game experience.

  4. Main Class: This final class contains the main method that executes the game It uses the scanner library to receive the user input and creates a new player, assigns a level, and sends the info to the game class to track the number of attempts, the player's previous guesses, and the number of bulls and cows achieved. In the event that the player does not reach the specified number of attempts, it handles the end-game scenario.

Overall, this project provides an engaging gaming experience for users to challenge their logic and deduction skills in a terminal-based environment, with a detailed visual dashboard to enhance the gameplay experience.



Algorithm and Game Play

1. Initialize Game

   • Input: None

   • Step:

      • Initialize necessary variables (game instance).

      • Create an instance of the Game class.


Compile and execute the main class of the Main.java file.
You should get an output like this:
 



2. Create Player

   • Input: Player name

   • Step:

      • Prompt the user to enter their name.

      • Create a new player instance with the provided name.


Enter your Nick Name, and hit Enter. 
You should get the selection game mode menu like this:



3. Select Game Mode

   • Input: Game mode choice (Campaign or Free Mode)

   • Step:

      • Prompt the user to choose between Campaign Mode and Free Mode.


Enter either 1 or 2 (the game mode you want to play) and press enter.
You should get the following Output:

To Free Mode:

 
To Campaign Mode:



4. Campaign Mode

   • Input: None

   • Step:

      • Set initial level to 1.

      • Start game loop.

         • Display dashboard.

         • Prompt the user to guess.

         • Check if the guess is correct.

         • Update player's score, lives, and level if necessary.

         • Increment total attempts.

         • Check for game-over condition.

            • If the game is over and the player hasn't completed level 5, offer the option to retry or quit.


If you selected the Campaign Mode, at this point you have to select the Game Difficulty you want to play.
Then, go to the 6-step (Game Mode/Difficulty Selection).


5. Free Mode

   • Input: User-selected level (1 to 5)

   • Step:

      • Prompt the user to choose a level (1 to 5).

      • Set the selected level.

      • Start game loop (similar to Campaign Mode).


If you selected the Free Mode, enter the level you want to play (from 1 to 5) and hit Enter.
You should get the difficulty menu, which means getting an output like this:



6. Game Mode/Difficulty Selection 

   • Input: User-select between Difficulty Modes (Amateur, Normal, and Expert). 
   • Step: 
      • Prompt the user to choose the difficulty.
      • Start the game loop (with the selected level and difficulty).


Then, enter the Game Difficulty you want to choose (Amateur, Normal, or Expert) and press Enter.
You should start the game level, which means getting an output like this:



7. Display Dashboard

   • Input: Player information, level, previous guesses

   • Step:

      • Display the player's name, level, remaining lives, current score, and previous guesses.


Awesome, at this point you are ready to play. Star entering your code input (one by one [And pressing enter]). 
You will be getting your name, level, remaining lives, current score, and previous guesses...

This menu will continue to display (with the respective variants) until you correctly guess the Secret Code or fail in the attempt (game over).


8. Prompt the User for Guess

   • Input: User's guess

   • Step:

      • Prompt the user to input their guess.


***This process is executed internally by the code to get the output that we saw in the previously shown Dashboard.***


9. Check Guess

   • Input: User's guess, target combination

   • Step:

      • Compare the user's guess with the target combination.

      • Determine the number of Bulls and Cows.


***This process is executed internally by the code to get the output that we saw in the previously shown Dashboard.***


10. Update Player's Stats

   • Input: Bulls, Cows

   • Step:

      • Update player's score, lives, and level based on the outcome of the guess.


***This process is executed internally by the code to get the output that we saw in the previously shown Dashboard.***


11. Increment Total Attempts

    • Input: None

    • Step:

       • Increment in the total number of attempts made.


***This process is executed internally by the code to get the output that we saw in the previously shown Dashboard.***

11. Check for Game Over

    • Input: None

    • Step:

       • Check if the game is over (e.g., A player runs out of lives or completes all levels).


If you expend all your tries, you will get a Game Over message like this:
 


12. End Game

    • Input: None

    • Step:

       • Display end game message with final statistics (e.g., score, number of attempts, completion status).


At this point if you successfully guessed the code. Then you will get an end-game message with final statistics (e.g., score, number of attempts, completion status).




Gratitude Section

I would like to express my sincere gratitude for taking the time to thoroughly review this project. I hope you found it helpful, detailed, and easy to understand. My ultimate goal was to provide you with a comprehensive understanding of how the project works, and I hope that it has accomplished precisely that. Thank you for your time and effort.



Bulls & Cows Game
EQP Solutions, Esteban Quevedo January 13, 2024
Share this post
Tags
Dropbox API Integration Sample
A Practical Guide to Dropbox API Integration in Python