Skip to content
Snippets Groups Projects
Commit 23bd47ef authored by 's avatar
Browse files

full implementation

parent e746e3e1
No related branches found
No related tags found
No related merge requests found
Showing
with 79 additions and 27 deletions
......@@ -6,6 +6,7 @@
from random import randint
from Snake import *
from Food import *
import ScoreDisplay
def game(speed, colour,food_colour, backgroundColour):
x = randint(0, grid_length) * size
......@@ -93,8 +94,9 @@ def game(speed, colour,food_colour, backgroundColour):
y < 0 or
y > screenSize - size or
x > screenSize - size):
pygame.quit() #for now, quit the game when snake hits boundary
ScoreDisplay.display(score)
#pygame.quit() #for now, quit the game when snake hits boundary
## snake.die()
......@@ -121,8 +123,9 @@ def game(speed, colour,food_colour, backgroundColour):
win.blit(text,(0,0))
if ([x,y] in snake_loc) and snake_length > 1:
pygame.time.delay(1000)
pygame.quit() #quit for now, but should return to main menu
pygame.time.delay(1000)
# pygame.quit() #quit for now, but should return to main menu
ScoreDisplay.display(score)
snake_head = []
snake_head.append(x)
......@@ -157,4 +160,4 @@ def game(speed, colour,food_colour, backgroundColour):
pygame.quit()
#game(70, [255,0,0], [255,255,255])
#game(70, [255,0,0], [255,255,0],[0,0,0])
## @file ScoreDisplay.py
# @author Vaibhav Chadha
# @brief implements the interface after the snake dies
# @date 11/22/2018
import pygame, sys
import highscore, Interface
def storeScore(score):
prevScore = int(highscore.HighScore.findHighScore())
#print(prevScore)
if(score > prevScore):
infile = open("highscore.txt", "w")
infile.write(str(score))
else: return
def display(score):
pygame.init()
storeScore(score)
run = True
while run:
mousepos = pygame.mouse.get_pos() #checking mouse position
mouseclick = pygame.mouse.get_pressed()#checking mouse pressed
lastPage = pygame.display.set_mode((400, 400))
lastPage.fill([200,150,100])
highscore.HighScore.text('WOAHH Your Score is ' + str(score),"comicsansms", 30,[0, 200, 200],(10,50),lastPage)
if (100 <= mousepos[0] <= 100+200 and 150 <= mousepos[1] <= 150+60 ):
highscore.HighScore.button(lastPage,[0,255,0], [100,150,200,60], 0)
if mouseclick[0] == 1:
Interface.main()
else:
highscore.HighScore.button(lastPage,[0,170,0], [100,150,200,60], 0)
highscore.HighScore.text('PLAY MORE!',"comicsansms", 30,[0,0,0],(110,160),lastPage)
if (100 <= mousepos[0] <= 100+200 and 260 <= mousepos[1] <= 260+60 ):
highscore.HighScore.button(lastPage,[250,0,0], [100,260,200,60], 0)
if mouseclick[0] == 1:
pygame.quit()
sys.exit()
else:
highscore.HighScore.button(lastPage,[170,0,0], [100,260,200,60], 0)
highscore.HighScore.text('CAN\'T PLAY',"comicsansms", 30,[0,0,0],(110,270),lastPage)
pygame.display.update()
#display(99)
No preview for this file type
No preview for this file type
No preview for this file type
File added
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -2,7 +2,7 @@
# @author Vaibhav Chadha
# @brief implements the highscore interface
# @date 11/09/2018
import pygame, sys, Interface
import pygame, sys, Interface, pathlib
## @brief A Class that will contain useful functions in order for the creation of highscore page
class HighScore():
......@@ -31,13 +31,20 @@ class HighScore():
## @brief Finds the highest score from the file
# @details This writes the input from the file in an array and find the max number from it
def findHighscore():
infile = open("highscore.txt","r")
mylist = []
for line in infile:
a = line.strip()
mylist.append(a)
return max(mylist)
def findHighScore():
file = pathlib.Path("highscore.txt")
if file.exists ():
infile = open("highscore.txt","r")
mylist = []
for line in infile:
a = line.strip()
mylist.append(a)
if (len(mylist) == 0):
return 0
else: return max(mylist)
else:
makingfile = open("highscore.txt","w+")
return 0
## @brief Makes the highscore interface
# @details This will output the final interface using the class above
# which can be seen by executing this function.
......@@ -51,7 +58,7 @@ def main():
#highscore.fill([213, 219, 219])
pygame.display.set_caption("Highscore")
HighScore.text('Highest Score: ' + str(HighScore.findHighscore()),"comicsansms", 30,[0, 0, 200],(10,20),highscore)
HighScore.text('Highest Score: ' + str(HighScore.findHighScore()),"comicsansms", 30,[0, 0, 200],(10,20),highscore)
HighScore.button(highscore,[0,0,0], [90,70,120,26], 0)
HighScore.text('Main Menu',"times", 25,red,(90,70),highscore)
......
10
20
45
3
47
10
48
48
49
\ No newline at end of file
20
\ No newline at end of file
......@@ -55,13 +55,13 @@ class Themes():
Themes.text('Regular',"maiandragd", 40,white_green,(80,170),theme)
if (75 <= mousepos[0] <= 75+150 and 150 <= mousepos[1] <= 150+100 ):
if mouseclick[0] == 1:
Gameplay.game(speed,[255,0,0],[255,255,255])
Gameplay.game(speed,[255,0,0],[0,255,0],[255,255,255])
Themes.button(theme,black1, [280,150,150,100], 0)
Themes.text('Dark',"maiandragd", 40,white,(305,170),theme)
if (280 <= mousepos[0] <= 280+150 and 150 <= mousepos[1] <= 150+100 ):
if mouseclick[0] == 1:
Gameplay.game(speed,white,[10,10,10])
Gameplay.game(speed,white,[255,255,0],[10,10,10])
Themes.button(theme,lightBlue, [175,300,80,50], 0)
Themes.button(theme,[200,200,200], [175,350,80,50], 0)
......@@ -71,8 +71,8 @@ class Themes():
if (180 <= mousepos[0] <= 180+160 and 315 <= mousepos[1] <= 315+100 ):
if mouseclick[0] == 1:
x = randint(0, 1)
if(x == 1): Gameplay.game(speed,[255,0,0],[255,255,255])
else: Gameplay.game(speed,[255,255,255],[10,10,10])
if(x == 1): Gameplay.game(speed,[255,0,0],[0,255,0],[255,255,255])
else: Gameplay.game(speed,white,[255,255,0],[10,10,10])
pygame.display.update()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment