0% found this document useful (0 votes)
30 views

Cs Project 1

Uploaded by

hmd2182006
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Cs Project 1

Uploaded by

hmd2182006
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

COMPUTER SCIENCE PROJECT

TOPIC - BASIC CRICKET GAME

SUBMITTED BY –
NAME - HAMMAD ZAIDI.
ROLL NO – 35
STD - XII
DIV – E
INDEX

SR.NO TOPIC

1 INTRODUCTION

2 OBJECTIVES OF PROJECT

3 TOOLS AND TECHNOLOGIES USED

4 OVERVIEW OF THE CRICKET GAME

5 REQUIRMENT ANALYSIS

6 DESIGN OF CRICKET GAME

➢ GAME FLOW

➢ GAME RULES

7 PYTHON CODE

➢ MAIN CODE STRUCTURES

➢ FUNCTIONS AND MODULES

8 SAMPLE OUTPUT

9 TESTING AND VALIDATION

10 CONCLUSION

11 FUTURE ENHANCEMENTS

12 BIBLIOGRAPHY
INTRODUCTION

Cricket is not only a sport but a phenomenon enjoyed by millions worldwide. A


cricket game involves complex rules, a variety of strategies, and requires a
balanced mix of skill, timing, and technique. In this project, I aim to recreate the
basic essence of cricket through a simplified, text-based version in Python. This
game allows players to experience the excitement of cricket in a quick and
interactive format, even if it's only a single over (6 balls).

Why Choose Python?

Python is a powerful programming language known for its simplicity and


readability, making it an ideal choice for beginners and experienced
programmers alike. It allows us to focus on core concepts without getting
bogged down by complex syntax. This project leverages Python’s simplicity to
design and execute the core game logic.

The basic cricket game project in Python will be a text-based simulation that
enables the player to "bat" while the computer plays as the opponent. The
project incorporates fundamental concepts such as loops, conditional
statements, random number generation, and functions, making it a good starting
point for exploring game development in Python.

Significance of the Project

Creating a simplified cricket game allows us to practice coding and develop


problem-solving skills. We also gain hands-on experience in structuring a
project, developing logic, and implementing user interactions, which are crucial
for programming in any field.
OBJECTIVES OF THE PROJECT

The main objectives of this project are as follows:

• Develop a Text-Based Game: To create a simplified version of a cricket


game that runs in the console. This game will simulate a one-over (6-ball)
match where the player faces off against the computer.

• Implement Core Game Logic Using Python: To apply programming


fundamentals such as loops, conditionals, and functions to achieve the
game’s core mechanics, including batting, scoring, and determining the
“out” condition.

• Randomized Gameplay: By using Python’s random library, we can


introduce an element of unpredictability, making the game more
engaging. The computer’s moves will be randomized within the rules of
the game, making it difficult for the player to anticipate the outcome.

• Build a Scoring and Outcome System: The project will include a scoring
mechanism to keep track of runs and determine the game’s outcome. This
will allow us to implement win, loss, and tie conditions based on the
player’s and computer’s scores.

• Enhance Problem-Solving Skills: Through this project, we aim to


improve our ability to break down problems, develop algorithms, and
organize code into modular functions.

• Each of these objectives contributes to our understanding of


programming and our ability to think like developers.
TOOLS AND TECHNOLOGY USED

The tools and technologies required for this project are listed below:

Python: Python’s simplicity makes it ideal for this project. It has a minimal
learning curve, allowing us to focus on the core logic. Python also has extensive
documentation and community support, which makes troubleshooting easier.

IDE or Text Editor: Various options can be used for writing and running Python
code. Some popular choices include:

PyCharm: A Python-specific IDE that offers features like code completion,


debugging, and project management.

Jupyter Notebook: Often used in data science, Jupyter Notebook allows us to


run code in cells, making it easier to test small portions of code.

Visual Studio Code (VS Code): A general-purpose editor with robust Python
support, extensions, and customization.

Random Library: The random library in Python allows us to generate random


numbers, which is essential for simulating the computer’s unpredictable actions
during the game. We use random.randint(1, 6) to mimic the roll of a dice,
adding an element of chance to the game.
OVERVIEW OF CRICKET GAME

In this project, we will develop a simplified version of a cricket game. This will
be a one-over game where each player gets 6 balls to score as many runs as
possible. The gameplay mechanics are as follows:

1. Gameplay Style: The player and the computer each get one turn to bat.
The player can choose numbers between 1 and 6, representing the runs
they want to score. The computer’s moves are determined randomly.

2. Rules: Scoring: Each run is added to the total score if it does not match
the opposing player’s chosen number. If the player’s and computer’s
numbers match, the batter is “out”.

Winning Conditions: The game compares the player’s and computer’s scores to
determine the winner.

Tie: If both the player and the computer score the same number of runs, the
game is a tie.

The simplified rules allow for quick and easy gameplay while providing a

foundation for expanding the game in the future .


REQUIREMENT ANALYSIS

This section breaks down the requirements into functional and non-functional
categories.

Functional Requirements:

• Player Input: The game should prompt the player to enter a number
between 1 and 6 for each ball.

• Computer’s Random Selection: The game should generate a random


number between 1 and 6 for the computer’s choice.

• Scoring System: Each correct input should add to the score unless the
player is “out”.

• Win/Loss Conditions: The game should determine the outcome based on


the player’s and computer’s scores.

• Out Condition: If the player’s and computer’s numbers match, the batter
is “out,” and their turn ends.

• High Score Tracker: The game will track and display the highest score
achieved by the player at the end of each game, encouraging
improvement and competition.
Non-functional Requirements:

• Responsiveness: The game should provide real-time feedback to the


player, updating the score immediately after each ball.

• User-Friendly Interface: The text-based interface should be simple to use,


with clear instructions and feedback messages.

• Code Readability: The code should be well-organized with comments and


modular functions for each part of the game, making it easier to
understand and modify.

• Performance: The game should execute player inputs and computer


actions within one second for a smooth experience.

• Usability: Instructions and prompts should be clear and simple, making


the game easy to understand for users of all ages.

• Scalability: The game should be modular, allowing for easy integration of


new features, such as multiple overs or a leaderboard.
DESIGN OF THE CRICKET GAME

This section describes the design aspects of the game, including the flow of
gameplay and the game’s rules.

Game Flow:

The game flow is divided into two main parts: the player’s innings and the
computer’s innings. Here’s a step-by-step breakdown:

• Start: The player is prompted to choose between batting or bowling first.

• Player’s Turn: The player selects a number between 1 and 6 for each ball.

• Computer’s Response: The computer randomly chooses a number


between 1 and 6 for each ball.

• Out Condition: If the player’s number matches the computer’s number,


the player is "out."

• Switch Turns: After the player completes 6 balls or is out, it’s the
computer’s turn to bat.

• Result: The game declares the winner based on the final scores.
Game Rules:

• Objective: The objective of the game is for the player to score more runs
than the computer within a set number of balls (6). The player bats first,
followed by the computer.

• Batting: The player will face 6 balls from the computer. For each ball, the
player chooses a number between 1 and 6. The computer also randomly
selects a number between 1 and 6. If the player’s choice matches the
computer’s choice, the player is declared "out," and their batting turn
ends.

• Scoring: If the player’s choice does not match the computer’s, the chosen
number is added to the player's score. After the player completes their 6
balls (or is out), their total score is recorded.

• Computer Batting: The computer will also face 6 balls, using the same
rules as the player. The player inputs a number for each ball to determine
the computer's "out" condition. If the computer’s score exceeds the
player's score during its turn, it is declared the winner, and the game ends.

• Winning the Game: At the end of both turns, the scores are compared.
The player with the higher score is declared the winner. If both scores are
equal, the game ends in a tie.
PYTHON CODE

The following Python code implements the basic cricket game, where the player
bats first, followed by the computer. Each turn involves comparing choices to
determine scores and track when a player is "out."

import random

# Function to get player input


def get_player_choice():
while True:
try:
player_input = int(input("Enter your choice (1-6): "))
if 1 <= player_input <= 6:
return player_input
else:
print("Please enter a number between 1 and 6.")
except ValueError:
print("Invalid input! Please enter a number between 1 and 6.")

# Function for player batting


def player_batting():
score = 0
balls = 6
print("\n--- Player's Batting ---")
for i in range(balls):
player_choice = get_player_choice()
computer_choice = random.randint(1, 6)
print(f"Computer's choice: {computer_choice}")
if player_choice == computer_choice:
print("You are OUT!")
break # Player is out, end of turn
else:
score += player_choice # Add the chosen number to the player's score
print(f"Current Score: {score}")
return score # Return the final score after 6 balls or out

# Function for computer batting


