voilà je me suis amusé a codé un petit "simon"
Il n'y a rien d'extraordinaire dans ce code, donc rien d'extraordinaire a dire dessus
Règle du jeu :
Il vous faut juste cliquer et avoir de la mémoire.Source wikipedia a écrit :Le jeu du Simon trouve son origine dans le jeu pour enfant Jacques a dit, d'où il tire également son nom, puisque dans les pays anglophones ce n'est pas Jacques mais Simon (Simon Says…) qui donne les ordres.
Le jeu, éclaire une des quatre couleurs et produit un son toujours associé à cette couleur. Le joueur doit alors appuyer sur la touche de la couleur qui vient de s'allumer.
Le jeu répète la même couleur et le même son, puis ajoute au hasard une nouvelle couleur. Le joueur doit reproduire cette nouvelle séquence. Chaque fois que le joueur reproduit correctement la séquence, le jeu ajoute une nouvelle couleur.
Source + fichiers
Code seul :
Code : Tout sélectionner
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; + Autor : Venom +
; + Project name : Simon Says +
; + Version : V 1.0 +
; + Compilator : PureBasic V5.73 +
; + Date : 16/01/2021 +
; + OS : Windows 10 +
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;- Window Constants
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Enumeration
#Window_0
EndEnumeration
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;- Gadgets Constants
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Enumeration
#GreenNight
#RedNight
#YellowNight
#BlueNight
#GreenLight
#RedLight
#YellowLight
#BlueLight
#Sound_1
#Sound_2
#Sound_3
#Sound_4
#Sound_Over
#Button_1
#Button_2
#Button_3
#Button_4
EndEnumeration
EnableExplicit
Global EventID
Global a, NbCoups = 0, CoupEnCours = 0, ID_Button_1 = 1, ID_Button_2 = 2, ID_Button_3 = 3, ID_Button_4 = 4, Time = 500, TimeGamer = 200,TimeOver = 1000
Global DossierGraphique$ = "gfx\"
Global DossierSons$ = "sfx\"
Global Dim TabGame(99)
Declare LoadFilesAndTab()
Declare Intro(*Valeur)
Declare Over(*Valeur)
Declare PlayTab(*valeur)
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;- ouverture de la fenetre
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
If OpenWindow(#Window_0, 0, 0, 300, 300, "Simon Says", #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
LoadFilesAndTab()
ButtonImageGadget(#Button_1, 0, 0, 150, 150, ImageID(#GreenNight))
ButtonImageGadget(#Button_2, 150, 0, 150, 150, ImageID(#RedNight))
ButtonImageGadget(#Button_3, 0, 150, 150, 150, ImageID(#YellowNight))
ButtonImageGadget(#Button_4, 150, 150, 150, 150, ImageID(#BlueNight))
CreateThread(@Intro(), 23)
EndIf
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;- Boucle principale
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_Event_Gadget
Select EventGadget()
Case #Button_1
SetGadgetAttribute(#Button_1, #PB_Button_Image, ImageID(#GreenLight))
PlaySound(#Sound_1, #PB_Sound_MultiChannel, 100)
Delay(TimeGamer)
SetGadgetAttribute(#Button_1, #PB_Button_Image, ImageID(#GreenNight))
Delay(TimeGamer)
If TabGame(CoupEnCours) = ID_Button_1
If CoupEnCours = NbCoups
SetWindowTitle(#Window_0, "Simon Says | tour : "+Str(NbCoups+1)+" terminé")
NbCoups = NbCoups+1
CreateThread(@PlayTab(), 23)
CoupEnCours = 0
ElseIf CoupEnCours < NbCoups And TabGame(CoupEnCours) = ID_Button_1
CoupEnCours = CoupEnCours+1
EndIf
Else
PlaySound(#Sound_Over, #PB_Sound_MultiChannel, 100)
SetWindowTitle(#Window_0, "Simon Says | game over")
Delay(TimeOver)
CreateThread(@Over(), 23)
EndIf
Case #Button_2
SetGadgetAttribute(#Button_2, #PB_Button_Image, ImageID(#RedLight))
PlaySound(#Sound_2, #PB_Sound_MultiChannel, 100)
Delay(TimeGamer)
SetGadgetAttribute(#Button_2, #PB_Button_Image, ImageID(#RedNight))
Delay(TimeGamer)
If TabGame(CoupEnCours) = ID_Button_2
If CoupEnCours = NbCoups
SetWindowTitle(#Window_0, "Simon Says | tour : "+Str(NbCoups+1)+" terminé")
NbCoups = NbCoups+1
CreateThread(@PlayTab(), 23)
CoupEnCours = 0
ElseIf CoupEnCours < NbCoups And TabGame(CoupEnCours) = ID_Button_2
CoupEnCours = CoupEnCours+1
EndIf
Else
PlaySound(#Sound_Over, #PB_Sound_MultiChannel, 100)
SetWindowTitle(#Window_0, "Simon Says | game over")
Delay(TimeOver)
CreateThread(@Over(), 23)
EndIf
Case #Button_3
SetGadgetAttribute(#Button_3, #PB_Button_Image, ImageID(#YellowLight))
PlaySound(#Sound_3, #PB_Sound_MultiChannel, 100)
Delay(TimeGamer)
SetGadgetAttribute(#Button_3, #PB_Button_Image, ImageID(#YellowNight))
Delay(TimeGamer)
If TabGame(CoupEnCours) = ID_Button_3
If CoupEnCours = NbCoups
SetWindowTitle(#Window_0, "Simon Says | tour : "+Str(NbCoups+1)+" terminé")
NbCoups = NbCoups+1
CreateThread(@PlayTab(), 23)
CoupEnCours = 0
ElseIf CoupEnCours < NbCoups And TabGame(CoupEnCours) = ID_Button_3
CoupEnCours = CoupEnCours+1
EndIf
Else
PlaySound(#Sound_Over, #PB_Sound_MultiChannel, 100)
SetWindowTitle(#Window_0, "Simon Says | game over")
Delay(TimeOver)
CreateThread(@Over(), 23)
EndIf
Case #Button_4
SetGadgetAttribute(#Button_4, #PB_Button_Image, ImageID(#BlueLight))
PlaySound(#Sound_4, #PB_Sound_MultiChannel, 100)
Delay(TimeGamer)
SetGadgetAttribute(#Button_4, #PB_Button_Image, ImageID(#BlueNight))
Delay(TimeGamer)
If TabGame(CoupEnCours) = ID_Button_4
If CoupEnCours = NbCoups
SetWindowTitle(#Window_0, "Simon Says | tour : "+Str(NbCoups+1)+" terminé")
NbCoups = NbCoups+1
CreateThread(@PlayTab(), 23)
CoupEnCours = 0
ElseIf CoupEnCours < NbCoups And TabGame(CoupEnCours) = ID_Button_4
CoupEnCours = CoupEnCours+1
EndIf
Else
PlaySound(#Sound_Over, #PB_Sound_MultiChannel, 100)
SetWindowTitle(#Window_0, "Simon Says | game over")
Delay(TimeOver)
CreateThread(@Over(), 23)
EndIf
EndSelect
EndIf
Until EventID = #PB_Event_CloseWindow
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;- Procedures
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Procedure LoadFilesAndTab()
UsePNGImageDecoder()
If InitSound() = 0
MessageRequester("Erreur", "Impossible d'initialisé le son", 0)
End
EndIf
; chargement des images
LoadImage(#GreenNight, DossierGraphique$+"GreenNight.png", 0)
LoadImage(#RedNight, DossierGraphique$+"RedNight.png", 0)
LoadImage(#YellowNight, DossierGraphique$+"YellowNight.png", 0)
LoadImage(#BlueNight, DossierGraphique$+"BlueNight.png", 0)
;
LoadImage(#GreenLight, DossierGraphique$+"Green.png", 0)
LoadImage(#RedLight, DossierGraphique$+"Red.png", 0)
LoadImage(#YellowLight, DossierGraphique$+"Yellow.png", 0)
LoadImage(#BlueLight, DossierGraphique$+"Blue.png", 0)
; Chargement des sons
LoadSound(#Sound_1, DossierSons$+"1.wav")
LoadSound(#Sound_2, DossierSons$+"2.wav")
LoadSound(#Sound_3, DossierSons$+"3.wav")
LoadSound(#Sound_4, DossierSons$+"4.wav")
LoadSound(#Sound_Over, DossierSons$+"over.wav")
; rempli le tableau aléatoire entre 1 et 4
For a = 0 To 99
TabGame(a) = Random(4, 1)
Next
EndProcedure
Procedure Intro(*Valeur)
Delay(TimeGamer)
SetGadgetAttribute(#Button_1, #PB_Button_Image, ImageID(#GreenLight)); allume la case green
PlaySound(#Sound_1, #PB_Sound_MultiChannel, 100); joue le son
Delay(TimeGamer)
SetGadgetAttribute(#Button_2, #PB_Button_Image, ImageID(#RedLight)); allume la case red
PlaySound(#Sound_2, #PB_Sound_MultiChannel, 100); joue le son
Delay(TimeGamer)
SetGadgetAttribute(#Button_3, #PB_Button_Image, ImageID(#YellowLight)); allume la case yellow
PlaySound(#Sound_3, #PB_Sound_MultiChannel, 100); joue le son
Delay(TimeGamer)
SetGadgetAttribute(#Button_4, #PB_Button_Image, ImageID(#BlueLight)); allume la case blue
PlaySound(#Sound_4, #PB_Sound_MultiChannel, 100); joue le son
Delay(Time)
SetGadgetAttribute(#Button_1, #PB_Button_Image, ImageID(#GreenNight)); eteint la case green
SetGadgetAttribute(#Button_2, #PB_Button_Image, ImageID(#RedNight)); eteint la case red
SetGadgetAttribute(#Button_3, #PB_Button_Image, ImageID(#YellowNight)); eteint la case yellow
SetGadgetAttribute(#Button_4, #PB_Button_Image, ImageID(#BlueNight)); eteint la case blue
Delay(Time)
;- demarre la game
CreateThread(@PlayTab(), 23)
EndProcedure
Procedure Over(*Valeur)
Delay(Time)
SetGadgetAttribute(#Button_4, #PB_Button_Image, ImageID(#GreenLight)); allume la case green
PlaySound(#Sound_4, #PB_Sound_MultiChannel, 100); joue le son
Delay(TimeGamer)
SetGadgetAttribute(#Button_3, #PB_Button_Image, ImageID(#RedLight)); allume la case red
PlaySound(#Sound_3, #PB_Sound_MultiChannel, 100); joue le son
Delay(TimeGamer)
SetGadgetAttribute(#Button_2, #PB_Button_Image, ImageID(#YellowLight)); allume la case yellow
PlaySound(#Sound_2, #PB_Sound_MultiChannel, 100); joue le son
Delay(TimeGamer)
SetGadgetAttribute(#Button_1, #PB_Button_Image, ImageID(#BlueLight)); allume la case blue
PlaySound(#Sound_1, #PB_Sound_MultiChannel, 100); joue le son
Delay(Time)
End
EndProcedure
Procedure PlayTab(*valeur)
Delay(TimeGamer)
For a = 0 To NbCoups
If TabGame(a) = 1
SetGadgetAttribute(#Button_1, #PB_Button_Image, ImageID(#GreenLight))
PlaySound(#Sound_1, #PB_Sound_MultiChannel, 100)
Delay(Time)
SetGadgetAttribute(#Button_1, #PB_Button_Image, ImageID(#GreenNight))
ElseIf TabGame(a) = 2
SetGadgetAttribute(#Button_2, #PB_Button_Image, ImageID(#RedLight))
PlaySound(#Sound_2, #PB_Sound_MultiChannel, 100)
Delay(Time)
SetGadgetAttribute(#Button_2, #PB_Button_Image, ImageID(#RedNight))
ElseIf TabGame(a) = 3
SetGadgetAttribute(#Button_3, #PB_Button_Image, ImageID(#YellowLight))
PlaySound(#Sound_3, #PB_Sound_MultiChannel, 100)
Delay(Time)
SetGadgetAttribute(#Button_3, #PB_Button_Image, ImageID(#YellowNight))
ElseIf TabGame(a) = 4
SetGadgetAttribute(#Button_4, #PB_Button_Image, ImageID(#BlueLight))
PlaySound(#Sound_4, #PB_Sound_MultiChannel, 100)
Delay(Time)
SetGadgetAttribute(#Button_4, #PB_Button_Image, ImageID(#BlueNight))
EndIf
Delay(Time)
Next
EndProcedure
@++