Advertisement
pigmansuper

Przykładowy kod widoku

Oct 18th, 2020
2,211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.14 KB | None | 0 0
  1. class ActionType:
  2.     def __init__(self, method):
  3.         self.method = method
  4.  
  5. class Action:
  6.     def __init__(self, desc, type):
  7.         self.desc = desc
  8.         self.type = type
  9.        
  10. class View:
  11.     def __init__(self, desc, actions):
  12.         self.desc = desc
  13.         self.actions = actions
  14.    
  15.     def showMe(self):
  16.         print(self.desc)
  17.         # normalnie bedziesz musial podzielic tablice action na rozpoznawanie czy ktos wpisal a-x czy 0-100, twoj wybor, ja teraz mam że cokolwiek ktoś wpisze to stanie się przekierowanie z pierwszej akcji
  18.         for action in self.actions:
  19.             print(action.desc)
  20.         input()
  21.         self.actions[0].type.method()
  22.  
  23. class Game:
  24.     def __init__(self, baza):
  25.         self.views = []
  26.         for view in baza['widoki']:
  27.             actions = []
  28.             for action in view['akcje']:
  29.                 actions.append(
  30.                     Action(
  31.                         action['opis'],
  32.                         self.generateActionTypeByDatabaseData(action['akcja'])
  33.                     )
  34.                 )
  35.             self.views.append(View(view['opis'], actions))
  36.  
  37.    
  38.     def generateActionTypeByDatabaseData(self, akcja):
  39.         if(akcja['typ'] == 'przekierowanie-widok'):
  40.             return ActionType(lambda: self.changeView(akcja['przekierowany-widok-id']))
  41.         else:
  42.             return None #TODO
  43.    
  44.     def changeView(self, id):
  45.         self.views[id].showMe()
  46.        
  47.     def start(self):
  48.         self.changeView(1)
  49.         # ja tutaj troche pokręciłem z tym id,bo id nie do końca jest numerem tablicy, więc uważaj!
  50.        
  51. gra = Game(BazaDanych)
  52. gra.start()
  53.  
  54. # OUTPUT
  55. # Jesteś w Phandalin i podchodzi do ciebie starsza kobieta. Mówi Ci, że nie ma zbyt wielu pieniędzy, ale potrzebuje pomocy poszukiwacza # przygód. Ma domek w lesie, który został napadnięty i przejęty przez orki. Jej udało się uciec, ale jej mały wnuk schował się w domku, # w szafie i jest uwięziony.
  56. # Oczywiście, że ci pomogę. Gdzie ten domek?
  57. # Spadaj!
  58. # INPUT
  59. # > test
  60. # OUTPUT
  61. # Zauważasz z oddali domek. Co robisz?
  62. # Skradam się
  63. # Walczę od razu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement