I just started my programming lessons in school today and I decided to start learning more at home. This is my first day and I know the basics of if conditions, for and while loops and variables.
I decided to start my dice game project and the point of the game is to have 2 players competing against each other and different combinations will reward you with points. My goal is to create a game where each round each player will roll 5 dice and you will be able to get points from rolling a pair (higher pair = more points), three of a kind, straights and a full house.
So far I managed to create a game where each player gets to roll three dice and if you manage to roll a pair you will be rewarded with one point. The system works so far and in the end the program will decide a winner, but I have some problems.
I need some help with figuring out how to implement a system where different pairs give different points, a pair of 2 gives you two points and so on. I also have some problem with the three of a kind feature, every time I hit it I also hit a pair so it will only add one point because it is earlier in the if conditions.
Straights and full house's is also something that I'm not sure how to implement.
I would also be very happy to hear if you guys have anything that you would do different and why. I am new to this and I want to improve the code in any possible way.
The Code
import random
import time
player1 = 0
player2 = 0
rounds_to_play = 4
for round_number in range(1, rounds_to_play, 1):
print("Round", round_number, "is about to start!")
time.sleep(2)
roll = input("Player 1, are you ready to throw your dice? (y/n)")
if roll == "y":
while roll == 'y':
print('Rolling the dice...')
time.sleep(.5)
dice1 = random.randint(1, 6)
dice2 = random.randint(1, 6)
dice3 = random.randint(1, 6)
print("You rolled:")
print(dice1, dice2, dice3)
time.sleep(1)
if dice1 == dice2 or dice1 == dice3 or dice2 == dice3:
print("Well done! You rolled a pair (1p)")
player1 = player1 + 1
print("Player 1:", player1)
elif dice1 == dice2 == dice3:
print("WOW! You hit a three of a kind! (5p)")
player1 = player1 + 5
print("Player 1:", player1)
else:
print("Unlucky, you missed!")
roll = 0
else:
print("Wow")
time.sleep(5)
roll = input("Player 2, are you ready to throw your dice? (y/n)")
if roll == "y":
while roll == 'y':
print('Rolling the dice...')
time.sleep(.5)
dice1 = random.randint(1, 6)
dice2 = random.randint(1, 6)
dice3 = random.randint(1, 6)
print("You rolled:")
print(dice1, dice2, dice3)
time.sleep(1)
if dice1 == dice2 or dice1 == dice3 or dice2 == dice3:
print("Well done! You rolled a pair (1p)")
player2 = player2 + 1
print("Player 2:", player2)
elif dice1 == dice2 == dice3:
print("WOW! You hit a three of a kind! (5p)")
player2 = player2 + 5
print("Player 2:", player1)
else:
print("Unlucky, you missed!")
roll = 0
else:
print("Wow")
time.sleep(3)
print("Calculating who the winner is...")
time.sleep(3)
if player1 > player2:
print("Player 1 is the winner!")
elif player2 > player1:
print("Player 2 is the winner!")
else:
print("It's a draw!")
dice1,dice2, etc, it is time to replace them with a list so you can dodice[0],dice[1], etc. \$\endgroup\$