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 379 additions and 0 deletions
File added
File added
File added
File added
File added
File added
File added
## @file colors.py
# @author Andy Hameed
# @brief Initializes color constants as tuples of (R,G,B) values
# @date 12/02/2018
white = (255,255,255)
red = (255,0,0)
black1 = (48,47,47)
white_green = (239,246,224)
blue = (0,0,255)
black = (0,0,0)
lightBlue = (89,131,145)
darkgray = (100,100,100)
offwhite = (239, 245, 224)
lightR = (220,128,128)
lightB = (29,85,145)
## @file help.py
# @author Vaibhav Chadha
# @brief implements the help interface of this game
# @date 11/09/2018
#importing necessary libraries
x = 10
y = 40
import os
os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (x,y)
import pygame, sys
import Interface
import GUI
def main():
pygame.init()
image1 = pygame.image.load("Images/Exit_image_empty.png")
run = True
while run:
help_ = pygame.display.set_mode((500,500))
help_.blit(image1,(0,0))
mousepos = pygame.mouse.get_pos() #checking mouse position
mouseclick = pygame.mouse.get_pressed()#checking mouse pressed
pygame.display.set_caption("Help")
GUI.text('Use the following keys for the movement of the snake:','times',20,[130,190,0],(40,30),help_)
GUI.text('"Up" arrow key for turning Upwards','times',20,[90,190,0],(60,60),help_)
GUI.text('"Down" arrow key for turning Downwards','times',20,[90,190,0],(60,90),help_)
GUI.text('"Right" arrow key for turning Rightwards','times',20,[90,190,0],(60,120),help_)
GUI.text('"Left" arrow key for turning Leftwards','times',20,[90,190,0],(60,150),help_)
GUI.text('Beginner:','times',20,[200,0,0],(60,190),help_)
GUI.text('The snake can cross through the boundaries','times',20,[90,190,0],(140,190),help_)
GUI.text('Intermediate:','times',20,[200,0,0],(60,220),help_)
GUI.text('The snake will die as it touches the ','times',20,[90,190,0],(165,220),help_)
GUI.text('boundary.(The speed is faster than beginner)','times',20,[90,190,0],(140,250),help_)
GUI.text('Advance:','times',20,[200,0,0],(60,280),help_)
GUI.text('The snake will die as it touches the boundary','times',20,[90,190,0],(140,280),help_)
GUI.text('or barrier.(Same speed as intermediate)','times',20,[90,190,0],(120,310),help_)
GUI.text('THEMES','times',20,[0,50,200],(110,340),help_)
GUI.text('Regular Dark','times',20,[200,0,0],(220,340),help_)
GUI.text('Snake','times',20,[200,0,0],(100,370),help_)
GUI.text('Background','times',20,[200,0,0],(80,400),help_)
GUI.text('BLUE WHITE','times',20,[90,190,0],(220,370),help_)
GUI.text('WHITE BLACK','times',20,[90,190,0],(220,400),help_)
if (160 <= mousepos[0] <= 160+180 and 440 <= mousepos[1] <= 440+50 ):
#checks if the mouse is hovering over the button
GUI.button(help_,[100,100,100], [160,440,180,50], 0)
#checking if the button is clicked
if mouseclick[0] == 1:
Interface.main()
else:
GUI.button(help_,[180,180,180], [160,440,180,50], 0)
GUI.custom_text('Main Menu',"Roboto-Light.ttf", 30,[0, 0, 0],(172,447),help_)
pygame.display.update()
## @file highscore.py
# @author Vaibhav Chadha
# @brief implements the highscore interface
# @date 11/09/2018
import pygame, sys, Interface, pathlib
import GUI
from colors import *
## @brief A Class that will contain useful functions in order for the creation of highscore page
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():
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.
def main():
pygame.init()
while True:
mousepos = pygame.mouse.get_pos() #checking mouse position
mouseclick = pygame.mouse.get_pressed()#checking mouse pressed
highscore = pygame.display.set_mode((300, 150))
highscore.fill(white)
pygame.display.set_caption("Highscore")
GUI.custom_text('Highest Score: ' + str(HighScore.findHighScore()),"Roboto-Light.ttf", 30,black,(10,20),highscore)
GUI.custom_text('Main Menu',"Roboto-Light.ttf", 25,black,(90,70),highscore)
if (90 <= mousepos[0] <= 90+120 and 70 <= mousepos[1] <= 70+27 ):
if mouseclick[0] == 1:
Interface.main()
GUI.custom_text('Quit',"Roboto-Light.ttf", 25,black,(125,105),highscore)
if (125 <= mousepos[0] <= 125+45 and 105 <= mousepos[1] <= 105+27 ):
if mouseclick[0] == 1:
pygame.quit()
sys.exit()
pygame.display.update()
220
\ No newline at end of file
## @file Colors.py
# @author Andy Hameed
# @brief Define color constants
# @date 11/09/2018
import pygame
from random import randint
#initializing PyGame and setting game window dimensions
pygame.init()
screenSize = 500
win = pygame.display.set_mode((screenSize,screenSize))
pygame.display.set_caption("Snake")
# One size for all blocks created for snake
size = 20
grid_length = screenSize/size
#make initial position sit within the grid
x = randint(0, grid_length) * size
y = randint(0, grid_length) * size
from random import randint
from colors import *
import pygame, sys
import Gameplay
import init
import GUI
theme = 0
class Themes():
## @brief A function for running other files
# @details Executes another python file when this is selected, Given that the file is in same folder.
# @param runfilename The name of the file to be executed
def runfile(runfilename):
with open(runfilename,"r") as rnf:
exec(rnf.read())
def themes(speed):
pygame.init()
run = True
while run:
theme = pygame.display.set_mode((500, 500))
theme.fill(offwhite)
mousepos = pygame.mouse.get_pos() #checking mouse position
mouseclick = pygame.mouse.get_pressed()#checking mouse pressed
pygame.display.set_caption("Snake 2.o")
GUI.custom_text('Choose Your Theme',"Roboto-Light.ttf",45,[96,96,96],(70,50),theme)
GUI.button(theme,lightBlue, [75,150,150,100], 0)
GUI.custom_text('Regular',"Roboto-Light.ttf", 30,offwhite,(95,180),theme)
if (75 <= mousepos[0] <= 75+150 and 150 <= mousepos[1] <= 150+100 ):
if mouseclick[0] == 1:
Gameplay.game(speed, lightB,lightR, white)
GUI.button(theme,black1, [280,150,150,100], 0)
GUI.custom_text('Dark',"Roboto-Light.ttf", 30,white,(325,180),theme)
if (280 <= mousepos[0] <= 280+150 and 150 <= mousepos[1] <= 150+100 ):
if mouseclick[0] == 1:
Gameplay.game(speed,white,[255,255,0],black1)
GUI.button(theme,[255,255,255], [175,300,160,100], 0)
GUI.custom_text('Random',"Roboto-Light.ttf", 30,[0, 0, 0],(200,330),theme)
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,lightB,lightR,white)
else: Gameplay.game(speed,white,[255,255,0],black1)
pygame.display.update()
Copyright © Patrick Gillespie, http://patorjk.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
JavaScript Snake<br/>
By Patrick Gillespie<br/>
License: MIT<br/>
http://patorjk.com/games/snake
This is a DOM-based game of Snake that I wrote in JavaScript a few years back.
Other than the full screen mode demonstrated in the code, it can also be
initialized in div tags within a page. Example:
var mySnakeBoard = new SNAKE.Board( {
boardContainer: "game-area",
fullScreen: false,
width: 580,
height:400
});
The comments are formatted a little strange because at the time I was playing
around with YUI Doc.
/*
JavaScript Snake
By Patrick Gillespie
http://patorjk.com/games/snake
*/
select {
border: black;
color: #3E2E44;
background: black;
}
button {
border: black;
color: #3E2E44;
background: black;
}
body {
margin:0px;
padding:0px;
}
#game-area {
margin:0px;
padding:0px;
}
#high-score {
position: relative;
left: 200px;
bottom: 50px;
}
#game-area:focus { outline: none; }
#mode-wrapper {
font-family: Verdana, arial, helvetica, sans-serif;
font-size: 14px;
color: black;
}
a.snake-link, a.snake-link:link, a.snake-link:visited {
color: black;
}
a.snake-link:hover {
color: #3E2E44;
}
.snake-pause-screen {
font-family: Verdana, arial, helvetica, sans-serif;
font-size: 14px;
position:absolute;
width:300px;
height:80px;
text-align:center;
top:50%;
left:50%;
margin-top:-40px;
margin-left:-150px;
display:none;
background-color:#3E2E44;
color:black;
}
.snake-panel-component {
position: absolute;
font-family: Verdana, arial, helvetica, sans-serif;
font-size: 14px;
color: black;
text-align: center;
background-color: #3E2E44;
padding: 8px;
margin: 0px;
}
.snake-snakebody-block {
margin: 0px;
padding: 0px;
background-color: #3E2E44;
position: absolute;
border: 0px solid black;
background-repeat: no-repeat;
}
.snake-snakebody-alive {
background-image: url('./images/dark-snakeblock.png');
}
.snake-snakebody-dead {
background-image: url('./images/dead-dark-snakeblock.png');
}
.snake-food-block {
margin: 0px;
padding: 0px;
background-color: black;
border: 2px solid #3E2E44;
position: absolute;
}
.snake-playing-field {
margin: 0px;
padding: 0px;
position: absolute;
background-color: #312E44;
border: 3px solid black;
}
.snake-game-container {
margin: 0px;
padding: 0px;
border-width: 0px;
border-style: none;
zoom: 1;
background-color: #3E2E44;
position: relative;
}
.snake-welcome-dialog {
padding: 8px;
margin: 0px;
background-color: black;
color: #3E2E44;
font-family: Verdana, arial, helvetica, sans-serif;
font-size: 14px;
position: absolute;
top: 50%;
left: 50%;
width: 300px;
/*height: 150px;*/
margin-top: -100px;
margin-left: -158px;
text-align: center;
display: block;
}
.snake-try-again-dialog {
padding: 8px;
margin: 0px;
background-color: black;
color: #312E44;
font-family: Verdana, arial, helvetica, sans-serif;
font-size: 14px;
position: absolute;
top: 50%;
left: 50%;
width: 300px;
height: 100px;
margin-top: -75px;
margin-left: -158px;
text-align: center;
display: none;
}
File added
Javascript_Snake_Original/css/images/dark-snakeblock.png

1.01 KiB

Javascript_Snake_Original/css/images/dead-dark-snakeblock.png

1.22 KiB

Javascript_Snake_Original/css/images/deadblock.png

240 B