def helpscreen(self): comm = self.screen comm.reset() comm.parse('1510w text table help screen') comm.parse('2010y text press any key to continue ...') comm.go() gg.getch() return False
def translate_parameter(self, parameter): def isnum(t): for i in range(len(t)): o, a, z = ord(t[i]), ord('0'), ord('9') if o < a or o > z: return False return True def istext(what): t = what.upper() for i in range(len(t)): o, a, z = ord(t[i]), ord('A'), ord('Z') if o < a or o > z: return False return True p = parameter if p == 'True': return True if p == 'False': return False if isnum(p): return int(p) if istext(p): return p print('\n\nSomething wrong in glist.py.translate_parameter():' + str(type(p))) gg.getch() return None
def aditional_initialisation(self): # setting starting type and ownership of fields on battlefield for i in range(15): if i < 3: terrain = gg.FOREST elif i < 6: terrain = gg.RIVER elif i < 9: terrain = gg.PLAIN elif i < 12: terrain = gg.BASE_H elif i < 15: terrain = gg.BASE_A self.fields[i] = Field(i, self.territory_at_start[i // 3][i % 3], terrain) # load the definition of all cards self.all_existing_cards = [] all_lines = [] f = open('./data/cards', 'r') for line in f: if len(line.strip()) == 0 or line[0] == '#': continue self.all_existing_cards.append(Card(0, gg.AWAY, line)) all_lines.append(line) f.close() # all_existing_cards now contains exactly what one would suppose it does # help method def include_card(card_id, player, textline): switch = False for one in range(len(self.all_existing_cards)): if self.all_existing_cards[one].get_name() == textline: switch = True self.list_of_all_cards_in_game.append( Card(card_id, player, all_lines[one])) return switch # loading the first deck card_id, first, second = 0, open(self.homedeck, 'r'), open(self.awaydeck, 'r') for line in first: if len(line.strip()) == 0 or line[0] == '#': continue else: if include_card(card_id, gg.HOME, line.strip()): self.player_home.add_card_into_library(card_id) card_id += 1 else: print('\n\nWrong card name:', '|' + line.strip() + '|', '\n') gg.getch() # loading the second deck for line in second: if len(line.strip()) == 0 or line[0] == '#': continue else: if include_card(card_id, gg.AWAY, line.strip()): self.player_away.add_card_into_library(card_id) card_id += 1 else: print('\n\nWrong card name:', '|' + line.strip() + '|', '\n') gg.getch() first.close() second.close() # both players have library full of integers # those integers are unique card-ids. the usage would be for example: # self.list_of_all_cards_in_game[self.player_away.library.draw_a_card()].get_name() # very useful debug-print print('\nall_existing_cards:') for one in self.all_existing_cards: print('|' + one.get_name() + '|') print('\nlist_of_all_cards_in_game:') for a in self.list_of_all_cards_in_game: print(a.get_owner(), a.identity(), a.get_name()) if a.get_type() == gg.SQUAD: (a.get_attack(), a.get_defense(), a.get_shooting()) print('\nBEFORE DRAWING THE CARDS:') print('\nfirst library:\nlength = ', self.player_home.library.length()) print(self.player_home.library.get()) print('\nsecond library:\nlength = ', self.player_away.library.length()) print(self.player_away.library.get()) print('\nboth players hand &grave:') print(self.player_home.hand.get(), self.player_away.hand.get(), self.player_home.grave.get(), self.player_away.grave.get()) # end of very useful debug-print # 7 cards for both players #for a in range(7): self.player_home.draw_card(); self.player_away.draw_card() #for i in (0, 20, 25, 35, 42, 44, 59): self.player_home.draw_card(i) for i in (0, 1, 2, 3, 4, 5, 6): self.player_home.draw_card(i) #for i in (62, 68, 75, 84, 90, 118, 80): self.player_away.draw_card(i) for i in (60, 61, 62, 63, 64, 65, 66): self.player_away.draw_card(i) # another debug print. from here... print('\nAFTER DRAWING THE CARDS:') print('\nfirst library:\nlength = ', self.player_home.library.length()) print(self.player_home.library.get()) print('\nsecond library:\nlength = ', self.player_away.library.length()) print(self.player_away.library.get()) print('\nboth players hands:') print( str(self.player_home.hand.get()) + '\n' + str(self.player_away.hand.get())) print('\n&graves:') print( str(self.player_home.grave.get()) + '\n' + str(self.player_away.grave.get())) # ... to here #gg.getch() ## ## ## UNHASH PREVIOUS LINE TO READ THE DEBUG PRINTS ## ## ## return True
def get_screen_exits(self, key): if key == '___Start': exits = {gg.ALL: '___Game'} if key == '___Game': exits = { gg.ENTE: '___Deckmaking', gg.KEY3: 'Switch_bf_view', gg.ESC: '___Quit' } if key == '___Fight': exits = {gg.ALL: '___Other_player_turn', gg.DONT_PAUSE: True} if key == '___Other_player_turn': exits = {gg.ALL: '___Game'} if key == '___Deckmaking': exits = {gg.ALL: '___Game', gg.DONT_PAUSE: True} if key == '___Info_screen': exits = {gg.ESC: '___Quit', gg.KEY1: '___Game', gg.ALL: '___Game'} if key == '___Message_log': exits = {gg.ESC: '___Quit', gg.KEY1: '___Game', gg.ALL: '___Game'} if key == '___Quit': exits = {gg.ALL: '___Quit_for_real'} if key == '___Hand_right': exits = { gg.KEY3: '___Game', gg.KEY2: '__Hand_right_buildings', gg.ESC: '___Game' } if key == '___Hand_left': exits = { gg.KEY3: '___Game', gg.KEY2: '__Hand_left_buildings', gg.ESC: '___Game' } if key == '__Hand_right_buildings': exits = { gg.KEY3: '___Game', gg.KEY2: '__Hand_right_landsearch', gg.ESC: '___Game' } if key == '__Hand_left_buildings': exits = { gg.KEY3: '___Game', gg.KEY2: '__Hand_left_landsearch', gg.ESC: '___Game' } if key == '__Hand_right_landsearch': exits = { gg.KEY3: '___Game', gg.KEY2: '___Hand_right', gg.ESC: '___Game' } if key == '__Hand_left_landsearch': exits = { gg.KEY3: '___Game', gg.KEY2: '___Hand_left', gg.ESC: '___Game' } #if key == 'Movement': exits = {gg.ALL: '___Game', gg.DONT_PAUSE: True} if key == 'invitation': exits = {gg.ALL: '<--'} if key == 'ridiculous': exits = {gg.ALL: '<--'} if key == 'no_visible_units': exits = {gg.ALL: '<--'} if key == 'allgangTablEscreen': exits = {gg.ALL: '<--', gg.DONT_PAUSE: True} if key == 'table': exits = {gg.ALL: '<--', gg.DONT_PAUSE: True} if key == 'table_shifted': exits = {gg.ALL: '<--', gg.DONT_PAUSE: True} if key == 'command_the_gang': exits = {gg.ALL: '<--', gg.DONT_PAUSE: True} if key == 'spellcasting': exits = {gg.ALL: '<--', gg.DONT_PAUSE: True} if key == 'Switch_bf_view': exits = {gg.ALL: '___Game', gg.DONT_PAUSE: True} if key == '___Quit_for_real': exits = {gg.DONT_PAUSE: True, gg.ALL: '<--'} try: return exits except UnboundLocalError: print('\n\n\nParser.get_screen_exits(): wrong key: {' + key + '}\n\n\n') gg.getch() return False
def get_players_colors(self, key = '1234'): ret = [] if '1' in key: ret.append(self.home_player_color1) if '2' in key: ret.append(self.home_player_color2) if '3' in key: ret.append(self.away_player_color1) if '4' in key: ret.append(self.away_player_color2) if not len(ret): print("\n\nSomething is wrong in Signal.get_players_colors()\n\n"); gg.getch(); return False return ret[0] if len(ret) == 1 else ret
def initialisation(self, decks = ''): self.table_color = gg.GRAY self.home_player_color1 = gg.RED self.home_player_color2 = gg.VIOLET self.away_player_color1 = gg.LBLUE self.away_player_color2 = gg.BLUE with open('./data/config', 'r') as f: for line in f: if 'deck_home' in line: homedeck = './decks/' + line[line.index('=') +1:].strip() if 'deck_away' in line: awaydeck = './decks/' + line[line.index('=') +1:].strip() try: a = awaydeck; a = homedeck except NameError: print('\n\n\nONE OF THE PLAYERS HAVE NOT HIS DECK SET\n\nyou can fix it by editing data/config\n'); gg.getch(); return False self.homedeck, self.awaydeck = homedeck, awaydeck return True
def get_player_battlefield_cursor(self): if self.get_whos_on_turn() == gg.HOME: x = self.home_player_battlefield_cursor_position; return x elif self.get_whos_on_turn() == gg.AWAY: x = self.away_player_battlefield_cursor_position; return x else: print('\n\ngamestate.py.Signal.get_player_battlefield_cursor(): game dont know whos on turn\n'); gg.getch() return False
def set_player_battlefield_cursor(self, cursor_value = -1): c = self.get_cursor() if cursor_value == -1 else cursor_value if self.get_whos_on_turn() == gg.HOME: self.home_player_battlefield_cursor_position = c elif self.get_whos_on_turn() == gg.AWAY: self.away_player_battlefield_cursor_position = c else: print('\n\ngamestate.py.Signal.set_player_battlefield_cursor(): game dont know whos on turn\n'); gg.getch(); return False return True