def computer_batting(target):
score = 0
balls = 6
print("\n--- Computer's Batting ---")
for i in range(balls):
player_choice = get_player_choice()
computer_choice = random.randint(1, 6)
print(f"Computer's choice: {computer_choice}")
if player_choice == computer_choice:
print("Computer is OUT!")
break # Computer is out, end of turn
else:
score += computer_choice # Add the computer's choice to its score
print(f"Computer Score: {score}")
if score > target: # Check if computer has surpassed the player's score
print("Computer Wins!")
return score # End game early if computer wins
return score # Return final score after 6 balls or out

# Main game function


def cricket_game():
print("Welcome to the Cricket Game!")
print("You have 6 balls to score as many runs as possible.")

# Player's turn to bat


player_score = player_batting()
print(f"\nYour Total Score: {player_score}")

# Computer's turn to bat


computer_score = computer_batting(player_score)
print(f"\nComputer's Total Score: {computer_score}")

# Determine the winner


if player_score > computer_score:
print("\nCongratulations! You Win!")
elif player_score < computer_score:
print("\nComputer Wins! Better luck next time!")
else:
print("\nIt's a Tie!")

# Run the game


cricket_game()
SAMPLE OUTPUT

This section provides a sample output of the game to illustrate how the game
would look in a real execution. This sample includes prompts, player
interactions, and final results to help clarify gameplay.

Example Game Output

Welcome to the Cricket Game!


You have 6 balls to score as many runs as possible.

--- Player's Batting ---


Enter your choice (1-6): 4
Computer's choice: 3
Current Score: 4
Enter your choice (1-6): 5
Computer's choice: 2
Current Score: 9
Enter your choice (1-6): 6
Computer's choice: 6
You are OUT!

Your Total Score: 9

--- Computer's Batting ---


Enter your choice (1-6): 3
Computer's choice: 4
Computer Score: 4
Enter your choice (1-6): 2
Computer's choice: 5
Computer Score: 9
Enter your choice (1-6): 6
Computer's choice: 1
Computer Score: 10
Computer Wins! Better luck next time!
TEXTING AND VALIDATION

Testing and validation ensure that the game runs smoothly and achieves its
intended objectives. Testing steps for this cricket game include:

• Input Testing: Ensuring the game handles invalid inputs (such as letters or
numbers outside the 1–6 range) correctly.

• Functional Testing: Confirming that each feature (e.g., batting, scoring,


out conditions) works as expected.

• Game Logic Testing: Ensuring that the game stops correctly when the
player or computer is "out" and that the score comparisons yield accurate
results.

• Edge Case Testing: Testing scenarios such as ties, lowest possible scores,
or high scores to ensure consistent gameplay under all conditions.

Example Testing Scenario

• Test Case 1: Input a number outside the allowed range (e.g., 10).
Expected behavior: The game should prompt the user to enter a valid
number within 1-6.

• Test Case 2: Both player and computer select the same number on the
first ball. Expected behavior: The player is declared "out," and their score
should remain zero.
CONCLUSION

This project successfully demonstrates a simplified cricket game using Python,


allowing players to experience a quick, turn-based match. Key programming
concepts such as functions, loops, conditionals, and random number generation
are implemented to simulate the game's mechanics. The project is educational,
as it allows us to practice essential coding skills while understanding how basic
game logic is structured and executed.

By completing this project, we also gain insight into:

• Writing modular code that can be expanded upon.

• Understanding the principles of user input handling.

• Utilizing randomness to create engaging and unpredictable gameplay


experiences.

Overall, the project serves as a good introduction to both Python programming


and the basics of game development.
FUTURE ENHANCEMENT

There are several potential enhancements that could be made to improve this
game:

• Multiple Overs: Expanding the game to allow for more overs, thus
creating a longer and more strategic experience.

• Enhanced UI: Developing a graphical user interface (GUI) to make the


game visually engaging.

• Bowling and Fielding Mechanics: Adding options for the player to bowl
and introducing fielding mechanics could add depth and realism.

• Difficulty Levels: Including difficulty levels to control the computer’s


randomness and make the game more challenging.

• Score History and Leaderboard: Storing scores from previous games


could make it competitive by allowing players to track their performance
over time.
BIBLIOGRAPHY

• Unity Documentation - Unity User Manual


• Guides on coding, physics, and graphics for Unity game engine.
• Python Documentation - Python Docs
• Useful Python libraries and instructions for basic game functions.
• Khan Academy - Intro to JS: Games and Visualizations
• Game programming basics in JavaScript, ideal for web-based games.
• ESPNcricinfo - Cricket Rules and Regulations
• Complete guide to cricket rules, essential for game logic.
• TutorialsPoint - Game Development Basics
• Step-by-step tutorials on game development for beginners.

You might also like