Class 12 CBSE Boards Computer Project File
Class 12 CBSE Boards Computer Project File
SESSION: 2021-2022
COMPUTER SCIENCE
PROJECT REPORT FILE
TOPIC: GAMES
SUBMITTED BY
AVIRAL DWIVEDI CLASS 12-A
ROLL NO 23680726
Sno Topic Page No.
1 Acknowledgement 3
2 Topics 4
3 Hardware Requirements 6
3 Software Requirements 7
4 User Mannual 8
5 Program Codes 13
6 System Flowcharts 49
7 Application Flowcharts 51
8 Outputs 60
9 Limitations 65
10 Bibliography 66
Firstly, I want to express my heartfelt gratitude
towards our computer teacher Mrs. Rumana
Ahmad for giving such a nice topic for project.
Secondly, I want to thank our Principal Brother
Joy Thomas for giving such a tallented and
excellent teacher.
Lastly, I want to thank my parents who helped
me a lot by arranging all the resources for the
making of this project.
The topic chosen by me is GAMES in which I have
created 4 games as following
❖ Tic Tac Toe
❖ Snake and Apple
❖ Hangman
❖ Tetris
The software will run through cmd and the module
used for linking is “import OS” choices for the
games to be played will be given through the menu
driven program. This menu driven program is
created through python IDLE. Simple interface and
easy to understand concept attract the player or
the user of the software.
500 GB HDD
Storage
2 GB graphic
card
Minimum 2 GB RAM
Python IDLE or VS Code
should be installed
2. Software Introduction
The software of games is saved with the name “menu”
which is .py extension file that will open in association
with Command Prompt [CMD].
There are some contents as well named on the names
of games created that is Hangman, snake game, Tic tac
Toe and Tetris. These are resources used in the main
coding of the software and are the components of
graphic games.
3. Game Guide
Now below are the full instructions to play every game
You can follow them to succeed the game.
• Tic tac toe
In this game a tic tac toe table is created using 9
positions and you can tell where the ‘X’ or ‘0’ has to
be placed as it is a two-player game so you can’t
play it alone and you require a partner.
And as soon as the sequence of three continuous
characters either ‘X’ or ‘0’ forms game is over and
player with the sequence forming character wins.
Sequence ca be latitudinal, longitudinal or even
diagonal so play it accordingly.
• Snake Game
In this game there is a snake moving and you have
to feed the apple as food to the snake this will
increase the length of the snake. As you eat an
apple the snake will increase 1 block as it is a
graphical game and also contains sound effects so
you will require good quality speakers and a
graphic card of minimum 2 GB for better
experience.
The movement of the snake is guided by the arrow
keys press upper arrow to move forward down
arrow to move downwards in the same way left
arrow for left turn and right arrow for right
turn.
There is a caution also as it is an endless game so
game overs only when the body of snake gets hit by
snake’s head so play carefully and the longest
length is the high score of your game play.
• Hangman
This a game which is not common at all and a game
which may be confusing but once you read the
instructions you will surely gain success.
So, in this game there is a list of random words the
software will choose a word at a random and you
have to guess its spelling and as you guess the
correct spelling you will win at the end of spelling.
If the spelling guessed by you keeps on going
incorrect some portion of the man is drawn by the
program and the image of is a hanging man which
you have to prevent by guessing the correct
spelling.
As the spelling entered is correct your man gets
prevented otherwise, he hangs and you lose the
game.
• Tetris
Tetris is a very old game and very easy to play.
There are some colourful blocks which will be
coming down in various shapes you have to set them
in the way that they form a full line sequence and
gets vanished in this way the game continues and
the game ends as there is no row left for the block
to come down.
The game also contains sound so you need good
quality speakers for the best experience.
4. EXIT
If you don’t like any game or have completed all of them
you can exit the program/software by the exit option
which directly breaks the program and prevents next
choice asking.
CODES
Menu Page
import os
print("=================================
======================================
=HELLO EVERYONE
!!=====================================
======================================
===")
print(""
"")
print(" I AM A
GAMING SOFTWARE CREATED BY AVIRAL
DWIVEDI ")
print("
************************************************")
print("""
""")
print ("BELOW ARE SOME EXCITING GAMES
PLEASE SELECT A CHOICE AS PER YOUR
INTEREST :")
print(""
"")
print("1. TIC TAC TOE GAME [COMMONLY CALLED
'X' AND '0' GAME]")
print("2. SNAKE GAME [A GAME WITH MOVING
SNAKE CONTROLLED BY USER AND EARNS A
POINT WHEN FEEDS AN APPLE]")
print("3. HANGMAN [A GAME OF SPELLINGS
THE MAN HANGS AS THE SPELLING GOES
WRONG]")
print("4. TETRIS [A BEAUTIFUL AND
COLOURFUL BLOCK PUZZLE]")
print("5. EXIT ")
print("""
""")
while True:
choice=input("Enter` Your Choice as per the number
listed above against each game :")
if choice == "1":
os.system("python tic/tic.py")
if choice == "2":
os.system("cd snakegame && python main.py &&
cd ..")
if choice == "3":
os.system("python Hangman/hangman.py")
if choice == "4":
os.system("python Tetris/tetris.py")
if choice == "5":
break
exit()
Tic Tac Toe
#tic tac toe
"""
tic tac toe board
[
[x, -, -],
[-, -, -],
[-, -, -]
]
user_input -> something 1-9
if they enter anything else: tell them too go again
check if the user_input is already taken
add it to the board
check if user won: checking rows, columns and
diagonals
toggle between users upon succesful moves
"""
board = [
["-", "-", "-"],
["-", "-", "-"],
["-", "-", "-"]
]
def print_board(board):
for row in board:
for slot in row:
print(f"{slot} ", end="")
print()
def quit(user_input):
if user_input.lower() == "q":
print("Thanks for playing")
return True
else: return False
def check_input(user_input):
# check if its a number
if not isnum(user_input): return False
user_input = int(user_input)
# check if its 1 - 9
if not bounds(user_input): return False
return True
def isnum(user_input):
if not user_input.isnumeric():
print("This is not a valid number")
return False
else: return True
def bounds(user_input):
if user_input > 9 or user_input < 1:
print("This is number is out of bounds")
return False
else: return True
def coordinates(user_input):
row = int(user_input / 3)
col = user_input
if col > 2: col = int(col % 3)
return (row,col)
def add_to_board(coords, board, active_user):
row = coords[0]
col = coords[1]
board[row][col] = active_user
def current_user(user):
if user: return "x"
else: return "o"
turns += 1
if turns == 9: print("Tie!")
user = not user
Snake Game
# Add background image and music
import pygame
from pygame.locals import *
import time
import random
SIZE = 40
BACKGROUND_COLOR = (110, 110, 5)
class Apple:
def __init__(self, parent_screen):
self.parent_screen = parent_screen
self.image =
pygame.image.load("resources/apple.jpg").convert()
self.x = 120
self.y = 120
2
def draw(self):
self.parent_screen.blit(self.image, (self.x, self.y))
pygame.display.flip()
def move(self):
self.x = random.randint(1,24)*SIZE
self.y = random.randint(1,19)*SIZE
class Snake:
def __init__(self, parent_screen):
self.parent_screen = parent_screen
self.image =
pygame.image.load("resources/block.jpg").convert()
self.direction = 'down'
self.length = 1
self.x = [40]
self.y = [40]
def move_left(self):
self.direction = 'left'
def move_right(self):
self.direction = 'right'
def move_up(self):
self.direction = 'up'
def move_down(self):
self.direction = 'down'
def walk(self):
# update body
for i in range(self.length-1,0,-1):
self.x[i] = self.x[i-1]
self.y[i] = self.y[i-1]
# update head
if self.direction == 'left':
self.x[0] -= SIZE
if self.direction == 'right':
self.x[0] += SIZE
if self.direction == 'up':
self.y[0] -= SIZE
if self.direction == 'down':
self.y[0] += SIZE
self.draw()
def draw(self):
for i in range(self.length):
self.parent_screen.blit(self.image, (self.x[i],
self.y[i]))
pygame.display.flip()
def increase_length(self):
self.length += 1
self.x.append(-1)
self.y.append(-1)
class Game:
def __init__(self):
pygame.init()
pygame.display.set_caption("Codebasics Snake
And Apple Game")
pygame.mixer.init()
self.play_background_music()
self.surface = pygame.display.set_mode((1000,
800))
self.snake = Snake(self.surface)
self.snake.draw()
self.apple = Apple(self.surface)
self.apple.draw()
def play_background_music(self):
pygame.mixer.music.load('resources/bg_music_1.mp
3')
pygame.mixer.music.play(-1, 0)
pygame.mixer.Sound.play(sound)
def reset(self):
self.snake = Snake(self.surface)
self.apple = Apple(self.surface)
def render_background(self):
bg =
pygame.image.load("resources/background.jpg")
self.surface.blit(bg, (0,0))
def play(self):
self.render_background()
self.snake.walk()
self.apple.draw()
self.display_score()
pygame.display.flip()
def display_score(self):
font = pygame.font.SysFont('arial',30)
score = font.render(f"Score:
{self.snake.length}",True,(200,200,200))
self.surface.blit(score,(850,10))
def show_game_over(self):
self.render_background()
font = pygame.font.SysFont('arial', 30)
line1 = font.render(f"Game is over! Your score is
{self.snake.length}", True, (255, 255, 255))
self.surface.blit(line1, (200, 300))
line2 = font.render("To play again press Enter. To
exit press Escape!", True, (255, 255, 255))
self.surface.blit(line2, (200, 350))
pygame.mixer.music.pause()
pygame.display.flip()
def run(self):
running = True
pause = False
while running:
for event in pygame.event.get():
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
running = False
if event.key == K_RETURN:
pygame.mixer.music.unpause()
pause = False
if not pause:
if event.key == K_LEFT:
self.snake.move_left()
if event.key == K_RIGHT:
self.snake.move_right()
if event.key == K_UP:
self.snake.move_up()
if event.key == K_DOWN:
self.snake.move_down()
if not pause:
self.play()
except Exception as e:
self.show_game_over()
pause = True
self.reset()
time.sleep(.25)
if __name__ == '__main__':
game = Game()
game.run()
Hangman
import random
from words import word_list
def get_word():
word = random.choice(word_list)
return word.upper()
def play(word):
word_completion = "_" * len(word)
guessed = False
guessed_letters = []
guessed_words = []
tries = 6
print("Let's play Hangman!")
print(display_hangman(tries))
print(word_completion)
print("\n")
while not guessed and tries > 0:
guess = input("Please guess a letter or word:
").upper()
if len(guess) == 1 and guess.isalpha():
if guess in guessed_letters:
print("You already guessed the letter", guess)
elif guess not in word:
print(guess, "is not in the word.")
tries -= 1
guessed_letters.append(guess)
else:
print("Good job,", guess, "is in the word!")
guessed_letters.append(guess)
word_as_list = list(word_completion)
indices = [i for i, letter in enumerate(word) if
letter == guess]
for index in indices:
word_as_list[index] = guess
word_completion = "".join(word_as_list)
if "_" not in word_completion:
guessed = True
elif len(guess) == len(word) and guess.isalpha():
if guess in guessed_words:
print("You already guessed the word", guess)
elif guess != word:
print(guess, "is not the word.")
tries -= 1
guessed_words.append(guess)
else:
guessed = True
word_completion = word
else:
print("Not a valid guess.")
print(display_hangman(tries))
print(word_completion)
print("\n")
if guessed:
print("Congrats, you guessed the word! You
win!")
else:
def display_hangman(tries):
stages = [ # final state: head, torso, both arms, and
both legs
"""
--------
| |
| O
| \\|/
| |
| / \\
-
""",
# head, torso, both arms, and one leg
"""
--------
| |
| O
| \\|/
| |
| /
-
""",
# head
"""
--------
| |
| O
|
|
|
-
""",
# initial empty state
"""
--------
| |
|
|
|
|
-
"""
]
return stages[tries]
def main():
word = get_word()
play(word)
while input("Play Again? (Y/N) ").upper() == "Y":
word = get_word()
play(word)
if __name__ == "__main__":
main()
Tetris
import pygame
import random
"""
10 x 20 square grid
shapes: S, Z, I, O, J, L, T
represented in order by 0 - 6
"""
pygame.font.init()
# GLOBALS VARS
s_width = 800
s_height = 700
play_width = 300 # meaning 300 // 10 = 30 width per
block
play_height = 600 # meaning 600 // 20 = 20 height
per blo ck
block_size = 30
# SHAPE FORMATS
S = [['.....',
'.....',
'..00.',
'.00..',
'.....'],
['.....',
'..0..',
'..00.',
'...0.',
'.....']]
Z = [['.....',
'.....',
'.00..',
'..00.',
'.....'],
['.....',
'..0..',
'.00..',
'.0...',
'.....']]
I = [['..0..',
'..0..',
'..0..',
'..0..',
'.....'],
['.....',
'0000.',
'.....',
'.....',
'.....']]
O = [['.....',
'.....',
'.00..',
'.00..',
'.....']]
J = [['.....',
'.0...',
'.000.',
'.....',
'.....'],
['.....',
'..00.',
'..0..',
'..0..',
'.....'],
['.....',
'.....',
'.000.',
'...0.',
'.....'],
['.....',
'..0..',
'..0..',
'.00..',
'.....']]
L = [['.....',
'...0.',
'.000.',
'.....',
'.....'],
['.....',
'..0..',
'..0..',
'..00.',
'.....'],
['.....',
'.....',
'.000.',
'.0...',
'.....'],
['.....',
'.00..',
'..0..',
'..0..',
'.....']]
T = [['.....',
'..0..',
'.000.',
'.....',
'.....'],
['.....',
'..0..',
'..00.',
'..0..',
'.....'],
['.....',
'.....',
'.000.',
'..0..',
'.....'],
['.....',
'..0..',
'.00..',
'..0..',
'.....']]
shapes = [S, Z, I, O, J, L, T]
shape_colors = [(0, 255, 0), (255, 0, 0), (0, 255, 255),
(255, 255, 0), (255, 165, 0), (0, 0, 255), (128, 0, 128)]
# index 0 - 6 represent shape
class Piece(object):
rows = 20 # y
columns = 10 # x
for i in range(len(grid)):
for j in range(len(grid[i])):
if (j,i) in locked_positions:
c = locked_positions[(j,i)]
grid[i][j] = c
return grid
def convert_shape_format(shape):
positions = []
format = shape.shape[shape.rotation %
len(shape.shape)]
return positions
def valid_space(shape, grid):
accepted_positions = [[(j, i) for j in range(10) if
grid[i][j] == (0,0,0)] for i in range(20)]
accepted_positions = [j for sub in
accepted_positions for j in sub]
formatted = convert_shape_format(shape)
return True
def check_lost(positions):
for pos in positions:
x, y = pos
if y < 1:
return True
return False
def get_shape():
global shapes, shape_colors
inc = 0
for i in range(len(grid)-1,-1,-1):
row = grid[i]
if (0, 0, 0) not in row:
inc += 1
# add positions to remove from locked
ind = i
for j in range(len(row)):
try:
del locked[(j, i)]
except:
continue
if inc > 0:
for key in sorted(list(locked), key=lambda x:
x[1])[::-1]:
x, y = key
if y < ind:
newKey = (x, y + inc)
locked[newKey] = locked.pop(key)
sx = top_left_x + play_width + 50
sy = top_left_y + play_height/2 - 100
format = shape.shape[shape.rotation %
len(shape.shape)]
def draw_window(surface):
surface.fill((0,0,0))
# Tetris Title
font = pygame.font.SysFont('comicsans', 60)
label = font.render('TETRIS', 1, (255,255,255))
for i in range(len(grid)):
for j in range(len(grid[i])):
pygame.draw.rect(surface, grid[i][j], (top_left_x
+ j* 30, top_left_y + i * 30, 30, 30), 0)
locked_positions = {} # (x,y):(255,0,0)
grid = create_grid(locked_positions)
change_piece = False
run = True
current_piece = get_shape()
next_piece = get_shape()
clock = pygame.time.Clock()
fall_time = 0
level_time = 0
fall_speed = 0.27
score = 0
while run:
grid = create_grid(locked_positions)
fall_time += clock.get_rawtime()
level_time += clock.get_rawtime()
clock.tick()
if level_time/1000 > 4:
level_time = 0
if fall_speed > 0.15:
fall_speed -= 0.005
# PIECE FALLING CODE
if fall_time/1000 >= fall_speed:
fall_time = 0
current_piece.y += 1
if not (valid_space(current_piece, grid)) and
current_piece.y > 0:
current_piece.y -= 1
change_piece = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
current_piece.x -= 1
if not valid_space(current_piece, grid):
current_piece.x += 1
if event.key == pygame.K_DOWN:
# move shape down
current_piece.y += 1
if not valid_space(current_piece, grid):
current_piece.y -= 1
print(convert_shape_format(current_piece))''' # todo
fix
shape_pos =
convert_shape_format(current_piece)
draw_window(win)
draw_next_shape(next_piece, win)
pygame.display.update()
def main_menu():
run = True
while run:
win.fill((0,0,0))
draw_text_middle('Press any key to begin.', 60,
(255, 255, 255), win)
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if event.type == pygame.KEYDOWN:
main()
pygame.quit()
FLOWCHART
Start
program
A
Display Choices
Tic tac
Choice 1 A
Toe
Snake
Choice 2 A
Game
2 == 2
Choice 3 Hangman A
Choice 4 Tetris A
Choice 5
STOP
APPLICATION
FLOWCHART
Tic Tac Toe
Python code
Tic Tak Toe
Game
Snake Game
Turn right
If Choice = A
Move
If Choice =
upwards
A
Turn Left A
If Choice =
Turn
If Choice = Down A
Game
Hangman
correct
Entered letter Get one
chance A
Incorrect
Incorrect
GAME OVER
Game
Tetris
Turn right
If Choice A
Turn
If Choice Down
A
Areas of Improvement
There are several areas where improvisation is required
like Boundaries of Snake game has to be made so that it
cannot escape out.
All games should me made for a simultaneous multiplayer
platform. In tetris game the blocks coming done should
land directly ig the player presses the down arrow key.
Bibliography
All the coding and Programming
is done by :
www.google.com
www.shutterstock.com
www.gettyimages.com