Jeu du ping

Description

Il s'agit du jeu du Ping. Permet à l'utilisateur de sauveguarder les parties réussies, ce qui permet utlérieurement de consulter les slutions.

Sauveguarde aussi la partie courante pour etre rejoué dans le cas ou elle n'a pas été finie.

Source / Exemple :


;	 ASM 2 ? Le jeu du Ping
;
;  Auteur	: Neoplayer
;  Date		: Mars 2005
;  Description	: Jeu du ping, petit jeu ou le but est
;               de retourner toute les cases, sauveguarde des solution dans des fichiers.
;==========================================================
.model small
.stack 100h
.486
locals
jumps

AvanceDeUn MACRO handleEnParam, NbCaract
    mov cx,NbCaract
    lea dx,CaseSolution                          ;
    mov bx,handleEnParam                         ;    Je place 1 bytes dans le fichier CaseSolution
    mov ah,3fh                                   ;
    int 21h
ENDM AvanceDeUn
;--------------------
;                    |
;Placement du curseur|
;                    |
;--------------------
pointeur MACRO X, Y
     mov dl,X
     mov dh,Y

     mov bh,0
     mov ah,02h               ;appel de l'interruption pour placer mon curseur a la position
     int 10h                  ;AX AY
ENDM pointeur
;--------------------
;                    |
;Affichage de texte  |
;                    |
;--------------------
text MACRO txt
        mov ah,09h       ; Intérruption affichant du Text
        lea dx,txt
        int 21h
ENDM text
;--------------------
;                    |   ;Valeur en entre dans al et ah
;Transforme 2 chifs  |   ;Valeur de sortie dans ax
;    en 1 Nb         |
;--------------------
DeuxChiffreUnNb MACRO
       mov cl,ah
       mov ah,0
       mov dl,10
       mul dl
       add al,cl

ENDM DeuxChiffreUnNb

EcrireDeuxCaract MACRO handleBelin
      pusha
      add aEcrire[0],48
      add aEcrire[1],48
      mov ah,40h
      mov bx,handleBelin
      mov cx,2
      lea dx,aEcrire
      int 21h
      popa
ENDM EcrireDeuxCaract

EcrireDuTxtEnRouge MACRO LeTexte, PosX, PosY, NbCaract
      mov dl,PosX
      mov dh,PosY
      pointeur PosX PosY

      mov cl,0
      mov bx,0
      @@boucle:
      mov al,LeTexte[bx]
      pusha                                      ;Affichage des caractere 1 par 1
      CALL AfficherUneChaineCaraParCaract        ;Avec une fonte grise
      popa                                       ;et la couleur du caractere rouge
      inc dl
      pointeur dl dh
      inc bx
      cmp bx,NbCaract
      jne @@boucle
ENDM EcrireDuTxtEnRouge

Cadre MACRO XA, YA, XB, YB

      mov al,blanc
      mov dx,YA
      mov cx,XA

      @@BordHaut:            ;
      CALL pixel             ;   Trace la ligne blanche du haut pour l effet 3d
      inc cx                 ;
      cmp cx,XB         ;
      jne @@BordHaut         ;

      mov al,gris

      @@redebut:              ; Passe a la ligne et on retrace
      mov cx,XA
      inc dx
      @@debut:                ;
      CALL pixel              ;  Tracage d'une ligne horrizontal
      inc cx                  ;
      cmp cx,XB          ;
      jne @@debut             ;
      cmp dx,YB
      jne @@redebut

      mov al,noir             ; Tracage de la derniere ligne en noir pour un effet 3d
      mov cx,XA
      @@BordBas:
      CALL pixel
      inc cx
      cmp cx,XB
      jne @@BordBas

      mov cx,XB
      mov dx,YA
      @@BordDroite:           ; Tracage de la ligne de droite pour un effet 3d
      CALL pixel
      inc dx
      cmp dx,YB
      jle @@BordDroite

      mov dx,YA
      mov cx,XA
      mov al,blanc

      @@BordGauche:           ; Tracage de la ligne de gauche pour un effet 3d
      CALL pixel
      inc dx
      cmp dx,YB
      jl @@BordGauche

ENDM Cadre
;------------------------------------------------------------------------------------------------
;                               Macro des gestions de fichier
;------------------------------------------------------------------------------------------------
OuvrirFichier MACRO fichier               ;
mov ah,3DH                                ;
mov al,2                                  ;     Ouvrir un fichier
lea dx,fichier                            ;
int 21h                                   ;
ENDM OuvrirFichier

