Add commands for autoplay and cheat
parent
9a9f52185e
commit
75604d6f0d
35
main.py
35
main.py
|
@ -5,14 +5,12 @@ import random
|
||||||
import pickle
|
import pickle
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
AUTOPLAY = False
|
|
||||||
|
|
||||||
|
|
||||||
class GameScreen(view.PygView):
|
class GameScreen(view.PygView):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, autoplay=False, view_all_cards=False, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.table = players.Table(0, 0, self.width, self.height, (0, 32, 0), autoplay=AUTOPLAY)
|
self.table = players.Table(0, 0, self.width, self.height, (0, 32, 0),
|
||||||
|
autoplay=autoplay, view_all_cards=view_all_cards)
|
||||||
self.table.update_table.connect(self.draw_table)
|
self.table.update_table.connect(self.draw_table)
|
||||||
self.draw_table()
|
self.draw_table()
|
||||||
|
|
||||||
|
@ -65,19 +63,32 @@ class GameScreen(view.PygView):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
AUTOPLAY = False
|
||||||
|
VIEW_ALL_CARDS = False
|
||||||
|
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
if sys.argv[1] == "--seed":
|
prev_command = ""
|
||||||
with open(sys.argv[2], 'rb') as f:
|
for command in sys.argv[1:]:
|
||||||
# The protocol version used is detected automatically, so we do not
|
if prev_command == "--seed" or prev_command == "-s":
|
||||||
# have to specify it.
|
try:
|
||||||
rng_state = pickle.load(f)
|
with open(command, 'rb') as f:
|
||||||
random.setstate(rng_state)
|
# The protocol version used is detected automatically, so we do not
|
||||||
|
# have to specify it.
|
||||||
|
rng_state = pickle.load(f)
|
||||||
|
random.setstate(rng_state)
|
||||||
|
except:
|
||||||
|
print("RNG File not Found")
|
||||||
|
if command == "--view-all" or command == "-va":
|
||||||
|
VIEW_ALL_CARDS = True
|
||||||
|
if command == "--auto" or command == "-a":
|
||||||
|
AUTOPLAY = True
|
||||||
|
prev_command = command
|
||||||
|
|
||||||
rng_state = random.getstate()
|
rng_state = random.getstate()
|
||||||
with open('last_game_rng.rng', 'wb') as f:
|
with open('last_game_rng.rng', 'wb') as f:
|
||||||
pickle.dump(rng_state, f)
|
pickle.dump(rng_state, f)
|
||||||
|
|
||||||
main_view = GameScreen(800, 600, clear_colour=(255, 0, 0))
|
main_view = GameScreen(800, 600, clear_colour=(255, 0, 0),
|
||||||
|
autoplay=AUTOPLAY, view_all_cards=VIEW_ALL_CARDS)
|
||||||
|
|
||||||
main_view.run()
|
main_view.run()
|
|
@ -14,7 +14,7 @@ STARTING_HAND = 13
|
||||||
HIGHEST_CARD = 414
|
HIGHEST_CARD = 414
|
||||||
LOWEST_CARD = 102
|
LOWEST_CARD = 102
|
||||||
VIEW_TRANSPARENT = False
|
VIEW_TRANSPARENT = False
|
||||||
VIEW_ALL_CARDS = False
|
|
||||||
|
|
||||||
class GameState(Enum):
|
class GameState(Enum):
|
||||||
DEALING = 0
|
DEALING = 0
|
||||||
|
@ -67,7 +67,7 @@ class Table:
|
||||||
"""
|
"""
|
||||||
update_table = Signal()
|
update_table = Signal()
|
||||||
|
|
||||||
def __init__(self, x, y, width, height, clear_colour, autoplay=False):
|
def __init__(self, x, y, width, height, clear_colour, autoplay=False, view_all_cards=False):
|
||||||
# TODO: Reduce the amount of update_table call
|
# TODO: Reduce the amount of update_table call
|
||||||
self.x = x
|
self.x = x
|
||||||
self.y = y
|
self.y = y
|
||||||
|
@ -148,7 +148,7 @@ class Table:
|
||||||
spacing = v_spacing
|
spacing = v_spacing
|
||||||
|
|
||||||
reveal_mode = cards.DeckReveal.HIDE_ALL
|
reveal_mode = cards.DeckReveal.HIDE_ALL
|
||||||
if i == 0 or VIEW_ALL_CARDS:
|
if i == 0 or view_all_cards:
|
||||||
reveal_mode = cards.DeckReveal.SHOW_ALL
|
reveal_mode = cards.DeckReveal.SHOW_ALL
|
||||||
self.players.append(Player(playerx[i], playery[i],
|
self.players.append(Player(playerx[i], playery[i],
|
||||||
l_deck, w_deck,
|
l_deck, w_deck,
|
||||||
|
|
Loading…
Reference in New Issue