gpt4 book ai didi

assembly - 蛇形组件 8086 : not moving correctly

转载 作者:行者123 更新时间:2023-12-04 18:04:26 30 4
gpt4 key购买 nike

.model small.data;variables needed for snake bodyhead db '@', '$' ;head and body symbolstail db ' ', '$' ;tail part set color to blacksnake_length db 3 ; 1-2 body 3 tailcopy_snake_length db ? ;for loopsEnd 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 keysinput db ?.stack 100h.code;to delay timedelay proc    mov ah, 00    int 1Ah    mov bx, dxjmp_delay:    int 1Ah    sub dx, bx    cmp dl, delaytime    jl jmp_delay    retdelay endp;make snake head go to the rightrighty 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 endpstartgame 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 21hretstartgame endpmov cl, head_rowmov copy_row,clmov cl, head_colmov copy_col, cl;print headmov dh, head_rowmov dl, head_colxor bh, bhmov ah, 02hint 10h mov dx, offset headmov ah, 09hint 21hmain    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;controlmov ah,00hint 16hmov input, 'd';to change direction or to keep on goinggetinput:mov ah, 01hint 16hjz keymov ah,00hint 16hmov input,al;control keyskey:;cmp input, 'w';je w ;cmp input, 's';je s ;cmp input, 'a';je a cmp input, 'd'je djne rakd:    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 10hmov cl, snake_lengthmov copy_snake_length, cldec copy_snake_lengthmov bl,0printbody:mov al, head_rowmov copy_row,almov al, head_colmov copy_col, alcall 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_colmov al,copy_colmov head_col,alinc bl; now loop to print other characterscmp bl,copy_snake_lengthjl printbodydec head_coljmp rakrak: call delayjmp getinputmov ax, 4c00hint 21hmain endpend main

如果您想尝试代码,请按 d 移动角色。

问题是,当它到达最后一列时,我的函数应该正确地将 head_col 更改为 0,这样它看起来就像到达了屏幕的末尾。不幸的是,它在第​​ 80 列末尾遗漏了一个字符,然后继续打印但在下一行。

然后当它到达第 13 行的末尾时,它不会在 col 0 处留下一个字符,但仍然会下降到另一行,并且在 3 继续打印之后,它似乎又回到了原始行,然后当它到达起点它不再打印任何东西。

最佳答案

The problem is that when it reaches the last column, my function righty suppose to change head_col to 0 so that it looks like it reaches the end of the screen. Unfortunately, it leaves out one character at the end col 80 then it continues to print but in the next row.

您正在使用 DOS 函数 9 来显示您的蛇,但忘记了 DOS 使光标前进。您不应输入第 80 列。将 79 的限制更改为 78,看看问题是否消失。或者使用 BIOS 功能 9 来显示蛇头。您已经将它用于蛇尾。

关于assembly - 蛇形组件 8086 : not moving correctly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29459705/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com