Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fixed places in gamestats; end game requires only one click/key to re…

…turn to main menu.
  • Loading branch information...
commit d313d65b7ab5dbb05436249cc3eb1b6d00023cfd 1 parent ef0acb2
Mike McConnell authored

Showing 1 changed file with 121 additions and 81 deletions. Show diff stats Hide diff stats

  1. +121 81 snakey_party.py
202 snakey_party.py
... ... @@ -1,5 +1,8 @@
1 1 #!/usr/bin/env python
2   -# a snakey clone using pygame
  2 +# A Snakey clone made with Pygame.
  3 +# Includes various fruits with different effects in regards to score,
  4 +# snake size, and other in-game effects.
  5 +# Includes various Snake AIs and game modes (Arcade, Duel, Party).
3 6
4 7 import random, pygame, sys
5 8 from pygame.locals import *
@@ -10,11 +13,11 @@
10 13 MIN_FPS = 3
11 14 MAX_FPS = 60
12 15 CELLSIZE = 20
13   -BUFFER = CELLSIZE * 1 # number of cells to exclude from grid height; displays in-game info
  16 +TOP_BUFFER = CELLSIZE * 1 # displays in-game info
14 17 assert WINDOWWIDTH % CELLSIZE == 0, "Window width must be a multiple of cell size."
15   -assert (WINDOWHEIGHT - BUFFER) % CELLSIZE == 0, "Window height must be a multiple of cell size."
  18 +assert (WINDOWHEIGHT - TOP_BUFFER) % CELLSIZE == 0, "Window height must be a multiple of cell size."
16 19 CELLWIDTH = int(WINDOWWIDTH / CELLSIZE)
17   -CELLHEIGHT = int((WINDOWHEIGHT - BUFFER) / CELLSIZE)
  20 +CELLHEIGHT = int((WINDOWHEIGHT - TOP_BUFFER) / CELLSIZE)
18 21
19 22 # colors - (R G B)
20 23 WHITE = (255, 255, 255)
@@ -42,10 +45,10 @@
42 45 PURPLE = (142, 56, 142)
43 46 MAROON = (255, 52, 179)
44 47 BACKGROUNDCOLOR = BLACK
45   -BUTTON_COLOR = GREEN
46   -BUTTON_TEXT = DARKGRAY
47   -BUTTON_COLOR_SELECTED = COBALTGREEN
48   -BUTTON_TEXT_SELECTED = GOLDENROD
  48 +BUTTONCLR = GREEN
  49 +BUTTONTXT = DARKGRAY
  50 +BUTTONCLR_SELECTED = COBALTGREEN
  51 +BUTTONTXT_SL = GOLDENROD
49 52 MESSAGE_COLOR = GREEN
50 53
51 54 # for consistency in direction types
@@ -104,7 +107,7 @@ def __init__(self, n=SNAKEY, c=False, sc=GREEN, sb=COBALTGREEN):
104 107 self.alive = True
105 108
106 109 if c == False:
107   - self.coords = getStartPosition(1)
  110 + self.coords = getStartCoords(1)
108 111 else:
109 112 self.coords = c
110 113 # ensure snake length
@@ -124,7 +127,8 @@ def __init__(self, n=SNAKEY, c=False, sc=GREEN, sb=COBALTGREEN):
124 127 self.multipliertimer = 0
125 128 self.score = 0
126 129 self.place = False
127   - self.fruitEaten = {'apple':0, 'poison':0, 'orange':0, 'raspberry':0, 'blueberry':0, 'lemon':0}
  130 + self.fruitEaten = {'apple':0, 'poison':0, 'orange':0,
  131 + 'raspberry':0, 'blueberry':0, 'lemon':0}
128 132
129 133 def updateScore(self, points_input):
130 134 """
@@ -146,25 +150,43 @@ def updateMultiplier(self, multiplier_input, timer_input):
146 150 self.multiplier = multiplier_input
147 151 self.multipliertimer = self.multipliertimer + timer_input
148 152
149   - def getPlace(self, snakes):
  153 + def getPlace(self, totaldead, totalsnakes):
150 154 """
151   - Returns a string containing the death order of snake, based on number of snakes.
  155 + Returns a string containing the 'place' of a snake (longest lasting = 1st)
  156 + If game aborted early, will grant all living snakes '1st (alive)'
