Aujourd'hui je ne savais pas quoi faire alors j'ai réinventé la roue
 
 Donc, voici un grand classique du jeu vidéo Pong.
C'est un programme qui doit être compilé en mode console pour fonctionner.
Voici le code source :
► Afficher le textePong.au3
Code : Tout sélectionner
#Region
#AutoIt3Wrapper_Change2CUI=y
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion
#include "Console.au3"
#cs ----------------------------------------------------------------------------
 AutoIt Version : 3.3.8.1
 Auteur :         TT22
 Version :        1.1
 Date :           30/07/2012
 Fonction du Script :
    Jeu Pong en console.
#ce ----------------------------------------------------------------------------
If Not _IsConsole() Then ; Verifis si le script est compilé en mode console...
    MsgBox(16,"Pong : Erreur","Erreur : Ce script doit être compilé en mode console pour fonctionner !")
    Exit
EndIf
Global $LeftPos = 9 ; Depuis le haut de la console...
Global $RightPos = 9
Global $LeftPoints = 0 ; Nombre de points des joueurs...
Global $RightPoints = 0
Global $Ball[2] = [2,12] ; Position de la balle : [Left,Top]
Global $Speed = 5 ; Vitesse de la balle.
If Random(2,3,1) = 2 Then
    Global $BallDirection[4] = [1,0,Random(0,1,0.2),0] ; Direction de la balle : [Left,Right,Up,Down]
Else
    Global $BallDirection[4] = [1,0,0,Random(0,1,0.2)] ; Direction de la balle : [Left,Right,Up,Down]
EndIf
_cls() ; Efface le contenu de la console.
_SetConsoleTitle("Pong") ; Titre de la fenêtre DOS.
For $k = 1 To 8 Step 1 ; Affiche le message de départ...
    _printf()
    _ReduceMemory() ; Vide la mémoire innutile.
Next
_SetConsoleTextAttribute(BitOR($FOREGROUND_RED,$FOREGROUND_INTENSITY))
_printf("                          PPPPP    OOOO   NN  NN   GGGG")
_printf("                          PPPPPP  OOOOOO  NNN NN  GG")
_printf("                          PP  PP  OO  OO  NNNNNN  GG GGG")
_printf("                          PPPPP   OO  OO  NNNNNN  GG  GG")
_printf("                          PP      OOOOOO  NN NNN  GG  GG")
_printf("                          PP       OOOO   NN  NN   GGGG")
_SetConsoleTextAttribute($DEFAULT_COLOR)
_printf()
_printf()
_printf("                                                   Par TT22")
_printf("                                       Vitesse actuelle : %d", $Speed)
_printf("                                  Pour jouer, appuyez sur A")
_printf("                             Pour gagner, marquez 10 points")
_printf("                        Pour mettre en pause, appuyez sur P")
While Not __IsPressed(41) ; Attend que la touche A soit pressé...
    _ReduceMemory() ; Vide la mémoire innutile.
