Skip to content

Vatsal1312/PROJECT_1-stone_paper_scissors_game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

Situation:

I needed to apply my knowledge of the C programming language through a practical project.So i searched on the internet and I found the classic Stone Paper Scissors game which can be played against the computer. The game had to handle user inputs, randomize the computer's choices, and keep track of the overall score in a way that was both engaging and reflective of real-world coding practices.

Task:

My task was to design and implement a fully functioning command-line game in C that would allow users to:

  1. Select how many games they want to play, with the condition that it must be an odd number to avoid tie series.
  2. Play multiple rounds of Stone Paper Scissors, where each round would result in either a win, loss, or tie.
  3. Keep a running tally of wins, losses, and ties, and declare the overall winner at the end of the series.
  4. Handle invalid user inputs (e.g., entering a number outside the valid range).
  5. Make the game visually appealing using ANSI color codes.

Action:

To accomplish this, I took the following steps:

  1. Input Handling: I wrote a function to ask the user how many games they want to play. The function ensured that the number entered was odd.
  2. Game Logic: I created a function to handle the core game logic. The game compared the user's input (Stone, Paper, or Scissors) with a random choice generated by the computer(this is carried by rand() & srand function.
  3. Scoring System: I implemented a system that tracked the number of wins for the user, the computer, and any ties that occurred. This tally was updated after every round & if the computer or user wins the majority of the games it will stop and declare the winner.
  4. Error Handling: I added checks to handle invalid inputs from the user (like entering a number outside the allowed range).
  5. User Experience: I used ANSI color codes to enhance the user experience, making the game more visually engaging.
  6. Final Output: After all rounds were played, the program printed the results of the game, declaring who won the overall series.

Result:

The final product was a fully functional Stone Paper Scissors game that:

  • Allowed users to play multiple rounds.
  • Enforced an odd number of games to prevent ties in the series.
  • Handled invalid inputs gracefully and prompted the user to try again if necessary.
  • Displayed the choices of both the user and the computer in each round.
  • Kept an accurate tally of wins, losses, and ties, and declared the winner at the end of the series.
  • Provided a visually appealing interface using colors to make the gameplay more engaging.

This project successfully demonstrated my understanding of C programming concepts such as:

  • Functions
  • Conditionals and loops
  • Random number generation
  • Error handling
  • User interaction via the command line

It also allowed me to practice structuring a larger project, handling both the logic and user interface aspects in a cohesive manner.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages