本文整理汇总了Python中game_state.GameState类的典型用法代码示例。如果您正苦于以下问题:Python GameState类的具体用法?Python GameState怎么用?Python GameState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GameState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
class Game:
def __init__(self, slack_client):
self.slack_client = slack_client
self.game_state = GameState(slack_client)
self.invalid_handler = InvalidHandler(self.game_state)
def process(self, data):
# TODO: quit handler
try:
is_invalid = self.invalid_handler.is_invalid(data)
if is_invalid and not isinstance(self.game_state.handler, InvalidHandler):
self.game_state.interrupt_handler(self.invalid_handler)
self.invalid_handler.request_invalid_confirmation(data['user'])
else:
if self.game_state.handler:
self.game_state.handler.process(data)
except GameEndException:
self.__init__(self.slack_client)
def tick(self):
try:
if self.game_state.handler:
self.game_state.handler.tick()
except GameEndException:
self.__init__(self.slack_client)
示例2: __init__
def __init__(self, p, interactive=False, board_size=3, current_board=None):
''' (TippyGameState, str, int, list) -> NoneType
Initialize TippyGameState self with board_size '3x3'
Assume: '3x3' <= board_size is an str
p in {'p1', 'p2'}
'''
if interactive:
board_size = int(input('Board size? '))
GameState.__init__(self, p)
if not current_board: # if board is not created, create it
self.current_board = []
for x in range(board_size):
d = []
for y in range(board_size):
d.append('_ ')
self.current_board.append(d)
self.board_size = board_size
else:
self.current_board = deepcopy(current_board)
self.board_size = len(self.current_board)
# check if the game is over
self.over = self.winner(self.next_player) or self.winner(
self.opponent()) or self.possible_next_moves() == []
self.instructions = ('On your turn, you may put your symbol'
'on any empty position of the game board ')
示例3: __init__
def __init__(self, p, interactive=False, grid_num=None, _grid=None):
'''
(TippyState, str)-> NoneType
Initialize the class TippyState with grid_num as the size of the grid
to be played on to form a Tippy.
'''
if interactive:
start_grid_num = input('Maximum grid number which is equal '
'or greater than 3? ')
while not start_grid_num.isnumeric():
start_grid_num = input('Maximum grid number which is equal '
'or greater than 3? ')
grid_num = randint(3, int(start_grid_num))
GameState.__init__(self, p)
self.grid_num = grid_num
self.instructions = ('On your turn, you may place at any position '
'so long as the row number and column number '
'not greater than the grid number.')
self._grid = {}
if _grid is None:
for i in range(grid_num + 1):
for j in range(grid_num + 1):
if j == 0:
self._grid[(i, j)] = i
elif i == 0:
self._grid[(i, j)] = j
else:
self._grid[(i, j)] = ' '
else:
self._grid = _grid
self.over = not self.possible_next_moves()
示例4: Service
class Service(object):
"""
Handles the game logic.
"""
def __init__(self):
self.state = None
self.tick = 0
def new_game(self):
self.state = GameState()
def move(self, character_id, coordinates):
result = self.state.move_character(character_id, coordinates)
return result
def character_location(self, character_id):
return self.state.character_location(character_id)
def interact(self):
pass
def inc_tick(self):
self.state.progress()
self.tick += 1
def dispatch_command(self, command_obj):
if command_obj.id == CommandIds.MOVE:
result = self.move(command_obj.character_id, command_obj.coordinates)
return result
elif command_id == CommandIds.INTERACT:
pass
else:
pass
示例5: test_serialization
def test_serialization(self):
for s in self.SERIALIZATION_FIXTURES:
self.assertEqual(repr(GameState.from_string(s)), s, "Invalid deserialize & serialize transformation")
for _ in range(10):
game_state = GameStateFactory.build_with_creatures()
s = repr(game_state)
self.assertEqual(repr(GameState.from_string(s)), s, "Invalid deserialize & serialize transformation")
示例6: __init__
def __init__(self, p, interactive=False, board=[], turn=0):
'''(TippyGameState, str, bool, list of list of str, int) -> None Type
Initialize TippyGameState self with a empty board on the first turn
'''
GameState.__init__(self, p)
'''
Create a 2D board. ' ' means empty, 'x' means a x piece on the
board, 'o' means a o piece on the board
'''
self.board = deepcopy(board)
if interactive:
size = int(input('Enter board size. 3 or greater\n'))
while size < 3:
print('It has to be greater or equal to 3')
size = int(input('Enter board size. 3 or greater\n'))
self.board = [[TippyGameState.EMPTY] * size for i in range(size)]
if p == 'p1':
self.P1 = TippyGameState.PIECES[turn]
self.P2 = TippyGameState.PIECES[turn - 1]
else:
self.P2 = TippyGameState.PIECES[turn]
self.P1 = TippyGameState.PIECES[turn - 1]
self.turn = turn
self.over = self.game_over()
self.instructions = ('play to form a s-shaped or z-shaped tippy'
'\n'
'on your turn, you can choose a coordinate '
'on the board with no x or o piece on it')
示例7: main
def main():
# Initialise screen
pygame.init()
screen = pygame.display.set_mode(common.RESOLUTION, FULLSCREEN)
pygame.display.set_caption('Super Geek Fighter II Turbo')
# Start the camera
capture = cv.CaptureFromCAM(0)
background = pygame.image.load(common.BACKGROUND_IMAGE).convert()
background = pygame.transform.scale(background, common.RESOLUTION)
# calibrate the camera with the projection
calibration_state = CalibrationState(screen, capture)
transform_mat = calibration_state.run()
reference_img = calibration_state.make_background(background, transform_mat)
music_started = False
try:
while True:
tutorial_state = TutorialState(screen, background, capture, reference_img, transform_mat)
tutorial_state.run()
players_height = [tutorial_state.player1_height, tutorial_state.player2_height]
total_win = False
wins = {'Player 1': 0, 'Player 2': 0}
pgmusic.start_music_thread()
music_started = True
while not total_win:
countdown_state = CountdownState(screen, background, capture, reference_img, transform_mat)
countdown_state.run()
game_state = GameState(screen, background, capture, reference_img, transform_mat, wins, players_height)
game_state.run()
winning_player = None
if game_state.player2.dead:
winning_player = game_state.player1
winning_player.name = 'Player 1'
if game_state.player1.dead:
winning_player = game_state.player2
winning_player.name = 'Player 2'
# TODO: What if both die at the same time?
if winning_player:
wins[winning_player.name] += 1
winning_state = WinningState(screen, background, capture, reference_img, transform_mat, wins, winning_player, game_state.sprites)
winning_state.run()
total_win = winning_state.big_win
pgmusic.fadeout()
music_started = False
except InterruptedException:
print 'Bye bye!'
finally:
if music_started:
pgmusic.fadeout()
示例8: test_equality
def test_equality(self):
game_state1 = GameStateFactory.build_with_creatures(9)
game_state2 = GameStateFactory.build_with_creatures(8)
self.assertNotEqual(game_state1, game_state2)
game_state2.battleground = game_state1.battleground
self.assertEqual(game_state1, game_state2)
game_state1 = GameState.from_string("20/20 (1/0): vs 1/2")
game_state2 = GameState.from_string("20/20 (1/0): vs 1/2")
self.assertEqual(game_state1, game_state2)
示例9: __init__
def __init__(self):
GameState.__init__(self, GameState.STATE_MENU, GameState.STATE_LOAD)
self.player_num = 1
self.background = None
self.title = None
self.title_rect = None
self.init_background()
self.text_helper = TextHelper()
item_objects_ss = SpriteSheet("data/item_objects.png")
self.selector_frame = item_objects_ss.get_image(coords.TITLE_SELECTOR, constants.IMG_MULTIPLIER)
示例10: play_whist
def play_whist(record_game):
players, partners = get_players_and_partners()
game_state = GameState(players, partners)
dealer_index = 0
while not game_state.is_game_over():
play_deal(game_state, dealer_index)
dealer_index = (dealer_index + 1) % NUM_PLAYERS
print 'The game is over! Final scores:'
game_state.print_scores()
if record_game:
outfile = open(GAME_RECORD_FILE, 'a')
outfile.write(game_state.get_team_scores_str())
outfile.close()
示例11: Game
class Game(object):
def __init__(self):
self.clock = pygame.time.Clock()
self.display = Display()
self.game_state = GameState()
self.control_state = ControlState()
def run(self):
pygame.init()
while True:
self.control_state.update()
self.game_state.update(self.control_state)
self.display.update(self.game_state)
self.clock.tick(60)
示例12: read_dialog_script
def read_dialog_script(dialog):
"""
Reads in JSON array of dialog boxes to be spoken
"""
if not dialog:
# Return if no dialog given (i.e. no intro script)
return
logging.debug(pprint.pformat(dialog))
for line in dialog:
char = Character.load_character(line['character'])
speech_box(line['text'], speaker=char.name)
if 'unlocks' in line:
from game_state import GameState
GameState.update(line['unlocks'])
示例13: __init__
def __init__(self, p, interactive=False, current_total=0):
''' (SubtractSquareState, int, str) -> NoneType
Initialize SubtractSquareState self with current_total the number
to decrease to 0.
Assume: 0 <= current_total is an int
p in {'p1', 'p2'}
'''
if interactive:
current_total = randint(1, int(input('Maximum starting value? ')))
GameState.__init__(self, p)
self.current_total = current_total
self.instructions = ('On your turn, you may remove any number so long '
'as it is (a) a perfect square, and '
'(b) no more than the current number.')
示例14: test_dfs_walk
def test_dfs_walk(self):
strategy = BruteForceStrategy()
for game_state_string, expected_outcome in self.GET_OUTCOME_TESTS:
game_state = GameState.from_string(game_state_string)
dfs_walk = DFSWalk(strategy)
outcome = dfs_walk.walk(game_state)
self.assertEqual(outcome, expected_outcome,
'incorrect outcome for %s' % game_state)
示例15: move
def move(self):
"""
Initiates move.
"""
from game_state import GameState
# Load destinations for the current location from the current GAME_MAP
destinations = GameState.GAME_MAP.get_destinations_for_location(self.tag)
# Display list box for the possible destinations
selection = ui.list_box("Move to...", destinations)
# If selection is None then we go back
if not selection:
return
# Updates the current location in the GameState
GameState.update_current_location(selection)
GameState.CURRENT_LOCATION.start()