Advertisement
KirillMysnik

Untitled

May 19th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.03 KB | None | 0 0
  1. # I have a MapGame with abstract .spawn_players method, MapGame_FreeForAll(MapGame) and MapGame_TeamBased(MapGame)
  2.  
  3. class MapGame(BaseGame):
  4.     stage_groups = {
  5.         'game-start': ["spawn-players"],
  6.         'game-end': ["send-some-message", "destroy"],
  7.     }
  8.    
  9.     # I'll skip send-some-message and destroy stages as they're unrelated
  10.    
  11.     @stage('spawn-players')
  12.     def spawn_players(self):
  13.         raise NotImplementedError
  14.  
  15. class MapGame_FreeForAll(MapGame):
  16.     @stage('spawn-players')
  17.     def spawn_players(self):
  18.         spawnpoints = list(self.spawnpoints)
  19.         for player in self.players:
  20.             teleport_to_spawnpoint(spawnpoints.pop(0))
  21.  
  22.  
  23. class MapGame_TeamBased(MapGame):
  24.     @stage('spawn-players')
  25.     def spawn_players(self):
  26.         spawnpoints_team1 = list(self.spawnpoints_team1)
  27.         spawnpoints_team2 = list(self.spawnpoints_team2)
  28.  
  29.         for player in self.players_team1:
  30.             teleport_to_spawnpoint(spawnpoints_team1.pop(0))
  31.  
  32.         for player in self.players_team2:
  33.             teleport_to_spawnpoint(spawnpoints_team2.pop(0))
  34.  
  35.  
  36. # Then I have a SurvivalGame_FreeForAll and SurvivalGame_TeamBased that inherit from SurvivalGame
  37. class SurvivalGame_FreeForAll(SurvivalGame):
  38.     pass
  39.     # Some methods specific to SurvivalGame_FreeForAll
  40.  
  41. class SurvivalGame_TeamBased(SurvivalGame):
  42.     pass
  43.     # Some methods specific to SurvivalGame_TeamBased
  44.  
  45.  
  46. # And here goes SurvivalGame itself
  47. # Now to the funny part - survival games require setting damage hooks - that's another stage
  48. class SurvivalGame(??????????????):     # I'll skip inheritance for this class
  49.     stage_groups = {
  50.         'game-start': ["spawn-players", "setup-damage-hooks"]   # Note how game-start stage is altered,
  51.                                                                 # but the stage_groups dict still retains
  52.                                                                 # original "game-end" stage untouched
  53.     }
  54.     @stage('setup-damage-hooks')
  55.     def setup_damage_hooks(self):
  56.         for player in self.player:
  57.             setup_damage_hook(player)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement