Fun (beginner) Python (size doesn't matter-) Dice game

Fun (beginner) Python (size doesn't matter-) Dice game

·

3 min read

The rules: One random dice is displayed, then you press enter and two dices are shown for each player. Every dice which is closer to the initial dice wins! In case of a draw (if the initial dice is 4 and player one throws a 3 and player two throws a 5, then both have the same distance from the original,but any one with a smaller number wins, in this case 3, so actually size matters, the small ones :D ) Maybe I should have changed the name..

So I was taking a look at ascii.co.uk and there was a lot of fun stuff there, and decided to make some dice using characters (yes, I just learned about the three single quotes symbol and its function) and a simple dice game inspired by Developer Joseph !

Here is how it goes:

import random

while True:
  rolls=['''
-------
|     |
|  0  |
|     |
-------   ''', '''

-------
|    0|
|     |
|0    |
------- ''', '''

-------
|    0|
|  0  |
|0    |
------- ''', '''
-------
|0   0|
|     |
|0   0|
------- ''', '''
-------
|0   0|
|  0  |
|0   0|
------- ''', '''
-------
|0   0|
|0   0|
|0   0|
------- '''

]
  random_num=random.randint(1,6) 
  start = rolls[random_num-1]
  print(f"A new game: This is the number : {start}\n")

  input("Press enter to play: ")

  dice1 = random.randint(1,6)
  dice2 = random.randint(1,6)
  dice1_roll = rolls[dice1-1]
  dice2_roll = rolls[dice2-1]

  Difference1 = abs(random_num - dice1)
  Difference2 = abs(random_num - dice2)

  if Difference1 == Difference2:
      if dice1<dice2:
        print(f"\n Player1 : {dice1_roll} \n- Player2: {dice2_roll} -Same difference, but Player one has a smaller one! They win, Size doesn't matter!!!")
      elif dice1>dice2:
        print(f"\n Player1 : {dice1_roll}- \n Player2: {dice2_roll} -Same difference, but Player two has a smaller one! They win, Size doesn't matter!!!")
      else:
        print(f"\n Player1 : {dice1_roll}- \n Player2: {dice2_roll} - It's a draw!!!")

  elif Difference1 < Difference2:
    print(f"\n Player1 : {dice1_roll}- \n Player2: {dice2_roll} so Player1 has won! \n ")

  elif Difference2 < Difference1:
     print(f"\n Player1 : {dice1_roll}- \n Player2: {dice2_roll} so Player2 has won! \n ")