Skip to content

Commit

Permalink
edit
Browse files Browse the repository at this point in the history
  • Loading branch information
Haz001 committed Jan 7, 2019
1 parent 8a51c5f commit 7c2065f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions hs.data
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
13
24 changes: 20 additions & 4 deletions snake-6.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@


class game:

class var:
class grid:
width = 16
Expand All @@ -38,6 +37,7 @@ class misc:
font = pygame.font.SysFont('Consolas', 15)
coloroffset = 4
class current:
highscore = 0
points = 0
deaths = 0
state = 0
Expand Down Expand Up @@ -84,7 +84,12 @@ class tail:


def setup():

file = open("hs.data",'r')
try:
game.var.current.highscore = int(file.read())
except:
game.var.current.highscore = 0
file.close()
game.var.screen.width = game.var.grid.width*game.var.grid.blockwidth
game.var.screen.height = game.var.grid.height*game.var.grid.blockwidth
if (game.var.screen.full):
Expand All @@ -99,15 +104,25 @@ def setup():
game.var.snake.tail.y = []
game.var.apple.place()
game.var.bomb.place()
game.var.current.points = 0
print("Screen: Setup")
print("done")
class fun:
def start():
game.var.setup()
game.fun.draw.screen()


def death():
game.var.snake.deaths+=1
game.fun.draw.string(game.var.py.screen,game.var.grid.blockwidth,game.var.grid.blockwidth,72,"Game over!\nScore: "+str(game.var.snake.length-4),(255,0,0))
if (game.var.current.highscore > game.var.current.points):
game.fun.draw.string(game.var.py.screen,game.var.grid.blockwidth,game.var.grid.blockwidth,50,"Game over!\nScore: "+str(game.var.current.points)+"\nHighScore: "+str(game.var.current.highscore),(255,0,0))
elif (game.var.current.highscore <= game.var.current.points):
game.fun.draw.string(game.var.py.screen,game.var.grid.blockwidth,game.var.grid.blockwidth,50,"Game over!\nNew HighScore!\nHighScore: "+str(game.var.current.points),(255,0,0))
game.var.current.highscore = game.var.current.points
file = open("hs.data",'w')
file.write(str(game.var.current.highscore))
file.close()

pygame.display.flip()
time.sleep(1.5)
Expand Down Expand Up @@ -230,6 +245,7 @@ def move(x,y):
# apple
if (game.var.snake.x == game.var.apple.x) and (game.var.snake.y == game.var.apple.y):
game.var.snake.length+=1
game.var.current.points+=1
game.var.apple.lvl+=1

game.var.apple.place()
Expand Down Expand Up @@ -292,7 +308,7 @@ def loop():
c=0
#snake.speed+=1
if not(game.var.snake.direction == 5):
pygame.display.set_caption("Snake!!!|Score: "+str(game.var.snake.length-4))
pygame.display.set_caption("Snake!!!|Score: "+str(game.var.current.points))
pygame.display.flip()
game.var.py.clock.tick(100)
try:
Expand Down

0 comments on commit 7c2065f

Please sign in to comment.