RETROGICIEL
LE HUIT MAGIQUE
RETROGICIEL
LE HUIT MAGIQUE
⇩. Présentation
La Magic 8-Ball est un jouet créé en 1950 par Abe Bookman et Albert C. Carter. Elle est censée répondre aux questions. Elle ressemble à une boule de billard numéro 8 : une boule noire avec un rond blanc et le chiffre 8 d’un côté, et une petite fenêtre de l’autre.
Pour l’utiliser, on tient la boule avec le 8 face à soi, on pose sa question, puis on la retourne pour voir s’afficher, au hasard, une des 20 réponses possibles.
Mais en réalité, la Magic 8-Ball n’a aucun pouvoir magique. C’est seulement un jouet qui donne des réponses au hasard. Même si certaines réponses semblent justes, ce n’est qu’une coïncidence. C’est donc un gadget pour s’amuser, et il ne faut pas se fier à ses réponses.
⇩. Consignes
Le programme doit :
présenter la Magic 8-Ball en 2D (si les graphismes sont possibles) ;
permettre au joueur de saisir une question ;
attendre que le joueur appuie sur la touche Entrée ;
animer la Magic 8-Ball avec des secousses (si les graphismes sont possibles) ;
afficher aléatoirement une réponse ;
proposer de recommencer ou ;
quitter le programme.
D'abord, faite-le fonctionner. Ensuite, faite-le beau. Enfin, faite-le performant.
Amusez-vous bien !
Télécharger RETROGICIEL - Le huit magique.
Cette présentation nécessite que Python 3 soit installé sur votre machine.
Après avoir téléchargé le fichier Le huit magiquel.7z, décompressez-le dans le répertoire de votre choix.
Ouvrez le répertoire qui vient d'être créé.
Lancez le fichier Retrogiciel.py.
Cliquez sur l'onglet RUN et testez le programme.
Créez votre propre script dans un des langages proposés ou un autre de votre choix.
Le répertoire contient aussi :
- Python.py, l'exemple en PYTHON sans tkinter ;
- Tkinter.py, l'exemple en PYTHON avec tkinter ;
- Qb84.bas, l'exemple en QBASIC avec qb64 ;
- Bbc.bas, l'exemple en BBC BASIC avec bbc sdl.
# --- Origine Nerd ---
# --- RETROGICIEL - PYTHON ---
# --- Le huit magique ---
# -*- coding: utf-8 -*-
# --- IMPORTATION DES MODULES ---
import random
# --- INITIALISATION GÉNÉRALE ---
TPL_Reponses = ( "Essaye plus tard." , "Essaye encore." , "Pas d'avis." , "C'est ton destin." , "Le sort en est jeté." , "Une chance sur deux." ,
"Repose ta question." , "D'après moi oui." , "C'est certain." , "Oui absolument." , "Tu peux compter dessus." , "Sans aucun doute" ,
"Très probable." , "Oui." , "C'est bien parti." , "C'est non." , "Peu probable.", "Faut pas rêver." , "N'y compte pas." , "Impossible." )
# --- PRESENTATION ---
print ( "LE HUIT MAGIQUE." )
# --- BOUCLE PRINCIPALE ---
while True :
# --- Saisies de la questions ---
kquestion = input ( "\nQuelle est votre question ? " )
print ( random.choice ( TPL_Reponses ) )
# --- Choix du bouclage du programme ---
kchoix = input ( "\nAvez-vous une autre question (O ou N) ?" )
if kchoix.upper ( ) == "N" : break
# --- FIN DU PROGRAMME ---
print ( "Au revoir" )
# --- Programme : JFB ---
# --- Avril 2026 ---
# --- Fin ---
Pour mieux comprendre l'exemple en PYTHON sans tkinter.
# --- Origine Nerd ---
# --- RETROGICIEL - TKINTER ---
# --- Le huit magique ---
# -*- coding: utf-8 -*-
# --- IMPORTATION DES MODULES ---
# --- Modules de la bibliothèque standard ---
import tkinter
import random
# --- INITIALISATION GÉNÉRALE ---
TPL_Reponses = ( "Essaye plus tard." , "Essaye encore." , "Pas d'avis." , "C'est ton destin." , "Le sort en est jeté." , "Une chance sur deux." ,
"Repose ta question." , "D'après moi oui." , "C'est certain." , "Oui absolument." , "Tu peux compter dessus." , "Sans aucun doute" ,
"Très probable." , "Oui." , "C'est bien parti." , "C'est non." , "Peu probable.", "Faut pas rêver." , "N'y compte pas." , "Impossible." )
# --- DÉFINITION DES FONCTIONS PERSONNALISEES ---
# --- Animation de la boule ---
def FNC_Animation ( ) :
CAN_Toile.itemconfig ( CAN_Reponse , text = "" )
CAN_Toile.coords ( CAN_Reponse , [ -10 , -10 ] )
CAN_Toile.coords ( CAN_Centre , [ 65 , 65 , 140 , 140 ] )
CAN_Toile.coords ( CAN_Huit , [ 105 , 100 ] )
khorizontal = -5
kvertical = 3
for kagitation in range ( 35 ) :
kabsicsse = CAN_Toile.coords ( CAN_Boule ) [ 0 ]
if kabsicsse < 16 : khorizontal = 5
elif kabsicsse > 26 : khorizontal = -5
kordonnee = CAN_Toile.coords ( CAN_Boule ) [ 1 ]
if kordonnee < 16 : kvertical = 3
elif kordonnee > 26 : kvertical = -3
CAN_Toile.move ( CAN_Boule , khorizontal , kvertical )
CAN_Toile.move ( CAN_Centre , khorizontal , kvertical )
CAN_Toile.move ( CAN_Huit , khorizontal , kvertical )
CAN_Toile.update ( )
TKI_Principal.after ( 20 )
CAN_Toile.coords ( CAN_Boule , [ 25 , 25 , 175 , 175 ] )
CAN_Toile.update ( )
TKI_Principal.after ( 20 )
FNC_Reponse ( )
# --- Affichage de la réponse ---
def FNC_Reponse ( ) :
kreponse = random.choice ( TPL_Reponses )
ENT_Saisie.delete ( 0 , "end" )
CAN_Toile.coords ( CAN_Centre , [ -15 , -15 , -15 , -15 ] )
CAN_Toile.coords ( CAN_Huit , [ -15 , -15 ] )
CAN_Toile.coords ( CAN_Reponse , [ 100 , 100 ] )
CAN_Toile.itemconfig ( CAN_Reponse , text = kreponse )
CAN_Toile.update ( )
# --- CREATION DE L'INTERFACE GRAPHIQUE ---
# --- Création de la fenêtre principale ---
TKI_Principal = tkinter.Tk ( )
TKI_Principal.title ( "RETROGICIEL - Le huit magique" )
# --- Création des controles nommées ---
CAN_Toile = tkinter.Canvas ( TKI_Principal , bg = "white" , relief = "solid" , bd = 3 , width = 195 , height = 195 )
CAN_Boule = CAN_Toile.create_oval ( [ 25 , 25 , 175 , 175 ] , fill = "black" )
CAN_Centre = CAN_Toile.create_oval ( [ 65 , 65 , 140 , 140 ] , fill = "white" )
CAN_Huit = CAN_Toile.create_text ( [ 105 , 100 ] , text = "8" , font = ( None , 40 , "bold" ) , fill = "black" )
CAN_Reponse = CAN_Toile.create_text ( [ -10 , -10 ] , font = ( None , 14 , "bold italic" ) , fill = "yellow" , justify = "center" )
ENT_Saisie = tkinter.Entry ( TKI_Principal )
# --- Mise en place des controles (anonymes et nommés) dans la fenêtre principale ---
CAN_Toile.pack( padx = 5 , pady = 5 )
tkinter.Label ( TKI_Principal , text = "Quelle est votre question ? " , bg = "white" ).pack ( fill = "both" )
ENT_Saisie.pack ( fill = "both" )
tkinter.Button ( TKI_Principal , text = "Quitter" , command = TKI_Principal.destroy ).pack ( side = "left" , fill = "both" )
tkinter.Button ( TKI_Principal , text = "Répondre ..." , command = FNC_Animation ).pack ( side = "right" , fill = "both" )
# --- DEBUT DU PROGRAMME ---
TKI_Principal.mainloop ( )
# --- Programme : JFB ---
# --- Avril 2026 ---
# --- Fin ---
Pour mieux comprendre l'exemple en PYTHON avec tkinter.
' --- Origine Nerd propose pour ---
' --- RETROGICIEL - QB64 ---
' --- Le huit magique ---
' --- INITIALISATION GENERALE ---
' --- Initialisation principale ---
SCREEN 12
RANDOMIZE TIMER
' --- Declarations des variables globales ---
DIM SHARED LST_Reponses(19) AS STRING
DIM SHARED IMG_Boule(53000) AS INTEGER
' --- Initialisation des valeurs ---
LST_Reponses$(0) = "Essaye plus tard."
LST_Reponses$(1) = "Essaye encore."
LST_Reponses$(2) = "Pas d'avis."
LST_Reponses$(3) = "C'est ton destin."
LST_Reponses$(4) = "Le sort en est jete."
LST_Reponses$(5) = "Une chance sur deux."
LST_Reponses$(6) = "Repose ta question."
LST_Reponses$(7) = "D'apres moi oui."
LST_Reponses$(8) = "C'est certain."
LST_Reponses$(9) = "Oui absolument."
LST_Reponses$(10) = "Tu peux compter dessus."
LST_Reponses$(11) = "Sans aucun doute"
LST_Reponses$(12) = "Tres probable."
LST_Reponses$(13) = "Oui."
LST_Reponses$(14) = "C'est bien parti."
LST_Reponses$(15) = "C'est non."
LST_Reponses$(16) = "Peu probable."
LST_Reponses$(17) = "Faut pas rever."
LST_Reponses$(18) = "N'y compte pas."
LST_Reponses$(19) = "Impossible."
' --- DEBUT DU PROGRAMME ---
FNC_Boule
' --- BOUCLE PRINCIPALE ---
DO
' --- Saisie ... ---
LOCATE 24, 2: INPUT "Votre Question "; kquestion$
LOCATE 24, 1: PRINT SPC(79)
FNC_Animation
FNC_Reponse
' --- Bouclage du programme ---
LOCATE 21, 21: PRINT "Avez-vous une autre question [ O ou N ] ?"
DO: kchoix$ = INKEY$: _DELAY 0.005: LOOP UNTIL UCASE$(kchoix$) <> ""
LOCATE 20, 1: PRINT SPC(79)
LOCATE 21, 1: PRINT SPC(79)
LOOP UNTIL UCASE$(kchoix$) = "N"
' --- FIN DU PROGRAMME ---
LOCATE 21, 37: PRINT "Au revoir."
END
' --- DEFINITION DES FONCTIONS PERSONNALISEES ---
' --- Animation de la boule 8 magique ---
SUB FNC_Animation
kabsicsse = 210: khorizontal = -5
kordonnee = 90: kvertical = -3
FOR kvaleur = O TO 45
IF kabsicsse < 201 THEN khorizontal = 5
IF kabsicsse > 219 THEN khorizontal = -5
kabsicsse = kabsicsse + khorizontal
IF kordonnee < 83 THEN kvertical = 3
IF kordonnee > 97 THEN kvertical = -3
kordonnee = kordonnee + kvertical
PUT (kabsicsse, kordonnee), IMG_Boule(), PSET
_DELAY 0.01
NEXT kvaleur
PUT (210, 90), IMG_Boule(), PSET
END SUB
' --- Dessin initial de la boule 8 magique ---
SUB FNC_Boule
COLOR 0, 15: CLS
CIRCLE (320, 200), 40
FOR kcercle = 8 TO 14
CIRCLE (320, 189), kcercle - 2
CIRCLE (320, 211), kcercle
NEXT kcercle
CIRCLE (320, 200), 100: PAINT (250, 200), 0
GET (210, 90)-(430, 310), IMG_Boule()
LOCATE 2, 32: PRINT "LE HUIT MAGIQUE."
END SUB
' --- Reponse de l'oracle ---
SUB FNC_Reponse
kindex = INT(RND * 19)
kreponse$ = LST_Reponses(kindex)
kcolonne = (82 - LEN(kreponse$)) / 2
LOCATE 20, kcolonne: PRINT kreponse$
END SUB
' --- Programme : JFB ---
' --- Avril 2026 ---
' --- Fin ---
Pour mieux comprendre l'exemple en QB64.
REM --- Origine Nerd propose pour ---
REM --- RETROGICIEL - BBC BASIC ---
REM --- Le huit magique ---
REM --- Origine Nerd propose pour ---
REM --- RETROGICIEL - BBC BASIC ---
REM --- Le huit magique ---
REM --- INITIALISATION GENERALE ---
REM --- Initialisation principale ---
MODE 8
REM --- Déclarations des variables globales ---
DIM LST_Reponses$(19)
REM --- Initialisation des valeurs ---
LST_Reponses$(0) = "Essaye plus tard."
LST_Reponses$(1) = "Essaye encore."
LST_Reponses$(2) = "Pas d'avis."
LST_Reponses$(3) = "C'est ton destin."
LST_Reponses$(4) = "Le sort en est jete."
LST_Reponses$(5) = "Une chance sur deux."
LST_Reponses$(6) = "Repose ta question."
LST_Reponses$(7) = "D'apres moi oui."
LST_Reponses$(8) = "C'est certain."
LST_Reponses$(9) = "Oui absolument."
LST_Reponses$(10) = "Tu peux compter dessus."
LST_Reponses$(11) = "Sans aucun doute"
LST_Reponses$(12) = "Tres probable."
LST_Reponses$(13) = "Oui."
LST_Reponses$(14) = "C'est bien parti."
LST_Reponses$(15) = "C'est non."
LST_Reponses$(16) = "Peu probable."
LST_Reponses$(17) = "Faut pas rever."
LST_Reponses$(18) = "N'y compte pas."
LST_Reponses$(19) = "Impossible."
REM --- DEBUT DU PROGRAMME ---
PROC_Boule
REM --- BOUCLE PRINCIPALE ---
REPEAT
REM --- Saisie ... ---
INPUT TAB( 1 , 22 ) "Votre Question "; kquestion$
PRINT TAB( 0 , 22 ) SPC(79)
PROC_Animation
PROC_Reponse
REM --- Bouclage du programme ---
PRINT TAB( 20 , 19 ) "Avez-vous une autre question [ O ou N ] ?"
kchoix$ = GET$
PRINT TAB( 0 , 18 ) SPC( 79 )
PRINT TAB( 0 , 19 ) SPC( 79 )
UNTIL kchoix$ = "N" OR kchoix$ = "n"
REM --- FIN DU PROGRAMME ---
PRINT TAB( 35 , 19 ) "Au revoir."
END
REM --- DEFINITION DES FONCTIONS PERSONNALISEES ---
REM --- Animation de la boule 8 magique ---
DEF PROC_Animation
kabscisse = 420 : khorizontal = -10
kordonnee = 460 : kvertical = 8
FOR kvaleur = 0 TO 45
kx = kabscisse : ky = kordonnee
IF kabscisse < 401 THEN khorizontal = 10
IF kabscisse > 439 THEN khorizontal = -10
kabscisse = kabscisse + khorizontal
IF kordonnee < 455 THEN kvertical = 8
IF kordonnee > 485 THEN kvertical = -8
kordonnee = kordonnee + kvertical
RECTANGLE FILL kx , ky , 440 , 440 TO kabscisse , kordonnee
WAIT( 1 )
NEXT kvaleur
RECTANGLE FILL kabscisse , kordonnee , 440 , 440 TO 420 , 460
ENDPROC
REM --- Dessin de la boule initaile ---
DEF PROC_Boule
COLOUR 0 : COLOUR 143 : CLS
GCOL 143 : CLG
GCOL 0 : CIRCLE FILL 640 , 680 , 200
GCOL 15 : CIRCLE FILL 640 , 680 , 80
GCOL 0 : CIRCLE FILL 640 , 708 , 34
GCOL 15 : CIRCLE FILL 640 , 708 , 16
GCOL 0 : CIRCLE FILL 640 , 652 , 37
GCOL 15 : CIRCLE FILL 640 , 652 , 19
PRINT TAB( 32 , 1 ) "LE HUIT MAGIQUE."
ENDPROC
REM --- Reponse de l'oracle ---
DEF PROC_Reponse
kindex = RND( 19 )
kreponse$ = LST_Reponses$( kindex )
kcolonne = ( 82 - LEN( kreponse$ ) ) / 2
PRINT TAB( kcolonne , 18 ) kreponse$
ENDPROC
REM --- Programme : JFB ---
REM --- Avril 2026 ---
REM --- Fin ---
Pour mieux comprendre l'exemple en BBC BASIC.