应天论坛

 找回密码
 参与我们

QQ登录

只需一步,快速开始

搜索
查看: 744|回复: 0

汇编 五子棋

[复制链接]

276

主题

303

帖子

3197

积分

管理员

湘南小侠客

Rank: 9Rank: 9Rank: 9

积分
3197

优质服务勋章论坛元老

QQ
发表于 2017-5-1 14:27:40 | 显示全部楼层 |阅读模式
a,s,d,w控制上下左右,空格键落子

20160730_878b7af02ac91de33f5ep6CEtBvV5HpU.jpg

[mw_shl_code=asm,true].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[/mw_shl_code]
每次见你穿短裤打领带,还穿个拖鞋,下次再这样穿不要从我家门口过了!
http://gsh.yzqz.cn/CassettePlayer/index.html

天之道,损有余而补不足.人之道则不然,损不足以奉有余.孰能有余以奉天下,唯有道者.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 参与我们

本版积分规则

QQ|Archiver|手机版|小黑屋|应天社区 ( 湘ICP备17015224号 )

GMT+8, 2024-12-22 18:38 , Processed in 0.078125 second(s), 31 queries .

Powered by Discuz!

© 2001-2017 Comsenz Inc.


免责声明:
本站所发布的第三方软件及资源(包括但不仅限于文字/图片/音频/视频等仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢某程序或某个资源,请支持正版软件及版权方利益,注册或购买,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To: admin@yzqz.cn

快速回复 返回顶部 返回列表