152 157 """
153   - if self.place == snakes:
154   - return '1st'
155   - elif self.place + 1 == snakes:
  158 + totalalive = totalsnakes - totaldead
  159 +
  160 + # snake not dead
  161 + if self.place == False:
  162 + return '1st (alive)'
  163 + # if not aborted early
  164 + elif totalalive == 0:
  165 + if self.place == totalsnakes:
  166 + return '1st'
  167 + elif self.place + 1 == totalsnakes:
  168 + return '2nd'
  169 + elif self.place + 2 == totalsnakes:
  170 + return '3rd'
  171 + else:
  172 + return 'last'
  173 + # aborted early; factor in living snakes
  174 + elif self.place == totalsnakes - totalalive:
156 175 return '2nd'
157   - elif self.place + 2 == snakes:
  176 + elif self.place + 1 == totalsnakes - totalalive:
158 177 return '3rd'
159 178 else:
160   - return 'Last'
  179 + return 'last'
161 180
162 181 def boundsCollision(self):
163 182 """
164 183 This returns True if snake (head) is ever out of grid parameters.
165 184 """
166 185 # check if out of bounds -- offset on on 'y' for buffer.
167   - if self.coords[HEAD]['x'] == -1 or self.coords[HEAD]['x'] == CELLWIDTH or self.coords[HEAD]['y'] == -1 + (BUFFER / CELLSIZE) or self.coords[HEAD]['y'] == CELLHEIGHT + (BUFFER / CELLSIZE):
  186 + if self.coords[HEAD]['x'] == -1 or \
  187 + self.coords[HEAD]['x'] == CELLWIDTH or \
  188 + self.coords[HEAD]['y'] == -1 + (TOP_BUFFER / CELLSIZE) or \
  189 + self.coords[HEAD]['y'] == CELLHEIGHT + (TOP_BUFFER / CELLSIZE):
168 190 return True
169 191 else:
170 192 return False
@@ -176,11 +198,13 @@ def snakeCollision(self, snake):
176 198 if self is snake:
177 199 # exclude head if checked against self
178 200 for snakebody in snake.coords[1:]:
179   - if snakebody['x'] == self.coords[HEAD]['x'] and snakebody['y'] == self.coords[HEAD]['y']:
  201 + if snakebody['x'] == self.coords[HEAD]['x'] and \
  202 + snakebody['y'] == self.coords[HEAD]['y']:
180 203 return True
181 204 else:
182 205 for snakebody in snake.coords:
183   - if snakebody['x'] == self.coords[HEAD]['x'] and snakebody['y'] == self.coords[HEAD]['y']:
  206 + if snakebody['x'] == self.coords[HEAD]['x'] and \
  207 + snakebody['y'] == self.coords[HEAD]['y']:
184 208 return True
185 209 # no collision
186 210 return False
@@ -189,7 +213,8 @@ def fruitCollision(self, fruit):
189 213 """
190 214 This returns True if snake (head) has collided with a given fruit.
191 215 """
192   - if self.coords[HEAD]['x'] == fruit.coords['x'] and self.coords[HEAD]['y'] == fruit.coords['y']:
  216 + if self.coords[HEAD]['x'] == fruit.coords['x'] and \
  217 + self.coords[HEAD]['y'] == fruit.coords['y']:
193 218 return True
194 219 else:
195 220 return False
@@ -219,13 +244,17 @@ def move(self):
219 244
220 245 # determine new head coordinates by direction
221 246 if self.direction == UP:
222   - newhead = {'x': self.coords[HEAD]['x'], 'y': self.coords[HEAD]['y'] - 1}
  247 + newhead = {'x': self.coords[HEAD]['x'],
  248 + 'y': self.coords[HEAD]['y'] - 1}
223 249 elif self.direction == DOWN:
224   - newhead = {'x': self.coords[HEAD]['x'], 'y': self.coords[HEAD]['y'] + 1}
  250 + newhead = {'x': self.coords[HEAD]['x'],
  251 + 'y': self.coords[HEAD]['y'] + 1}
225 252 elif self.direction == LEFT:
226   - newhead = {'x': self.coords[HEAD]['x'] - 1, 'y': self.coords[HEAD]['y']}
  253 + newhead = {'x': self.coords[HEAD]['x'] - 1,
  254 + 'y': self.coords[HEAD]['y']}
227 255 elif self.direction == RIGHT:
228   - newhead = {'x': self.coords[HEAD]['x'] + 1, 'y': self.coords[HEAD]['y']}
  256 + newhead = {'x': self.coords[HEAD]['x'] + 1,
  257 + 'y': self.coords[HEAD]['y']}
229 258
230 259 # insert new head segment
231 260 self.coords.insert(HEAD, newhead)
@@ -290,9 +319,9 @@ def updateDirection(self, grid):
290 319 nextDirection[LEFT] = nextDirection[LEFT] - 100
291 320 if x == CELLWIDTH - 1:
292 321 nextDirection[RIGHT] = nextDirection[RIGHT] - 100
293   - if y == (BUFFER / CELLSIZE):
  322 + if y == (TOP_BUFFER / CELLSIZE):
294 323 nextDirection[UP] = nextDirection[UP] - 100
295   - if y == CELLHEIGHT + (BUFFER / CELLSIZE) - 1:
  324 + if y == CELLHEIGHT + (TOP_BUFFER / CELLSIZE) - 1:
296 325 nextDirection[DOWN] = nextDirection[DOWN] - 100
297 326
298 327 # prefer same direction
@@ -335,8 +364,8 @@ def updateDirection(self, grid):
335 364 # update snake direction to direction with highest score
336 365 self.direction = max(nextDirection, key=nextDirection.get)
337 366
338   - def getPlace(self, snakes):
339   - return Snake.getPlace(self, snakes)
  367 + def getPlace(self, totaldead, totalsnakes):
  368 + return Snake.getPlace(self, totaldead, totalsnakes)
340 369
341 370 def updateScore(self, points_input):
342 371 Snake.updateScore(self, points_input)
@@ -368,7 +397,8 @@ def drawScore(self, position, allsnake):
368 397
369 398 class Fruit:
370 399 """
371   - Fruit class houses all information for fruit objects. Base class is not meant to be instantiated, but rather provide base methods shared by all fruit.
  400 + Fruit class houses all information for fruit objects.
  401 + Base class is not meant to be instantiated, but rather provide base methods shared by all fruit.
