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 1383 additions and 0 deletions
This diff is collapsed.
#standard set up
import pygame
from random import randint
pygame.init()
#setting width and height of window
screen_x = 500
screen_y = 500
win = pygame.display.set_mode((screen_x,screen_y))
pygame.display.set_caption("My Game")
white = (255,255,255)
black = (0,0,0)
x = randint(40,400)
y = randint(40,400)
width = 20
height = 20
vel = 10
speed = 40
# 0 - (- direction) , 1 - (+ direction)
direction = 0
# 0 - x-axis , 1 - y-axis
axis = 0
run = True
while run:
pygame.time.delay(speed) #create a delay to prevent any unwanted behaviour
#events are anything that happens from the user
#we loop through the list of events that happen by the user's actions
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
#Each event type has an integer assigned to it. KEYDOWN has the code 2
if event.type == pygame.KEYDOWN:
if (event.key == pygame.K_LEFT):
axis = 0;direction=-1
if (event.key == pygame.K_RIGHT):
axis = 0;direction=1
if (event.key == pygame.K_UP):
axis = 1;direction=-1
if (event.key == pygame.K_DOWN):
axis = 1;direction=1
#Snake moving depending on axis and direction
if (axis):
y += vel*direction
else:
x += vel*direction
if x < 0:
#x = 0
x = screen_x - height
if y < 0:
#y = 0
y = screen_y - width
if y > screen_y - width:
#y = 500 - width
y = 0
if x > screen_x - height:
#x = 500 - height
x = 0
win.fill(white)
#all colors are defined in RGB with Pygame
pygame.draw.rect(win,(255,0,0), (x,y,width, height))
#we have to update the display to see the drawing of our object. Since it does
#not automatically update
pygame.display.update()
#Quit the game
pygame.quit()
#importing necessary libraries
import pygame, sys
#a function made to execute other files from the system
def runfile(runfilename):
with open(runfilename,"r") as rnf:
exec(rnf.read())
pygame.init()
#while loop required to always refresh the page
while True:
game = pygame.display.set_mode((800, 610))
game.fill([213, 219, 219])
mousepos = pygame.mouse.get_pos() #checking mouse position
mouseclick = pygame.mouse.get_pressed()#checking mouse pressed
pygame.display.set_caption("Lets Play")
title_font = pygame.font.SysFont("monospace", 80)
#Adding the title
gamename = title_font.render('SNAKE GAME', True, (255, 0, 0))
game.blit(gamename,(150,80))
#Adding the play game button
if (270 <= mousepos[0] <= 270+250 and 505 <= mousepos[1] <= 555 ):
#checks if the mouse is hovering over the button
pygame.draw.rect(game,[100,100,100], [270,505,250,50], 0)
#checking if the button is clicked
if mouseclick[0] == 1:
runfile('Snake_2.o_Demo.py')
else:
pygame.draw.rect(game,[180,180,180], [270,505,250,50], 0)
playgame_font = pygame.font.SysFont("comicsansms", 40)
gamebutton = playgame_font.render('GAME TIME', True, (0, 0, 200))
game.blit(gamebutton,(275,500))
#Taking user name
UserName = playgame_font.render('NAME:', True, (0, 250, 0))
game.blit(UserName,(50,200))
#Asking user for theme
ThemeOption = playgame_font.render('THEMES:', True, (0, 200, 0))
game.blit(ThemeOption,(50,300))
#Asking user for speed
SpeedOption = playgame_font.render('SPEED:', True, (0, 150, 0))
game.blit(SpeedOption,(50,400))
#If user wants to quit
pygame.draw.rect(game,[180,180,180], [650,550,130,55], 0)
Quit = playgame_font.render('QUIT', True, (0, 0, 0))
game.blit(Quit,(650,550))
if ( 650 <= mousepos[0] <= 650+130 and 550 <= mousepos[1] <= 550 +55):
#checks if the mouse is hovering over the button
#checking if the button is clicked
if mouseclick[0] == 1:
#print ("quiting")
#pygame.display.quit()
pygame.quit()
sys.exit()
pygame.display.update()
<?xml version="1.0" encoding="UTF-8"?><project name="3XA3: Team Project" company="" webLink="http://" view-date="2018-10-23" view-index="0" gantt-divider-location="300" resource-divider-location="300" version="2.8.9" locale="en_CA">
<description><![CDATA[Developing the clasical Snake game using python and front-end development languages.]]></description>
<view zooming-state="default:0" id="gantt-chart">
<field id="tpd3" name="Name" width="167" order="0"/>
<field id="tpd4" name="Begin date" width="65" order="1"/>
<field id="tpd5" name="End date" width="64" order="2"/>
</view>
<view id="resource-table">
<field id="0" name="Name" width="210" order="0"/>
<field id="1" name="Default role" width="86" order="1"/>
</view>
<!-- -->
<calendars>
<day-types>
<day-type id="0"/>
<day-type id="1"/>
<default-week id="1" name="default" sun="1" mon="0" tue="0" wed="0" thu="0" fri="0" sat="1"/>
<only-show-weekends value="false"/>
<overriden-day-types/>
<days/>
</day-types>
</calendars>
<tasks empty-milestones="true">
<taskproperties>
<taskproperty id="tpd0" name="type" type="default" valuetype="icon"/>
<taskproperty id="tpd1" name="priority" type="default" valuetype="icon"/>
<taskproperty id="tpd2" name="info" type="default" valuetype="icon"/>
<taskproperty id="tpd3" name="name" type="default" valuetype="text"/>
<taskproperty id="tpd4" name="begindate" type="default" valuetype="date"/>
<taskproperty id="tpd5" name="enddate" type="default" valuetype="date"/>
<taskproperty id="tpd6" name="duration" type="default" valuetype="int"/>
<taskproperty id="tpd7" name="completion" type="default" valuetype="int"/>
<taskproperty id="tpd8" name="coordinator" type="default" valuetype="text"/>
<taskproperty id="tpd9" name="predecessorsr" type="default" valuetype="text"/>
</taskproperties>
<task id="0" name="Development Plan" color="#8cb6ce" meeting="false" start="2018-09-25" duration="4" complete="0" thirdDate="2018-09-27" thirdDate-constraint="0" expand="false">
<task id="19" name="Team Meeting Plan" color="#8cb6ce" meeting="false" start="2018-09-25" duration="1" complete="0" thirdDate="2018-09-19" thirdDate-constraint="0" expand="true"/>
<task id="20" name="Team Communication Plan" color="#8cb6ce" meeting="false" start="2018-09-25" duration="1" complete="0" thirdDate="2018-09-13" thirdDate-constraint="0" expand="true"/>
<task id="29" name="Copy_Team Communication Plan" color="#8cb6ce" meeting="false" start="2018-09-25" duration="1" complete="0" thirdDate="2018-09-13" thirdDate-constraint="0" expand="true"/>
<task id="21" name="Team Member Roles" color="#8cb6ce" meeting="false" start="2018-09-25" duration="1" complete="0" thirdDate="2018-09-13" thirdDate-constraint="0" expand="true"/>
<task id="22" name="Git workflow plan" color="#8cb6ce" meeting="false" start="2018-09-25" duration="1" complete="0" thirdDate="2018-09-13" thirdDate-constraint="0" expand="true"/>
<task id="23" name="Proof of Concept" color="#8cb6ce" meeting="false" start="2018-09-26" duration="1" complete="0" thirdDate="2018-09-13" thirdDate-constraint="0" expand="true"/>
<task id="24" name="Technology" color="#8cb6ce" meeting="false" start="2018-09-26" duration="1" complete="0" thirdDate="2018-09-13" thirdDate-constraint="0" expand="true"/>
<task id="25" name="Coding Style" color="#8cb6ce" meeting="false" start="2018-09-27" duration="1" complete="0" thirdDate="2018-09-13" thirdDate-constraint="0" expand="true"/>
<task id="26" name="Project Schedule" color="#8cb6ce" meeting="false" start="2018-09-27" duration="1" complete="0" thirdDate="2018-09-13" thirdDate-constraint="0" expand="true"/>
<task id="27" name="Project review" color="#8cb6ce" meeting="false" start="2018-09-28" duration="1" complete="0" thirdDate="2018-09-13" thirdDate-constraint="0" expand="true"/>
</task>
<task id="8" name="Requirements Document Revision" color="#8cb6ce" meeting="false" start="2018-09-18" duration="14" complete="0" thirdDate="2018-09-27" thirdDate-constraint="0" expand="false">
<task id="31" name="Project Drivers" color="#8cb6ce" meeting="false" start="2018-10-01" duration="2" complete="0" thirdDate="2018-09-17" thirdDate-constraint="0" expand="true"/>
<task id="49" name="Functional Requirements" color="#8cb6ce" meeting="false" start="2018-10-02" duration="2" complete="0" thirdDate="2018-09-12" thirdDate-constraint="0" expand="true"/>
<task id="42" name="Non-Functional Requirements" color="#8cb6ce" meeting="false" start="2018-10-03" duration="2" complete="0" thirdDate="2018-09-12" thirdDate-constraint="0" expand="true"/>
<task id="44" name="Project Issues" color="#8cb6ce" meeting="false" start="2018-10-03" duration="2" complete="0" thirdDate="2018-09-12" thirdDate-constraint="0" expand="true">
<depend id="52" type="2" difference="0" hardness="Strong"/>
</task>
<task id="52" name="Push &amp; Tag Document" color="#8cb6ce" meeting="false" start="2018-10-05" duration="1" complete="0" thirdDate="2018-09-17" thirdDate-constraint="0" expand="true"/>
<task id="55" name="SpellCheck" color="#8cb6ce" meeting="false" start="2018-10-04" duration="1" complete="0" thirdDate="2018-09-18" thirdDate-constraint="0" expand="true">
<depend id="52" type="2" difference="0" hardness="Strong"/>
</task>
<task id="58" name="task_58" meeting="false" start="2018-09-18" duration="1" complete="0" expand="true"/>
</task>
<task id="9" name="Proof of Concept Demonstration" color="#8cb6ce" meeting="false" start="2018-10-10" duration="4" complete="0" thirdDate="2018-09-27" thirdDate-constraint="0" expand="false">
<task id="59" name="Snake Body &amp; Movement" color="#8cb6ce" meeting="false" start="2018-10-10" duration="2" complete="0" thirdDate="2018-09-17" thirdDate-constraint="0" expand="true"/>
<task id="61" name="Home Page GUI" color="#8cb6ce" meeting="false" start="2018-10-11" duration="2" complete="0" thirdDate="2018-09-17" thirdDate-constraint="0" expand="true"/>
<task id="63" name="Border Boundaries" color="#8cb6ce" meeting="false" start="2018-10-15" duration="1" complete="0" thirdDate="2018-09-17" thirdDate-constraint="0" expand="true"/>
</task>
<task id="12" name="Test Plan Revision" color="#8cb6ce" meeting="false" start="2018-10-19" duration="5" complete="0" thirdDate="2018-09-27" thirdDate-constraint="0" expand="false">
<task id="64" name="General Information" color="#8cb6ce" meeting="false" start="2018-10-19" duration="2" complete="0" thirdDate="2018-10-08" thirdDate-constraint="0" expand="true"/>
<task id="65" name="Plan" color="#8cb6ce" meeting="false" start="2018-10-19" duration="2" complete="0" thirdDate="2018-10-08" thirdDate-constraint="0" expand="true"/>
<task id="66" name="System Test Description" color="#8cb6ce" meeting="false" start="2018-10-22" duration="2" complete="0" thirdDate="2018-10-08" thirdDate-constraint="0" expand="true"/>
<task id="67" name="Tests for Proof of Concept" color="#8cb6ce" meeting="false" start="2018-10-23" duration="3" complete="0" thirdDate="2018-10-08" thirdDate-constraint="0" expand="true">
<task id="82" name="Tests for Functional Req." color="#8cb6ce" meeting="false" start="2018-10-23" duration="3" complete="0" thirdDate="2018-10-15" thirdDate-constraint="0" expand="true"/>
<task id="83" name="Tests for Non-Functional Req." color="#8cb6ce" meeting="false" start="2018-10-23" duration="2" complete="0" thirdDate="2018-10-15" thirdDate-constraint="0" expand="true"/>
</task>
<task id="68" name="Comparison to Existing Implementation" color="#8cb6ce" meeting="false" start="2018-10-24" duration="2" complete="0" thirdDate="2018-10-08" thirdDate-constraint="0" expand="true"/>
<task id="69" name="Unit Test Plan" color="#8cb6ce" meeting="false" start="2018-10-24" duration="2" complete="0" thirdDate="2018-10-08" thirdDate-constraint="0" expand="true"/>
</task>
<task id="13" name="Design &amp; Document Revision" color="#8cb6ce" meeting="false" start="2018-10-31" duration="4" complete="0" thirdDate="2018-09-27" thirdDate-constraint="0" expand="true">
<task id="85" name="Anticipated and Unlikely Changes" color="#8cb6ce" meeting="false" start="2018-11-05" duration="1" complete="0" thirdDate="2018-10-18" thirdDate-constraint="0" expand="true"/>
<task id="86" name="Module Hierarchy" color="#8cb6ce" meeting="false" start="2018-11-01" duration="2" complete="0" thirdDate="2018-10-18" thirdDate-constraint="0" expand="true"/>
<task id="91" name="Conncection between Requirements and Design" color="#8cb6ce" meeting="false" start="2018-10-31" duration="3" complete="0" thirdDate="2018-10-18" thirdDate-constraint="0" expand="true"/>
<task id="93" name="Module Decomposition" color="#8cb6ce" meeting="false" start="2018-10-31" duration="4" complete="0" thirdDate="2018-10-18" thirdDate-constraint="0" expand="true" cost-manual-value="33.0" cost-calculated="false"/>
<task id="96" name="Traceability Matrix" color="#8cb6ce" meeting="false" start="2018-10-31" duration="4" complete="0" thirdDate="2018-10-18" thirdDate-constraint="0" expand="true"/>
<task id="98" name="Use Heirarchy between modules" color="#8cb6ce" meeting="false" start="2018-11-02" duration="2" complete="0" thirdDate="2018-10-18" thirdDate-constraint="0" expand="true"/>
<task id="99" name="MIS" meeting="false" start="2018-11-02" duration="2" complete="0" expand="true">
<task id="100" name="Interface - Doxygen" color="#8cb6ce" meeting="false" start="2018-11-02" duration="2" complete="0" thirdDate="2018-10-29" thirdDate-constraint="0" expand="true"/>
<task id="101" name="Food &amp; barriers - Doxygen" color="#8cb6ce" meeting="false" start="2018-11-02" duration="2" complete="0" thirdDate="2018-10-29" thirdDate-constraint="0" expand="true"/>
<task id="102" name="Snake body &amp; movement - doxygen" color="#8cb6ce" meeting="false" start="2018-11-02" duration="2" complete="0" thirdDate="2018-10-29" thirdDate-constraint="0" expand="true"/>
</task>
</task>
<task id="14" name="Revision 0 Demonstration" color="#8cb6ce" meeting="false" start="2018-11-12" duration="2" complete="0" thirdDate="2018-09-27" thirdDate-constraint="0" expand="true"/>
<task id="15" name="Final Demonstration" color="#8cb6ce" meeting="false" start="2018-11-19" duration="7" complete="0" thirdDate="2018-09-27" thirdDate-constraint="0" expand="true"/>
<task id="17" name="Peer Evaluation - Final Demo" color="#8cb6ce" meeting="false" start="2018-11-27" duration="4" complete="0" thirdDate="2018-09-27" thirdDate-constraint="0" expand="true"/>
<task id="18" name="Final Documentation" color="#8cb6ce" meeting="false" start="2018-12-06" duration="1" complete="0" thirdDate="2018-09-27" thirdDate-constraint="0" expand="true">
<notes><![CDATA[Problem Statement
Development Plan
Requirements Document
Design Document
Test Plan
Test Report
Users Guide (optional)
Source Code]]></notes>
</task>
</tasks>
<resources>
<resource id="3" name="Andy" function="1" contacts="hameea1@mcmaster.ca" phone="6479276093"/>
<resource id="4" name="Usman" function="4" contacts="irfanm7@mcmaster.ca" phone="4168787844">
<rate name="standard" value="99"/>
</resource>
<resource id="5" name="Vaibhav" function="8" contacts="chadhav@mcmaster.ca" phone="6474545182">
<rate name="standard" value="100"/>
</resource>
<resource id="6" name="Varun Hooda" function="2" contacts="hoodav@mcmaster.ca" phone=""/>
<resource id="7" name="Dr. Bokhari" function="3" contacts="bokhari@mcmaster.ca" phone=""/>
</resources>
<allocations>
<allocation task-id="31" resource-id="3" function="1" responsible="true" load="100.0"/>
<allocation task-id="8" resource-id="3" function="1" responsible="true" load="33.333332"/>
<allocation task-id="44" resource-id="3" function="1" responsible="true" load="100.0"/>
<allocation task-id="55" resource-id="3" function="1" responsible="true" load="100.0"/>
<allocation task-id="59" resource-id="3" function="1" responsible="true" load="100.0"/>
<allocation task-id="67" resource-id="3" function="1" responsible="true" load="100.0"/>
<allocation task-id="66" resource-id="3" function="1" responsible="true" load="20.0"/>
<allocation task-id="64" resource-id="3" function="1" responsible="true" load="100.0"/>
<allocation task-id="85" resource-id="3" function="1" responsible="true" load="100.0"/>
<allocation task-id="93" resource-id="3" function="1" responsible="true" load="33.0"/>
<allocation task-id="96" resource-id="3" function="1" responsible="false" load="100.0"/>
<allocation task-id="102" resource-id="3" function="1" responsible="true" load="100.0"/>
<allocation task-id="8" resource-id="4" function="4" responsible="false" load="33.333332"/>
<allocation task-id="49" resource-id="4" function="4" responsible="true" load="100.0"/>
<allocation task-id="65" resource-id="4" function="4" responsible="true" load="100.0"/>
<allocation task-id="66" resource-id="4" function="4" responsible="false" load="40.0"/>
<allocation task-id="86" resource-id="4" function="4" responsible="true" load="100.0"/>
<allocation task-id="93" resource-id="4" function="4" responsible="false" load="33.0"/>
<allocation task-id="98" resource-id="4" function="4" responsible="true" load="100.0"/>
<allocation task-id="101" resource-id="4" function="4" responsible="true" load="100.0"/>
<allocation task-id="8" resource-id="5" function="8" responsible="false" load="33.333332"/>
<allocation task-id="42" resource-id="5" function="8" responsible="true" load="100.0"/>
<allocation task-id="52" resource-id="5" function="8" responsible="true" load="100.0"/>
<allocation task-id="61" resource-id="5" function="8" responsible="true" load="100.0"/>
<allocation task-id="68" resource-id="5" function="8" responsible="true" load="100.0"/>
<allocation task-id="69" resource-id="5" function="8" responsible="true" load="100.0"/>
<allocation task-id="66" resource-id="5" function="8" responsible="false" load="40.0"/>
<allocation task-id="91" resource-id="5" function="8" responsible="true" load="100.0"/>
<allocation task-id="93" resource-id="5" function="8" responsible="false" load="34.0"/>
<allocation task-id="96" resource-id="5" function="8" responsible="true" load="100.0"/>
<allocation task-id="100" resource-id="5" function="8" responsible="true" load="100.0"/>
</allocations>
<vacations/>
<previous/>
<roles roleset-name="Default"/>
<roles>
<role id="1" name="UI Deisgner | Project Schedule Administrator"/>
<role id="2" name="TA"/>
<role id="3" name="Course Professor"/>
<role id="4" name="Main Programmer | Requirements Documentation"/>
<role id="5" name="Tester"/>
<role id="6" name="Requirements &amp; Documentation Editor"/>
<role id="7" name="Project Schedule Editor"/>
<role id="8" name="Git master | Testing Requirements"/>
</roles>
</project>
File added
## @file Snake_2.o.py
# @author Andy Hameed, Usman Irfan
# @brief implements gameplay and connects the different components of the game
# @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 2.o")
#Define color constants
white = (255,255,255)
red = (255,0,0)
blue = (0,0,255)
black = (0,0,0)
# One size for all blocks created for snake
size = 20
#velocity and score
vel = 10
score = 0
#initial x and y coordinates of the snake
x_init = randint(0,screenSize - size)
y_init = randint(0, screenSize - size)
speed = 40
# 0 gives (- direction)
# 1 gives (+ direction)
direction = 0
# 0 - x-axis , 1 - y-axis
axis = 0
location = []
food_x = randint(0,screenSize - size)
food_y = randint(0,screenSize - size)
location = [food_x, food_y]
#Loop through the events as long as the game is running
run = True
while run:
pygame.time.delay(speed) #create a delay to prevent any unwanted behaviour
#events are anything that happens from the user
#we loop through the list of events that happen by the user's actions
for event in pygame.event.get():
#Check if the event is a quit command and quit the game if it is
if event.type == pygame.QUIT:
run = False
#Each event type has an integer assigned to it. KEYDOWN has the code 2
if event.type == pygame.KEYDOWN:
if (event.key == pygame.K_LEFT):
axis = 0;direction=-1
if (event.key == pygame.K_RIGHT):
axis = 0;direction=1
if (event.key == pygame.K_UP):
axis = 1;direction=-1
if (event.key == pygame.K_DOWN):
axis = 1;direction=1
#Snake moving depending on axis and direction
if (axis):
y += vel*direction
else:
x += vel*direction
#Boundary conditions for snake hitting window edge
if x < 0:
#x = 0
x = screenSize - size
if y < 0:
#y = 0
y = screenSize - size
if y > screenSize - size:
#y = 500 - size
y = 0
if x > screenSize - size:
#x = 500 - size
x = 0
#all colors are defined in RGB with Pygame
#consumption of food block
if( abs(x - food_x) < 15 and abs(y - food_y) < 15):
score += 1
food_x = randint(0,screenSize - size)
food_y = randint(0,screenSize - size)
location = [food_x, food_y]
## --------------------------DELETE --------------------------
#extend length or size depending on the direction of the snake
if (axis):
size += 20
else:
size += 20
##---------------------------DELETE----------------------------
print('score = ', score)
win.fill(white)
#Draw food item
pygame.draw.rect(win,blue, (location[0], location[1], size, size))
#Draw snake
pygame.draw.rect(win, red , (x,y,size, size))
#we have to update the display to see the drawing of our object. Since it does
#not automatically update
pygame.display.update()
#Quit the game
pygame.quit()
#importing necessary libraries
import pygame, sys
import highscore
class GUI():
#a function made to execute other files from the system
def runfile(runfilename):
with open(runfilename,"r") as rnf:
exec(rnf.read())
def button(Surface, color,Rect,width):
pygame.draw.rect(Surface, color,Rect,width)
def text(text,fontStyle,fontSize,color,coord,surface):
font = pygame.font.SysFont(fontStyle,fontSize)
text = font.render(text,True,color)
surface.blit(text,coord)
def main():
pygame.init()
gray = [180,180,180]
darkgray = [100,100,100]
red = [255,0,0]
#while loop required to always refresh the page
while True:
game = pygame.display.set_mode((800, 610))
game.fill([213, 219, 219])
mousepos = pygame.mouse.get_pos() #checking mouse position
mouseclick = pygame.mouse.get_pressed()#checking mouse pressed
pygame.display.set_caption("Lets Play")
GUI.text('SNAKE GAME',"monospace", 80,red,(150,80),game)
#Adding the play game button
if (270 <= mousepos[0] <= 270+250 and 450 <= mousepos[1] <= 450+55 ):
#checks if the mouse is hovering over the button
GUI.button(game,darkgray, [270,455,250,50], 0)
#checking if the button is clicked
if mouseclick[0] == 1:
GUI.runfile('Snake_2.o_Demo.py')
else:
GUI.button(game,gray, [270,455,250,50], 0)
GUI.text('GAME TIME',"comicsansms", 40,[0, 0, 200],(275,450),game)
GUI.text('THEMES:',"comicsansms", 40,(0, 200, 0),(50,250),game)
GUI.text('SPEED',"comicsansms", 40,(0, 150, 0),(50,350),game)
#Highest Score
if ( 10 <= mousepos[0] <= 310 and 550 <= mousepos[1] <= 550 +55):
GUI.button(game,[200,0,0],[10,550,300,55], 0)
if mouseclick[0] == 1:
#GUI.runfile('highscore.py')
highscore.main()
else:
GUI.button(game,[180,180,180], [10,550,300,55], 0)
GUI.text('HIGHEST SCORE',"comicsansms", 35,(0, 0, 0),(10,550),game)
#If user wants to quit
if ( 670 <= mousepos[0] <= 670+105 and 550 <= mousepos[1] <= 550 +55):
GUI.button(game,[200,0,0],[670,550,105,55], 0)
if mouseclick[0] == 1:
pygame.quit()
sys.exit()
else:
GUI.button(game,[180,180,180], [670,550,105,55], 0)
GUI.text('QUIT',"comicsansms", 35,(0, 0, 0),(670,550),game)
pygame.display.update()
if __name__ == "__main__":
main()
import pygame, sys
import Snake_Game
class HighScore():
def runfile(runfilename):
with open(runfilename,"r") as rnf:
exec(rnf.read())
def text(text,fontStyle,fontSize,color,coord,surface):
font = pygame.font.SysFont(fontStyle,fontSize)
text = font.render(text,True,color)
surface.blit(text,coord)
def button(Surface, color,Rect,width):
pygame.draw.rect(Surface, color,Rect,width)
def findHighscore():
infile = open("highscore.txt","r")
mylist = []
for line in infile:
a = line.strip()
mylist.append(a)
return max(mylist)
def main():
pygame.init()
red = [255,0,0]
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([213, 219, 219])
pygame.display.set_caption("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)
if (90 <= mousepos[0] <= 90+120 and 70 <= mousepos[1] <= 70+27 ):
if mouseclick[0] == 1:
#HighScore.runfile('Snake_Game.py')
Snake_Game.main()
HighScore.button(highscore,[0,0,0], [125,105,45,27], 0)
HighScore.text('Quit',"times", 25,red,(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()
#main()
10
20
45
3
47
10
48
48
49
\ No newline at end of file
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

Javascript_Snake_Original/css/images/deadblock_border.png

117 B

Javascript_Snake_Original/css/images/snakeblock.png

119 B

/*
JavaScript Snake
By Patrick Gillespie
http://patorjk.com/games/snake
*/
body {
margin:0px;
padding:0px;
}
#game-area {
margin:0px;
padding:0px;
}
#high-score {
position: relative;
left: 200px;
bottom: 50px;
}
#mode-wrapper {
color: #ffffff;
font-family: Verdana, arial, helvetica, sans-serif;
font-size: 14px;
}
#game-area:focus { outline: none; }
a.snake-link, a.snake-link:link, a.snake-link:visited {
color: #FCFC54;
}
a.snake-link:hover {
color: #FfFf54;
}
.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:black;
color:white;
}
.snake-panel-component {
position: absolute;
font-family: Verdana, arial, helvetica, sans-serif;
font-size: 14px;
color: #ffffff;
text-align: center;
background-color: #FC5454;
padding: 8px;
margin: 0px;
}
.snake-snakebody-block {
margin: 0px;
padding: 0px;
background-color: #FF0000;
position: absolute;
border: 0px solid #000080;
background-repeat: no-repeat;
}
.snake-snakebody-alive {
background-image: url('./images/snakeblock.png');
}
.snake-snakebody-dead {
background-image: url('./images/deadblock.png');
}
.snake-food-block {
margin: 0px;
padding: 0px;
background-color: #FF0000;
border: 0px solid #000080;
position: absolute;
}
.snake-playing-field {
margin: 0px;
padding: 0px;
position: absolute;
background-color: #0000A8;
border: 0px solid #0000A8;
}
.snake-game-container {
margin: 0px;
padding: 0px;
border-width: 0px;
border-style: none;
zoom: 1;
background-color: #FC5454;
position: relative;
}
.snake-welcome-dialog {
padding: 8px;
margin: 0px;
background-color: #000000;
color: #ffffff;
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: #000000;
color: #ffffff;
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;
}
<!DOCTYPE html>
<!--<html manifest="snake.appcache">-->
<head>
<!--
JavaScript Snake
By Patrick Gillespie
http://patorjk.com/games/snake
Source code is available here: https://github.com/patorjk/JavaScript-Snake
-->
<title>JavaScript Snake</title>
<link rel=stylesheet id=style type=text/css href=./css/main-snake.css />
<button onclick=getTheme()>Click to use this theme.</button>
<select id="select">
<option>Dark Theme</option>
<option>Revert To Original</option>
</select>
<div id="mode-wrapper">Select which mode you would like to play in.<br /><button id="Easy">Easy</button><br /><button id="Medium">Medium</button><br /><button id="Difficult">Difficult</button></div>
<button id="high-score">Get your current high score for this game.</button>
<script>
function getTheme () {
function changeTheme (Theme) {
document.getElementById('style').setAttribute('href', Theme);
}
var index = document.getElementById("select").selectedIndex;
switch (index) {
case 0:
changeTheme('css/dark-snake.css');
break;
case 1: changeTheme('css/main-snake.css');
}
}
if (navigator.onLine && window.location.hostname === 'patorjk.com') {
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-3312460-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
}
</script>
</head>
<body>
<div id="game-area" tabindex="0">
</div>
<script type="text/javascript" src="./js/snake.js"></script>
<script type="text/javascript">
var mySnakeBoard = new SNAKE.Board( {
boardContainer: "game-area",
fullScreen: true
});
</script>
</body>
</html>