WEnd
_cls() ; Efface la console.
While 1
    _SetConsoleCursorPosition(0,0) ; Ecrit le score...
    ConsoleWrite($LeftPoints)
    _SetConsoleCursorPosition(79,0)
    ConsoleWrite($RightPoints)
    _SetConsoleCursorPosition(Round($Ball[0],0),Round($Ball[1],0)) ; Affiche la balle... Positionne le curseur.
    _SetConsoleTextAttribute($BACKGROUND_RED,$BACKGROUND_GREEN,$BACKGROUND_BLUE,$BACKGROUND_INTENSITY)
    ConsoleWrite(" ")
    _SetConsoleTextAttribute($DEFAULT_COLOR)
    For $i = -1 To 1 Step 1 ; Efface l'ancienne position de la balle...
        For $j = -1 To 1 Step 1
            If $i <> 0 Or $j <> 0 Then
                _SetConsoleCursorPosition(Round($Ball[0],0)+$i,Round($Ball[1],0)+$j)
                ConsoleWrite(" ")
            EndIf
        Next
    Next
    _SetConsoleTextAttribute($BACKGROUND_RED,$BACKGROUND_INTENSITY) ; Affiche la raquète rouge...
    For $i = 1 To 5 Step 1
        _SetConsoleCursorPosition(1,$i+$LeftPos) ; Positionne le curseur.
        ConsoleWrite(" ")
    Next
    _SetConsoleTextAttribute($DEFAULT_COLOR)
    _SetConsoleCursorPosition(1,$LeftPos) ; Efface l'ancienne raquète rouge... Positionne le curseur.
    ConsoleWrite(" ")
    _SetConsoleCursorPosition(1,$LeftPos+6) ; Positionne le curseur.
    ConsoleWrite(" ")
    _SetConsoleTextAttribute($BACKGROUND_BLUE,$BACKGROUND_INTENSITY) ; Affiche la raquète bleu...
    For $i = 1 To 5 Step 1
        _SetConsoleCursorPosition(78,$i+$RightPos) ; Positionne le curseur.
        ConsoleWrite(" ")
    Next
    _SetConsoleTextAttribute($DEFAULT_COLOR)
    _SetConsoleCursorPosition(78,$RightPos) ; Efface l'ancienne raquète bleu... Positionne le curseur.
    ConsoleWrite(" ")
    _SetConsoleCursorPosition(78,$RightPos+6) ; Positionne le curseur.
    ConsoleWrite(" ")
    If __IsPressed(26) And $LeftPos > 0 Then ; Déplacement du joueur...
        $LeftPos -= 1
    EndIf
    If __IsPressed(28) And $LeftPos+5 < 23 Then
        $LeftPos += 1
    EndIf
    If $BallDirection[2] <> 0 And $RightPos > 0 And $RightPos+5 > Round($Ball[1],0) Then ; Gestion du joueur automatique...
        If Random(1,3,1) = 2 Then $RightPos -= 1
    EndIf
    If $BallDirection[3] <> 0 And $RightPos+5 < 23 And $RightPos < Round($Ball[1],0) Then
        If Random(1,3,1) = 2 Then $RightPos += 1
    EndIf
    $Ball[0] += $BallDirection[0] - $BallDirection[1] ; Incrémentation de la position de la balle...
    $Ball[1] -= $BallDirection[2] - $BallDirection[3]
    $BallDirectionCpy = $BallDirection ; Gestion du changement de direction en cas de rencontre avec le bord...
    If Round($Ball[0],0) = 2 Then
        $BallDirection[0] = $BallDirectionCpy[1]
        $BallDirection[1] = $BallDirectionCpy[0]
        _RandomChangeUpDown() ; Changement de sens améatoire..
    EndIf
    If Round($Ball[0],0) = 77 Then
        $BallDirection[0] = $BallDirectionCpy[1]
        $BallDirection[1] = $BallDirectionCpy[0]
        _RandomChangeUpDown() ; Changement de sens améatoire..
    EndIf
    If Round($Ball[1],0) = 1 Then
        $BallDirection[2] = $BallDirectionCpy[3]
        $BallDirection[3] = $BallDirectionCpy[2]
    EndIf
    If Round($Ball[1],0) = 23 Then
        $BallDirection[2] = $BallDirectionCpy[3]
        $BallDirection[3] = $BallDirectionCpy[2]
    EndIf
    If Round($Ball[0],0) = 2 Then ; Gestion du marquage de points...
        If $LeftPos > Round($Ball[1],0) Or $LeftPos+5 < Round($Ball[1],0) Then
            $RightPoints += 1 ; Augmente le score.
            _Reinitialize(); Réinitialise les positions et directions.
            _cls()
        EndIf
        If $RightPoints = 10 Then ; Si le joueur bleu gagne..
            _cls()
            For $k = 1 To 10 Step 1
                _printf()
                _ReduceMemory() ; Vide la mémoire innutile.
            Next
            _printf("                    Le joueur Bleu a gagn‚ !")
            _printf("                    Pour rejouer, appuyez sur A")
            While Not __IsPressed(41)
                _ReduceMemory() ; Vide la mémoire innutile.
            WEnd
            _cls()
            Run (@ScriptFullPath)
            Exit
        EndIf
    EndIf
    If Round($Ball[0],0) = 77 Then ; Gestion du marquage de points...
        If $RightPos > Round($Ball[1],0) Or $RightPos+5 < Round($Ball[1],0) Then
            $LeftPoints += 1 ; Augmente le score.
            _Reinitialize(); Réinitialise les positions et directions.
            _cls()
        EndIf
        If $LeftPoints = 10 Then ; Si le joueur rouge gagne..
            _cls()
            For $k = 1 To 10 Step 1
                _printf()
                _ReduceMemory() ; Vide la mémoire innutile.
            Next
            _printf("                    Le joueur Rouge a gagn‚ !")
            _printf("                    Pour rejouer, appuyez sur A")
            While Not __IsPressed(41)
                _ReduceMemory() ; Vide la mémoire innutile.
            WEnd
            _cls()
            Run (@ScriptFullPath)
            Exit
        EndIf
    EndIf
    If __IsPressed(50) Then; Gestion de la pause...
        _DisplayPause() ; Affiche le message.
        While __IsPressed(50)
            _ReduceMemory() ; Vide la mémoire innutile.
        WEnd
        $Timer = TimerInit()
        $Show = False
        While 1
            If TimerDiff($Timer) >= 1000 Then
                _DisplayPause($Show)
                If $Show Then
                    $Show = False
                Else
                    $Show = True
                EndIf
                $Timer = TimerInit()
            EndIf
            If __IsPressed(50) Then ExitLoop
            _ReduceMemory() ; Vide la mémoire innutile.
        WEnd
        While __IsPressed(50)
            _ReduceMemory() ; Vide la mémoire innutile.
        WEnd
        _cls()
    EndIf
    Sleep(100/$Speed) ; Pause pour la rapidité.
    _ReduceMemory() ; Vide la mémoire innutile.