372 402 """
373 403 def __init__(self):
374 404 self.timer = 0
@@ -385,7 +415,7 @@ def getRandomLocation(self, allfruit, allsnake, game):
385 415 y = random.randint(int(CELLHEIGHT/5), CELLHEIGHT - int(CELLHEIGHT/5) - 1)
386 416 else:
387 417 x = random.randint(0, CELLWIDTH - 1)
388   - y = random.randint((BUFFER / CELLSIZE), CELLHEIGHT - 1)
  418 + y = random.randint((TOP_BUFFER / CELLSIZE), CELLHEIGHT - 1)
389 419 # ensure coordinates are not already occupied by fruit
390 420 for fruit in allfruit:
391 421 if fruit.coords['x'] == x and fruit.coords['y'] == y:
@@ -568,7 +598,8 @@ class GameData:
568 598 typeMax - the maximum value in determining bonus game type.
569 599 """
570 600 def __init__(self, st=20, bt=10, et=20, a=1, tmin=1, tmax=10):
571   - self.fruitEaten = {'apple':0, 'poison':0, 'orange':0, 'raspberry':0, 'blueberry':0, 'lemon':0}
  601 + self.fruitEaten = {'apple':0, 'poison':0, 'orange':0,
  602 + 'raspberry':0, 'blueberry':0, 'lemon':0}
