Advertisement
Guest User

Untitled

a guest
May 26th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. class Cell:
  2. color = 'black'
  3.  
  4. def update(self, game):
  5. return self
  6.  
  7. def on_bump(self, game):
  8. pass
  9.  
  10.  
  11. class SnakeCell(Cell):
  12. color = 'green'
  13.  
  14. def __init__(self, time_to_live):
  15. self.time_to_live = time_to_live
  16.  
  17. def update(self, game):
  18. if self.time_to_live == 1:
  19. return None
  20. return SnakeCell(self.time_to_live - 1)
  21.  
  22. def on_bump(self, game):
  23. game.is_dead = True
  24.  
  25.  
  26. class FoodCell(Cell):
  27. color = 'yellow'
  28.  
  29. def __init__(self):
  30. self.is_eaten = False
  31.  
  32. def on_bump(self, game):
  33. self.is_eaten = True
  34. game.snake.len += 1
  35. game.score += 1
  36. game.spawn_food()
  37.  
  38. def update(self, game):
  39. return None if self.is_eaten else self
  40.  
  41.  
  42. class FoodCell_poison(Cell):
  43. color = 'red'
  44.  
  45. def __init__(self):
  46. self.is_eaten = False
  47.  
  48. def on_bump(self, game):
  49. self.is_eaten = True
  50. game.snake.len -= 1
  51. if game.score != 0:
  52. game.score -= 1
  53. else:
  54. game.score = 0
  55. if game.snake.len == 0:
  56. game.is_dead = True
  57. else:
  58. game.spawn_food_poison()
  59.  
  60. def update(self, game):
  61. return None if self.is_eaten else self
  62.  
  63.  
  64. class DeathWallCell(Cell):
  65. color = 'grey'
  66.  
  67. def on_bump(self, game):
  68. game.is_dead = True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement