Roulette Game Schedule
Solved
DarkSniper
-
FiceA Posted messages 38 Status Member -
FiceA Posted messages 38 Status Member -
Hello to all the noobs,
here's my issue, a friend and I would like to program the roulette game (the one you find in casinos) in Python. The problem is that we're having a hard time structuring our program because we've added a difficulty which is the choice of the number of players for the game.
Let me explain the program we want to create:
Game flow: "Introduction":
-We choose the number of players
-We assign a name to each player (e.g., the 1st will be player1, the 2nd will be player2,...)
-We then specify their wallet amount (e.g., €1000 each)
-Then the minimum and maximum bets
The game (to be done in a loop):
-We ask the player, each in turn, to choose a number between 0 and 36, and then the amount of their bet
-When the bets are made, the program generates a random number between 0 and 36
-Then we display this winning number, and for each player, we show their winnings or losses.
-Next, we display their updated wallet amount
-If there is a bankruptcy (that is, if one of the players has no money left in their wallet), the game stops
-Finally, we ask if they want to play another round or quit
This is the program we would like to design.
We turned to the use of lists/arrays with the use of the For loop, which I think is the simplest way to make this program. But having some gaps in using these lists/arrays, we decided to ask you for a bit of help.
All ideas are welcome, thank you in advance for the help you will provide on this topic.
here's my issue, a friend and I would like to program the roulette game (the one you find in casinos) in Python. The problem is that we're having a hard time structuring our program because we've added a difficulty which is the choice of the number of players for the game.
Let me explain the program we want to create:
Game flow: "Introduction":
-We choose the number of players
-We assign a name to each player (e.g., the 1st will be player1, the 2nd will be player2,...)
-We then specify their wallet amount (e.g., €1000 each)
-Then the minimum and maximum bets
The game (to be done in a loop):
-We ask the player, each in turn, to choose a number between 0 and 36, and then the amount of their bet
-When the bets are made, the program generates a random number between 0 and 36
-Then we display this winning number, and for each player, we show their winnings or losses.
-Next, we display their updated wallet amount
-If there is a bankruptcy (that is, if one of the players has no money left in their wallet), the game stops
-Finally, we ask if they want to play another round or quit
This is the program we would like to design.
We turned to the use of lists/arrays with the use of the For loop, which I think is the simplest way to make this program. But having some gaps in using these lists/arrays, we decided to ask you for a bit of help.
All ideas are welcome, thank you in advance for the help you will provide on this topic.
3 answers
```python
from random import randrange
class Joueur:
def __init__(self, nom, argent):
self.nom = str(nom)
self.argent = int(argent)
self.numero = 0
self.mise = 0
nbJoueurs = int(input("Nombre de joueurs : "))
joueurs = []
sargent = [] # Changer ici pour une liste vide
argent_initial = int(input("Argent de départ : ")) # Convertir l'argent initial en entier
# Initialisation de la liste sargent avec l'argent de départ pour chaque joueur
for _ in range(nbJoueurs):
sargent.append(argent_initial)
continuer_partie = True
while continuer_partie:
for x in range(0, nbJoueurs):
joueurs.append(Joueur(input(("Numero choisit du joueur "+str(x+1)+" : ")), sargent[x]))
for x in range(0, nbJoueurs):
joueurs[x].mise = int(input("Mise du joueur "+str(x+1)+" : "))
# Affichage du numero gagnant (aléatoirement)
numero_gagnant = randrange(1)
print("La roulette tourne,...... tourne, ...... tourne, ...... tourne, et s'arrete sur le numero", numero_gagnant)
for x in range(0, nbJoueurs):
if joueurs[x].numero == numero_gagnant: # Utiliser joueurs[x].numero au lieu de joueurs[x]
print("Felicitation, votre numero est le bon, vous obtenez ", joueurs[x].mise * 35, "euros!")
sargent[x] += joueurs[x].mise * 35 # Utiliser l'opérateur +=
else:
print("Desoler l'ami, c'est pas pour cette fois. Vous perdez votre mise qui est de", joueurs[x].mise, "euros")
sargent[x] -= joueurs[x].mise # Utiliser l'opérateur -=
# On interrompt la partie si le joueur est ruine
for x in range(0, nbJoueurs):
if sargent[x] <= 0:
print("Vous etes ruine! C'est la fin de la partie.")
continuer_partie = False
break # Sortir de la boucle si un joueur est ruiné
else:
# On affiche l'argent du joueur
print("Le joueur "+str(x+1)+" a desormais", sargent[x], "euros")
quitter = input("Souhaitez-vous quitter le casino (o/n) ? ")
if quitter.lower() == "o": # Utiliser la méthode lower pour simplifier
print("Vous quittez le casino avec vos gains.")
continuer_partie = False
```
from random import randrange
class Joueur:
def __init__(self, nom, argent):
self.nom = str(nom)
self.argent = int(argent)
self.numero = 0
self.mise = 0
nbJoueurs = int(input("Nombre de joueurs : "))
joueurs = []
sargent = [] # Changer ici pour une liste vide
argent_initial = int(input("Argent de départ : ")) # Convertir l'argent initial en entier
# Initialisation de la liste sargent avec l'argent de départ pour chaque joueur
for _ in range(nbJoueurs):
sargent.append(argent_initial)
continuer_partie = True
while continuer_partie:
for x in range(0, nbJoueurs):
joueurs.append(Joueur(input(("Numero choisit du joueur "+str(x+1)+" : ")), sargent[x]))
for x in range(0, nbJoueurs):
joueurs[x].mise = int(input("Mise du joueur "+str(x+1)+" : "))
# Affichage du numero gagnant (aléatoirement)
numero_gagnant = randrange(1)
print("La roulette tourne,...... tourne, ...... tourne, ...... tourne, et s'arrete sur le numero", numero_gagnant)
for x in range(0, nbJoueurs):
if joueurs[x].numero == numero_gagnant: # Utiliser joueurs[x].numero au lieu de joueurs[x]
print("Felicitation, votre numero est le bon, vous obtenez ", joueurs[x].mise * 35, "euros!")
sargent[x] += joueurs[x].mise * 35 # Utiliser l'opérateur +=
else:
print("Desoler l'ami, c'est pas pour cette fois. Vous perdez votre mise qui est de", joueurs[x].mise, "euros")
sargent[x] -= joueurs[x].mise # Utiliser l'opérateur -=
# On interrompt la partie si le joueur est ruine
for x in range(0, nbJoueurs):
if sargent[x] <= 0:
print("Vous etes ruine! C'est la fin de la partie.")
continuer_partie = False
break # Sortir de la boucle si un joueur est ruiné
else:
# On affiche l'argent du joueur
print("Le joueur "+str(x+1)+" a desormais", sargent[x], "euros")
quitter = input("Souhaitez-vous quitter le casino (o/n) ? ")
if quitter.lower() == "o": # Utiliser la méthode lower pour simplifier
print("Vous quittez le casino avec vos gains.")
continuer_partie = False
```
it's the starting money for all players (s for start) which is an int.
To access the money of one of the players, you shouldn't do but
Finally, for optimization purposes, instead of
for x in range(0, nbJoueurs): joueurs.append(Joueur(input(("Numero choisit du joueur "+str(x+1)+" : ")), sargent)) for x in range(0, nbJoueurs): joueurs[x].mise = int(input("Mise du joueur "+str(x+1)+" : "))rather do:
for x in range(0, nbJoueurs): joueurs.append(Joueur(input(("Numero choisit du joueur "+str(x+1)+" : ")), sargent)) joueurs[x].mise = int(input("Mise du joueur "+str(x+1)+" : "))