572 603 self.speedTrigger = st
573 604 self.bonusTrigger = bt
574 605 self.easyTrigger = et
@@ -626,7 +657,8 @@ def updateBaseSpeed(self, value):
626 657 Updates basespeed by value inputted.
627 658 Checks against parameters
628 659 """
629   - if (self.basespeed + value > MIN_FPS) and (self.basespeed + value < MAX_FPS):
  660 + if (self.basespeed + value > MIN_FPS) and \
  661 + (self.basespeed + value < MAX_FPS):
630 662 self.basespeed = self.basespeed + value
631 663 self.currentspeed = self.basespeed
632 664
@@ -719,12 +751,12 @@ class Button():
719 751 """
720 752 def __init__(self, text, x, y):
721 753 self.text = text
722   - startSurf = BUTTONFONT.render(self.text, True, BUTTON_COLOR, BUTTON_TEXT)
  754 + startSurf = BUTTONFONT.render(self.text, True, BUTTONCLR, BUTTONTXT)
723 755 self.rect = startSurf.get_rect()
724 756 self.rect.center = x,y
725 757
726 758 def display(self):
727   - startSurf = BUTTONFONT.render(self.text, True, BUTTON_COLOR, BUTTON_TEXT)
  759 + startSurf = BUTTONFONT.render(self.text, True, BUTTONCLR, BUTTONTXT)
728 760 DISPLAYSURF.blit(startSurf, self.rect)
729 761
730 762 def pressed(self, mouse):
@@ -749,9 +781,9 @@ def __init__(self, text, x, y, a=False):
749 781
750 782 def display(self):
751 783 if self.active == True:
752   - startSurf = BUTTONFONT.render(self.text, True, BUTTON_COLOR_SELECTED, BUTTON_TEXT_SELECTED)
  784 + startSurf = BUTTONFONT.render(self.text, True, BUTTONCLR_SELECTED, BUTTONTXT_SL)
753 785 else:
754   - startSurf = BUTTONFONT.render(self.text, True, BUTTON_COLOR, BUTTON_TEXT)
  786 + startSurf = BUTTONFONT.render(self.text, True, BUTTONCLR, BUTTONTXT)
755 787
756 788 DISPLAYSURF.blit(startSurf, self.rect)
757 789
@@ -864,24 +896,24 @@ def runGame(game, players=[]):
864 896
865 897 # create snakes based on name. 'player' is set to false initially to handle input
866 898 player = False
867   - cur_position = 1
  899 + pos = 1
868 900 for snake in players:
869 901 if snake == SNAKEY:
870   - player = Snake(SNAKEY, getStartPosition(cur_position))
  902 + player = Snake(SNAKEY, getStartCoords(pos))
871 903 allsnake.append(player)
872   - cur_position = cur_position + 1
  904 + pos = pos + 1
873 905 elif snake == LINUS:
874   - linus = Opponent(LINUS, getStartPosition(cur_position), IVORY, COBALTGREEN, 5, 20)
  906 + linus = Opponent(LINUS, getStartCoords(pos), IVORY, COBALTGREEN, 5, 20)
875 907 allsnake.append(linus)
876   - cur_position = cur_position + 1
  908 + pos = pos + 1
877 909 elif snake == WIGGLES:
878   - wiggles = Opponent(WIGGLES, getStartPosition(cur_position), OLIVEGREEN, PURPLE, 20, 5)
  910 + wiggles = Opponent(WIGGLES, getStartCoords(pos), OLIVEGREEN, PURPLE, 20, 5)
879 911 allsnake.append(wiggles)
880   - cur_position = cur_position + 1
  912 + pos = pos + 1
881 913 elif snake == GIGGLES:
882   - giggles = Opponent(GIGGLES, getStartPosition(cur_position), PURPLE, EMERALDGREEN, 10, 10)
  914 + giggles = Opponent(GIGGLES, getStartCoords(pos), PURPLE, EMERALDGREEN, 10, 10)
883 915 allsnake.append(giggles)
884   - cur_position = cur_position + 1
  916 + pos = pos + 1
885 917
886 918 # create initial apple(s)
887 919 appleCounter = game.apples
@@ -909,7 +941,8 @@ def runGame(game, players=[]):
909 941 nextEvent = 0
910 942 stop = True
911 943 # check for exit/quit/debug keys
912   - if event.type == KEYDOWN and (event.key == K_ESCAPE or event.key == K_q):
  944 + if event.type == KEYDOWN and \
  945 + (event.key == K_ESCAPE or event.key == K_q):
913 946 terminate()
914 947 elif event.type == KEYDOWN and event.key == K_e:
915 948 showGameStats(allsnake)
@@ -918,15 +951,18 @@ def runGame(game, players=[]):
918 951 stop = True
919 952 debugPrintGrid(grid)
920 953 # if player is dead / does not exist - check for speed controls
921   - elif event.type == KEYDOWN and event.key == K_f and (player == False or player.alive == False):
  954 + elif event.type == KEYDOWN and event.key == K_f and \
  955 + (player == False or player.alive == False):
922 956 game.updateBaseSpeed(10)
923 957 game.updateCurrentSpeed(False, True)
924   - elif event.type == KEYDOWN and event.key == K_s and (player == False or player.alive == False):
  958 + elif event.type == KEYDOWN and event.key == K_s and \
  959 + (player == False or player.alive == False):
925 960 game.updateBaseSpeed(-10)
926 961 game.updateCurrentSpeed(False, True)
927 962
928 963 # if player exists - check for direction input
929   - if event.type == KEYDOWN and player != False and stop == False:
  964 + if event.type == KEYDOWN and \
  965 + player != False and stop == False:
930 966 if event.key == K_LEFT and player.direction != RIGHT:
931 967 player.direction = LEFT
932 968 stop = True
@@ -1050,8 +1086,8 @@ def runGame(game, players=[]):
1050 1086 a = Apple(allfruit, allsnake, game)
1051 1087 allfruit.append(a)
1052 1088 elif fruit.__class__ == Blueberry:
1053   - # update speed
1054   - game.slowtimer = game.slowtimer + game.currentspeed * 9 # add 9 seconds
  1089 + # update game frames to be 'slow' by 7 seconds
  1090 + game.slowtimer = game.slowtimer + game.currentspeed * 7
1055 1091 # remove fruit
1056 1092 allfruit.remove(fruit)
1057 1093
@@ -1106,9 +1142,12 @@ def runGame(game, players=[]):
1106 1142 position = position + 1
1107 1143 # if player is dead, print extra messages
1108 1144 if player == False or player.alive == False:
1109   - drawMessage('press (e) to end game early', WINDOWWIDTH / 2, WINDOWHEIGHT / 20 * 16)
1110   - drawMessage('press (f) to fast-forward game', WINDOWWIDTH / 2, WINDOWHEIGHT / 20 * 17)
1111   - drawMessage('press (s) to slow game', WINDOWWIDTH / 2, WINDOWHEIGHT / 20 * 18)
  1145 + endMessage = 'press (e) to end game early'
  1146 + fastMessage = 'press (f) to fast-forward game'
  1147 + slowMessage = 'press (s) to slow game'
  1148 + drawMessage(endMessage, WINDOWWIDTH / 2, WINDOWHEIGHT / 20 * 16)
  1149 + drawMessage(fastMessage, WINDOWWIDTH / 2, WINDOWHEIGHT / 20 * 17)
  1150 + drawMessage(slowMessage, WINDOWWIDTH / 2, WINDOWHEIGHT / 20 * 18)
1112 1151 pygame.display.update()
1113 1152 FPSCLOCK.tick(game.currentspeed)
1114 1153
@@ -1137,12 +1176,10 @@ def waitForInput():
1137 1176 elif event.type == KEYDOWN:
1138 1177 if event.key == K_ESCAPE or event.key == K_q:
1139 1178 terminate()
1140   - elif event.type == KEYDOWN:
1141   - pygame.event.get()
  1179 + else:
1142 1180 return
1143 1181 elif event.type == MOUSEBUTTONDOWN:
1144 1182 if pygame.mouse.get_pressed() != None:
1145   - pygame.event.get()
1146 1183 return
1147 1184
1148 1185
@@ -1150,7 +1187,7 @@ def showSelectPlayersScreen():
1150 1187 """
1151 1188 Blits player/opponent select onto screen. Returns selection as list.
1152 1189 """
1153   - playerbuttons = [] # not yet implemented
  1190 + playerbuttons = []