WEnd
Func __IsPressed($sHexKey, $vDLL = 'user32.dll')
    ; $hexKey must be the value of one of the keys.
    ; _Is_Key_Pressed will return 0 if the key is not pressed, 1 if it is.
    Local $a_R = DllCall($vDLL, "short", "GetAsyncKeyState", "int", '0x' & $sHexKey)
    If @error Then Return SetError(@error, @extended, False)
    Return BitAND($a_R[0], 0x8000) <> 0
EndFunc   ;==> _IsPressed
Func _Reinitialize()
    $LeftPos = 9
    $RightPos = 9
    $Ball[0] = 2
    $Ball[1] = 12
    $BallDirection[0] = 1
    $BallDirection[1] = 0
    If Random(2,3,1) = 2 Then
        $BallDirection[2] = Random(0,1,0.2)
        $BallDirection[3] = 0
    Else
        $BallDirection[2] = 0
        $BallDirection[3] = Random(0,1,0.2)
    EndIf
    Return 0
EndFunc   ;==> _Reinitialize
Func _RandomChangeUpDown()
    $Random = Random(5,7,1)
    If $Random = 6 Then
        If Random(2,3,1) = 2 Then
            $BallDirection[2] = Random(0,1,0.2)
            $BallDirection[3] = 0
        Else
            $BallDirection[2] = 0
            $BallDirection[3] = Random(0,1,0.2)
        EndIf
    EndIf
    If $Random = 6 Then Return True
    Return False
EndFunc   ;==> _RandomChangeUpDown
Func _ReduceMemory()
    DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
    Return 0
