| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 8686 人关注过本帖, 1 人收藏
标题:【原创】五子棋
只看楼主 加入收藏
Valenciax
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:11
帖 子:340
专家分:2482
注 册:2016-5-15
收藏
得分:0 
代码做了修改,光标控制改用方向键,加了框线(若不要框线,删去draw line一段即可),加了提示谁下子(左下角)。
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编辑过]

2016-07-30 17:13
zhulei1978
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:53
帖 子:1351
专家分:1200
注 册:2006-12-17
收藏
得分:0 
厉害,压缩到只有400多行

其实我就是改变社会风气,提高少女素质,刺激电影市道,提高年轻人内涵,玉树临风,风度翩翩的整蛊专家,我名叫古晶,英文名叫JingKoo!
2016-07-31 09:48
Valenciax
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:11
帖 子:340
专家分:2482
注 册:2016-5-15
收藏
得分:0 
回复 12楼 zhulei1978
班竹可以考虑写写悔棋,或者添加其他细节
2016-07-31 11:26
Valenciax
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:11
帖 子:340
专家分:2482
注 册:2016-5-15
收藏
得分:0 
今天有点空闲,把悔棋功能也做了。
按backspace(退位)悔一子,连按就不断悔,直到第一手为止。
按=(或+)是重下一子,即把悔棋的步再走一次,直到最后的落子为止。
图片附件: 游客没有浏览图片的权限,请 登录注册


压缩包是代码和可执行程序
5c.rar (4.63 KB)





[此贴子已经被作者于2016-8-8 06:54编辑过]

2016-08-07 09:21
Valenciax
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:11
帖 子:340
专家分:2482
注 册:2016-5-15
收藏
得分:0 
接下来班竹可以想想AI了
2016-08-08 06:54
zhulei1978
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:53
帖 子:1351
专家分:1200
注 册:2006-12-17
收藏
得分:0 
看别的呢,一会顾不上

其实我就是改变社会风气,提高少女素质,刺激电影市道,提高年轻人内涵,玉树临风,风度翩翩的整蛊专家,我名叫古晶,英文名叫JingKoo!
2016-08-08 14:15
xiagood
Rank: 1
等 级:新手上路
帖 子:6
专家分:2
注 册:2009-1-1
收藏
得分:0 
利害啊,汇编语言学不会。只能给大家鼓鼓掌。
2016-10-07 19:25
worldlc
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:44
专家分:117
注 册:2016-10-13
收藏
得分:0 
不忍心看下去了  ,注释 少的 可怜。
2016-10-13 15:09
快速回复:【原创】五子棋
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.069472 second(s), 11 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved