PEP8 checking

master
En Yi 2019-06-04 11:29:14 +01:00
parent 91dd14b701
commit e74c6125a5
1 changed files with 54 additions and 57 deletions

View File

@ -22,11 +22,13 @@ class GameState(Enum):
PLAYING = 3 PLAYING = 3
ENDING = 4 ENDING = 4
class PlayerRole(Enum): class PlayerRole(Enum):
UNKNOWN = 0 UNKNOWN = 0
ATTACKER = 1 ATTACKER = 1
DEFENDER = 2 DEFENDER = 2
class Table: class Table:
""" """
A Table is the place where all actions takes place. It is essentially a FSM, doing different A Table is the place where all actions takes place. It is essentially a FSM, doing different
@ -91,7 +93,8 @@ class Table:
w_deck = min(self.height, self.width) * 0.15 w_deck = min(self.height, self.width) * 0.15
l_deck = min(self.width, self.height) * 0.7 l_deck = min(self.width, self.height) * 0.7
self.discard_deck = cards.prepare_playing_cards(int(w_deck), int(w_deck)) # This is not a deck as it will never be drawn # This is not a deck as it will never be drawn
self.discard_deck = cards.prepare_playing_cards(int(w_deck), int(w_deck))
playerx = ((self.width - l_deck)//2, playerx = ((self.width - l_deck)//2,
0, 0,
@ -104,17 +107,6 @@ class Table:
spacing = 20 spacing = 20
for i in range(4):
vert = i % 2 == 1
self.players.append(Player(playerx[i], playery[i],
l_deck, w_deck,
spacing, vert_orientation=vert,
deck_reveal=cards.DeckReveal.HIDE_ALL))
self.players[i].connect_to_table(self.table_status)
if i>0:
self.players[i].add_ai(ai.RandomAI(self.table_status))
playfield_margins = 10 playfield_margins = 10
margins_with_w_deck = w_deck + playfield_margins margins_with_w_deck = w_deck + playfield_margins
playfield_x = margins_with_w_deck playfield_x = margins_with_w_deck
@ -133,20 +125,28 @@ class Table:
stats_width = 100 stats_width = 100
self.stats_height = 100 self.stats_height = 100
self.player_stats_x = ((self.width - l_deck) // 2, stats_spacing = 10
w_deck, self.player_stats_x = (playdeckx[0] - stats_width - stats_spacing,
(self.width + l_deck) // 2 - stats_width, playdeckx[1],
self.width - w_deck - stats_width) playdeckx[2] + w_deck + stats_spacing,
self.player_stats_y = ((self.height - w_deck - self.stats_height), playdeckx[3])
w_deck, self.player_stats_y = (playdecky[0] + w_deck - self.stats_height,
w_deck, playdecky[1] - self.stats_height - stats_spacing,
self.height - w_deck - self.stats_height) playdecky[2],
playdecky[3] + w_deck + stats_spacing)
self.player_stats = [[], [], [], []] self.player_stats = [[], [], [], []]
for i in range(4): for i in range(4):
vert = i % 2 == 1
self.players.append(Player(playerx[i], playery[i],
l_deck, w_deck,
spacing, vert_orientation=vert,
deck_reveal=cards.DeckReveal.HIDE_ALL))
self.players[i].connect_to_table(self.table_status)
if i > 0:
self.players[i].add_ai(ai.RandomAI(self.table_status))
self.players_playzone.append(cards.Deck(playdeckx[i], playdecky[i], self.players_playzone.append(cards.Deck(playdeckx[i], playdecky[i],
w_deck, w_deck, 0)) w_deck, w_deck, 0))
for j in range(3): for j in range(3):
@ -160,15 +160,12 @@ class Table:
self.announcer_y = playfield_y + announcer_spacing self.announcer_y = playfield_y + announcer_spacing
self.announcer_width = playfield_width - 2 * announcer_spacing self.announcer_width = playfield_width - 2 * announcer_spacing
self.announcer_height = playfield_height - 2 * announcer_spacing self.announcer_height = playfield_height - 2 * announcer_spacing
#self.announcer = pygame.Surface((announcer_width, self.announcer_height), pygame.SRCALPHA)
self.announcer_line = [] self.announcer_line = []
for i in range(3): for i in range(3):
surf = pygame.Surface((self.announcer_width, self.announcer_height/3), pygame.SRCALPHA) surf = pygame.Surface((self.announcer_width, self.announcer_height/3), pygame.SRCALPHA)
self.announcer_line.append(surf) self.announcer_line.append(surf)
self.write_message("Press P to play!")
#self.write_message("Testing....")
self.ongoing = False self.ongoing = False
@ -176,6 +173,8 @@ class Table:
""" """
Write a message into the center board surface (announcer) Write a message into the center board surface (announcer)
:param text: String to be displayed on the center board :param text: String to be displayed on the center board
:param delay_time: How much delay to put once the string is display
:param line: Which line of the announcer to write to
:return: None :return: None
""" """
print(text) print(text)
@ -201,8 +200,7 @@ class Table:
What takes place in the state should be in a function. What takes place in the state should be in a function.
:return: None :return: None
""" """
# TODO: slow down the game a bit using sleep # TODO: Adjust the timing of sleep
#while(True):
if self.game_state == GameState.DEALING: if self.game_state == GameState.DEALING:
self.shuffle_and_deal() self.shuffle_and_deal()
self.write_message("Shuffle Complete!") self.write_message("Shuffle Complete!")
@ -354,7 +352,6 @@ class Table:
self.write_message("Partner Revealed!", delay_time=1) self.write_message("Partner Revealed!", delay_time=1)
self.update_table.emit() self.update_table.emit()
#time.sleep(1)
# Once all player played, find out who wins # Once all player played, find out who wins
card_suits = [card.suit() for card in self.table_status["played cards"]] card_suits = [card.suit() for card in self.table_status["played cards"]]
card_nums = [card.number() for card in self.table_status["played cards"]] card_nums = [card.number() for card in self.table_status["played cards"]]
@ -381,9 +378,10 @@ class Table:
self.table_status['leading player'] = winning_player self.table_status['leading player'] = winning_player
self.table_status['round history'].append(copy.copy(self.table_status["played cards"])) self.table_status['round history'].append(copy.copy(self.table_status["played cards"]))
self.write_message("Defender:{0:d}, Attacker:{1:d}\n".format(self.table_status['defender']['wins'], self.write_message("Defender:{0:d}, Attacker:{1:d}\n".format(self.table_status['defender']['wins'],
self.table_status['attacker']['wins']), line=2) self.table_status['attacker']['wins']),
line=2)
# TODO: Add function to reflect the score on the screen # TODO: Add function to reflect the score on the screen. Kinda added
self.update_table.emit() self.update_table.emit()
@ -582,7 +580,6 @@ class Player(cards.Deck):
return True return True
class MainPlayer(cards.PlayerDeck): class MainPlayer(cards.PlayerDeck):
def __init__(self, *args, ai_component=None, **kwargs): def __init__(self, *args, ai_component=None, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
@ -605,6 +602,7 @@ class MainPlayer(cards.PlayerDeck):
def check_for_valid_moves(self): def check_for_valid_moves(self):
pass pass
class TestView(view.PygView): class TestView(view.PygView):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -635,7 +633,7 @@ class TestView(view.PygView):
print('add cards') print('add cards')
pass pass
milliseconds = self.clock.tick(self.fps) # milliseconds = self.clock.tick(self.fps)
# self.playtime += milliseconds / 1000.0 # self.playtime += milliseconds / 1000.0
# self.draw_function() # self.draw_function()
@ -643,7 +641,6 @@ class TestView(view.PygView):
pygame.quit() pygame.quit()
if __name__ == '__main__': if __name__ == '__main__':
test_view = TestView(900, 600, clear_colour=(0, 0, 0)) test_view = TestView(900, 600, clear_colour=(0, 0, 0))
test_view.run() test_view.run()