This Rock Paper Scissors project is a graphical user interface (GUI) game built using Python with Tkinter. The game allows users to play the classic Rock Paper Scissors game against the computer. The project demonstrates the use of Tkinter for creating interactive GUI applications and JSON for data persistence.
Interactive Demo
Try out the Rock Paper Scissors game below. Enter your name, choose your move, and play against the computer!
Welcome to Rock Paper Scissors!
Game Over!
Rock Paper Scissors
You: 0 | Computer: 0
Your Choice
?
VS
Computer's Choice
?
Choose rock, paper, or scissors to start!
🪨
📄
✂️
Features
Player Personalization
Enter your name to personalize the game experience and keep track of your scores.
Interactive GUI
Intuitive graphical interface with emoji buttons makes the game engaging and easy to play.
Score Tracking
Keeps track of wins, losses, and ties with persistence between game sessions.
Smart Computer AI
Computer opponent uses randomized selection to ensure fair and unpredictable gameplay.
Save Progress
Save your game progress and statistics to continue from where you left off.
Reset Option
Reset the game scores and start fresh when you want a new challenge.
Welcome Screen
The game starts with a welcome screen where users can enter their name and choose to start a new game. The interface is designed to be user-friendly and intuitive.
Gameplay
During the game, users select Rock, Paper, or Scissors by clicking the corresponding emoji buttons. The computer randomly selects its choice, and the result is displayed on the screen. The game keeps track of the user's score and the computer's score, with the first to reach 3 points being declared the champion.
Key Features
Interactive GUI: The game features an interactive graphical user interface built with Python's Tkinter library.
Score Tracking: The game keeps track of the user's score and the computer's score, with persistence between sessions.
Player Customization: Users can enter their name, which is displayed during gameplay.
Random Computer Choice: The computer's choice is randomly generated to ensure fair gameplay.
Save/Reset Functionality: Users can save their progress or reset the game at any time.
Game Over Screen
When a player reaches 3 points, a game over message is displayed indicating the winner. Players can then restart the game to play again.
Technical Details
RockPaperScissors.py
This file contains the entire implementation of the game:
Game Logic: Handles the core rules of Rock Paper Scissors and determines the winner.
User Interface: Creates and manages the Tkinter GUI elements including buttons and labels.
User Input Handling: Processes user choices and name entry.
Score Management: Tracks and persists scores between game sessions using JSON.
Random Choice Generation: Generates random choices for the computer opponent.
Game State Management: Handles transitions between different game states (playing, game over).
defdetermine_winner(user_choice, computer_choice):
if user_choice == computer_choice:
result = "It's a tie!"elif (user_choice == 'rock'and computer_choice == 'scissors') or \
(user_choice == 'paper'and computer_choice == 'rock') or \
(user_choice == 'scissors'and computer_choice == 'paper'):
self.user_score += 1
result = "You win!"else:
self.computer_score += 1
result = "Computer wins!"
self.save_scores()
return result
defplay(self, choice):
if self.user_score < 3 and self.computer_score < 3:
computer_choice = self.get_computer_choice()
result = self.determine_winner(choice, computer_choice)
self.result_label.config(text=f"Computer chose: {computer_choice}\n{result}")
self.update_score_label()
if self.user_score == 3:
self.user_wins += 1
self.result_label.config(text=f"🎉 {self.user_name} are the champion! 🎉")
self.disable_buttons()
elif self.computer_score == 3:
self.result_label.config(text="😢 Computer is the champion! 😢")
self.disable_buttons()
else:
self.restart_game()
How to Play
Open the game and enter your name (optional).
Select Rock, Paper, or Scissors by clicking the corresponding emoji button.
The computer will make its choice, and the result will be displayed on the screen.
The first player to reach 3 points wins the game.
You can save your progress, restart the current game, or reset everything at any time.
Development Process
The Rock Paper Scissors game was developed using Python with a focus on creating a user-friendly interface:
Designing the game's user interface with Tkinter widgets
Implementing the core game logic and win determination
Adding user customization with name input
Building score tracking and persistence using JSON
Creating visual feedback for game outcomes
Testing the application across different scenarios