代码做了修改,光标控制改用方向键,加了框线(若不要框线,删去draw line一段即可),加了提示谁下子(左下角)。
400多行,时间不多,应该还有优化空间。
400多行,时间不多,应该还有优化空间。
程序代码:
.286 data segment SG DB 'http://bbs.bccn.net/' SG3 DB 'Do you want to play again?(Yes)' SG3_len equ $ - offset SG3 winstr DB 'Win Game !!!' winstr_len equ $ - offset winstr row db 15 col db 20 circle DB 00H,00H,07H,0C0H,1FH,0F0H,3FH,0F8H,3FH,0F8H,7FH,0FCH,7FH,0FCH,7FH,0FCH DB 7FH,0FCH,7FH,0FCH,3FH,0F8H,3FH,0F8H,1FH,0F8H,07H,0C0H,00H,00H,00H,00H flag db 0 victory db 0 form db 29 * 40 dup (0) color db 0 xcolor db 00001010b,00000101b data ends ; code segment assume cs:code,ds:data,es:data start: mov ax,data mov ds,ax mov es,ax MOV AX,0012H INT 10H fflag: mov row,15 mov col,20 mov al,0 mov victory,al mov flag,al ;---draw background--------- mov dx,0 mov bp,29 mov bl,00111001B mov bh,0 mov al,0dbh redraw: mov ah,2 int 10h mov ah,9 mov cx,80 int 10h inc dh dec bp jnz redraw ;-----draw line start------ ;----Vertical line--- mov bh,0 mov ah,0ch mov al,07h ;lineColor mov cx,15 mov dx,0 line10: push dx line20: int 10h inc dx cmp dx,479 - 16 jb line20 pop dx add cx,16 cmp cx,639 jb line10 ;----Horizontal line--- mov dx,15 mov cx,0 line30: push cx line40: int 10h inc cx cmp cx,639 jb line40 pop cx add dx,16 cmp dx,479-16 jb line30 ;------draw line end -------- mov al,0 mov di,offset form mov cx,29 * 40 repe stosb ;----------- MOV BP,OFFSET SG MOV CX,20 MOV DX,1D3BH MOV BH,0H MOV BL,00111010B MOV AX,1300H INT 10H stc keyboard: jnc keyboard1 call drawMove keyboard1: MOV AH,0 INT 16H keyboard2: CMP AL,1BH jnz keyboard3 jmp exit1 keyboard3: CMP ah,4bh ;left jz left CMP ah,50h ;down jz down CMP ah,4dh ;right jz right CMP ah,48h ;up jz up cmp al,' ' jz blank jmp short keyboard up: call up1 jmp keyboard down: call down1 jmp keyboard left: call left1 jmp keyboard right: call right1 jmp keyboard ;------------------------- blank: call calcPos mov al,[si] dec al jns keyboard1 ;occupancy mov al,flag inc al mov [si],al mov si,offset circle mov ax,word ptr xcolor test flag,1 jz blank1 xchg ah,al blank1: mov color,al push ax call show pop ax xchg al,ah mov color,al push word ptr row mov row,29 mov col,0 call show ;draw hint, which player active pop word ptr row call judgeperfect cmp victory,1 jz flag3 xor flag,1 ;change player jmp keyboard1 FLAG3: MOV BP,offset Winstr mov cx,winStr_len MOV DX,0E20H MOV BX,004fH MOV AX,1300H INT 10H MOV BP,offset SG3 mov cx,SG3_len MOV DX,0F15H INT 10H MOV AH,0 INT 16H and al,05fh cmp al,'Y' jnz exit1 jmp fflag exit1: mov ax,0003h int 10h MOV AX,4C00H INT 21H ;------------------------- drawMove proc near pusha mov dl,row mov dh,0 shl dx,4 ;x16 mov cl,col mov ch,0 shl cx,4 ;x16 mov di,16 drawM10: push cx mov bp,16 drawM20: mov ah,0ch mov al,10111001B ;80 or 00111001B ;mean xor function mov bh,0 int 10h inc cx dec bp jnz drawM20 pop cx inc dx dec di jnz drawM10 popa ret drawMove endp ;------------------------- calcPos: push bx mov si,offset form mov al,row mov bl,40 mul bl add si,ax mov al,col mov ah,0 add si,ax pop bx ret ;------------------------- up1 proc near cmp row,0 jz upx call drawMove dec row stc ret upx: clc RET up1 endp ;------------ down1 proc near cmp row,28 jae downx call drawMove inc row stc ret downx: clc ret down1 endp ;------------ left1 proc near cmp col,0 jz leftx call drawMove dec col stc ret leftx: clc ret left1 endp ;------------ right1 proc near cmp col ,39 jae rightx call drawMove inc col stc ret rightx: clc ret right1 endp ;------------------------- show proc near pusha mov dl,row mov dh,0 shl dx,4 mov bh,0 ;页 mov bp,16 ;外圈(行) ,垂直点数 sh0: push bp mov bp,16 ;内圈(列),水平点数 mov cl,col mov ch,0 shl cx,4 mov ax,[si] ;取值 xchg al,ah ;交换 mov di,ax mov ah,0ch mov al,color sh2: shl di,1 ;移出到 cf jnc sh3 ;无点 int 10h ;有点印出 sh3: inc cx ;下一点 dec bp ;完了一列? jnz sh2 ;未 add si,2 ;下一行 pop bp ; inc dx ;坐标移下一行 dec bp ;行回圈 jnz sh0 popa ret show endp ;------------------------- judgeperfect proc near push word ptr row mov dl,flag inc dl mov di,0 ;count ;--- Horizontal --- ' - ' ju05: call calcPos cmp [si],dl jnz ju20 dec col jns ju05 ju20: inc col cmp col,39 ja ju30 call calcPos cmp [si],dl jnz ju30 inc di jmp short ju20 ju30: pop word ptr row cmp di,5 jb vertical ;not match,next jmp WinGame ;-------vertical------ vertical: ; | push word ptr row mov di,0 ju40: call calcPos cmp [si],dl jnz ju50 dec row jns ju40 ju50: inc row cmp row,29 ja ju60 call calcPos cmp [si],dl jnz ju60 inc di jmp short ju50 ju60: pop word ptr row cmp di,5 jb Topleft ;not match,next jmp WinGame ; ----- \\\\\\\ ----------- Topleft: ;\ push word ptr row mov di,0 ju70: call calcPos mov al,0 cmp [si],dl jnz ju80 sub row,1 adc al,0 sub col,1 adc al,0 or al,al ;all ok jz ju70 ju80: inc row cmp row,29 ja ju90 inc col cmp col,39 ja ju90 call calcPos cmp [si],dl jnz ju90 inc di jmp short ju80 ju90: pop word ptr row cmp di,5 jb Topright ;not match,next jmp WinGame ;----- //////////------- Topright: push word ptr row mov di,0 ju100: call calcPos mov al,0 cmp [si],dl jnz ju110 inc col cmp col,40 cmc adc al,0 sub row,1 adc al,0 or al,al jz ju100 ju110: inc row cmp row,29 ja ju120 dec col js ju120 call calcPos cmp [si],dl jnz ju120 inc di jmp short ju110 ju120: pop word ptr row cmp di,5 jb jux ;not match, no cross 5 WinGame: mov victory,1 Jux: ret judgeperfect endp ;---------------------------------------- code ends end start
[此贴子已经被作者于2016-7-30 23:38编辑过]