Download as pdf or txt
Download as pdf or txt
You are on page 1of 41

KENDRIYA VIDYALAYA NO-1, JIPMER CAMPUS

PUDUCHERRY

ACADEMIC YEAR: 2023-24


COMPUTER SCIENCE
PROJECT REPORT
ON
GAMSTAT.NSS (GAME PORTAL)

SUBMITTED BY: SUBMITTED TO:

NAME: G G SUURAJ SMT. SHIKHA


BASNIWAL
CLASS: 12 (PGT Computer Science)
SECTION: A
ROLL NO:

Page 1 of 41
KENDRIYA VIDYALAYA NO-1, JIPMER CAMPUS
PUDUCHERRY

ACADEMIC YEAR: 2023-24

CERTIFICATE
This is to certify that this project is an original
work done by SUURAJ GG of class XII-A Computer
science during the academic year 2023-24 under
my guidance as per the guidelines issued by the
Central Board of Secondary Education.

EXAMINER EXTERNAL EXAMINER


SMT. SHIKHA BASNIWAL
(PGT Computer Science)

PRINCIPAL
SH. JOSE MATHEW
(PRINCIPAL, KV NO-1, PUDUCHERRY)

Page 2 of 41
TABLE OF CONTENTS

S.NO DESCRIPTION PAGE NO

1 ACKNOWLEDGEMENT 4

2 INTRODUCTION 5

3 OBJECTIVE 6

4 PROPOSED SYSTEM 7

5 FLOWCHART 8

6 SOFTWARE USED 9

7 SOURCE CODE 10

8 OUTPUT 25

9 REFERENCE 39

Page 3 of 41
ACKNOWLEDGEMENT

This project is done with my coding knowledge as well as


with guidelines of my computer teacher Mrs.Shikha
Basniwal(PGT Computer Science), who helped me
throughout the course of my project work. I extend my
heartfelt thanks for her constant motivation and
encouragement. I deeply express my sincere gratitude
for our Principal Sh.Jose Mathew for his continuous
encouragement and invaluable support. A project is a
bridge theoretical and practical learning and with this
thinking I worked on the project and made it successful
due to timely support and efforts of all who helped me.

Suuraj GG
XII-A

Page 4 of 41
INTRODUCTION

Gamstat.NSS is a game portal where you can


enjoy a variety of fun and challenging games, all
created with Python. Whether you want to test
your vocabulary with hangman, your logic with tic
tac toe, your luck with guess the number, your
math skills with math quiz, or your strategy with
rock paper scissor, we have something for
everyone. Our games are easy to play, but hard to
master. You can also compete with your friends
and see who can get the highest score.

Page 5 of 41
OBJECTIVE

Our game portal aims to offer a diverse selection


of engaging and educational games, including
guess the number, tic tac toe,rock-paper-scissors,
hangman,simple math quiz and dice simulation
with the following objectives:
1. Variety of Gameplay: Provide a wide array of
games to cater to different tastes and
interests.
2. Educational Value: Offer games like math quiz
to stimulate learning and critical thinking.

Page 6 of 41
PROPOSED SYSTEM

1) Education Module:
A dedicated section for educational games like the
math quiz, where players can test their knowledge
and learn new concepts.
2) Gameplay:
Players can access and play the games directly
within the portal.
Each game should have clear rules and
instructions.
3) Game Library:
Display game information, including
title,description, and genre

Page 7 of 41
FLOWCHART

Page 8 of 41
SOFTWARE USED

➢Python(spyder)
➢Python(3.11)
➢Visual communication code
➢tkinter

Page 9 of 41
SOURCE CODE

# Main source ……code:

print('''

*******************************************************************************

<<<<<<<<--- GAMSTAT.NSS --->>>>>>>

*******************************************************************************

:> Welcome to our GAMSTAT, where you can enjoy a variety of fun and challenging games, all created
with

Python. Whether you want to test your vocabulary with hangman, your logic with tic tac toe, your

luck with guess the number, your math skills with math quiz, or your strategy with rock paper
scissor,

we have something for everyone. Our games are easy to play, but hard to master. You can also
compete

with your friends and see who can get the highest score. So what are you waiting for? Start playing
and

have fun!...

:> Before you start every game we have been guiding you with some introduction or with some rules
to make

the games sufficient user friendly.

:> credits..

- Nandhana.K.S

- Suuraj.G.G

- Sheetal Bathri Narayanan

''')

Page 10 of 41
print(''' ( LETS GET STARTED!! )

-------------------------------------------------------------------------------------------------------------''')

n='y'

print('''

!!! these are the choice given to you,,,

''')

while n.lower() == 'y':

print("'1' to play guess the number .")

print("'2' to play tic tac toe .")

print("'3' to play rock paper scissor .")

print("'4' to play hangman .")

print("'5' to play simple math quiz .")

print("'6' to play dice simulation .")

print("'0' to QUIT .")

ch= input('Enter your choice to play (without any space) :')

if ch=='1':

print('''

>>>>>>>>> Welcome to Guess the number game !!!!

This fun and interactive game challenges you to guess

a secret number the game has generated. Your task is

to use your intuition to guess the correct number within

a limited number of attempts, making it a thrilling

test of your deduction skills!

''')

import random

num = random.randint(1, 5)

Page 11 of 41
guess = None

for i in range (1,4):

guess = input("guess a number between 1 and 5: ")

guess = int(guess)

if guess == num:

print("congratulations! you won!")

break

else:

print("Nope, sorry WRONG ")

print("-->you have ",3-i,"guess left")

print('''

HERE IS YOUR MENU !!

''')

elif ch=='2':

print('''

>>>>>>>>> Welcome to tic tac toe game !!!!

Tic Tac Toe is a simple yet engaging game that's perfect

for some quick fun and strategic thinking. In this classic

two-player game, you'll take turns marking the board with

'X' or 'O' in a quest to be the first to get three in a

row horizontally, vertically, or diagonally. Challenge a

friend and see who emerges as the ultimate Tic Tac Toe

champion!!!!

''')

# To create a GUI for a tic tac toe game in Python, we can use the tkinter module

Page 12 of 41
# First, we import tkinter and create a root window

import tkinter as tk

root = tk.Tk()

root.title("Tic Tac Toe")

# Next, we create a 3x3 grid of buttons to represent the board

buttons = []

for i in range(3):

row = []

for j in range(3):

# Each button has a text variable that stores its value (X, O or empty)

# Each button also has a command that calls the function play when clicked

text_var = tk.StringVar()

text_var.set(" ")

button = tk.Button(root, textvariable=text_var, font=("Arial", 20), width=4, height=2,


command=lambda r=i, c=j: play(r, c))

button.grid(row=i, column=j)

row.append((button, text_var))

buttons.append(row)

# We also create a label to display the game status (turn or result)

status_var = tk.StringVar()

status_var.set("X's turn")

status_label = tk.Label(root, textvariable=status_var, font=("Arial", 16))

status_label.grid(row=3, column=0, columnspan=3)

# We define some global variables to keep track of the game state

turn = "X" # The current player's turn

board = [[" ", " ", " "], [" ", " ", " "], [" ", " ", " "]] # The board as a 2D list of values

game_over = False # A flag to indicate if the game is over

Page 13 of 41
# We define the function play that handles the logic of the game

def play(row, col):

global turn, board, game_over

# If the game is not over and the clicked button is empty

if not game_over and board[row][col] == " ":

# Update the button's text and the board's value with the current turn

buttons[row][col][1].set(turn)

board[row][col] = turn

# Check if the current turn has won the game

if check_win(turn):

# Update the status label and set the game over flag to True

status_var.set(turn + " wins!")

game_over = True

# Check if the board is full and there is a tie

elif check_tie():

# Update the status label and set the game over flag to True

status_var.set("It's a tie!")

game_over = True

# If the game is not over yet, switch the turn and update the status label

else:

turn = "O" if turn == "X" else "X"

status_var.set(turn + "'s turn")

# We define the function check_win that returns True if the given player has formed a line of
three on the board

def check_win(player):

global board

# Check the rows

for i in range(3):

if board[i][0] == board[i][1] == board[i][2] == player:

return True

Page 14 of 41
# Check the columns

for j in range(3):

if board[0][j] == board[1][j] == board[2][j] == player:

return True

# Check the diagonals

if board[0][0] == board[1][1] == board[2][2] == player:

return True

if board[0][2] == board[1][1] == board[2][0] == player:

return True

# If none of the above conditions are met, return False

return False

# We define the function check_tie that returns True if the board is full and there is no winner

def check_tie():

global board

# Loop through the board and check if there is any empty space left

for i in range(3):

for j in range(3):

if board[i][j] == " ":

return False

# If no empty space is found, return True

return True

# Finally, we start the main loop of the tkinter window

root.mainloop()

print('''

HERE IS YOUR MENU !!

''')

elif ch=='3':

print('''

>>>>>>>>> Welcome ROCK PAPER SCISSOR game !!!!

Page 15 of 41
Rock, Paper, Scissors game is perfect for passing the time.

In this classic game, you'll face off against the computer

by choosing either rock, paper, or scissors, and the computer

will randomly select its move, determining the winner based

on the rules: rock beats scissors, scissors beat paper, and

paper beats rock. Let's dive in and have some fun!

''')

ch='y'

while ch.lower() == 'y':

# A simple rock paper scissor game program in python

import random

# Define the choices and the rules

choices = ["rock", "paper", "scissor"]

rules = {"rock": "scissor", "paper": "rock", "scissor": "paper"}

# Get the user's choice

user_choice = input("Enter your choice (rock, paper or scissor): ").lower()

# Validate the user's choice

if user_choice not in choices:

print("Invalid choice. Please try again.")

exit()

# Get the computer's choice

computer_choice = random.choice(choices)

# Print the choices

Page 16 of 41
print(f"You chose {user_choice}.")

print(f"Computer chose {computer_choice}.")

# Compare the choices and determine the winner

if user_choice == computer_choice:

print("It's a tie.")

elif rules[user_choice] == computer_choice:

print("You win!")

else:

print("You lose.")

ch=input('Do you want to continue..(y/n)')

print('''

HERE IS YOUR MENU !!

''')

elif ch=='4':

print('''

>>>>>>>>> Welcome ---HANGMAN--- game !!!!

Welcome user! Hangman, A game that promises hours of word-guessing fun.

In this game, you'll have to guess the hidden word letter by letter, but be

careful – with each incorrect guess, a part of the hangman's gallows will be

constructed, and you'll need to solve the word before the hangman meets his fate!

''')

print('''

The word is random from any field, BEST OF LUCK

''')

# This is a Python program to create a UI for hangman game

# Import the modules

Page 17 of 41
import tkinter as tk

import random

# Define the words list

words = ["python", "hangman", "program", "create",


"interface","physics","chemistry","mathematics","computer science","vectors"]

# Choose a random word

word = random.choice(words)

# Create the main window

root = tk.Tk()

root.title("Hangman Game")

# Create a canvas to draw the hangman

canvas = tk.Canvas(root, width=300, height=300)

canvas.pack()

# Draw the gallows

canvas.create_line(50, 250, 250, 250)

canvas.create_line(150, 250, 150, 50)

canvas.create_line(150, 50, 200, 50)

canvas.create_line(200, 50, 200, 100)

# Create a label to show the word

label = tk.Label(root, text="_ " * len(word), font=("Arial", 24))

label.pack()

# Create an entry to get the user input

entry = tk.Entry(root)

entry.pack()

Page 18 of 41
# Create a button to check the user input

button = tk.Button(root, text="Check")

button.pack()

# Define the global variables

guesses = [] # Store the guessed letters

mistakes = 0 # Count the number of mistakes

# Define the function to check the user input

def check():

global word, guesses, mistakes

# Get the user input and convert it to lowercase

letter = entry.get().lower()

# Clear the entry

entry.delete(0, tk.END)

# Check if the letter is valid and has not been guessed before

if letter.isalpha() and len(letter) == 1 and letter not in guesses:

# Add the letter to the guesses list

guesses.append(letter)

# Check if the letter is in the word

if letter in word:

# Update the label with the correct letter

new_text = ""

for c in word:

if c in guesses:

new_text += c + " "

else:

new_text += "_ "

label.config(text=new_text)

# Check if the user has guessed the whole word

Page 19 of 41
if new_text.replace(" ", "") == word:

# Congratulate the user and disable the button

label.config(text="You win!")

button.config(state=tk.DISABLED)

else:

# Increase the number of mistakes and draw a part of the hangman

mistakes += 1

draw_hangman(mistakes)

# Check if the user has made too many mistakes

if mistakes == 6:

# Show the correct word and disable the button

label.config(text=f"You lose! The word was {word}")

button.config(state=tk.DISABLED)

# Define the function to draw a part of the hangman

def draw_hangman(mistakes):

global canvas

# Draw a head for the first mistake

if mistakes == 1:

canvas.create_oval(180, 100, 220, 140)

# Draw a body for the second mistake