EndFunc   ;==> _ReduceMemory
Func _DisplayPause($Show = True)
    _SetConsoleTextAttribute($FOREGROUND_GREEN,$FOREGROUND_INTENSITY)
    _SetConsoleCursorPosition(35,10)
    ConsoleWrite("ÉÍÍÍÍÍÍÍ»")
    _SetConsoleCursorPosition(35,11)
    ConsoleWrite("º       º")
    _SetConsoleCursorPosition(35,12)
    If $Show Then
        ConsoleWrite("º PAUSE º")
    Else
        ConsoleWrite("º       º")
    EndIf
    _SetConsoleCursorPosition(35,13)
    ConsoleWrite("º       º")
    _SetConsoleCursorPosition(35,14)
    ConsoleWrite("ÈÍÍÍÍÍÍͼ")
    _SetConsoleTextAttribute($DEFAULT_COLOR)
    Return 0
EndFunc   ;==> _DisplayPause► Afficher le texteconsole.au3
Code : Tout sélectionner
#include-once
; #INDEX# =======================================================================================================================
; Title .........: Console
; AutoIt Version : 3.3.8.1
; Language ......: Français
; Description ...: Fonctions facilitant l'utilisation de la console.
; Author(s) .....: TT22, TommyDDR
; Dll(s) ........: kernel32.dll
; ===============================================================================================================================
; #CONSTANTS# ===================================================================================================================
Global Const $FOREGROUND_RED = 0x0004 ; Valeurs héxadécimales pour la fonction _SetConsoleTextAttribute()...
Global Const $FOREGROUND_GREEN = 0x0002
Global Const $FOREGROUND_BLUE = 0x0001
Global Const $FOREGROUND_INTENSITY = 0x0008
Global Const $BACKGROUND_RED = 0x0040
Global Const $BACKGROUND_GREEN = 0x0020
Global Const $BACKGROUND_BLUE = 0x0010
Global Const $BACKGROUND_INTENSITY = 0x0080
Global Const $DEFAULT_COLOR = BitOR($FOREGROUND_RED,$FOREGROUND_GREEN,$FOREGROUND_BLUE,$FOREGROUND_INTENSITY)
; ===============================================================================================================================
; #CURRENT# =====================================================================================================================
; _echo
; _cls
; _IsConsole
; _pause
; _printf
; _SetConsoleCursorPosition
; _SetConsoleTextAttribute
; _SetConsoleTitle
; _system
; ===============================================================================================================================
; #INTERNAL_USE_ONLY# ===========================================================================================================
; __WinAPI_GetStdHandle
; ===============================================================================================================================
; #FUNCTION# ====================================================================================================================
; Name...........: _cls
; Description ...: Efface le contenu de la fenêtre console.
; Syntax.........: _cls()
; Parameters ....:
; Return values .: Succès - 1
;                  Failure - 0 et met @error à 1
; Author ........: TT22
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Non
; ===============================================================================================================================
Func _cls()
    If _system("CLS") Then Return 1
    Return SetError(1)
EndFunc   ;==> _cls
; #FUNCTION# ====================================================================================================================
; Name...........: _echo
; Description ...: Envoie un texte à la console (de la même façon que la commande "ECHO").
; Syntax.........: _echo( [$Text])
; Parameters ....:
; Return values .: Succès - 1
;                  Failure - 0 et met @error à 1
; Author ........: TT22
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Non
; ===============================================================================================================================
Func _echo($Text = "")
    If $Text <> "" Then
        If _system("ECHO "&$Text) Then Return 1
    Else
        If _system("ECHO.") Then Return 1
    EndIf
    Return SetError(1)
EndFunc   ;==> _cls
; #FUNCTION# ====================================================================================================================
; Name...........: _IsConsole
; Description ...: Vérifis si le script est compilé en mode console.
; Syntax.........: _IsConsole()
; Parameters ....:
; Return values .: Succès - 1
;                  Echec - 0 et met @error à 1
; Author ........: TT22
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Non
; ===============================================================================================================================
Func _IsConsole()
    Local $aResult = DllCall("kernel32.dll", "bool", "WriteConsoleW", "handle", 0x7, "wstr", "", "dword", 0, "dword*", 0, "ptr", 0)
    If @error Then Return SetError(1)
    Return $aResult[0]
