Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions Rock Paper Scissor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 🎮 Rock Paper Scissors Game (Python)

Welcome to the **Rock Paper Scissors** Game!
This is a fun console-based Python project that simulates the classic **Rock Paper Scissors** game between **two players**, with random moves, score tracking, and a final result declaration.

This version is designed with **clean OOP principles**, **customizable rounds**, and **robust error handling**.

---

## 🧠 Game Overview

The rules of **Rock Paper Scissors** are simple:

| Move | Beats |
| ---------- | ---------- |
| Rock 🪨 | Scissor ✂️ |
| Paper 📄 | Rock 🪨 |
| Scissor ✂️ | Paper 📄 |

- If **both players** choose the **same move**, it’s a **tie** — both get 1 point.
- Otherwise, the player with the winning move earns **1 point**.
- After all rounds, the player with the **highest score** wins.

---

## 🚀 Features

✅ Two users can join with their own names
✅ Customizable number of rounds (default = 5)
✅ Random move generation for both players
✅ Automatic round evaluation
✅ Live score tracking
✅ Final winner announcement
✅ Comprehensive input validation

---

## 🧩 Project Structure
131 changes: 131 additions & 0 deletions Rock Paper Scissor/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import random


class RockPaperScissors:
def __init__(self):
self.user1 = ""
self.user1_score = 0
self.user2 = ""
self.user2_score = 0
self.rounds = 5

def my_new_user(self):
"""
Create 2 users with default 5 rounds.
Optionally allow changing the number of rounds.
"""
self.user1, self.user2 = input("Enter Username-").split()

change = (
input(
"Rock Paper Scissor starting...\n"
"5 rounds are going to be played. Want to change [y/n] - "
)
.strip()
.lower()
)

if change not in ["y", "n"]:
raise ValueError("Invalid decision")

if change == "y":
rounds = int(input("Enter number of rounds you want to play- ").strip())
if isinstance(rounds, int):
if rounds < 1:
raise ValueError("Rounds can't be smaller than 1")
self.rounds = rounds
else:
raise ValueError("Invalid round number")

def my_action(self):
"""Generate random action from Rock, Paper, Scissor."""
return random.choice(["Rock", "Paper", "Scissor"])

def increase_score(self, user):
"""Increase score for the given user (user1 or user2)."""
if user == "user1":
self.user1_score += 1
else:
self.user2_score += 1

def evaluate(self, user1_action, user2_action, round_no):
"""
Evaluate round result based on actions and
update the scores accordingly.
"""
print(f"\n**** Round {round_no} starts ****")
print(f"{self.user1} move {user1_action}," f"{self.user2} move {user2_action}")

if user1_action == user2_action:
self.increase_score("user1")
self.increase_score("user2")
round_won = "is tied"
else:
if user1_action == "Rock":
if user2_action == "Paper":
res = "user2"
round_won = f"won by {self.user2}"
else:
res = "user1"
round_won = f"won by {self.user1}"

elif user1_action == "Paper":
if user2_action == "Scissor":
res = "user2"
round_won = f"won by {self.user2}"
else:
res = "user1"
round_won = f"won by {self.user1}"

else:
if user2_action == "Rock":
res = "user2"
round_won = f"won by {self.user2}"
else:
res = "user1"
round_won = f"won by {self.user1}"

self.increase_score(res)

print(
f"This round {round_won}, score: "
f"{self.user1} {self.user1_score} -"
f" {self.user2} {self.user2_score}"
)

def serve_final_result(self):
"""Display final result after all rounds are completed."""

print("\n**** Final Result ****")
if self.user1_score > self.user2_score:

print(
f"{self.user1} won this game with score "
f"{self.user1_score} - {self.user2_score}"
)

elif self.user1_score < self.user2_score:

print(
f"{self.user2} won this game with score "
f"{self.user2_score} - {self.user1_score}"
)

else:

print(
f"This Game ties with score " f"{self.user1_score} - {self.user2_score}"
)


try:
game_instance = RockPaperScissors()
game_instance.my_new_user()
for i in range(1, game_instance.rounds + 1):
user1_action = game_instance.my_action()
user2_action = game_instance.my_action()
game_instance.evaluate(user1_action, user2_action, i)