CreeFichier MACRO fichier  ;
mov ah,3CH                 ;      Macro qui créé un fichier avec le nom du fichier fournit en param
mov cx,000000000b          ;                      Elle retourne dans ax le Handle
lea dx,fichier             ;
int 21h                    ;
ENDM CreeFichier           ;
;------------------------------------------------------------------------------------------------
;                             Procedure et variable a exporter, ou à importer
;------------------------------------------------------------------------------------------------

extrn Solution : proc
extrn tailleDamier :proc
extrn damier :proc
extrn clic_souris:proc
extrn un_coup:proc
extrn verif_gagner:proc
extrn fait_le:proc
extrn initrnd:proc
extrn random:proc
extrn v1
extrn longueur
extrn largeur
extrn etat_jeu:proc
public jeu
public pion1
public pion2
public exit
;------------------------------------------------------------------------------------------------
;                                  Mes Variables
;------------------------------------------------------------------------------------------------
.data

     ;Tout ce qui est pour l'affichage de l'entete en ecrivant direct dans la mem video
     ;------------------------------------------------------------------------------
     Y       EQU     5
     X       EQU     25
     INI     DW      0B800h
     Attribut EQU     0001111b

     LARGEUREntete EQU     28
     HAUTEUREntete EQU     5    ; en fait hauteur - 1
     ;-----------------------------------------------------------------------------

     efface equ 'A'

     blanc equ 0Fh
     rouge equ 04h
     bleu  equ 01h
     gris  equ 07h
     noir  equ 08h

    tailleCarre equ 28
    TailleCaseSOl equ 6
    Temps_de_Pause equ 2

    CarreAX dw ?
    CarreAY dw ?

    CarreBX dw ?
    CarreBY dw ?

    cpt2 dw 0

    Nb_Coup_Solution  dw 0
    Nb_Coup_Part_Cour dw 0

    Reprise db "Voulez vous reprendre l'ancienne partie commencer ?",'$'
    appuyerSurUneTouche db "Veuillez appuyer sur une touche pour continuer."
    TailleChaineAppuyer equ 47
    reprendrePartie     db "        Reprise de la patie en cours, veuillez patienter",'$'
    PasDImage           db "       Le fichier Image.hal n'a pu etre trouve    ",'$'
    YesTxt db "Yes",'$'
    NoTxt  db  "No",'$'
    SolutionB  db "Solution",'$'
    Reprendre  db "Reprendre",'$'
    PasDeSol   db "                    Pas de solution presente",'$'

    entete   DB  ' ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ',187
             DB  ' º Neoplayer               º'
             DB  ' º                         º'
             DB  ' ',204,'ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ',185
             DB  ' ','º       Jeu du Ping       º'
             DB  ,'ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ'

    diese db ?
    fichierSol db 'Solution.txt',0
    fichierTemp db 'ping_tem.txt',0
    fichierIma db 'image.hal',0
    recop      db 'recop.tmp',0

    handle dw ?                 ;Handle de fichierSol
    handleTemp dw ?             ;Handle de fichierTemp
    handleIma dw ?              ;Handle de fichierIma
    handleRecop dw ?            ;Handle de recopie

    CaseClique db 100 dup(0)           ; Tablo des clic de la partie   ;CaseClique
    CaseSolution db TailleCaseSOl dup('-')
    tabloImage dw 7056 dup(0)

    deb_pion1 dw ?
    deb_pion2 dw ?

    jeu db 100 dup (0)
    aEcrire db 2 dup(0)
.code

;----------------------------------------------------------------------------------------------------
;                                           Debut du Main
;----------------------------------------------------------------------------------------------------

