⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 源代码.asm

📁 一个五子棋游戏可以图形显示棋盘和网格线然后选择棋子 有一定智能
💻 ASM
📖 第 1 页 / 共 2 页
字号:
  名称:五子棋
  班级:00090B4 班
     
  第四组

  组长:
      黄柒光(41):主程序算法的实现及各模块之间的连接
  组员:   
      赵全乐(32):棋子的制作及调用
      武江波(26):文件的保存及打开
      祝  将(12):图形界面及边框
      洪春金(17):鼠标的响应及文字信息的显示
;Five Chess Game
up    equ 48h
down  equ 50h
right equ 4dh
left  equ 4bh
escape equ 01h  ;01h is scan code in ah,1bh is digit code in al
f1    equ 3bh    ;F1
f2    equ 3ch    ;F2
f3    equ 3dh    ;F3
f4    equ 3eh    ;F4
f5    equ 3fh    ;F5
;------------------------------
cal macro opr
  mov ax,opr
  mul ax
  endm
;------------------------
setcursor macro cury,curx
  ;position cursor macro
  mov ah,2
  mov bh,0
  mov dh,cury
  mov dl,curx
  int 10h
 endm
;------------------------------
blockpos macro bcolor,dlrow,dlcol,urrow,urcol
   ;ready for colorblock
  mov cx,urcol
  mov si,dlcol
  mov di,dlrow
  mov dx,urrow
  mov bl,bcolor   
  endm
;--------------------------------
rline macro rcolor,rrow,rcol,endcol
   local rline1 
   ; line horizon
    mov dx,rrow
   mov cx,rcol
 rline1:
     mov al,rcolor
     mov ah,0ch
     int 10h
     inc cx
     cmp cx,endcol
     jl rline1
     endm
 ;-------------------------------
 cline macro color,crow,ccol,endrow
    local cline1
    ;line vertical
   mov dx,crow
   mov cx,ccol
  cline1:
       mov al,color
       mov ah,0ch
       int 10h
       inc dx
       cmp dx,endrow
       jl cline1
       endm

 ;---------------------------------
 showmessage macro num
    ;show message
    lea dx,num
    mov ah,09h
    int 21h
    endm
;--------------------------------------
 setframe macro r1,r2,c1,c2
    ;set frame position
   mov si,c1
   mov di,r1
   mov col,c2
   mov row,r2
   endm
;-----------------------------------------
 data segment
 ;  m1 db  '************************$'
  m2 db  'Welcome you to play Five Chess game !?'
 ;  m3 db  '************************$'
  m4 db  ' Play_Enter$'
  m5 db  'Pause_Space$'
  m6 db  ' Exit_Esc  $'
  m7 db  ' Replay_F1 $'
  m8 db  '  Save_F2  $'
  m9 db  '  Open_F3  $'
  m0 db  ' Sound_F4  $'
  m00 db ' About_F5  $'
  ma db  'Black:$'
  mb db  'White:$'
  mc db  'Black Chess Win$'
  md db  'White Chess Win$'
  msave db 'Save current game ?$'
  msor db 'or$'
  mprod db 'Producers$'
  mhuang db 'Huang Qi Guang $'
  mzhao db 'Zhao Quan Le $'
  mzhu db 'Zhu Jiang $'
  mwu db 'Wu Jiang Bo $'
  mhong db 'Hong Chun Jin $'
  row dw ?
  col dw ?
  chessflg dw 0
  mskeyflg dw 0
  mchess db 256 dup(0)
  tempmchess db 256 dup(0)
  x dw ?
  y dw ?
  chessrad db ?
  tempt1 dw ?
  a1 db ?
  a2 db ?
  b1 db ?
  b2 db ?
  flg1 db 0
  row2 dw ?
  col2 dw ?
  exflg db 0
  ccount db ?
  colorflg db 0
  aboutflg db 1
  mflg1 dw ?
 data ends
;---------------------------------------------
   stack segment
      dw 100 dup(?)
   stack ends
 ;---------------------------------------
  ;start main
code segment
  main proc far
    assume cs:code,ds:data,es:data
     start:
       push ds
       xor ax,ax
       push ax
       mov ax,data
       mov ds,ax
       mov es,ax
       mov ax,stack
       mov ss,ax
       mov ah,0    ;set graphic mode
       mov al,12h
       int 10h
       call colorset  ;setbackcolor
       call mouseinit  ;set mouse
       call mouseshow
       call mouseshut
       call mainfrm    ;main frame
       call subfrm     ;subordinate frame
       call printmess
       call mouseshow
       call delay1
       call printwelcome
       call submain    ;subordinate main
       mov ah,0   ;clear screen
       mov al,12h
       int 10h
       ret
    main endp
  ; end of assembly
 ; --------------------------------------------
  colorset proc near
     push ax
     push bx
     mov ah,0bh  ;set color palette
     mov bh,0     ;1 ;0
     mov bl,0   ;4  ;2
     int 10h
     mov ah,0bh
     mov bh,1
     mov bl,0
     int 10h
     pop bx
     pop ax
      ret
     colorset endp
 ;---------------------------------------------
  mouseinit proc near
     mov ax,0
    int 33h
     ret
    mouseinit endp
 ;---------------------------------------------
   mouseshow proc near
     mov ax,1
     int 33h
      ret
     mouseshow endp
 ;------------------------------------------
 mouseshut proc near
     mov ax,2
     int 33h
      ret
     mouseshut endp
