Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • namy2/se3xa3
  • bokhari/se3xa3
  • kanwalg/se3xa3
  • sunx20/se3xa3
  • hameea1/se3xa3
  • aij/se3xa3
  • hanzy3/se3xa3
  • linl20/se3xa3
  • zhous20/se3xa3
9 results
Show changes
Showing
with 177 additions and 2 deletions
BlankProjectTemplate/src/Images/Exit_image.png

10 KiB

BlankProjectTemplate/src/Images/Exit_image_empty.png

1.45 KiB

BlankProjectTemplate/src/Images/Snake_Game_Logo_background.png

23.3 KiB

BlankProjectTemplate/src/Images/Snake_image.png

37.2 KiB

BlankProjectTemplate/src/Images/barrier.png

948 B

BlankProjectTemplate/src/Images/maze_border.png

853 B

## @file interface.py
# @author Vaibhav Chadha
# @brief implements the main interface of this game
# @date 11/09/2018
x = 10
y = 40
import os
os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (x,y)
import help_, highscore, theme
import pygame, sys
import GUI
from colors import *
## @brief Makes the main interface of this game
# @details This will output the main page of this game by using the class above
def main():
pygame.init()
image1 = pygame.image.load("Images/Snake_Game_Logo_background.png")
image2 = pygame.image.load("Images/Snake_image.png")
#while loop required to always refresh the page
run = True
while run:
game = pygame.display.set_mode((800, 610))
game.blit(image1,(0,0))
game.blit(image2,(550,0))
mousepos = pygame.mouse.get_pos() #checking mouse position
mouseclick = pygame.mouse.get_pressed()#checking mouse pressed
pygame.display.set_caption("Lets Play")
#Adding the play game button
if (400 <= mousepos[0] <= 400+170 and 250 <= mousepos[1] <= 250+50 ):
#checks if the mouse is hovering over the button
GUI.button(game,darkgray, [400,250,170,50], 0)
#checking if the button is clicked
if mouseclick[0] == 1:
theme.Themes.themes(100)
else:
GUI.button(game,lightBlue, [400,250,170,50], 0)
GUI.custom_text('Beginner',"Roboto-Light.ttf", 25, offwhite ,(438,260),game)
if (430 <= mousepos[0] <= 430+220 and 350 <= mousepos[1] <= 350+50 ):
#checks if the mouse is hovering over the button
GUI.button(game,darkgray, [430,350,220,50], 0)
#checking if the button is clicked
if mouseclick[0] == 1:
theme.Themes.themes(70)
else:
GUI.button(game,lightBlue, [430,350,220,50], 0)
GUI.custom_text('Intermediate',"Roboto-Light.ttf", 25, offwhite ,(470,357),game)
if (400 <= mousepos[0] <= 400+180 and 450 <= mousepos[1] <= 450+50 ):
#checks if the mouse is hovering over the button
GUI.button(game,darkgray, [400,450,180,50], 0)
#checking if the button is clicked
if mouseclick[0] == 1:
theme.Themes.themes(71)
else:
GUI.button(game,lightBlue, [400,450,180,50], 0)
GUI.custom_text('Advanced',"Roboto-Light.ttf", 25, offwhite ,(435,457),game)
if (365 <= mousepos[0] <= 365+55 and 565 <= mousepos[1] <= 565+35 ):
if mouseclick[0] == 1:
help_.main()
GUI.custom_text('Help',"Roboto-Light.ttf", 25, black ,(365,565),game)
if (15 <= mousepos[0] <= 15+115 and 565 <= mousepos[1] <= 565+35 ):
if mouseclick[0] == 1:
highscore.main()
if (725 <= mousepos[0] <= 725+50 and 565 <= mousepos[1] <= 565+35 ):
if mouseclick[0] == 1:
pygame.quit()
sys.exit()
pygame.display.update()
if __name__ == "__main__":
main()
# Project Name Source Code
# Snake 2.o Source Code
The folders and files for this project are as follows:
...
File added
## @file ScoreDisplay.py
# @author Vaibhav Chadha
# @brief implements the interface after the snake dies
# @date 11/22/2018
import pygame, sys
import highscore, Interface, Gameplay
import GUI
from colors import *
def storeScore(score):
prevScore = int(highscore.HighScore.findHighScore())
if(score > prevScore):
infile = open("highscore.txt", "w")
infile.write(str(score))
else: return
def display(score,speed, colour,food_colour, backgroundColour):
pygame.init()
storeScore(score)
image1 = pygame.image.load("Images/Exit_image.png")
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((500, 500))
lastPage.blit(image1,(0,0))
GUI.custom_text('Your Score is ' + str(score),"Roboto-Light.ttf", 40,black,(93,50),lastPage)
if (150 <= mousepos[0] <= 150+200 and 150 <= mousepos[1] <= 150+60 ):
GUI.button(lastPage,darkgray, [150,150,200,60], 0)
if mouseclick[0] == 1:
Gameplay.game(speed, colour,food_colour, backgroundColour)
else:
GUI.button(lastPage,lightBlue, [150,150,200,60], 0)
GUI.custom_text('Play Again',"Roboto-Light.ttf", 25, white,(193,165),lastPage)
if (150 <= mousepos[0] <= 150+200 and 260 <= mousepos[1] <= 260+60 ):
GUI.button(lastPage,darkgray, [150,260,200,60], 0)
if mouseclick[0] == 1:
Interface.main()
else:
GUI.button(lastPage,lightBlue, [150,260,200,60], 0)
GUI.custom_text('Main Menu',"Roboto-Light.ttf", 25,white,(189,275),lastPage)
if (150 <= mousepos[0] <= 150+200 and 370 <= mousepos[1] <= 370+60 ):
GUI.button(lastPage,darkgray, [150,370,200,60], 0)
if mouseclick[0] == 1:
pygame.quit()
sys.exit()
else:
GUI.button(lastPage,lightBlue, [150,370,200,60], 0)
GUI.custom_text('Quit',"Roboto-Light.ttf", 25,white,(225,385),lastPage)
pygame.display.update()
## @file Snake.py
# @author Andy Hameed
# @brief implements an abstract data type for a snake
# @date 11/09/2018
from random import randint
from init import *
## @brief An Abstract Data type representing a snake character object
class Snake():
## @brief Snake constructor
# @details Initializes a Snake object with its initial attributes
# @param blockSize the width and height of the square block representing the snake
# @param direct The direction of the snake's movement
# @param speed The initial speed of the snake's movement
def __init__(self, blockSize, direct, speed, axis):
self.speed = speed
self.direct = direct
self.size = blockSize
self.axis = axis
## @brief Draw method uses pygame to draw the snake object
# @param x The x-coordinate where the block should be drawn
# @param y The y-coordinate where the block should be drawn
def draw(self,colour, snake_loc):
for x,y in snake_loc:
pygame.draw.rect(win, colour , [x,y, self.size, self.size])
File added
File added
File added
File added
File added
File added
File added
File added
File added