main proc
     mov ax,@data
     mov ds,ax

     CALL ImageDansTablo                  ; Genere les nombres aleatoire + ouvre fichier image.hal
                                          ; Place tout le fichier dans le tablo tabloImage

     CALL  video
     
     CALL AfficherEnTete

     CALL attend

     OuvrirFichier fichierSol             ; J'essaye d'ouvrir le fichier Solution.txt
     jc @@FichierNonExistant              ; Je teste le carry flag si il est a 1, c que le fichier existe pas
                                          ; d ou la necessiter de le créer
     jmp @@FichierExistant

     @@FichierNonExistant:
     CreeFichier fichierSol
     @@FichierExistant:

     mov handle,ax                        ; Je sauveguarde le handle

     CALL pointeurDuFichier               ;On pointe sur la fin du fichier pour ne pas effacer ce qui si trouve deja

     CALL  video                          ;a remplacer plus tard avec un nettoyage ecran avec le 0b800....

     CALL  tailleDamier                   ;Initialisation de variables (avec demande des entre pour lg et la

     ;----------------------------------------------------------------------------------------------------------------
     ;      J'ouvre le fichier Temporaire de la partie precedente
     ;      Je teste si les 2 et 3 eme caractere sont egale a ce qui a été cliqué
     ;      Si c egale alors je propose a l'utilisateur de reprendre la partie la ou elle en etait la derniere fois.
     ;----------------------------------------------------------------------------------------------------------------

     OuvrirFichier fichierTemp                       ; On essaye d'ouvrir le fichier, si on y arrive pas
     mov handleTemp,bx

     jc @@@@FichierNonExistant
     jmp @@SuiteNext

     @@@@FichierNonExistant:
                                                     ;On le créée
     CreeFichier fichierTemp
     mov handleTemp,bx
     CALL CreeFichierTemp                            ;On cree le fichier Temp avec la bonne syntaxe

     jmp @@@@ZeDebut

     @@SuiteNext:

     CALL TestSiFichierTemp      ; On teste pour savoir si le fichier temporaire contient bien la meme Lo et LA
                                 ; Renvoi 1 dans DI si c la meme chose, 2 dans les autres cas

     cmp di,2
     je @@@@FichierNonExistant

    CALL ClicBelin
    cmp di,1                     ;On reprend la partie si DI = 2
    je @@@@suite

    jmp @@@@FichierNonExistant
    @@@@suite:
    CALL videoG
    CALL damier
    pointeur 8 28
    text reprendrePartie
    CALL ReprendreLaPartie
    jmp @@@@@@debut
@@@@ZeDebut:

    CALL videoG
    CALL damier

@@@@@@debut:

     CALL CadreSolution     ;Appel la macro Cadre trace un cadre avec les coordonées fournit en parametre
     CALL AfficherTexteSol

@@@@debut:
     CALL  affSouris

     CALL  Un_Coup

     cmp di,1
     jne @@next
     CALL reExist             ; On  teste pour savoir si il y a bien une solution
     cmp di,1                 ; dans le fichier solution
     je @@@@@@next
     pointeur 8 28

     text PasDeSol

     jmp @@@@debut
     @@@@@@next:
     mov cpt2,0
     CALL LireLeFichierSolution

     CALL  videoG
     CALL CadreSolution
     CALL AfficherTexteRejoue

     push cpt2
     CALL solution

     CALL affSouris

     CALL clicSouris

     CALL  videoG

     CALL Etat_jeu
     jmp @@@@@@debut

     @@next:

     ;------------------------      Ecriture dans le fichier Temporaire
     mov bx,v1
     inc CaseClique[bx]        ;    On incremente de 1 l'endroit ou on a cliquer
     CALL EcrireDansFichierTemp
     ;-----------------------

     CALL  verif_gagner
     CMP   al,1
     Jne   @@@@debut

      CALL VideMoi
      CALL  attend
      CALL  video   ;nettoye l'ecran et quitte

      CALL reExist
      cmp di,0
      je @@OnEcrit
      CALL CompterNbClic                   ; Dans le fichier solution
      CALL NbClicPartieCourante            ; De la partie courante
      mov ax,Nb_Coup_Solution
      mov bx,Nb_Coup_Part_Cour

      cmp ax,bx

      jl @@@@finito

      CALL RemplacerLaSolutionPlusLongue          ;On Recoppie tout le fichier sauf la partie que l'on a deja
                                                  ;Puis on Ré-ecrira la solution qui est plus petites

      @@OnEcrit:
      CALL EcritureDeEtatJeuSol

      @@@@finito:
      CALL effaceFichierTmp
      CALL exit

main ENDP

exit proc
    Call video
    mov ax,4C00h
    int 21h

ret
exit endp

initSouris proc
     mov     AX,00h
     int     33h
     ret
initSouris endp

pixel PROC
      pusha
      mov ah,0ch    ;numéro du service
      mov bx,0000ch
      int 10h
      popa
      ret
pixel ENDP

affSouris proc
     mov     ax,01h
     int     33h
     ret
affSouris endp

videoG PROC

      mov al,12h
      mov ah,00h
      int 10h
      ret

videoG ENDP

attend PROC
        mov ah,08h
        int 21h
        ret
attend ENDP

video proc
     pusha
     MOV     AH,00h
     MOV     AL,03h
     INT     10h
     popa
     ret
video endp

pion1 proc
      push cx
      push dx
      mov dx,0
      mov ax,deb_pion1
      mov bx,392
      mul bx

      pop dx
      pop cx
      inc cx
      inc dx

      mov CarreAX,cx
      mov CarreAY,dx

      add cx,tailleCarre
      add dx,tailleCarre

      mov CarreBX,cx
      mov CarreBY,dx

      mov bx,ax
      mov dx,CarreAY

 @@boucle2:
      mov cx,CarreAX

 @@boucle:
      mov ax,tabloImage[bx]
      mov ah,0
      shr ax,4
      CALL pixelBis
      inc cx

      mov ax,tabloImage[bx]
      shl ax,4
      mov ah,0
      shr ax,4
      CALL pixelBis
      inc bx
      inc cx
      cmp cx,CarreBX
jne @@boucle
      inc dx
      cmp dx,CarreBY
jne @@boucle2

      ret
pion1 endp
pion2 proc
      push cx
      push dx
      mov dx,0
      mov ax,deb_pion2
      mov bx,392
      mul bx

      pop dx
      pop cx
      inc cx
      inc dx

      mov CarreAX,cx
      mov CarreAY,dx

      add cx,tailleCarre
      add dx,tailleCarre

      mov CarreBX,cx
      mov CarreBY,dx

      mov bx,ax
      mov dx,CarreAY
      @@boucle2:
      mov cx,CarreAX

      @@boucle:
      mov ax,tabloImage[bx]
      mov ah,0
      shr ax,4
      CALL pixelBis
      inc cx

      mov ax,tabloImage[bx]
      shl ax,4
      mov ah,0
      shr ax,4
      CALL pixelBis
      inc bx
      inc cx
      cmp cx,CarreBX
      jne @@boucle
      inc dx
      cmp dx,CarreBY
      jne @@boucle2

      ret
pion2 endp
pixelBis PROC
      pusha
      mov ah,0ch    ;numéro du service
      mov bx,0
      int 10h
      popa
      ret
pixelBis ENDP

FermerFichier PROC
      mov ah,3eh
      mov bx,handle
      int 21h
ret
FermerFichier ENDP
EcritureDeEtatJeuSol PROC
      CALL PointeurDuFichierTemp

      mov aEcrire[0],243
      CALL EcrireUnCaract
      mov ax,longueur
      CALL EcrireLoLa
      EcrireDeuxCaract handle
      mov ax,largeur
      CALL EcrireLoLa
      EcrireDeuxCaract handle
      mov bx,0
      @@boucle:

                  ;mov aEcrire[0],','-48    ; Permet d'avoir les virgules dans le fichier
                  ;CALL EcrireUnCaract      ;

      mov ah,0
      mov al,CaseClique[bx]
      mov dx,0
      mov cx,2
      div cx
      cmp dx,0
      je @@pasclique
      push bx
      mov ax,bx
      mov dx,0
      mov cx,10
      div cx
      mov aEcrire[0],al
      mov aEcrire[1],dl
      EcrireDeuxCaract handle
      pop bx

      @@pasclique:

      inc bx
      mov ax,longueur
      mul largeur
      cmp bx,ax
      jne @@boucle

      CALL FermerFichier
ret
EcritureDeEtatJeuSol ENDP
PointeurDuFichierTemp PROC
      mov ah,42h
      mov al,0
      mov bx,HandleTemp
      mov dx,7
      mov cx,0
      int 21h
ret
PointeurDuFichierTemp ENDP

pointeurDuFichier PROC
         mov ah,42h
         mov al,2
         mov bx,handle
         mov cx,0
         mov dx,0
         int 21h
                  ret
pointeurDuFichier ENDP
LireLeFichierSolution PROC

        @@ttDebut:
        CALL RemiseAzero
        mov ah,3FH                    ;
        mov bx,handle                 ;
        mov cx,2                      ;  On place les 2 premiers caracteres du fichier dans le tablo caseSolution
        lea dx,caseSolution           ;
        int 21h                       ;

        mov al,caseSolution[0]
        cmp al,'#'
        je @@fin
        cmp al,'-'
        je @@fin
        mov ah,caseSolution[1]
        sub al,48
        sub ah,48
        DeuxChiffreUnNb
        CALL RemetreDansTabloJeu
        jmp @@ttdebut
        @@fin:
ret
LireLeFichierSolution ENDP
; valeur ax passe en parametre
RemetreDansTabloJeu PROC
        mov bx,cpt2
        mov jeu[bx],al
        inc cpt2
ret
RemetreDansTabloJeu ENDP
EcrireUnCaract PROC
        pusha
        add aEcrire[0],48
        mov ah,40h
        mov bx,handle
        mov cx,1
        lea dx,aEcrire
        int 21h
        popa
ret
EcrireUnCaract ENDP
handleDebut PROC
            mov ah,42h
            mov bx,handle
            mov al,0
            mov cx,0
            mov dx,0
            int 21h
            ret
handleDebut ENDP
RemiseAzero PROC
    mov bx,0
    @@boucle:
    mov CaseSolution[bx],'-'
    inc bx
    cmp bx,TailleCaseSOl
    jne @@boucle
ret
RemiseAzero ENDP
CadreSolution PROC
              Cadre  540 320 620 360
ret
CadreSolution  ENDP

ClicBelin PROC
     @@clic :

       CALL clic_souris
             ;pixel va dans cx, dx
       cmp cx,225                  ;
       jle @@next                              ; Bouton  Yes
       cmp cx,265                    ;
       jge @@next                              ;
       cmp dx,200                    ;
       jle @@next                              ;
       cmp dx,230                      ;
       jge @@next                              ;
       mov di,1
       jmp @@fin
       @@next:
       cmp cx,355                  ;
       jle @@clic                              ;  Bouton No
       cmp cx,395                    ;
       jge @@clic                              ;
       cmp dx,200                    ;
       jle @@clic                              ;
       cmp dx,230                      ;
       jge @@clic                              ;
       mov di,2

       @@fin:
ret
ClicBelin ENDP

clicSouris PROC
    @@clic :
     mov ax,3		; Permet de revenir ici si le clic est "hors zone"
     jmp @@rebond
     mov ax,3

     @@rebond :		; Attendre que les boutons soient relâchés
     INT 33h
     CMP BX,0
     JNE @@rebond
     @@attend:                 ; Attente d'un clic gauche ou droit
     INT 33h
     CMP BX,0

     JE @@attend
     CMP BX,1
     JE @@st
     jmp @@clic
     ; Test de la zone ?
       @@st :
             ;pixel va dans cx, dx
       cmp cx,540                  ;
       jle @@clic                              ;  Tant que le clic n est pas dans le quadrillage, refaire
       cmp cx,620                    ;
       jge @@clic                              ;
       cmp dx,320                    ;   Me permet de ne plus devoir apres tester si le clic est hors zone
       jle @@clic                              ;
       cmp dx,360                      ;
       jge @@clic                              ;

     ret
clicSouris ENDP
SolutionTxt PROC
      pointeur 68 21

      mov cl,0
      mov bx,0
      @@boucle:
      mov al,SolutionB[bx]
      pusha                                      ;Affichage des caractere 1 par 1
      CALL AfficherUneChaineCaraParCaract        ;Avec une fonte grise
      popa                                       ;et la couleur du caractere rouge
      inc dl
      pointeur dl dh
      inc bx
      cmp bx,8
      jne @@boucle
      ret
SolutionTxt ENDP
AfficherUneChaineCaraParCaract PROC
       mov ah,09H
       mov bh,0
       mov cx,1
       mov bl,11110011b
       int 10h
ret
AfficherUneChaineCaraParCaract ENDP

AfficherTexteSol PROC
     EcrireDuTxtEnRouge SolutionB, 69, 21, 8
ret
AfficherTexteSol ENDP

AfficherTexteRejoue PROC
     EcrireDuTxtEnRouge Reprendre, 68, 21, 9
     ret
AfficherTexteRejoue ENDP
;---------------------
;                     |
;Ecrit dans le fichier|
;     Temporaire      |
;---------------------
EcrireDansFichierTemp PROC
     mov ax,bx
     mov dx,0
     mov cx,10
     div cx
     mov aEcrire[0],al
     mov aEcrire[1],dl
     EcrireDeuxCaract handleTemp
ret
EcrireDansFichierTemp ENDP
;---------------------
;                     |
;Ecrit dans un fichier|
; la Longueur et Lar  |
;---------------------

EcrireLoLa PROC
     mov dx,0
     mov bx,10
     div bx
     mov aEcrire[0],al
     mov aEcrire[1],dl
ret
EcrireLoLa ENDP
ReprendreLaPartie PROC

     @@boucle:
     CALL RemiseAzero
     mov ah,3FH                    ;
     mov bx,handleTemp             ;
     mov cx,2                      ;  On place les 2 premiers caracteres du fichier dans le tablo caseSolution
     lea dx,caseSolution           ;
     int 21h                       ;

     cmp caseSolution[0],'-'
     je @@fin

     mov al,caseSolution[0]        ;
     mov ah,caseSolution[1]        ;
     sub al,48                     ;    On prend les deux premiers chiffres, on ne forme plus qu'un seul nb avec
     sub ah,48                     ;
                                   ;
     DeuxChiffreUnNb               ;
     push bx
     mov bx,ax
     inc CaseClique[bx]
     pop bx
     push ax
     CALL Fait_le
     CALL sleep                    ; On fait un pause de 2 seconde
     CALL sleep
     jmp @@boucle
     @@fin:

ret
ReprendreLaPartie ENDP
sleep PROC
     pusha
     mov ah,2ch
     int 21h
     mov al,dh
     cmp al,59
     je @@next
     add al,1    ;Temps de la pause
     jmp @@boucle
     @@next:
     mov al,0

    @@boucle:
     push ax
     mov ah,2ch
     int 21h
     pop ax
     cmp al,0
     jne @@mouk
     cmp dh,59
     je @@boucle

     @@mouk:
     cmp dh,al
     jb @@boucle

     popa
ret
sleep ENDP
Yes PROC
     Cadre 225 200 265 230
     EcrireDuTxtEnRouge YesTxt, 29, 13, 3
     CALL No
ret

Yes ENDP
No Proc
     Cadre 355 200 395 230
     EcrireDuTxtEnRouge NoTxt, 46, 13, 2
ret
No ENDP
;---------------------------------
;Renvoi dans DI 1 si il trouve    |
;     et 0 si il trouve rien dans |
;      le fichier solution        |
;---------------------------------
;En sortie mon handleTemp pointe sur le caractere apres le ##NbLigNbCol
reExist PROC
    CALL handleDebut
    mov di,0

    @@boucle:
    mov diese,'-'
    mov cx,1  ;Je prend le premier caractere
    lea dx,diese
    mov bx,handle                      ;
    mov ah,3fh                         ;
    int 21h
    mov di,0

    @@boucle2:
    cmp diese,'-'
    je @@fin
    cmp diese,'#'
    jne @@boucle

    mov cx,4                           ;
    lea dx,CaseSolution                ;      On Place les 4 premiers caracteres dans le tablo CaseSolution
    mov bx,handle                      ;
    mov ah,3fh                         ;
    int 21h

    mov al,Casesolution[0]       ; On place le premier chifre du fichier dans al
    mov ah,Casesolution[1]       ; On place le seconds chifres du fichier dans ah
    sub al,48
    sub ah,48
    DeuxChiffreUnNb              ; la macro place dans ax le nombre formé par ces deux chiffres
    cmp ax,longueur
    jne @@boucle
    mov al,Casesolution[2]
    mov ah,Casesolution[3]
    sub al,48
    sub ah,48
    DeuxChiffreUnNb
    cmp ax,largeur
    jne @@boucle
    mov di,1
 @@fin:
ret
reExist ENDP

effaceFichierTmp PROC
    mov ah,41h
    lea dx,fichierTemp
    int 21h
    lea dx,recop
    mov ah,41h
    int 21h
  ret
effaceFichierTmp ENDP

aleatoirePion PROC
CALL  initrnd
     mov ax,1
     mov bx,18
     push ax
     push bx

CALL random
     mov deb_pion1,ax
 @@SiMemeBouton:
CALL  initrnd
     mov ax,1
     mov bx,18
     push ax
     push bx

CALL random
     cmp ax,deb_pion1
  je @@SiMemeBouton
     mov deb_pion2,ax
   ret
aleatoirePion ENDP
ImageDansTablo PROC
CALL AleatoirePion                  ;Procedure qui genere Deux nombre aléatoire compris entre 1 et 18
                                    ;Puis qui le stock dans deb_pion1 et deb_pion2

     OuvrirFichier fichierIma       ;   On ouvre le fichier image
     mov handleIma,ax               ;   On place son Handle dans handleIma

     mov ah,3FH
     mov bx,handleIma                ;   On place dans un tablo les 7056 bytes qui composent le fichier
     mov cx,7056                     ;   image.hal
     lea dx,tabloImage
     int 21h
   ret
ImageDansTablo ENDP
;-------------------------------------------------------------------------------
; Procedure utiliser dans le cas ou le fichier est existant
; Elle permet de tester si les longueur et largeur entre sont
; bien identique a celle se trouvant dans le fichier temporaire
; Place dans DI 1 si le fichier temporaire correspond bien a ce que l'on a entre comme valeur
; pour la LA et la LA, sinon place dans DI, 2
;-------------------------------------------------------------------------------

TestSiFichierTemp PROC
     mov handleTemp,ax

     mov ah,3FH                        ;
     mov bx,handleTemp                 ;
     mov cx,6                          ;  On place les 6 premiers caracteres du fichier dans le tablo caseSolution
     lea dx,caseSolution               ;
     int 21h                           ;
     mov al,caseSolution[2]
     mov ah,caseSolution[3]
     sub al,48
     sub ah,48
     DeuxChiffreUnNb
     cmp ax,longueur                ;
  jne @@next                        ;
     mov al,caseSolution[4]         ;  Si longueur et largueur ne sont pas identiques
     mov ah,caseSolution[5]                       ;  Alors on est dans le cas ou on commence une partie normale
     sub al,48
     sub ah,48
     DeuxChiffreUnNb
     cmp ax,largeur                 ;
  jne @@next                        ;

CALL  videoG

     pointeur 13 5
     text Reprise                   ;Affiche la question pour savoir ce que l'on veut faire, reprendre ou recommencer
CALL Yes
CALL Affsouris
     mov di,1
     jmp @@fin
     @@next:
     mov di,2
     @@fin:
     ret
TestSiFichierTemp ENDP
CreeFichierTemp PROC

     mov handleTemp,ax
     mov aEcrire[0],'#'-48
     mov aEcrire[1],'#'-48
     EcrireDeuxCaract handleTemp
     mov ax,longueur
CALL EcrireLoLa
     EcrireDeuxCaract handleTemp
     mov ax,largeur
CALL EcrireLoLa
     EcrireDeuxCaract handleTemp

     ret
CreeFichierTemp ENDP
CompterNbClic PROC
    mov Nb_Coup_Solution,0

    @@RePartitPourUnTour:
    CALL RemiseAzero
    CALL AvanceDeDeux
    cmp Casesolution[0],'-'
    je @@fin
    cmp Casesolution[0],'#'
    je @@fin
    inc Nb_Coup_Solution
    jmp @@RePartitPourUnTour

   @@fin:

   mov bx,2
   mov ax,Nb_Coup_Solution
   mov dx,0
   div bx
   push ax

   mov al,1
   mov ah,42h                                    ;
   mov bx,handle                                 ;  Ne pas oublier de se replacer la ou j'etais dans le fichier
   pop dx
   mov cx,0                                              ;

   ret
CompterNbClic ENDP
AvanceDeDeux PROC
    mov cx,2
    lea dx,CaseSolution                          ;
    mov bx,handle                                ;    Je place 2 bytes dans le fichier CaseSolution
    mov ah,3fh                                   ;
    int 21h

ret
AvanceDeDeux ENDP

NbClicPartieCourante PROC
    mov Nb_Coup_Part_Cour,0
    mov ax,Longueur
    mov dx,0
    mul largeur

    mov bx,ax
    @@boucle:
    mov ah,0
    mov al,CaseClique[bx]
    mov dx,0
    mov cx,2
    div cx
    cmp dx,0
    je @@suite
    inc Nb_Coup_Part_Cour
    @@suite:
    dec bx
    cmp bx,0
    jg @@boucle
ret
NbClicPartieCourante ENDP
pointSolDeb PROC
    mov ah,42h
    mov al,0
    mov cx,0
    mov dx,0
    mov bx,handle       ;On positionne le pointeur du fichier Temporaire tout au debut du fichier
    int 21h
    mov ah,42h
    mov bx,Handlerecop  ;On fait la meme chose pour le fichier .tmp
    int 21h
ret
pointSolDeb ENDP
RemplacerLaSolutionPlusLongue PROC
    CreeFichier recop
    mov handleRecop,ax
    CALL pointSolDeb            ;On place le handle au debut du fichier Solution
    @@boucle:
    CALL RemiseAzero
    AvanceDeUn handle 1
    cmp CaseSolution[0],'-'

    je @@RecopieFini

    mov al,CaseSolution[0]
    mov aEcrire,al
    mov ah,40h           ;
    mov bx,handleRecop   ;
    mov cx,1             ;          Tant que on est pas a la fin du fichier, on ecrit le caractere dans le fichier Temp
    lea dx,aEcrire[0]    ;
    int 21h              ;

    jmp @@boucle

    @@RecopieFini:

   CreeFichier fichierSol  ;Apres sauveguarde dans le fichier .tmp, on le recrée pour le vider
   CALL pointSolDeb
;-------------------------------------------------------------------------------------------------------
;
;            Maintenant on recopie tout le fichier en analysant a chaque fois ce qu'il y a apres le diese
;                                  si c'est identique a LO et LA alors on copie pas
;                                                  Sinon on recopie
;-------------------------------------------------------------------------------------------------------

    @@@@boucle:
    CALL RemiseAzero

    AvanceDeUn handleRecop 1
    cmp CaseSolution[0],'-'
    je @@fin
    cmp caseSolution[0],'#'
    jne @@@@boucle
    @@Reprendre:

    AvanceDeUn handleRecop 4

    mov al,caseSolution[0]
    mov ah,caseSolution[1]
    sub al,48
    sub ah,48
    DeuxChiffreUnNb
    cmp ax,longueur                ;
  je @@@@boucle                    ;
    mov al,caseSolution[2]         ;  Si longueur et largueur ne sont pas identiques
    mov ah,caseSolution[3]         ;  Alors on est dans le cas ou on commence une partie normale
    sub al,48
    sub ah,48
    DeuxChiffreUnNb
    cmp ax,largeur                 ;
 je @@@@boucle                    ;

;--------------------------------------------------------------
    mov aEcrire,'#'-48
    CALL EcrireUnCaract
    mov ah,40h           ;
    mov bx,handle        ;                     On ecrit l'indexe
    mov cx,4             ;
    lea dx,CaseSolution
    int 21h
;--------------------------------------------------------------
    @@ImprimerDansFichier:
    CALL RemiseAzero
    AvanceDeUn handleRecop 1
    cmp CaseSolution[0],'-'
    je @@fin
    cmp CaseSolution[0],'#'
    je @@Reprendre

    mov al,CaseSolution[0]
    mov aEcrire,al
    mov ah,40h           ;
    mov bx,handle        ;
    mov cx,1             ;          Tant que on est pas a la fin du fichier ou a un diese, on ecrit le caractere dans le fichier
                         ;          Solution
    lea dx,aEcrire    ;
    int 21h
jmp @@ImprimerDansFichier

@@fin:
     CALL effaceFichierTmp
ret
RemplacerLaSolutionPlusLongue ENDP
AfficherEnTete PROC
	PUSHa
	MOV       ES,INI
        mov bx,0
        mov si,0
        MOV     BX,Y*80*2+X*2
	  ; Invariants : DI indice dans le tableau Cadre
	  ;              SI indice ecran
	SUB     DI,DI
	SUB     SI,SI
	MOV     AH,Attribut
@@lp1:
	MOV     AL,[entete]+DI           ; caractere a ecrire
	MOV     ES:[BX+SI],AX           ; position du caractere
	INC     SI                      ; un caractere = 2 bytes
	INC     SI
	INC     DI
	  ; Test fin de ligne
	CMP     SI,LARGEUREntete*2
	JB      @@lp1
	  ; Passage a la ligne suivante
	SUB     SI,SI
	ADD     BX,80*2
	  ; Test fin du cadre
	CMP     DI,(LARGEUREntete+1)*HAUTEUREntete
	JB      @@lp1
        mov SI,0
@@boucle:
        mov bh,Attribut
        mov bl,appuyerSurUneTouche[SI]
        push SI
        mov ax,SI
        mov cx,2
        mul cx
        mov SI,ax
        MOV ES:[2750+SI],BX           ; position du caractere
        pop SI
        inc SI
        mov cx,TailleChaineAppuyer
        cmp SI,cx
        jle @@boucle
        POPa
        RET
AfficherEnTete ENDP
;----------------------
;                      |
; Procedure qui vide   |
;      le buffer       |
;----------------------
VideMoi PROC
        pusha
       mov AX,0C00H
       int 21h
        popa
       ret
VideMoi ENDP

END main

Conclusion :


je n'ai pas encore trouvé de bug, avertisez moi si vus en voyez un.

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.