elif mistakes == 2:

canvas.create_line(200, 140, 200, 200)

# Draw a left arm for the third mistake

elif mistakes == 3:

canvas.create_line(200, 150, 170, 180)

# Draw a right arm for the fourth mistake

elif mistakes == 4:

canvas.create_line(200, 150, 230, 180)

# Draw a left leg for the fifth mistake

elif mistakes == 5:

Page 20 of 41
canvas.create_line(200, 200, 170, 230)

# Draw a right leg for the sixth mistake

elif mistakes == 6:

canvas.create_line(200, 200, 230, 230)

# Bind the button to the check function

button.config(command=check)

# Start the main loop

root.mainloop()

print('''

HERE IS YOUR MENU !!

''')

elif ch=='5':

print('''

>>>>>>>>> Welcome MATH QUIZ game !!!!

Welcome to the Math Quiz Game, a fun, educational and

brain-storming game. In this game, the computer will

generate random math questions for you to solve, and

all you need to do is provide the correct answers to

earn points and test your math skills. Let's get started

and see how sharp your mathematical mind is!

''')

import random

def generate_question():

num1 = random.randint(1, 20)

num2 = random.randint(1, 20)

Page 21 of 41
operator = random.choice(['+', '-', '*'])

answer = None

if operator == '+':

answer = num1 + num2

elif operator == '-':

answer = num1 - num2

elif operator == '*':

answer = num1 * num2

question = f"What is {num1} {operator} {num2}?"

return question, answer

def ask_question(question, correct_answer):

print(question)

user_answer = input("Your answer: ")

try:

user_answer = int(user_answer)

if user_answer == correct_answer:

print("Correct!\n")

return True

else:

print(f"Wrong. The correct answer is {correct_answer}.\n")

return False

except ValueError:

print("Invalid input. Please enter a number.\n")

return False

def math_quiz():

Page 22 of 41
score = 0

num_questions = 10

for _ in range(num_questions):

question, answer = generate_question()

is_correct = ask_question(question, answer)

if is_correct:

score += 1

print(f"Quiz completed! Your score: {score}/{num_questions}")

if __name__ == "__main__":

math_quiz()

print('''

HERE IS YOUR MENU !!

''')

elif ch=='6':

print('''

>>>>>>>>> Welcome to DICE SIMULATION game !!!!

The NSS dice simulator emulates a classic six-sided die we

all know and love. This die will generate a random number

between 1 and 6, simulating the roll of a standard dice.

''')

from tkinter import *

import random

window = Tk()

window.minsize(600,600)

window.maxsize(600,600) #makes the window size constant

Page 23 of 41
window.title("ROLL THE DICE ")

label = Label(window,font=('bold',300))

#Label is not kept in function if it were, the label woukd keep changing

def roll():

number=['\u2680','\u2681','\u2682','\u2683','\u2684','\u2685']

# '\u2680' is a special code for showing the face of the dice containing a single dot

label.config(text=f'{random.choice(number)}')

label.pack()

heading = Label(window,text='ROLL THE DICE', font=('Roman',30,'bold'), bg='purple')

heading.pack(fill=X) #to fill the heading bar instead of it just being it like a box

button=Button(window,text='Click me to roll!!',font=('normal',30),command=lambda:roll())

button.pack()

window.mainloop()

print('''

HERE IS YOUR MENU !!

''')

elif ch=='0':

break

else:

print('''

**** oops....sorry can't get in!!****

''')

break

Page 24 of 41
OUTPUT

Page 25 of 41
If you choose 1 :

Page 26 of 41
If you choose 2 :

Page 27 of 41
If you choose 3 :

Page 28 of 41
If you choose 4:

Page 29 of 41
Page 30 of 41
Page 31 of 41
Page 32 of 41
Page 33 of 41
Page 34 of 41
Page 35 of 41
If you give correct word and win :

If you choose 5 :

Page 36 of 41
If you choose 6 :

Page 37 of 41
Page 38 of 41
If you choose invalid choice :

Page 39 of 41
REFERENCE

i. Sumita Arora(2023).Computer science with


python:Textbook for class XII.Dhanpat Rai &
Co.
ii. Sumita Arora(2022).Computer science with
python:Textbook for class XI.Dhanpat Rai &
Co.
iii. https://www.w3schools.com
iv. Microsoft

Page 40 of 41
THANK
YOU!

Page 41 of 41

You might also like