EndFunc   ;==> _IsConsole
; #FUNCTION# ====================================================================================================================
; Name...........: _pause
; Description ...: Fait une pause.
; Syntax.........: _pause( [$Hide])
; Parameters ....: $Hide : Cacher le message de pause (défaut = False).
; Return values .: Succès - 1
;                  Echec - 0
; Author ........: TT22
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Non
; ===============================================================================================================================
Func _pause($Hide = False)
    If $Hide Then Return _system("PAUSE>NUL")
    Return _system("PAUSE")
EndFunc
; #FUNCTION# ====================================================================================================================
; Name...........: _printf
; Description ...: Ecrit une chaine de caractères formaté dans le flux de sortie standard (StdOut).
; Syntax.........: _printf([$Format [, $Var1 [, ... $Var32]])
; Parameters ....: $Format        : La chaine de caractère à formater.
;                  $Var1...$Var32 : Jusqu'à 32 variables de sortie qui seront selon $Format.
; Return values .: Succès - 1
;                  Echec - 0 et met @error à 1
; Author ........: TT22
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Pour le formatage de la chaine, voir StringFormat().
; ===============================================================================================================================
Func _printf($Format = "", $Var1 = "", $Var2 = "", $Var3 = "", $Var4 = "", $Var5 = "", $Var6 = "", $Var7 = "", $Var8 = "", _
                           $Var9 = "", $Var10 = "", $Var11 = "", $Var12 = "", $Var13 = "", $Var14 = "", $Var15 = "", $Var16 = "", _
                           $Var17 = "", $Var18 = "", $Var19 = "", $Var20 = "", $Var21 = "", $Var22 = "", $Var23 = "", $Var24 = "", _
                           $Var25 = "", $Var26 = "", $Var27 = "", $Var28 = "", $Var29 = "", $Var30 = "", $Var31 = "", $Var32 = "")
    ConsoleWrite(StringFormat($Format&"\n",$Var1, $Var2, $Var3, $Var4, $Var5, $Var6, $Var7, $Var8, _
                                           $Var9, $Var10, $Var11, $Var12, $Var13, $Var14, $Var15, $Var16, _
                                           $Var17, $Var18, $Var19, $Var20, $Var21, $Var22, $Var23, $Var24, _
                                           $Var25, $Var26, $Var27, $Var28, $Var29, $Var30, $Var31, $Var32))
    If @error Then Return SetError(1)
    Return 1
EndFunc   ;==> _printf
; #FUNCTION# ====================================================================================================================
; Name...........: _SetConsoleCursorPosition
; Description ...: Définit la position du curseur dans la mémoire tampon d'écran de la console spécifiée.
; Syntax.........: _SetConsoleCursorPosition($x, $y [, $handle])
; Parameters ....: $x      : Position X du curseur.
;                  $y      : Position Y du curseur.
;                  $handle : Handle de la console de sortie (par défaut = -1).
; Return values .: Succès - 1
;                  Echec - 0 et met @error à 1
; Author ........: TommyDDR
; Modified.......: TT22
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Non
; ===============================================================================================================================
Func _SetConsoleCursorPosition($x, $y, $handle = -1)
    If($handle = -1) Then
        $handle = __WinAPI_GetStdHandle(1)
    EndIf
    Local $coord = BitOR(BitAND(0x10000*$y, 0xFFFF0000), BitAND($x, 0xFFFF))
    $CallReturn = DllCall("kernel32.dll", "int", "SetConsoleCursorPosition", "handle", $handle, "dword", $coord)
    If $CallReturn[0] Then Return $CallReturn[0]
    Return SetError(1)
EndFunc
; #FUNCTION# ====================================================================================================================
; Name...........: _SetConsoleTextAttribute
; Description ...: Change la couleur du texte et de l'arrière plan de la console.
; Syntax.........: _SetConsoleTextAttribute($COLOR1 [, $COLOR2 [, ... $COLOR8]])
; Parameters ....: $COLOR1...$COLOR8  : Codes de couleurs (1 minimum et 8 maximum) (voir #CONSTANTS#).
; Return values .: Succès - 1
;                  Echec - 0 et met @error à 1
; Author ........: TT22
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Non
; ===============================================================================================================================
Func _SetConsoleTextAttribute($COLOR1, $COLOR2 = 0x0000, $COLOR3 = 0x0000, $COLOR4 = 0x0000, $COLOR5 = 0x0000, $COLOR6 = 0x0000, $COLOR7 = 0x0000, $COLOR8 = 0x0000)
    $COLOR = BitOR($COLOR1, $COLOR2, $COLOR3, $COLOR4, $COLOR5, $COLOR6, $COLOR7, $COLOR8)
    $CallReturn = DllCall("Kernel32.dll", "BOOL", "SetConsoleTextAttribute", "HANDLE", 0x7, "WORD", $COLOR)
    If $CallReturn[0] Then Return $CallReturn[0]
    Return SetError(1)
EndFunc   ;==> _SetConsoleTextAttribute
; #FUNCTION# ====================================================================================================================
; Name...........: _SetConsoleTitle
; Description ...: Change le titre de la console.
; Syntax.........: _SetConsoleTitle($TITLE)
; Parameters ....: $COLOR : Titre à mettre pour la fenêtre console.
; Return values .: Succès - 1
;                  Echec - 0 et met @error à 1
; Author ........: TT22
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Non
; ===============================================================================================================================
Func _SetConsoleTitle($TITLE)
    $CallReturn = DllCall("Kernel32.dll", "BOOL", "SetConsoleTitle", "str", $TITLE)
    If $CallReturn[0] Then Return $CallReturn[0]
    Return SetError(1)
EndFunc   ;==> _SetConsoleTitle
; #FUNCTION# ====================================================================================================================
; Name...........: _system
; Description ...: Execute une commande système.
; Syntax.........: _system($TITLE)
; Parameters ....: $COLOR : Titre à mettre pour la fenêtre console.
; Return values .: Succès - Retourne le code de sortie du programme exécuté.
;                  Echec - 0 et met @error à 1
; Author ........: TT22
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Non
; ===============================================================================================================================
Func _system($Command)
    If $Command Then
        Return RunWait(@ComSpec & " /c " & StringUpper($Command), @ScriptDir, Default, 0x10)
    EndIf
    Return SetError(1)
EndFunc   ;==> _system
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name...........: _WinAPI_GetStdHandle
; Description ...: Retrieves a handle for the standard input, standard output, or standard error device
; Syntax.........: _WinAPI_GetStdHandle($iStdHandle)
; Parameters ....: $iStdHandle  - Standard device for which a handle is to be returned. This can be one of the following values:
;                  |0 - Handle to the standard input device
;                  |1 - Handle to the standard output device
;                  |2 - Handle to the standard error device
; Return values .: Success      - Handle to the specified device
;                  Failure      - -1
; Author ........: Paul Campbell (PaulIA)
; Modified.......:
; Remarks .......: The handle has GENERIC_READ and GENERIC_WRITE access rights, unless the application has used  SetStdHandle  to
;                  set a standard handle with lesser access.  If an application does not have associated  standard  handles,  the
;                  return value is 0.
; Related .......:
; Link ..........: @@MsdnLink@@ GetStdHandle
; Example .......:
; ===============================================================================================================================
Func __WinAPI_GetStdHandle($iStdHandle)
    If $iStdHandle < 0 Or $iStdHandle > 2 Then Return SetError(2, 0, -1)
    Local Const $aHandle[3] = [-10, -11, -12]
    Local $aResult = DllCall("kernel32.dll", "handle", "GetStdHandle", "dword", $aHandle[$iStdHandle])
    If @error Then Return SetError(@error, @extended, -1)
    Return $aResult[0]
EndFunc   ;==> _WinAPI_GetStdHandleVoilà, dites-mois ce que vous en pensez

Edit : Mise à jour version 1.1 (merci à TommyDDR).














