| |
Voici le code source dans le langage Blitz : Type TPlateau Field Entity ;L'entité du sprite (un cube) Field x#, y#, z# End Type Type TJeton Field Entity ;L'entité du sprite (une sphere) Field x#, y#, z# End Type Type TSouris Field x#, y#, alpha#, zeta# End Type Type TCamera Field x#, y#, z# End Type Print "" valX% = Input("Nombre de colonne = ") valY% = Input("Nombre de ligne = ") valZ% = Input("Profondeur de la grille = ") ; Initialisation Generale Graphics3D 800, 600, 0, 0 SetBuffer BackBuffer() ; Les variables globales Global plateau.TPlateau = New TPlateau Global jeton.TJeton = New TJeton Global jetonAide.TJeton = New TJeton Global souris.TSouris = New TSouris Global cameraT.TCamera = New TCamera Global joueur = 1 Global win = False Dim tabTest(13-1, 3-1) ; Création de la caméra en globale Global camera = CreateCamera() Global PositionAatteindre = 0 Global JetonEnDeplacement = False ; Definition des positions souris\x# = 800 / 2 souris\y# = 640 / 2 MoveMouse 800/2, 640/2 souris\alpha# = 0 souris\zeta# = 0 cameraT\x# = 0 cameraT\y# = 5 cameraT\z# = -15 jeton\x# = 0 jeton\z# = 0 jetonAide\Entity = CreateSphere() ; Positionner la camera PositionEntity camera, cameraT\x#, cameraT\y#, cameraT\z# ; Timer afin de limiter a 60 fps frameTimer = CreateTimer(60) ; Creation du plateau Dim tab(valX%-1, valY%-1, valZ%-1) CreerPlateau(valX%, valY%, valZ%) CreerJeton() ; Tant que pas appuie sur la touche «ESC» While Not KeyHit(1) WaitTimer(frameTimer) UpdateWorld ; Mise à jour du monde RenderWorld ; Rendu du monde TournerAutour() ; Gere la posibilité de tourner autour du plateau avec la souris If (win = False ) DeplacerJeton() ; Fonction de deplacement du jeton If JetonEnDeplacement = False And (KeyHit(156) Or KeyHit(28)) And win = False Then PlacerJeton() ; Procedure de placement du jeton ; Print "[" + tab(0, 0, 0) + ". " + tab(0, 1, 0) + ". " + tab(0, 2, 0) + ". " + tab(0, 4, 0) + "] " ; Print win Flip Wend ; Fin du tant que ClearWorld ; Liberation de toutes les entitées du monde EndGraphics ; Libération de l'init graphique End ; Fermer proprement le programme ; ***************************************************************************************************************************** ; * Fonction : CreerPlateau ; * Infos : Cette fonction creer un plateau de Puissance4 au taille demandé ; * Param : x = nombre de case en x ; * y = nombre de case en y ; * z = nombre de case en z ; ***************************************************************************************************************************** Function CreerPlateau(x, y, z) plateau\Entity = CreateCube() ; Creation de l'entité Cubique plateau\x# = x plateau\y# = y plateau\z# = z PositionEntity plateau\Entity, x-1, 0, z-1 EntityAlpha plateau\Entity, 0.5 EntityColor plateau\Entity, 200, 0, 0 ScaleEntity plateau\Entity, plateau\x#, plateau\y#, plateau\z# End Function ; ***************************************************************************************************************************** ; * Fonction : ; * Infos : On creer un jeton. ; * Param : ; ***************************************************************************************************************************** Function CreerJeton() jeton\Entity = CreateSphere() ; Creation de l'entité Sphérique jeton\y# = plateau\y# +1 PositionEntity jeton\Entity, jeton\x# *2, jeton\y#, jeton\z# *2 If joueur = 1 EntityColor jeton\Entity, 0, 255, 0 ElseIf joueur = 2 EntityColor jeton\Entity, 0, 0, 255 EndIf End Function ; ***************************************************************************************************************************** ; * Fonction : ; * Infos : Fonction permettant de tourner autour du plateau avec la souris ; * Param : ; ***************************************************************************************************************************** Function TournerAutour() d# = MouseX() - souris\x# f# = MouseY() - souris\y# souris\alpha# = souris\alpha# + d# souris\zeta# = souris\zeta# - f# MoveMouse souris\x#, souris\y# r# = 15 beta# = (180 - souris\alpha#) / 2 t# = 2 * r# * Cos(beta#) nu# = 90 - beta# x# = t# * Cos (nu#) z# = t# * Sin (nu#) cameraT\x# = x# cameraT\z# = z# -15 cameraT\y# = souris\zeta# PositionEntity camera, cameraT\x#, cameraT\y#, cameraT\z# ;On se deplace (deplacement relatif avec translate mais pas suivant SON axe comme avec MoveEntity !!!) ;On fait en sorte que la camera se tourne vers le plateau PointEntity camera, plateau\Entity End Function ; ***************************************************************************************************************************** ; * Fonction : ; * Infos : Deplacement du jeton ; * Param : ; ***************************************************************************************************************************** Function DeplacerJeton() If JetonEnDeplacement = True And jeton\y# > PositionAatteindre jeton\y# = jeton\y# -0.5 PositionEntity jeton\Entity, jeton\x# *2, jeton\y#, jeton\z# *2 Else If JetonEnDeplacement = True And jeton\y# <= PositionAatteindre JetonEnDeplacement = False ; On dit que cet emplacement est utilisé tab(Int(jeton\x#), (Int(jeton\y#) + Int(plateau\y#) -1) /2, Int(jeton\z#)) = joueur ; On test si le joueur a gagné la partie TesterFinDePartie() ; On change de joueur joueur = joueur +1 If joueur > 2 Then joueur = 1 ; On creer un nouveau jeton If win = False CreerJeton() If win = False PlacerJetonAide() Else If KeyHit( 200 )=True And jeton\z# < plateau\z# -1 ; Touche HAUT jeton\z# = jeton\z# + 1 TranslateEntity jeton\Entity, 0, 0, +2 Else If KeyHit( 208 )=True And jeton\z# > 0 ; Touche BAS jeton\z# = jeton\z# - 1 TranslateEntity jeton\Entity, 0, 0, -2 Else If KeyHit( 203 )=True And jeton\x# > 0 ; Touche GAUCHE jeton\x# = jeton\x# -1 TranslateEntity jeton\Entity, -2, 0, 0 Else If KeyHit( 205 )=True And jeton\x# < plateau\x# -1 ; Touche DROITE jeton\x# = jeton\x# + 1 TranslateEntity jeton\Entity, +2, 0, 0 EndIf PlacerJetonAide() End If End Function ; ***************************************************************************************************************************** ; * Fonction : ; * Infos : On place le jeton si possible ; * Param : ; ***************************************************************************************************************************** Function PlacerJeton() ; On place le jeton si possible placer = False For i = 0 To plateau\y#-1 If tab(jeton\x#, i, jeton\z#) = False And placer = False PositionAatteindre = -plateau\y# +1 +i*2 JetonEnDeplacement = True placer = True EndIf Next End Function ; ***************************************************************************************************************************** ; * Fonction : ; * Infos : Placer un jeton blanc dans la grille, pour ne pas jouer à coté ; * Param : ; ***************************************************************************************************************************** Function PlacerJetonAide() ; On place le jeton si possible placer = False For i = 0 To plateau\y#-1 If tab(jeton\x#, i, jeton\z#) = False And placer = False PositionEntity jetonAide\Entity, jeton\x# * 2, -(plateau\y#/2 -i) *2 +1, jeton\z# * 2 placer = True EndIf Next If placer = False Then PositionEntity jetonAide\Entity, jeton\x# *2, jeton\y#, jeton\z# * 2 End Function ; ***************************************************************************************************************************** ; * Fonction : ; * Infos : Tester les combinaisons possibles pour gagner la fin de partie. ; * Param : ; ***************************************************************************************************************************** Function TesterFinDePartie() j = joueur ; Test des verticales For i = 0 To plateau\x# -1 For o = 0 To plateau\y# -1 -3 For p = 0 To plateau\z# -1 If tab(i, o +0, p) = j And tab(i, o +1, p) = j And tab(i, o +2, p) = j And tab(i, o +3, p) = j Then win = True Next Next Next ; Test des horizontales For i = 0 To plateau\x# -1 -3 For o = 0 To plateau\y# -1 For p = 0 To plateau\z# -1 If tab(i +0, o, p) = j And tab(i +1, o, p) = j And tab(i +2, o, p) = j And tab(i +3, o, p) = j Then win = True Next Next Next ; Test des profondeurs For i = 0 To plateau\x# -1 For o = 0 To plateau\y# -1 For p = 0 To plateau\z# -1 -3 If tab(i +0, o +0, p +0) = j And tab(i +0, o +0, p +1) = j And tab(i +0, o +0, p +2) = j And tab(i +0, o +0, p +3) = j Then win = True Next Next Next ; Diag / 2D [vue de face] For i = 0 To plateau\x# -1 -3 For o = 0 To plateau\y# -1 -3 For p = 0 To plateau\z# -1 If tab(i +0, o +0, p +0) = j And tab(i +1, o +1, p +0) = j And tab(i +2, o +2, p +0) = j And tab(i +3, o +3, p +0) = j Then win = True Next Next Next ; Diag \ 2D [vue de face] For i = plateau\x# -1 To 0 +3 Step -1 For o = 0 To plateau\y# -1 -3 For p = 0 To plateau\z# -1 If tab(i +0, o +0, p +0) = j And tab(i -1, o +1, p +0) = j And tab(i -2, o +2, p +0) = j And tab(i -3, o +3, p +0) = j Then win = True Next Next Next ; Diag / 2D [vue de dessus] For i = 0 To plateau\x# -1 -3 For o = 0 To plateau\y# -1 For p = 0 To plateau\z# -1 -3 If tab(i +0, o +0, p +0) = j And tab(i +1, o +0, p +1) = j And tab(i +2, o +0, p +2) = j And tab(i +3, o +0, p +3) = j Then win = True Next Next Next ; Diag \ 2D [vue de dessus] For i = plateau\x# -1 To 0 +3 Step -1 For o = 0 To plateau\y# -1 For p = 0 To plateau\z# -1 -3 If tab(i +0, o +0, p +0) = j And tab(i -1, o +0, p +1) = j And tab(i -2, o +0, p +2) = j And tab(i -3, o +0, p +3) = j Then win = True Next Next Next ; Diag / 2D [vue de coté] For i = 0 To plateau\x# -1 For o = 0 To plateau\y# -1 -3 For p = 0 To plateau\z# -1 -3 If tab(i +0, o +0, p +0) = j And tab(i +0, o +1, p +1) = j And tab(i +0, o +2, p +2) = j And tab(i +0, o +3, p +3) = j Then win = True Next Next Next ; Diag \ 2D [vue de coté] For i = 0 To plateau\x# -1 For o = 0 To plateau\y# -1 -3 For p = plateau\z# -1 To 0 +3 Step -1 If tab(i +0, o +0, p +0) = j And tab(i +0, o +1, p -1) = j And tab(i +0, o +2, p -2) = j And tab(i +0, o +3, p -3) = j Then win = True Next Next Next ; Diag 3D For i = 0 To plateau\x# -1 -3 For o = 0 To plateau\y# -1 -3 For p = 0 To plateau\z# -1 -3 If tab(i +0, o +0, p +0) = j And tab(i +1, o +1, p +1) = j And tab(i +2, o +2, p +2) = j And tab(i +3, o +3, p +3) = j Then win = True Next Next Next ; Diag 3D For i = plateau\x# -1 To 0 +3 Step -1 For o = 0 To plateau\y# -1 -3 For p = 0 To plateau\z# -1 -3 If tab(i -0, o +0, p +0) = j And tab(i -1, o +1, p +1) = j And tab(i -2, o +2, p +2) = j And tab(i -3, o +3, p +3) = j Then win = True Next Next Next ; Diag 3D For i = plateau\x# -1 To 0 +3 Step -1 For o = 0 To plateau\y# -1 -3 For p = plateau\z# -1 To 0 +3 Step -1 If tab(i -0, o +0, p +0) = j And tab(i -1, o +1, p -1) = j And tab(i -2, o +2, p -2) = j And tab(i -3, o +3, p -3) = j Then win = True Next Next Next ; Diag 3D For i = 0 To plateau\x# -1 -3 For o = 0 To plateau\y# -1 -3 For p = plateau\z# -1 To 0 +3 Step -1 If tab(i +0, o +0, p +0) = j And tab(i +1, o +1, p -1) = j And tab(i +2, o +2, p -2) = j And tab(i +3, o +3, p -3) = j Then win = True Next Next Next End Function |
|
Site Web de Division-par-zero v2.0
Mise à jour du site le Dimanche 22 avril 2007
Site web codé en PHP5, parceque ce n'est plus en beta-test depuis longtemps, et que PHP4 est loin d'être au point niveau POO. Compatible Internet Explorer / Mozila Firefox, et les écrans 800x600. |