game_instance.serve_final_result()
except Exception as e:
print(f"Error: {e}")
51 changes: 51 additions & 0 deletions Rock Paper Scissor/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# ==============================
# Project: Rock Paper Scissors Game
# Author: Anurodh Kumar (idabora)
# Description: A terminal-based Rock Paper Scissors game
# ==============================

# ------------------------------
# Core Requirements
# ------------------------------
# Python Standard Library modules are used (no external libs)
# So no third-party dependencies needed for core logic

# Random module (standard library)
# Used for generating random actions between Rock, Paper, Scissor
# import random

# ------------------------------
# Python Version
# ------------------------------
# Ensure compatibility with modern Python versions
python_version >= 3.8

# ------------------------------
# (Optional) Development Tools
# ------------------------------

# For formatting code (optional)
black==24.4.2

# For linting / code quality checks (optional)
flake8==7.1.1

# For static type checking (optional)
mypy==1.11.2

# For running unit tests (optional)
pytest==8.3.2

# For code coverage reporting during testing (optional)
pytest-cov==5.0.0

# ------------------------------
# (Optional) CLI Enhancements
# ------------------------------
# For better terminal interface (optional, not used by default)
rich==13.9.1 # Pretty console printing (optional)
colorama==0.4.6 # Colorized CLI text on Windows/Linux (optional)

# ------------------------------
# End of File
# ------------------------------
131 changes: 131 additions & 0 deletions RockPaperScissors
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import random


class RockPaperScissors:
def __init__(self):
self.user1 = ""
self.user1_score = 0
self.user2 = ""
self.user2_score = 0
self.rounds = 5

def my_new_user(self):
"""
Create 2 users with default 5 rounds.
Optionally allow changing the number of rounds.
"""
self.user1, self.user2 = input("Enter Username-").split()

change = (
input(
"Rock Paper Scissor starting...\n"
"5 rounds are going to be played. Want to change [y/n] - "
)
.strip()
.lower()
)

if change not in ["y", "n"]:
raise ValueError("Invalid decision")

if change == "y":
rounds = int(input("Enter number of rounds you want to play- ").strip())
if isinstance(rounds, int):
if rounds < 1:
raise ValueError("Rounds can't be smaller than 1")
self.rounds = rounds
else:
raise ValueError("Invalid round number")

def my_action(self):
"""Generate random action from Rock, Paper, Scissor."""
return random.choice(["Rock", "Paper", "Scissor"])

def increase_score(self, user):
"""Increase score for the given user (user1 or user2)."""
if user == "user1":
self.user1_score += 1
else:
self.user2_score += 1

def evaluate(self, user1_action, user2_action, round_no):
"""
Evaluate round result based on actions and
update the scores accordingly.
"""
print(f"\n**** Round {round_no} starts ****")
print(f"{self.user1} move {user1_action}," f"{self.user2} move {user2_action}")

if user1_action == user2_action:
self.increase_score("user1")
self.increase_score("user2")
round_won = "is tied"
else:
if user1_action == "Rock":
if user2_action == "Paper":
res = "user2"
round_won = f"won by {self.user2}"
else:
res = "user1"
round_won = f"won by {self.user1}"

elif user1_action == "Paper":
if user2_action == "Scissor":
res = "user2"
round_won = f"won by {self.user2}"
else:
res = "user1"
round_won = f"won by {self.user1}"

else:
if user2_action == "Rock":
res = "user2"
round_won = f"won by {self.user2}"
else:
res = "user1"
round_won = f"won by {self.user1}"

self.increase_score(res)

print(
f"This round {round_won}, score: "
f"{self.user1} {self.user1_score} -"
f" {self.user2} {self.user2_score}"
)

def serve_final_result(self):
"""Display final result after all rounds are completed."""

print("\n**** Final Result ****")
if self.user1_score > self.user2_score:

print(
f"{self.user1} won this game with score "
f"{self.user1_score} - {self.user2_score}"
)

elif self.user1_score < self.user2_score:

print(
f"{self.user2} won this game with score "
f"{self.user2_score} - {self.user1_score}"
)

else:

print(
f"This Game ties with score " f"{self.user1_score} - {self.user2_score}"
)


try:
game_instance = RockPaperScissors()
game_instance.my_new_user()
for i in range(1, game_instance.rounds + 1):
user1_action = game_instance.my_action()
user2_action = game_instance.my_action()
game_instance.evaluate(user1_action, user2_action, i)

game_instance.serve_final_result()
except Exception as e:
print(f"Error: {e}")