Mock Project Report: Game with Player Database
and Leaderboard
Name: Shubham Marewd
Emp ID: 156087
Mail ID: [email protected]
Location: PuneHinj-Phase3
Introduction:
The project implements a two-player game (e.g., Tic-Tac-Toe or Hangman). It tracks player
statistics, including wins, losses, game time, and stores this data in an Excel file. The
leaderboard ranks players based on their win percentage and time taken.
Game Description:
● Game Name: Tic-Tac-Toe (or Hangman, based on your preference)
● Players: 1 or 2 players
● Victory Status: Each game concludes with a win or loss for a player, updated in the
database.
Cases of Win and Lose:
1. Win: A player wins the game based on predefined rules (e.g., aligning three marks in
Tic-Tac-Toe).
2. Lose: A player loses when the opponent wins, or they fail to meet the conditions.
3. Draw: (Optional case for games like Tic-Tac-Toe) Both players fail to win.
Input and Output Format:
1. Input:
○ Player names or IDs
○ Start time of the game
○ Game choices or moves for each player
2. Output:
○ Game result (win/lose)
○ End time and time taken
○ Updated player statistics in the database
Database/Leaderboard Description:
● Player Database:
○ Player Name
○ Start Date and Time
○ Time Taken
○ Wins
○ Losses
○ Win Percentage
● Leaderboard:
○ Player Name
○ Win Percentage
○ Minimum Time Taken per Win
Code Snippet:
The game logic can be built using Python's openpyxl to manage the Excel files. Here's a
simplified approach to the structure:
import openpyxl
from datetime import datetime
# Load or create player database
def load_or_create_database(filename):
try:
workbook = openpyxl.load_workbook(filename)
except FileNotFoundError:
workbook = openpyxl.Workbook()
sheet = workbook.active
sheet.title = "Players"
sheet.append(["Player Name", "Start Time", "Time Taken (sec)", "Wins", "Losses", "Win
Percentage"])
workbook.save(filename)
return workbook
# Add new player
def add_player(workbook, player_name):
sheet = workbook['Players']
for row in sheet.iter_rows(min_row=2, values_only=True):
if row[0] == player_name:
print(f"Player {player_name} already exists!")
return
sheet.append([player_name, None, None, 0, 0, 0.0])
workbook.save('player_database.xlsx')
# Update win/lose status
def update_game_status(workbook, player_name, win_status, start_time, time_taken):
sheet = workbook['Players']
for row in sheet.iter_rows(min_row=2):
if row[0].value == player_name:
row[1].value = start_time
row[2].value = time_taken
if win_status == 'Win':
row[3].value += 1
else:
row[4].value += 1
row[5].value = (row[3].value / (row[3].value + row[4].value)) * 100
break
workbook.save('player_database.xlsx')
# Create Leaderboard
def create_leaderboard(workbook):
leaderboard = []
sheet = workbook['Players']
for row in sheet.iter_rows(min_row=2, values_only=True):
if row[2] is not None:
leaderboard.append((row[0], row[5], row[2]))
leaderboard.sort(key=lambda x: (-x[1], x[2])) # Sort by win percentage then time
return leaderboard
UI Artifacts:
Iteration-1:
Input:
● Player Names: Alice, Bob
● Game: Tic-Tac-Toe
● Start Time: 2024-09-20 10:00 AM
Output:
● Alice Wins
● Time Taken: 300 seconds
Database/Leaderboard:
Player Start Time Time Taken Win Losse Win
Name (sec) s s Percentage
Alice 2024-09-20 10:00 300 1 0 100.0%
AM
Bob 2024-09-20 10:00 300 0 1 0.0%
AM
Iteration-2:
Input:
● Player Names: Alice, Bob
● Game: Tic-Tac-Toe
● Start Time: 2024-09-21 11:00 AM
Output:
● Bob Wins
● Time Taken: 200 seconds
Updated Database/Leaderboard:
Player Start Time Time Taken Win Losse Win
Name (sec) s s Percentage
Alice 2024-09-21 11:00 200 1 1 50.0%
AM
Bob 2024-09-21 11:00 200 1 1 50.0%
AM
Iteration-3:
Input:
● Player Names: Alice, Charlie
● Game: Hangman
● Start Time: 2024-09-22 09:00 AM
Output:
● Alice Wins
● Time Taken: 180 seconds
Updated Database/Leaderboard:
Player Start Time Time Taken Win Losse Win
Name (sec) s s Percentage
Alice 2024-09-22 09:00 180 2 1 66.6%
AM
Bob 2024-09-21 11:00 200 1 1 50.0%
AM
Charlie 2024-09-22 09:00 180 0 1 0.0%
AM
Final Updated Database/Leaderboard:
After multiple iterations, the final leaderboard ranks players by their win percentage and time
taken:
Leaderboard:
Player Name Win Fastest Time
Percentage (sec)
Alice 66.6% 180
Bob 50.0% 200
Charlie 0.0% 180
This design outlines the game and its interactions with the player database and leaderboard,
demonstrating how wins, losses, and game times are managed and updated over time.
Would you like to proceed with a specific game, or should I assist in setting up this in a
particular development environment?