From 7ffa20720668ad9e8701d0b5f98a2e3161132423 Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Sun, 11 May 2014 19:31:14 +0200 Subject: [PATCH] Move player defaults into constants. --- naja/constants.py | 8 ++++++++ naja/gameboard.py | 10 +++++++--- naja/gamestate.py | 12 ------------ 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/naja/constants.py b/naja/constants.py index d7e023a..99dd99c 100644 --- a/naja/constants.py +++ b/naja/constants.py @@ -36,6 +36,14 @@ BITS = AttrDict({ DIRECTION_BITS = AttrDict((k, v) for k, v in BITS.items() if v < 4) CONDITION_BITS = AttrDict((k, v) for k, v in BITS.items() if v >= 4) +# Player defaults +PLAYER_DEFAULTS = AttrDict({ + 'INITIAL_BITS': BITS.NORTH | BITS.SOUTH | BITS.EAST | BITS.WEST, + 'INITIAL_POS': (2, 2), + 'MAX_HEALTH': 4, + 'WINS_REQUIRED': 4, +}) + # Game size constants TILE_SIZE = (96, 96) BOARD_SIZE = (5 * TILE_SIZE[0], 5 * TILE_SIZE[1]) diff --git a/naja/gameboard.py b/naja/gameboard.py index 5ec6150..5728d5d 100644 --- a/naja/gameboard.py +++ b/naja/gameboard.py @@ -1,6 +1,7 @@ from random import choice -from naja.constants import BITS, DIRECTION_BITS, CONDITION_BITS +from naja.constants import( + BITS, DIRECTION_BITS, CONDITION_BITS, PLAYER_DEFAULTS) from naja.player import Player from naja import actions @@ -20,8 +21,11 @@ class GameBoard(object): self.board_locations = board_locations @classmethod - def new_game(cls, initial_bits, initial_pos, max_health, wins_required, - locations_definition): + def new_game(cls, locations_definition, + initial_bits=PLAYER_DEFAULTS.INITIAL_BITS, + initial_pos=PLAYER_DEFAULTS.INITIAL_POS, + max_health=PLAYER_DEFAULTS.MAX_HEALTH, + wins_required=PLAYER_DEFAULTS.WINS_REQUIRED): state = { 'max_health': max_health, 'health': max_health, diff --git a/naja/gamestate.py b/naja/gamestate.py index dabf34a..4e892f8 100644 --- a/naja/gamestate.py +++ b/naja/gamestate.py @@ -2,7 +2,6 @@ The current game state. """ -from naja.constants import BITS from naja.gameboard import GameBoard @@ -11,19 +10,8 @@ class GameState(object): Naja game state. """ - INITIAL_BITS = ( - BITS.NORTH | BITS.SOUTH | - BITS.EAST | BITS.WEST - ) - MAX_HEALTH = 4 - WINS_REQUIRED = 4 - def __init__(self): self.gameboard = GameBoard.new_game( - initial_bits=self.INITIAL_BITS, - initial_pos=(2, 2), - max_health=self.MAX_HEALTH, - wins_required=self.WINS_REQUIRED, locations_definition=[]) # TODO: we will need some of these :) @property -- 2.34.1