working game?
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
|
||||
from deck import deck
|
||||
#from card import card
|
||||
from player import player
|
||||
from player import BotPlayer, HumanPlayer
|
||||
from rules import Rule, RuleEngine
|
||||
|
||||
import time
|
||||
@@ -11,13 +11,24 @@ d.shuffle()
|
||||
#d.show()
|
||||
d.first_card()
|
||||
|
||||
|
||||
people = ['Jake','bot1','bot2','bot3','bot4','bot5']
|
||||
player_count = int(input('How many players do you want to play with? '))
|
||||
players = []
|
||||
for i in range(player_count):
|
||||
player_name = input(f'Enter the name of player {i+1}: ')
|
||||
players.append(HumanPlayer(player_name))
|
||||
|
||||
bot_count = int(input('How many bots do you want to play against? '))
|
||||
bots = []
|
||||
for i in range(bot_count):
|
||||
bots.append(f'bot{i+1}')
|
||||
|
||||
players = []
|
||||
# In your main game loop
|
||||
players = [HumanPlayer('Jake')] # Add other players
|
||||
|
||||
# Create player objects
|
||||
for person in people:
|
||||
game_player = player(person)
|
||||
for person in bots:
|
||||
game_player = BotPlayer(person)
|
||||
players.append(game_player)
|
||||
|
||||
# Now you can use your player objects
|
||||
@@ -38,24 +49,34 @@ round_counter = 0
|
||||
for i in range(50):
|
||||
round_counter += 1
|
||||
print(f'round: {round_counter}')
|
||||
for game_player in players: # loop through each player
|
||||
#time.sleep(2)
|
||||
has_played,given_command = game_player.play(d) # play a card
|
||||
for game_player in players:
|
||||
if isinstance(game_player, HumanPlayer):
|
||||
has_played, given_command = game_player.play(d)
|
||||
else:
|
||||
has_played, given_command = game_player.play(d) # Bot player's turn
|
||||
|
||||
if has_played: # if the player has played a card
|
||||
command = rule_engine.check_rule(d.discard_pile[-1], game_player.hand)
|
||||
print(f'expected command: {command}')
|
||||
time.sleep(1)
|
||||
if given_command != command:
|
||||
print(f'{game_player.name} made the wrong announcement\n')
|
||||
print(f'{game_player.name} made the wrong announcement')
|
||||
#need to put the card back in the hand
|
||||
game_player.hand.append(d.discard_pile.pop())
|
||||
game_player.draw(d)
|
||||
if given_command == command:
|
||||
print(f'{game_player.name} announced the correct rule\n')
|
||||
print(f'Player {game_player.name} has {game_player.check_hand()} cards left\n')
|
||||
print(f'{game_player.name} announced the correct rule')
|
||||
print(f'{game_player.name} has {game_player.check_hand()} cards left\n')
|
||||
time.sleep(1)
|
||||
if game_player.check_hand() == 0: # if the player has no cards left
|
||||
print(f'{game_player.name} has won')
|
||||
print(f'rounds played: {round_counter}')
|
||||
exit()
|
||||
else:
|
||||
game_player.draw(d) # if the player has not played a card, draw a card
|
||||
print(f'{game_player.name} drew a card')
|
||||
print(f'{game_player.name} has {game_player.check_hand()} cards left\n')
|
||||
time.sleep(1)
|
||||
if d.check_empty(): # if the deck is empty
|
||||
d.shuffle()
|
||||
d.first_card()
|
||||
|
||||
Reference in New Issue
Block a user