1154 1191 playersnakeybutton = SelectButton('(s)nakey', WINDOWWIDTH / 3, WINDOWHEIGHT * 2/7, True)
1155 1192 playerbuttons.append(playersnakeybutton)
1156 1193 playerlinusbutton = SelectButton('(l)inus', WINDOWWIDTH / 3, WINDOWHEIGHT * 3/7)
@@ -1160,7 +1197,7 @@ def showSelectPlayersScreen():
1160 1197 playergigglesbutton = SelectButton('(g)iggles', WINDOWWIDTH / 3, WINDOWHEIGHT * 5/7)
1161 1198 playerbuttons.append(playergigglesbutton)
1162 1199
1163   - opponentbuttons = [] # not yet implemented
  1200 + opponentbuttons = []
1164 1201 opponentlinusbutton = SelectButton('(l)inus', WINDOWWIDTH / 3 * 2, WINDOWHEIGHT * 3/7, True)
1165 1202 opponentbuttons.append(opponentlinusbutton)
1166 1203 opponentwigglesbutton = SelectButton('(w)iggles', WINDOWWIDTH / 3 * 2, WINDOWHEIGHT * 4/7)
@@ -1224,7 +1261,7 @@ def showSelectPlayersScreen():
1224 1261 elif opponentgigglesbutton.active:
1225 1262 final.append(GIGGLES)
1226 1263 return final
1227   -
  1264 +
1228 1265 elif event.type == KEYDOWN:
1229 1266 if event.key == K_s:
1230 1267 pygame.event.get()
@@ -1309,25 +1346,32 @@ def showGameStats(allsnake):
1309 1346 Displays game stats for all snakes at end of game.
1310 1347 Returns when any key pressed.
1311 1348 """
  1349 + totaldead = 0 #stil lneeds to be fixed
  1350 + for snake in allsnake:
  1351 + if snake.alive == False:
  1352 + totaldead = totaldead + 1
  1353 +
1312 1354 position = 1
1313 1355 for snake in allsnake:
1314   - drawMessage(snake.name, getPosition(position, allsnake), WINDOWHEIGHT / 20 * 3, snake.color)
  1356 + pos_x = getPosition(position, allsnake)
  1357 + pos_y = WINDOWHEIGHT / 20
  1358 + drawMessage(snake.name, pos_x, WINDOWHEIGHT / 20 * 3, snake.color)
1315 1359 if len(allsnake) != 1:
1316   - drawText('place:', snake.getPlace(len(allsnake)), getPosition(position, allsnake), WINDOWHEIGHT / 20 * 5, snake.color)
1317   - drawText('score:', snake.score, getPosition(position, allsnake), WINDOWHEIGHT / 20 * 6, snake.color)
1318   - drawText('apples:', snake.fruitEaten['apple'], getPosition(position, allsnake), WINDOWHEIGHT / 20 * 7, RED)
1319   - drawText('poison:', snake.fruitEaten['poison'], getPosition(position, allsnake), WINDOWHEIGHT / 20 * 8, GREEN)
1320   - drawText('oranges:', snake.fruitEaten['orange'], getPosition(position, allsnake), WINDOWHEIGHT / 20 * 9, ORANGE)
1321   - drawText('raspberries:', snake.fruitEaten['raspberry'], getPosition(position, allsnake), WINDOWHEIGHT / 20 * 10, PURPLE)
1322   - drawText('blueberries:', snake.fruitEaten['blueberry'], getPosition(position, allsnake), WINDOWHEIGHT / 20 * 11, BLUE)
  1360 + drawText('place:', snake.getPlace(totaldead, len(allsnake)), pos_x, pos_y * 5, snake.color)
  1361 + drawText('score:', snake.score, pos_x, pos_y * 6, snake.color)
  1362 + drawText('apples:', snake.fruitEaten['apple'], pos_x, pos_y * 7, RED)
  1363 + drawText('poison:', snake.fruitEaten['poison'], pos_x, pos_y * 8, GREEN)
  1364 + drawText('oranges:', snake.fruitEaten['orange'], pos_x, pos_y * 9, ORANGE)
  1365 + drawText('raspberries:', snake.fruitEaten['raspberry'], pos_x, pos_y * 10, PURPLE)
  1366 + drawText('blueberries:', snake.fruitEaten['blueberry'], pos_x, pos_y * 11, BLUE)
1323 1367 position = position + 1
1324 1368
1325   - drawMessage('Press any key.', WINDOWWIDTH / 2, WINDOWHEIGHT / 20 * 19, GOLDENROD)
  1369 + drawMessage('Press any key.', WINDOWWIDTH / 2, pos_y * 19, GOLDENROD)
1326 1370 pygame.display.update()
1327 1371 pygame.time.wait(300)
1328   - #checkForKeyPress() # clear out any key presses in the event queue
1329 1372 pygame.event.get() # clear event queue
1330 1373 showGameOverScreen()
  1374 + waitForInput()
1331 1375
1332 1376
1333 1377 def showGameOverScreen():
@@ -1341,13 +1385,9 @@ def showGameOverScreen():
1341 1385 gameOverRect.midtop = (WINDOWWIDTH / 2, WINDOWHEIGHT / 3 * 2)
1342 1386
1343 1387 DISPLAYSURF.blit(gameOverSurf, gameOverRect)
1344   - drawMessage('Press any key.', WINDOWWIDTH / 2, WINDOWHEIGHT / 20 * 19, GOLDENROD)
  1388 + #drawMessage('Press any key.', WINDOWWIDTH / 2, WINDOWHEIGHT / 20 * 19, GOLDENROD)
1345 1389 pygame.display.update()
1346   - pygame.time.wait(100)
1347   - pygame.event.get()
1348   - #checkForKeyPress() # clear out any key presses in the event queue
1349   -
1350   - waitForInput()
  1390 + #pygame.time.wait(100)
1351 1391
1352 1392
1353 1393 def getGrid(allsnake, allfruit):
@@ -1357,7 +1397,7 @@ def getGrid(allsnake, allfruit):
1357 1397 Used by AI when choosing best path.
1358 1398 """
1359 1399 # refresh grid, dictionary representation of playing board used by AI
1360   - grid = {(x,y):0 for x in range(CELLWIDTH) for y in range(CELLHEIGHT + (BUFFER / CELLSIZE))}
  1400 + grid = {(x,y):0 for x in range(CELLWIDTH) for y in range(CELLHEIGHT + (TOP_BUFFER / CELLSIZE))}
