def get_user(): name = input(Locale.__('Please input your name: ')) description = input(Locale.__('Describe yourself: ')) player = Player(name, description) Logger(player.name) Logger.add('Player {} has been created.\nAnd He is: {}'.format( player.name, player.description)) return player
def __get_player(self, filename, medium=False): try: with open(filename, 'rb') as p_f: player = pickle.load(p_f) player.set_health(10) except Exception: if medium: player = PlayerMedium(health=10, max_r=10, min_r=1) else: player = Player(health=10) return player
def __init__(self, *args, **kwargs): super(TestPlayer, self).__init__(*args, **kwargs) self.player1 = Player("A", "B", "C", "D", "E", "F") self.player2 = Player("G", "H", "I", "J", "K", "L") self.player3 = Player("A", "B", "C", "D", "E", "G") self.player4 = Player("A", "B", "D", "E", "F", "G") self.player5 = Player("Le", "Quick", "Browne", "Focks", "Jumps", "Over")
def initialise(filepath): """ Initialises program to encapsulate processing of csv file :param filepath: File path to valid csv file containing valid data :return: List of chess players in Players object """ csv = Parser(filepath) players = [] # Create Player objects from CSV for player in csv.list: players.append(Player(player[0], player[1], player[2], player[3], player[4], player[5])) # Sort Player objects return merge_sort(players)
class TestPlayer(TestCase): def __init__(self, *args, **kwargs): super(TestPlayer, self).__init__(*args, **kwargs) self.player1 = Player("A", "B", "C", "D", "E", "F") self.player2 = Player("G", "H", "I", "J", "K", "L") self.player3 = Player("A", "B", "C", "D", "E", "G") self.player4 = Player("A", "B", "D", "E", "F", "G") self.player5 = Player("Le", "Quick", "Browne", "Focks", "Jumps", "Over") def test_eq(self): """Test equality override on Player class on 1 object""" self.assertEqual(self.player1, self.player1) def test_ne(self): """Test inverse of equality override on Player class""" self.assertNotEqual(self.player2, self.player1) def test_lt(self): """Test "less than" override on Player class""" self.assertLess(self.player1, self.player3) def test_lt2(self): """Test "less than" override on Player class where the higher value is determined in the middle of the properties being evaluated """ self.assertLess(self.player1, self.player4) def test_gt(self): """Test "greater than" override on Player class""" self.assertGreater(self.player2, self.player1) def test_contains(self): """Test if player contains certain keywords and is case insensitive""" self.assertTrue(self.player5.contains("V"))
def join(self, username): if not self.has_player(username): self.players.append(Player(username)) self.set_user_status(username, 'SUBMIT_INITIAL_PHRASE') db.session.commit()
def setUp(self): self.printer = Printer() self.player = Player() self.machine = Machine(Reel) self.gamerunner = GameRunner(self.machine, self.player, self.printer)
def setUp(self): self.player = Player() self.minimum_bet = 1
class PlayerTestSpec(unittest.TestCase): def setUp(self): self.player = Player() self.minimum_bet = 1 def test_player_has_initial_wallet_of_10(self): self.assertEqual(self.player.wallet(), Player.DEFAULT_FUNDS) def test_debit_method_reduces_balance_by_debit_amount(self): self.player.debit(1) self.assertEqual(self.player.wallet(), Player.DEFAULT_FUNDS - self.minimum_bet) def test_debit_method_reduces_balance_by_correct_debit_amount(self): stake = 4 self.player.debit(stake) self.assertNotEqual(self.player.wallet(), Player.DEFAULT_FUNDS) self.assertEqual(self.player.wallet(), Player.DEFAULT_FUNDS - stake) def test_player_debit_will_throw_error_if_insufficient_funds(self): with self.assertRaises(Exception): self.player.debit(Player.DEFAULT_FUNDS + self.minimum_bet) self.assertEqual(self.player.wallet(), Player.DEFAULT_FUNDS) def test_credit_method_increases_balance_by_correct_debit_amount(self): stake = 4 self.player.credit(stake) self.assertNotEqual(self.player.wallet(), Player.DEFAULT_FUNDS) self.assertEqual(self.player.wallet(), Player.DEFAULT_FUNDS + stake)