2017-12-27 23:32:16 +00:00
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
2017-12-29 21:54:52 +00:00
|
|
|
|
# 1.9-zCasino.py: petit jeu de roulette très simplifié
|
2018-01-03 21:53:59 +00:00
|
|
|
|
import math
|
|
|
|
|
import random
|
2018-01-07 23:13:05 +00:00
|
|
|
|
import os
|
2017-12-27 23:32:16 +00:00
|
|
|
|
|
2017-12-29 21:54:52 +00:00
|
|
|
|
# OpenClassrooms - Apprenez à programmer en Python - TP: tous au ZCasino
|
2017-12-27 23:32:16 +00:00
|
|
|
|
# https://openclassrooms.com/courses/apprenez-a-programmer-en-python/tp-tous-au-zcasino
|
|
|
|
|
|
2017-12-29 00:30:34 +00:00
|
|
|
|
# Le joueur mise sur un numéro compris entre 0 et 49
|
|
|
|
|
# En choisissant son numéro, il mise
|
2017-12-29 21:54:52 +00:00
|
|
|
|
# Les numéros pairs sont noire, les impairs sont de rouge
|
2017-12-29 00:30:34 +00:00
|
|
|
|
# Quand la roulette s'arrête:
|
2017-12-29 21:54:52 +00:00
|
|
|
|
# -Si numéro gagnant: gain = 3x la mise
|
|
|
|
|
# -Si même couleur: gain = 50% de la mise
|
2017-12-29 00:30:34 +00:00
|
|
|
|
# -Sinon la mise est perdue
|
|
|
|
|
|
2018-01-04 00:16:55 +00:00
|
|
|
|
#############
|
|
|
|
|
# VARIABLES #
|
|
|
|
|
#############
|
|
|
|
|
jeu_continu = True
|
|
|
|
|
credit = 1000
|
2018-01-07 23:13:05 +00:00
|
|
|
|
filename = ".highscore"
|
|
|
|
|
old_highscore = -1
|
2018-01-04 00:16:55 +00:00
|
|
|
|
|
2017-12-29 21:54:52 +00:00
|
|
|
|
#########
|
|
|
|
|
# TEXTE #
|
|
|
|
|
#########
|
2018-01-04 00:16:55 +00:00
|
|
|
|
curr_symb = "€"
|
|
|
|
|
disclamer = "Bienvenu à la roulette, vous avez un crédit de " + \
|
|
|
|
|
str(credit) + curr_symb + ": bonne partie."
|
2018-01-03 22:57:05 +00:00
|
|
|
|
err_plage = "Il faut saisir un nombre dans la plage indiquée! "
|
|
|
|
|
err_saisie = "Il faut saisir un nombre! "
|
2017-12-29 21:54:52 +00:00
|
|
|
|
msg_resultat = "\nLa bille s'arrête sur le nunéro: "
|
|
|
|
|
msg_numero = "\nVotre nombre est gagnant! Votre gain: "
|
|
|
|
|
msg_couleur = "\nVotre couleur est gagnante! Votre gain: "
|
|
|
|
|
msg_perdu = "\nVous perdez votre mise!"
|
|
|
|
|
msg_continue = "Pour arrêter la partie, tapez « n »: "
|
|
|
|
|
msg_solde = "Votre solde : "
|
|
|
|
|
msg_arret = "Vous avez décidé d'arrêter la partie avec un solde de: "
|
|
|
|
|
msg_final = "Votre solde à atteind 0€: la partie s'arrête"
|
2018-01-07 23:13:05 +00:00
|
|
|
|
msg_no_score = "Pas d'ancien score."
|
|
|
|
|
msg_best_score = "Bravo, vous battez le précédent record de gain qui était: "
|
|
|
|
|
msg_bad_score = "Le record de gain enregistré était: "
|
2017-12-29 21:54:52 +00:00
|
|
|
|
|
|
|
|
|
################
|
|
|
|
|
# DÉBUT DU JEU #
|
|
|
|
|
################
|
|
|
|
|
print(disclamer)
|
|
|
|
|
|
|
|
|
|
while jeu_continu is True:
|
|
|
|
|
# Saisie & validation du choix
|
2018-01-03 22:57:05 +00:00
|
|
|
|
choix_valeur = 50
|
|
|
|
|
while choix_valeur >= 50 or choix_valeur < 0:
|
|
|
|
|
choix_valeur = input("Quel numéro choisissez vous (0-49)?")
|
2017-12-29 00:30:34 +00:00
|
|
|
|
try:
|
2018-01-03 22:57:05 +00:00
|
|
|
|
choix_valeur = int(choix_valeur)
|
|
|
|
|
except ValueError:
|
2017-12-29 21:54:52 +00:00
|
|
|
|
print(err_saisie)
|
2018-01-03 22:57:05 +00:00
|
|
|
|
choix_valeur = 50
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
if choix_valeur >= 50 or choix_valeur < 0:
|
|
|
|
|
print(err_plage)
|
2017-12-29 21:54:52 +00:00
|
|
|
|
|
|
|
|
|
# Saisie & validation de la mise
|
2018-01-03 23:08:50 +00:00
|
|
|
|
mise = 0
|
|
|
|
|
while mise <= 0 or mise > credit:
|
|
|
|
|
mise = input("Quelle est votre mise (1-" + str(credit) + "?)")
|
2017-12-29 00:30:34 +00:00
|
|
|
|
try:
|
2018-01-03 23:08:50 +00:00
|
|
|
|
mise = int(mise)
|
|
|
|
|
except ValueError:
|
2017-12-29 21:54:52 +00:00
|
|
|
|
print(err_saisie)
|
2018-01-03 23:08:50 +00:00
|
|
|
|
mise = 0
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
if mise <= 0 or mise > credit:
|
|
|
|
|
print(err_plage)
|
2017-12-29 21:54:52 +00:00
|
|
|
|
|
2018-01-04 00:16:55 +00:00
|
|
|
|
result_valeur = random.randrange(50) # Roulette
|
2017-12-29 21:54:52 +00:00
|
|
|
|
|
|
|
|
|
# Comparaison
|
|
|
|
|
if result_valeur == choix_valeur:
|
|
|
|
|
gain = mise * 3
|
2018-01-03 21:53:59 +00:00
|
|
|
|
msg = msg_resultat + str(result_valeur) + msg_numero + \
|
|
|
|
|
str(gain) + curr_symb
|
2018-01-03 22:19:34 +00:00
|
|
|
|
elif result_valeur % 2 == choix_valeur % 2:
|
2017-12-29 21:54:52 +00:00
|
|
|
|
gain = math.ceil(mise / 2)
|
2018-01-03 21:53:59 +00:00
|
|
|
|
msg = msg_resultat + str(result_valeur) + msg_couleur + \
|
|
|
|
|
str(gain) + curr_symb
|
2017-12-29 21:54:52 +00:00
|
|
|
|
else:
|
2018-01-03 23:08:50 +00:00
|
|
|
|
gain = - mise
|
2017-12-29 21:54:52 +00:00
|
|
|
|
msg = msg_resultat + str(result_valeur) + msg_perdu
|
|
|
|
|
|
|
|
|
|
credit = credit + gain
|
2018-01-04 00:16:55 +00:00
|
|
|
|
print(msg) # Affichage de fin de tour
|
2017-12-29 21:54:52 +00:00
|
|
|
|
|
2018-01-04 00:16:55 +00:00
|
|
|
|
if credit > 0: # affiche credit
|
2017-12-29 21:54:52 +00:00
|
|
|
|
print(msg_solde + str(credit))
|
|
|
|
|
|
2018-01-04 00:16:55 +00:00
|
|
|
|
ask_continue = str(input(msg_continue)) # demande de continuer
|
2018-01-04 00:02:04 +00:00
|
|
|
|
|
2018-01-04 00:16:55 +00:00
|
|
|
|
if ask_continue == "n": # Arret demandé par le joueur
|
2018-01-04 00:02:04 +00:00
|
|
|
|
jeu_continu = False
|
2018-01-07 23:13:05 +00:00
|
|
|
|
msg_final = (msg_arret + str(credit) + curr_symb)
|
2017-12-29 21:54:52 +00:00
|
|
|
|
|
|
|
|
|
else:
|
2018-01-07 23:13:05 +00:00
|
|
|
|
jeu_continu = False # fin du jeu
|
|
|
|
|
|
|
|
|
|
if os.path.isfile(filename) is True: # On recupere le highscore
|
|
|
|
|
with open(filename, "r") as highscore:
|
|
|
|
|
old_highscore = int(highscore.read())
|
|
|
|
|
|
|
|
|
|
if old_highscore == -1: # Pas encore de partie gagnante
|
|
|
|
|
msg_score = msg_no_score
|
|
|
|
|
|
|
|
|
|
elif credit > old_highscore and old_highscore != -1: # Highscore battu
|
|
|
|
|
msg_score = msg_best_score + str(old_highscore) + curr_symb
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
msg_score = msg_bad_score + str(old_highscore) + curr_symb
|
|
|
|
|
|
|
|
|
|
if (credit > 0 and old_highscore == -1) or credit > old_highscore:
|
|
|
|
|
with open(filename, "w") as highscore:
|
|
|
|
|
highscore.write(str(credit))
|
|
|
|
|
|
|
|
|
|
print(msg_final) # Affichage du message de fin de partie
|
|
|
|
|
print(msg_score) # Affichage du score/highscore
|