1361 1401
1362 1402 # add snakes to grid
1363 1403 for snake in allsnake:
@@ -1407,8 +1447,8 @@ def drawGrid():
1407 1447 Draws grid to screen.
1408 1448 """
1409 1449 for x in range(0, WINDOWWIDTH, CELLSIZE): # draw vertical lines
1410   - pygame.draw.line(DISPLAYSURF, DARKGRAY, (x, BUFFER), (x, WINDOWHEIGHT))
1411   - for y in range(BUFFER, WINDOWHEIGHT, CELLSIZE): # draw horizontal lines
  1450 + pygame.draw.line(DISPLAYSURF, DARKGRAY, (x, TOP_BUFFER), (x, WINDOWHEIGHT))
  1451 + for y in range(TOP_BUFFER, WINDOWHEIGHT, CELLSIZE): # draw horizontal lines
1412 1452 pygame.draw.line(DISPLAYSURF, DARKGRAY, (0, y), (WINDOWWIDTH, y))
1413 1453
1414 1454
@@ -1437,7 +1477,7 @@ def getPosition(position, allsnake):
1437 1477 return (WINDOWWIDTH - (float(position) / float(len(allsnake)) * WINDOWWIDTH))
1438 1478
1439 1479
1440   -def getStartPosition(pos=1):
  1480 +def getStartCoords(pos=1):
1441 1481 if pos == 1:
1442 1482 return [{'x':5, 'y':5},{'x':4, 'y':5},{'x':3, 'y':5}]
1443 1483 elif pos == 2:

0 comments on commit d313d65

Please sign in to comment.
Something went wrong with that request. Please try again.