Print figure of hangman in assembly

2019-09-19 07:38发布

问题:

Is there a better way to print a hangman figure?

FIG0    DB 0DH,0AH,' +=======+',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH,'$'
FIG1    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH,'$'
FIG2    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/        |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH,'$'
FIG3    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/ \      |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH,'$'
FIG4    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/|\      |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH,'$'
FIG5    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/|\      |',0DH,0AH,' |       |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH,'$'
FIG6    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/|\      |',0DH,0AH,' |       |',0DH,0AH,'/        |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH,'$'
FIG7    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/|\      |',0DH,0AH,' |       |',0DH,0AH,'/ \      |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH,'$'
FIG8    DB 0DH,0AH,' +=======+',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'   \O/   |',0DH,0AH,'    |    |',0DH,0AH,'    |    |',0DH,0AH,'   / \   |',0DH,0AH,' ========+',0DH,0AH,'$'

Here is some nice figure. https://youtu.be/e2S_POws3DQ?t=42s

Its look really cool when he jump if you win game. I try to use call Clrscr and make him jump, but no luck.

回答1:

First of all: Don't change your environment (Windows, 32-bit, Console, MASM, Irvine32)! You will meet a lot of people who suggest you to change it (Do it with BIOS, MS-DOS, Linux. Do it with GDI, OpenGL, DirectX. And so on.). You might solve a problem better with another environment, but you'll get new problems, which can be solved with changing the environment. At the end you'll quit the whole project - unfinished.

"$"is the termination character of a MS-DOS string. In Windows/Irvine32 you handle with a null-termination.

Even the Console mode of Windows is quite quick. So you need Irvine's Delay function to see an animation:

INCLUDE Irvine32.inc

.DATA

FIG0    DB 0DH,0AH,' +=======+',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH, 0
FIG1    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH, 0
FIG2    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/        |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH, 0
FIG3    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/ \      |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH, 0
FIG4    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/|\      |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH, 0
FIG5    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/|\      |',0DH,0AH,' |       |',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH, 0
FIG6    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/|\      |',0DH,0AH,' |       |',0DH,0AH,'/        |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH, 0
FIG7    DB 0DH,0AH,' +=======+',0DH,0AH,' |       |',0DH,0AH,' O       |',0DH,0AH,'/|\      |',0DH,0AH,' |       |',0DH,0AH,'/ \      |',0DH,0AH,'         |',0DH,0AH,' ========+',0DH,0AH, 0
FIG8    DB 0DH,0AH,' +=======+',0DH,0AH,'         |',0DH,0AH,'         |',0DH,0AH,'   \O/   |',0DH,0AH,'    |    |',0DH,0AH,'    |    |',0DH,0AH,'   / \   |',0DH,0AH,' ========+',0DH,0AH, 0

.CODE

main PROC

    mov eax, 1000                       ; 1000 milliseconds = 1 second
    call Delay                          ; Irvine32: Delay ECX milliseconds
    call ClrScr                         ; Irvine32; Clear Screen
    lea edx, FIG0
    call WriteString                    ; Irvine32: Write a string pointed to by EDX

    mov eax, 1000                       ; 1000 milliseconds = 1 second
    call Delay                          ; Irvine32: Delay ECX milliseconds
    call ClrScr                         ; Irvine32; Clear Screen
    lea edx, FIG1
    call WriteString                    ; Irvine32: Write a string pointed to by EDX

    mov eax, 1000                       ; 1000 milliseconds = 1 second
    call Delay                          ; Irvine32: Delay ECX milliseconds
    call ClrScr                         ; Irvine32; Clear Screen
    lea edx, FIG2
    call WriteString                    ; Irvine32: Write a string pointed to by EDX

    mov eax, 1000                       ; 1000 milliseconds = 1 second
    call Delay                          ; Irvine32: Delay ECX milliseconds
    call ClrScr                         ; Irvine32; Clear Screen
    lea edx, FIG3
    call WriteString                    ; Irvine32: Write a string pointed to by EDX

    mov eax, 1000                       ; 1000 milliseconds = 1 second
    call Delay                          ; Irvine32: Delay ECX milliseconds
    call ClrScr                         ; Irvine32; Clear Screen
    lea edx, FIG4
    call WriteString                    ; Irvine32: Write a string pointed to by EDX

    mov eax, 1000                       ; 1000 milliseconds = 1 second
    call Delay                          ; Irvine32: Delay ECX milliseconds
    call ClrScr
    lea edx, FIG5
    call WriteString                    ; Irvine32: Write a string pointed to by EDX

    mov eax, 1000                       ; 1000 milliseconds = 1 second
    call Delay                          ; Irvine32: Delay ECX milliseconds
    call ClrScr                         ; Irvine32; Clear Screen
    lea edx, FIG6
    call WriteString                    ; Irvine32: Write a string pointed to by EDX

    mov eax, 1000                       ; 1000 milliseconds = 1 second
    call Delay                          ; Irvine32: Delay ECX milliseconds
    call ClrScr                         ; Irvine32; Clear Screen
    lea edx, FIG7
    call WriteString                    ; Irvine32: Write a string pointed to by EDX

    mov eax, 1000                       ; 1000 milliseconds = 1 second
    call Delay                          ; Irvine32: Delay ECX milliseconds
    call ClrScr                         ; Irvine32; Clear Screen
    lea edx, FIG8
    call WriteString                    ; Irvine32: Write a string pointed to by EDX

    exit                                ; Irvine32: ExitProcess

main ENDP

END main

ClrScr is not ideal for your purpose since it clears the whole screen including the inputs. Use Irvine's GotoXY. Delete the old picture by writing spaces.