蛇装配8086:不正确移动
.model small .data ;variables needed for snake body head db '@', '$' ;head and body symbols tail db ' ', '$' ;tail part set color to black snake_length db 3 ; 1-2 body 3 tail copy_snake_length db ? ;for loop sEnd db ? head_col db 40 ;starting col for snake head_row db 12 ;starting row for snake ; snake movement algorithm ; always copy the coordinates of the symbol in front. copy_col db ? copy_row db ? delaytime db 1 ;variable for control keys input db ? .stack 100h .code ;to delay time delay proc mov ah, 00 int 1Ah mov bx, dx jmp_delay: int 1Ah sub dx, bx cmp dl, delaytime jl jmp_delay ret delay endp ;make snake head go to the right righty proc cmp head_col,79 je resetposl zero: inc head_col jmp rightyie resetposl: mov head_col, 0 rightyie: mov dl,head_col mov dh,head_row xor bh, bh mov ah, 02h int 10h ret righty endp startgame proc mov dh, 12 ;row mov dl, 40 ;column xor bh, bh mov ah, 02h int 10h mov dx, offset head mov ah, 09h int 21h ret startgame endp mov cl, head_row mov copy_row,cl mov cl, head_col mov copy_col, cl ;print head mov dh, head_row mov dl, head_col xor bh, bh mov ah, 02h int 10h mov dx, offset head mov ah, 09h int 21h main proc mov ax, @data mov ds, ax ;set video mode mov al, 03h mov ah, 00h int 10h ;clear screen ;only need it once (reason no need to use function) mov ax, 0600h mov bh, 07h xor cx, cx mov dx, 184fh int 10h mov cx, 3200h ;stop cursor blinking mov ah, 01h int 10h ;set start head snake in the middle of the screen call startgame ;control mov ah,00h int 16h mov input, 'd' ;to change direction or to keep on going getinput: mov ah, 01h int 16h jz key mov ah,00h int 16h mov input,al ;control keys key: ;cmp input, 'w' ;je w ;cmp input, 's' ;je s ;cmp input, 'a' ;je a cmp input, 'd' je d jne rak d: mov cl, head_row mov copy_row,cl mov cl, head_col mov copy_col, cl mov dh, head_row mov dl, head_col xor bh, bh mov ah, 02h int 10h mov al, tail mov bh, 0 mov bl, 000h mov cx, 1 mov ah, 09h int 10h mov cl, snake_length mov copy_snake_length, cl dec copy_snake_length mov bl,0 printbody: mov al, head_row mov copy_row,al mov al, head_col mov copy_col, al call righty ;print head ;coordinates mov dh, head_row mov dl, head_col xor bh, bh mov ah, 02h int 10h ;printing "@" mov dx, offset head mov ah, 09h int 21h ; inc copy_col to update the head. inc copy_col mov al,copy_col mov head_col,al inc bl ; now loop to print other characters cmp bl,copy_snake_length jl printbody dec head_col jmp rak rak: call delay jmp getinput mov ax, 4c00h int 21h main endp end main
如果您想尝试使用代码,请按d移动角色。
问题是,当它到达最后一列时,我的函数正确地假设将head_col更改为0,以使它看起来像到达屏幕的末尾。 不幸的是,它在结尾80处留下了一个字符,然后继续打印,但是在下一行。
然后,当它到达第13行的末尾时,它不会在col 0处留下字符,但仍然沿着另一个行向下,并且在3继续打印之后,似乎它会回到原始行,然后当它到达起点它不再打印任何东西。
问题是,当它到达最后一列时,我的函数正确地假设将head_col更改为0,以使它看起来像到达屏幕的末尾。 不幸的是,它在结尾80处留下了一个字符,然后继续打印,但是在下一行。
您正在使用DOS功能9显示您的蛇,但忘记DOS提前光标。 你不应该输入第80列。 将79的限制更改为78,并查看问题是否消失。 或者使用BIOS功能9显示蛇头。 你已经将它用于snaketail。
链接地址: http://www.djcxy.com/p/62701.html上一篇: Snake Assembly 8086: not moving correctly
下一篇: mov ah,01h int16h, how to use it to change the direction of the snake