def __init__(self, print_func=print, input_func=input, dealer=None, user=None): """ This is where most of the basic game set up should take place. Namely the creation of the deck as well as the dealer. For now we can also add the player. In: None Exceptions: None Out: None """ # Variables to control both the users starting bank as well as their goal self.starting_bank = 100 self.score_goal = 250 # Override functions so you can create a wrapper around the program self._print = print_func self._input = input_func # Create a new deck of cards self.deck = Deck(deck_count=2) # Add the players that the game cares about self.dealer = dealer or Dealer() self.user = user or User(starting_bank=self.starting_bank) self.round = 0
def __init__(self, size=10): self.size = size board_1 = self.random_board() board_2 = self.random_board() board_2.hid = True self.user = User(board_1, board_2) self.ai = AI(board_2, board_1)
def playeradvance(levelnow): ball = pygame.image.load('wimages/ball.png') player_x = 640 # levelnow[0] player_y = 360 # levelnow[1] player = User(ball, player_x, player_y) player.walls = wall_list sprite_list.add(player) return player
def difficulty_level(self): valid_easy_responses = {'e', 'easy'} valid_hard_responses = {'h', 'hard'} while True: level_response = self._input( 'Which difficulty? \nEasy: start with 100 chips, and goal is 250 chips \nHard: start with 50 chips, and goal is 500 chips \nPress (e) or (h): ' ) if level_response.lower() in valid_easy_responses: self.user = User(starting_bank=100) self.score_goal = 250 break if level_response.lower() in valid_hard_responses: self.user = User(starting_bank=50) self.score_goal = 500 break self._print('Difficulty must be Easy or Hard')
def test_doubleElim(self): entrant1 = User("entrant1") entrant2 = User("entrant2") entrant3 = User("entrant3") entrant4 = User("entrant4") entrant5 = User("entrant5") entrant6 = User("entrant6") entrant7 = User("entrant7") entrant8 = User("entrant8") tournament = Tournament([entrant1, entrant2, entrant3, entrant4, entrant5, entrant6, entrant7, entrant8], BracketTypes.DOUBLEELIMINATION) self.assertTrue(tournament.bracket.rounds[0].matches[0].entrant1 == entrant1) self.assertTrue(tournament.bracket.rounds[0].matches[0].loserPlaysInMatch == tournament.bracket.rounds[0].matches[1].loserPlaysInMatch) self.assertTrue(tournament.bracket.rounds[0].matches[0].winnerPlaysInMatch == tournament.bracket.rounds[0].matches[1].winnerPlaysInMatch) self.assertTrue(tournament.bracket.rounds[5].matches[0].winnerPlaysInMatch == tournament.bracket.rounds[1].matches[0].loserPlaysInMatch)
def difficulty_level(self): """ Set the difficulty level for game. Out: (boolean) Should start game """ valid_easy_responses = {'e', 'easy'} valid_hard_responses = {'h', 'hard'} while True: self._print( 'On easy difficulty you start with 100 chips and try to get to 250 chips.' ) self._print( 'On hard difficulty you start with 50 chips and try to get to 500 chips.' ) level_response = self._input( 'Which difficulty do you want to play on?') if level_response.lower() in valid_easy_responses: self.starting_bank = 100 self.score_goal = 250 self.user = User(starting_bank=self.starting_bank) return True if level_response.lower() in valid_hard_responses: self.starting_bank = 50 self.score_goal = 500 self.user = User(starting_bank=self.starting_bank) return True if level_response.lower() in self._valid_exit: return False self._print('Difficulty must be easy or hard.')
def player_process(self, id, deck): me = User(id) myQueue = self.turns[id] nextQueue = self.turns[(id + 1) % self.numOfPlayers] self.players.append(me) deck.to_hand(me, self.numOfCardsPerPlayer) me.turnsLeft = 1 while True: # If player's turn if not myQueue.empty(): # Implement game logic here if me.turnsLeft > 0: # if there are still turns left, don't change turns response = input("> ") #"> spit?(f)/slap?(j) " if response == "f": # spit self.game_logic(me, id, deck) elif response == "j": # slap me.slap(deck) # print(self) elif response == "d": # print deck print_deck(deck) elif me.turnsLeft == 0: # if there are no turns left, change turns self.change_turns(nextQueue) # Even if not player's turn, ask for response; only choice is slap else: pass
def test_dealer_instance(): assert User()
def user(): return User()
user.hit(test_input_4) assert user.get_score() == expected @pytest.mark.parametrize("test_input_1, test_input_2, test_input_3, test_input_4, expected", [(Card(10), Card(3), Card(5), Card(7), True), (Card(6), Card(5), Card(9), Card(1), False), (Card(10), Card(1), Card(5), Card(6), True)]) def test_user_bust(test_input_1, test_input_2, test_input_3, test_input_4, expected, user): user.hit(test_input_1) user.hit(test_input_2) user.hit(test_input_3) user.hit(test_input_4) assert user.bust() == expected @pytest.mark.parametrize("test_input_1, test_input_2,expected", [(Card(10), Card(11), True and len(User().hand) == 2), (Card(10), Card(10), False and len(User().hand) == 2)]) def test_user_blackjack(test_input_1, test_input_2,expected, user): user.hit(test_input_1) user.hit(test_input_2) assert user.blackjack() == expected def test_user_reset_hand(user): assert user.reset_hand() == None def test_get_bank(user): user.bank = 100 actual = user.get_bank() assert user.bank == actual def test_get_bet_and_place_bet(user):
from game import Game from player import User from interface import HumanInterface, RuleAIInterface if __name__ == '__main__': human_interface = HumanInterface() ai_interface = RuleAIInterface() users = [ User('A', ['q', 'w', 'e', 'r'], human_interface), User('B', ['a', 's', 'd', 'f'], ai_interface), ] game = Game(users) game.play()