Computer Science Investigatory Project

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 15
At a glance
Powered by AI
The key takeaways are developing a simple color game using Python and learning about basic game development. The game helps reduce stress and improve typing and thinking speed by trying to beat previous scores.

The aim of the project is to develop a basic color game to get introduced to game development and as a first step for those wanting to pursue it as a career.

Python is used because it is an interpreted, object-oriented language that is easy to learn and emphasizes readability and code reuse. It is well suited for rapid application development and scripting.

COMPUTER SCIENCE

INVESTIGATORY PROJECT
ON
DEVELOPING A COLOR GAME
Using Python

AISSCE 2019-20
CENTRAL BOARD OF SECONDARY EDUCATION

Guided by: Submitted by:


Sir Kapil Deva Goswami Jayaditya Dey
XII (Science) A1
Roll no:

DEPARTMENT OF COMPUTER SCIENCE


GURUKUL GRAMMAR SENIOR SECONDARY SCHOOL
Guwahati – 020
Assam
CERTIFICATE

This is to certify that the embodied work on the project entitled


“Color Game in Python” for the partial fulfillment of the AISSCE
2019-20 is a part of the practical examination of Computer Science
subject. It has been successfully conducted and completed by the
candidate, Jayaditya Dey, bearing Roll No: ___________ of Gurukul
Grammar Senior Secondary School, Guwahati–781020, appearing for
AISSCE 2019-20. This project is the genuine work done by him under
our proper supervision and guidance, and has been submitted well in
time.

We wish him success in life.

Signature of the Examiner Signature


of Guide

Signature of Principal
ACKNOWLEDGEMENT

I, Jayaditya Dey, would like to thank our principal, Dr. B.K. Bhuyan,
who has inspired and encouraged us by his deeds and achievements, as
he always tells us what we do the best and be the best in it.

Next, I would like to express my sincere gratitude towards our


Computer Science teacher, Mr. Kapil Deva Goswami, for his continuous
support and valuable guidance in making this project a great success.

Jayaditya Dey
Class – XII (Science) A1
Roll No:
AIM OF THE PROJECT

DEVELOPING A
COLOR GAME
CONTENTS
 Purpose
 What is python?
 Why python?
 About the game and how it works
 Modules/functions used in coding
 Coding for the snake game
 Output
 Conclusion
 Bibliography

PURPOSE
Game Development has emerged as an integral field in the sector of
technological advancement. Gamers and gaming professional are slowly
improving on this sector and every now and then new games are being
developed by such programmers.

For the ones who wish to make a career in this field, this small
project can be regarded as their first step.

The game has also provided me an avenue for eliminating stress once
in a while. It’s extremely simple and yet competitive. Trying to
beat my previous score pushes me toward typing quicker and thinking
faster.

WHAT IS PYHTON?
Python is an interpreted, object-oriented, high-level programming
language with dynamic semantics. Its high-level built in data
structures, combined with dynamic typing and dynamic binding, make it
very attractive for Rapid Application Development, as well as for use
as a scripting or glue language to connect existing components
together. Python's simple, easy to learn syntax emphasizes
readability and therefore reduces the cost of program maintenance.
Python supports modules and packages, which encourages program
modularity and code reuse. The Python interpreter and the extensive
standard library are available in source or binary form without
charge for all major platforms, and can be freely distributed.

WHY PYHTON?

Why is Python so popular?


1. Syntax is extremely simple to read and follow
2. Python is very beginner-friendly
3. Millions of happy learners
4. Easier than other programming language.

Why should we learn Python?


1. General-purpose language
2. Wide range of applications
3. Web development-django Bottle
4. Mathematical computations (numpy and simpy)
5. Graphical user interface (Panda 3D)
6. Length of the code is relatively short
7. Fun to work with

ABOUT THE GAME AND


HOW IT WORKS

This game is a quick response time killer. Anyone can play it. It
attempts to trick the player into entering an incorrect input. The
goal is to enter as many correct inputs as possible within the given
time. The primary goal of the game is to break the previous record
for highest score.
There are ten available colors in this game; Red, Blue, Green, Pink,
Black, Yellow, Orange, White, Purple and Brown. The game window
displays one of the color names as text. Here comes the catch. The
text is formatted and displayed in another color (from the available
colors). The player must enter the name of the color with which the
text is formatter and not the name already on display. This demands
quick thinking and even faster typing. As soon as a player registers
the correct input, the name and color on display changes and a point
is scored.
The goal is to get as many points as possible within 30 seconds.

CODE FOR THE PROGRAM

# import the modules


import tkinter
import random

# list of possible colour.


colours = ['Red','Blue','Green','Pink','Black',
'Yellow','Orange','White','Purple','Brown']
score = 0

# the game time left, initially 30 seconds.


timeleft = 30

# function that will start the game.


def startGame(event):
if timeleft == 30:

# start the countdown timer.


countdown()

# run the function to


# choose the next colour.
nextColour()

# Function to choose and


# display the next colour.
def nextColour():

# use the globally declared 'score'


# and 'play' variables above.
global score
global timeleft

# if a game is currently in play


if timeleft > 0:

# make the text entry box active.


e.focus_set()

# if the colour typed is equal


# to the colour of the text
if e.get().lower() == colours[1].lower():

score += 1

# clear the text entry box.


e.delete(0, tkinter.END)

random.shuffle(colours)

# change the colour to type, by changing the


# text _and_ the colour to a random colour value
label.config(fg = str(colours[1]), text = str(colours[0]))

# update the score.


scoreLabel.config(text = "Score: " + str(score))

# Countdown timer function


def countdown():

global timeleft

# if a game is in play
if timeleft > 0:

# decrement the timer.


timeleft -= 1
# update the time left label
timeLabel.config(text = "Time left: "
+ str(timeleft))

# run the function again after 1 second.


timeLabel.after(1000, countdown)

# Driver Code

# create a GUI window


root = tkinter.Tk()

# set the title


root.title("COLORGAME")

# set the size


root.geometry("375x200")

# add an instructions label


instructions = tkinter.Label(root, text = "Type in the colour"
"of the words, and not the word text!",
font = ('Helvetica', 12))
instructions.pack()

# add a score label


scoreLabel = tkinter.Label(root, text = "Press enter to start",
font = ('Helvetica', 12))
scoreLabel.pack()

# add a time left label


timeLabel = tkinter.Label(root, text = "Time left: " +
str(timeleft), font = ('Helvetica', 12))

timeLabel.pack()

# add a label for displaying the colours


label = tkinter.Label(root, font = ('Helvetica', 60))
label.pack()

# add a text entry box for


# typing in colours
e = tkinter.Entry(root)

# run the 'startGame' function


# when the enter key is pressed
root.bind('<Return>', startGame)
e.pack()

# set focus on the entry box


e.focus_set()
# start the GUI
root.mainloop()

OUTPUT
CONCLUSION
We learned how to create the color game in Python. Many things could
be added to this little toy game but this serves as a very simple
example.

The good thing about this game and our solution is that it is very
simple. The approach is pretty simple and easy to understand even for
beginners. This game could run on many platforms.

There can be many more features which can be added to this game to
make it more interactive and interesting.

BIBLIOGRAPHY
Books used:
Sumita Arora Computer text book for class XI
Sumita Arora Computer text book for class XII
Websites:
1. https://www.geeksforgeeks.org/introduction-to-pygame/
2. https://www.pythonforbeginners.com/random/how-to-use-the-random-module-in-python
3. https://www.geeksforgeeks.org/python-gui-tkinter/

You might also like