Cs Project 1
Cs Project 1
SUBMITTED BY –
NAME - HAMMAD ZAIDI.
ROLL NO – 35
STD - XII
DIV – E
INDEX
SR.NO TOPIC
1 INTRODUCTION
2 OBJECTIVES OF PROJECT
5 REQUIRMENT ANALYSIS
➢ GAME FLOW
➢ GAME RULES
7 PYTHON CODE
8 SAMPLE OUTPUT
10 CONCLUSION
11 FUTURE ENHANCEMENTS
12 BIBLIOGRAPHY
INTRODUCTION
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.
• 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.
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:
Visual Studio Code (VS Code): A general-purpose editor with robust Python
support, extensions, and customization.
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
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.
• Scoring System: Each correct input should add to the score unless the
player is “out”.
• 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:
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:
• Player’s Turn: The player selects a number between 1 and 6 for each ball.
• 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
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.
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.
• 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.
• 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
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.
• Bowling and Fielding Mechanics: Adding options for the player to bowl
and introducing fielding mechanics could add depth and realism.