;------------------------------------------
  mousestau proc near
     mov ax,3   ;return button status in bx
     int 33h    ;horizion in cx
                 ;vertical in dx
      ret
    mousestau endp
 ;-------------------------------------
  mousepressed proc near
     mov bx,0    ;check for left button
     mov ax,5    ;return statu in ax
     int 33h     ;num in bx
                 ;horizion in cx,vertical in dx
     
     ret
    mousepressed endp
 ;-----------------------------------
  
   mouseliberty proc near
      mov bx,0    ;check for left
      mov ax,6    ;liberty mouse
      int 33h
      ret
      mouseliberty endp
 ;----------------------------------
  mainfrm proc near
    rline 1,65,1,640
    rline 1,415,1,640
    cline 1,65,480,415
    blockpos 9,64,640,1,1   ;for upbackground
    call colorblock
    blockpos 9,479,640,416,1    ;for downbackground
    call colorblock
    blockpos 9,414,78,66,1    ;for rightbackground
    call colorblock
    blockpos 9,414,479,66,402   ;for leftbackground
    call colorblock
    blockpos 9,78,402,66,78    ;for up1background
    call colorblock
    blockpos 9,414,402,402,78  ;for down1background
    call colorblock
    blockpos 8,414,639,66,481  ;for leftbackground
    call colorblock
    blockpos 6,402,402,78,78
    call colorblock           ;for chess background
    call linechess
    ret
     mainfrm endp
 ;----------------------------------
  colorblock proc near
    mov col,cx
  line:
     mov ah,0ch  ;draw colorblock
     mov al,bl
     int 10h
     inc cx
     cmp cx,si
     jne line
     mov cx,col
     inc dx
     cmp dx,di
     jne line
     ret
     colorblock endp
 ;------------------------------------
 linechess proc near
     mov dx,90  ;init row
 hline:
     mov cx,90   ;init column
 hdot:
      mov al,0fh   ;set color
      mov ah,0ch
      int 10h
      inc cx
      cmp cx,390
      jle hdot
      add dx,20
      cmp dx,390
      jle hline
   ;end of 15 hline

      mov cx,90
  vline:
      mov dx,90
  vdot:
      mov al,0fh
      mov ah,0ch
      int 10h
      inc dx
      cmp dx,390
      jle vdot
      add cx,20
      cmp cx,390
      jle vline
    ;end of 15 vline
      ret
     linechess endp
 ;-----------------------------
   subfrm proc near
    setframe 78,96,518,610
    call lineframe    ;for play frame
    setframe 110,128,518,610
    call lineframe    ;for pause frame
    setframe 142,160,518,610
    call lineframe    ;for exit frame
    setframe 174,192,518,610
    call lineframe   ;for replay frame
    setframe 206,224,518,610
    call lineframe   ;for save frame
    setframe 238,256,518,610
    call lineframe   ;for open frame
    setframe 270,288,518,610
    call lineframe   ;for sound frame
    setframe 302,320,518,610
    call lineframe   ;for about frame
     ret
    subfrm endp
 ;--------------------------------------
  lineframe proc near
    mov cx,si
    mov dx,di
 l1:
    mov ah,0ch
    mov al,3
    int 10h
    inc cx
    cmp cx,col
    jne l1
    mov dx,row
    mov cx,si
 l2:
    mov al,3
    int 10h
    inc cx
    cmp cx,col
    jne l2
   ;end of 2 horzions
    mov cx,si
    mov dx,di
 v1:
    mov ah,0ch
    mov al,3
    int 10h
    inc dx
    cmp dx,row
    jne v1
    mov dx,di
    mov cx,col
 v2:
    mov ah,0ch
    mov al,3
    int 10h
    inc dx
    cmp dx,row
    jne v2
    ret
   lineframe endp
 ;-------------------------
 printmess proc near
   setcursor 5,65
   showmessage m4    ;for play
   setcursor 7,65
   showmessage m5    ;for stop
   setcursor 9,65
   showmessage m6    ;for exit
   setcursor 11,65
   showmessage m7    ;for replay
   setcursor 13,65
   showmessage m8    ;for save
   setcursor 15,65
   showmessage m9    ;for open
   setcursor 17,65
   showmessage m0    ;for sound
   setcursor 19,65   
   showmessage m00   ;for about
   setcursor 22,62
   showmessage mA    ;for blacktime
   setcursor 24,62
   showmessage mB    ;for whitetime
   ret
   printmess endp
 ;-------------------------------------
   printwelcome proc near
      setcursor 1,20
      mov bx,offset m2
   output:
      call delay1
      mov al,[bx]
      cmp al,'?'
      je exit0
      mov ah,02h
      mov dl,[bx]
      int 21h
      inc bx
      jmp output
  exit0:
       ret
       printwelcome endp
  ;--------------------------------------
   delay1 proc near    ;for delay
     push cx
     push dx
     mov dx,5000
   del1:
      mov cx,5000
   del2:
       loop del2
       dec dx
       jne del1
       pop dx
       pop cx
       ret
     delay1 endp
 ;----------------------------------
 submain proc near
   next0:
       mov ah,1
       int 16h
       jz inmouse
    inkey:               ;for keyboard
       cmp ah,1ch  ;is Enter
       je kstart1
       cmp ah,39h  ;is Space
       je kstop1
       cmp ah,01h  ;is Esc
       je exit111
       cmp ah,3bh  ;is F1
       je kreplay11
       jmp sa1
   kreplay11:
        mov ah,0ch   ;for clear buffter
        mov al,0
        int 21h
        jmp replay1  
    sa1:
        cmp ah,3ch   ;is F2
        je ksave1
        cmp ah,3dh  ;is F3
        je kopen1
        cmp ah,3eh   ;is F4
        je ksound1
         cmp ah,3fh   ;is F5
         je kabout1
         jmp next0

     kstop1:
          mov ah,0ch   ;for clear buffter
          mov al,0
          int 21h
          jmp inmouse
     ksound1:          ;for clear buffter
          mov ah,0ch
          mov al,0
          int 21h
          jmp inmouse


   inmouse:           ;for inmouse
       mov ah,1
       int 16h
       jnz inkey       ;local mouse position
       call mousepressed
       cmp ax,1
       jb inmouse
       jmp inm
  
    
  inm:
       cmp cx,510
       jb inmouse
       cmp cx,610
       ja inmouse
       cmp dx,75
       jb inmouse
       cmp dx,97
       jb kstart1     ; in mnu play area
       jmp n8
  exit111:
       jmp exit11     ;because of out of jump range
   ksave1:            ;
                      ;
       jmp save1      ;
   kopen1:            ;
       jmp open1      ;
   kstart1:           ;for clear buffter
       mov ah,0ch
       mov al,0
       int 21h
       jmp start1
   kabout1:
        mov ah,0ch
        mov al,0
        int 21h
        jmp about1
   inmousee: jmp inmouse  ;for two jump

     n8:
       cmp dx,109
       jb inmousee
       cmp dx,128      ;in mnu pause area
       jb pause1
       cmp dx,141
       jb inmousee
       cmp dx,160
       jb exit11       ;in mnu exit area
       cmp dx,173
       jb inmousee
       cmp dx,192
       jb replay1       ;in mnu replay area
       cmp dx,205
       jb inmousee
       cmp dx,224
       jb save1         ;in mun save area
       cmp dx,237
       jb inmousee
       cmp dx,256
       jb open1         ;in mnu open area
       cmp dx,269
       jb inmousee
       cmp dx,288       
       jb sound1       ;in mnu sound area
       cmp dx,301
       jb inmousee
       cmp dx,320
       jb about1       ;in mnu about area
       jmp inmouse
     ;because of out of range
  exit11:
       jmp exit12
 
  pause1:
          jmp inmouse
  replay1:
           mov ah,0ch
           mov al,0
           int 21h
           inc colorflg      ;for color flag
           call mouseshut     
           call mainfrm2      ;change chess pan
           call mouseshow     
           mov cx,256         ;for clear mchess buffter
           mov si,0           ;
        kkk:                  ;
           mov mchess[si],0   ;
           inc si             ;
           loop kkk           ;
           jmp inmouse        ;
  
  save1: call mouseshut
         mov ah,0ch
         mov al,0
         int 21h
         call chesssave1      ;save chess
         call mouseshow
         jmp start1
  open1:
        call mouseshut
        mov ah,0ch
        mov al,0
        int 21h
        call chessopen1
        call mouseshow
        jmp start1
  sound1:
        jmp inmouse
  inmouse1:
        jmp inmouse
  about1:
        call mouseshut
        mov ah,0ch     ;for clear buffter
        mov al,0
        int 21h
        call chessabout1
        call mouseshow
        jmp start1
    start1:
     ;  call bchesstime    ;for time blackchess
    n1:
        mov ah,1
        int 16h
        jnz inmouse1       ;if no keyboard
        call mousepressed  ;else
        cmp ax,1           ;if left hit mouse
        jb n1              ;else
        cmp cx,90
        jb n1
        cmp cx,390          ;in chess area
        jb bchesspan1
        cmp cx,515           ;no chess area
        jb n1
        cmp cx,605
        ja n1
        cmp dx,77
        jb n1
        cmp dx,320
        ja n1
        jmp inm
  inkey1:jmp inkey
  bchesspan1:
        cmp dx,90
        jb n1
        cmp dx,390
        ja n1
  bchesspan2:               ;if in chess area
        call countmemchess   ;for count chess in mem pos
        cmp byte ptr mchess[bp][si],0  ;Have chess?

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -