?? russia box.asm
字號:
;經典俄羅斯方塊游戲程序
;本程序是我自學win32匯編語言三個月后的成果花了我4個夜晚,其中定有不足希望網上的高手們多多指點。
;本人自學用的書是羅云彬編寫的《Windwos 環境下32位匯編語言程序設計(第2版)》(電子工業出版社)定價79.00元,此書是中文版中的經典,我極力向廣大初學者推薦。
;本人網名:HAM
;電子郵箱:jiangsunantongfeng@163.com 有點長^_^
.386
.model flat,stdcall
option casemap:none
include windows.inc
include gdi32.inc
includelib gdi32.lib
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
L equ -1
R equ 1
.data?
a dd ?
b dd ?
hInstance dd ?
hWinMain dd ?
random1 dd ?
random2 dd ?
timergame dd ?
quickdiadown dd ?
timerleft dd ?
timerright dd ?
timercir dd ?
cirjh dd ?
achievement dd ?
achbuff db 5 dup(?)
dialeft dd ?;左移標記
diaright dd ?;右稱標記
diacia dd ?;旋轉標記
rdtop dd ?;記錄每種組合的狀態
rdcoord db 4 dup(?);記錄每個小方格的偏移位置
rdbuff db 210 dup(?);整個活動區域
systime SYSTEMTIME <>
poly struct
tlX dd ?
tlY dd ?
blX dd ?
blY dd ?
brX dd ?
brY dd ?
trX dd ?
trY dd ?
poly ends
.const
szClassName db 'MyGame',0
szCaptionMain db 'Rd',0
explain db '↑ ↓ ← →',0
.code
_dia proc _x,_y,_p,@hdc
;----------------------------------------------------
;繪制小方格
;----------------------------------------------------
LOCAL @poly:poly
pushad
mov eax,_p
push _x
pop @poly.tlX
push _y
pop @poly.tlY
push _x
pop @poly.blX
push _y
pop @poly.blY
add @poly.blY,eax
push _x
pop @poly.brX
add @poly.brX,eax
push _y
pop @poly.brY
add @poly.brY,eax
push _x
pop @poly.trX
add @poly.trX,eax
push _y
pop @poly.trY
invoke MoveToEx,@hdc,@poly.trX,@poly.trY,0
invoke PolylineTo,@hdc,addr @poly,4
popad
ret
_dia endp
_scanplot proc @hdc
LOCAL @x
LOCAL @y
pushad
lea esi,rdbuff
xor ecx,ecx
@@:
cmp ecx,200
jz @f
push ecx
mov eax,ecx
xor edx,edx
mov ebx,10
div ebx
mov ecx,edx
mov ebx,7
mul ebx
xchg eax,ecx
mul ebx
mov @x,eax
mov @y,ecx
mov al,byte ptr[esi]
.if al
invoke GetStockObject,BLACK_PEN
invoke SelectObject,@hdc,eax
invoke _dia,@x,@y,6,@hdc
add @x,2
add @y,2
invoke _dia,@x,@y,2,@hdc
.else
invoke GetStockObject,WHITE_PEN
invoke SelectObject,@hdc,eax
invoke _dia,@x,@y,6,@hdc
add @x,2
add @y,2
invoke _dia,@x,@y,2,@hdc
.endif
inc esi
pop ecx
inc ecx
jmp @b
@@:
popad
ret
_scanplot endp
_next proc n,@hdc
LOCAL @poly:poly
;----------------------------------------------------------
;清除上次圖形
;----------------------------------------------------------
invoke GetStockObject,WHITE_BRUSH
invoke SelectObject,@hdc,eax
invoke GetStockObject,NULL_PEN
invoke SelectObject,@hdc,eax
invoke Rectangle,@hdc,77,7,99,36
;----------------------------------------------------------
;在右欄繪制下一個圖形
;----------------------------------------------------------
invoke CreatePen,PS_SOLID,1,0
push eax
invoke SelectObject,@hdc,eax
.if n == 1
invoke _dia,91, 7,6,@hdc
invoke _dia,93, 9,2,@hdc
invoke _dia,91,14,6,@hdc
invoke _dia,93,16,2,@hdc
invoke _dia,91,21,6,@hdc
invoke _dia,93,23,2,@hdc
invoke _dia,91,28,6,@hdc
invoke _dia,93,30,2,@hdc
.elseif n == 2
invoke _dia,84,21,6,@hdc
invoke _dia,86,23,2,@hdc
invoke _dia,84,28,6,@hdc
invoke _dia,86,30,2,@hdc
invoke _dia,91,28,6,@hdc
invoke _dia,93,30,2,@hdc
invoke _dia,91,21,6,@hdc
invoke _dia,93,23,2,@hdc
.elseif n == 3
invoke _dia,84,14,6,@hdc
invoke _dia,86,16,2,@hdc
invoke _dia,84,21,6,@hdc
invoke _dia,86,23,2,@hdc
invoke _dia,84,28,6,@hdc
invoke _dia,86,30,2,@hdc
invoke _dia,91,28,6,@hdc
invoke _dia,93,30,2,@hdc
.elseif n == 4
invoke _dia,91,14,6,@hdc
invoke _dia,93,16,2,@hdc
invoke _dia,91,21,6,@hdc
invoke _dia,93,23,2,@hdc
invoke _dia,91,28,6,@hdc
invoke _dia,93,30,2,@hdc
invoke _dia,84,28,6,@hdc
invoke _dia,86,30,2,@hdc
.elseif n == 5
invoke _dia,84,21,6,@hdc
invoke _dia,86,23,2,@hdc
invoke _dia,77,28,6,@hdc
invoke _dia,79,30,2,@hdc
invoke _dia,84,28,6,@hdc
invoke _dia,86,30,2,@hdc
invoke _dia,91,28,6,@hdc
invoke _dia,93,30,2,@hdc
.elseif n == 6
invoke _dia,77,21,6,@hdc
invoke _dia,79,23,2,@hdc
invoke _dia,84,21,6,@hdc
invoke _dia,86,23,2,@hdc
invoke _dia,84,28,6,@hdc
invoke _dia,86,30,2,@hdc
invoke _dia,91,28,6,@hdc
invoke _dia,93,30,2,@hdc
.else
invoke _dia,84,21,6,@hdc
invoke _dia,86,23,2,@hdc
invoke _dia,91,21,6,@hdc
invoke _dia,93,23,2,@hdc
invoke _dia,77,28,6,@hdc
invoke _dia,79,30,2,@hdc
invoke _dia,84,28,6,@hdc
invoke _dia,86,30,2,@hdc
.endif
pop eax
invoke DeleteObject,eax
ret
_next endp
_shift proc LorR
pushad
mov ebx,LorR
lea esi,rdcoord
add byte ptr[esi],bl
add byte ptr[esi+1],bl
add byte ptr[esi+2],bl
add byte ptr[esi+3],bl
popad
ret
_shift endp
_init proc ;初始化方塊偏侈坐標
lea esi,rdcoord
.if random2 == 1
mov byte ptr[esi],4
mov byte ptr[esi+1],14
mov byte ptr[esi+2],24
mov byte ptr[esi+3],34
.elseif random2 == 2
mov byte ptr[esi],4
mov byte ptr[esi+1],5
mov byte ptr[esi+2],14
mov byte ptr[esi+3],15
.elseif random2 == 3
mov byte ptr[esi],4
mov byte ptr[esi+1],14
mov byte ptr[esi+2],24
mov byte ptr[esi+3],25
.elseif random2 == 4
mov byte ptr[esi],5
mov byte ptr[esi+1],15
mov byte ptr[esi+2],25
mov byte ptr[esi+3],24
.elseif random2 == 5
mov byte ptr[esi],4
mov byte ptr[esi+1],13
mov byte ptr[esi+2],14
mov byte ptr[esi+3],15
.elseif random2 == 6
mov byte ptr[esi],3
mov byte ptr[esi+1],4
mov byte ptr[esi+2],14
mov byte ptr[esi+3],15
.else
mov byte ptr[esi],4
mov byte ptr[esi+1],5
mov byte ptr[esi+2],13
mov byte ptr[esi+3],14
.endif
mov rdtop,1
ret
_init endp
_setbuff proc zhi,clear ;給圖形緩沖區設定有無方塊
pushad
mov ecx,clear
lea edi,rdbuff
lea esi,rdcoord
mov eax,zhi
xor ebx,ebx
mov bl,byte ptr[esi]
sub ebx,ecx
mov byte ptr[edi+ebx],al
xor ebx,ebx
mov bl,byte ptr[esi+1]
sub ebx,ecx
mov byte ptr[edi+ebx],al
xor ebx,ebx
mov bl,byte ptr[esi+2]
sub ebx,ecx
mov byte ptr[edi+ebx],al
xor ebx,ebx
mov bl,byte ptr[esi+3]
sub ebx,ecx
mov byte ptr[edi+ebx],al
popad
ret
_setbuff endp
_ran proc uses ebx edx
invoke GetLocalTime,addr systime
mov ax,systime.wMilliseconds
xor dx,dx
mov bx,7
div bx
inc dx
movzx edx,dx
mov eax,edx
ret
_ran endp
_down proc uses ebx ecx edx edi esi
lea edi,rdbuff
lea esi,rdcoord
xor ebx,ebx
.if random2 == 1
.if rdtop == 1
mov bl,byte ptr[esi+3]
cmp byte ptr[edi+ebx],0
jnz @f
invoke _setbuff,0,10
invoke _setbuff,1,0
jmp l
@@:
mov eax,0
ret
l:
.elseif rdtop == 2
mov bl,byte ptr[esi]
cmp byte ptr[edi+ebx],0
jnz @f
mov bl,byte ptr[esi+1]
cmp byte ptr[edi+ebx],0
jnz @f
mov bl,byte ptr[esi+2]
cmp byte ptr[edi+ebx],0
jnz @f
mov bl,byte ptr[esi+3]
cmp byte ptr[edi+ebx],0
jnz @f
invoke _setbuff,0,10
invoke _setbuff,1,0
jmp l1
@@:
mov eax,0
ret
l1:
.endif
.elseif random2 == 2
mov bl,byte ptr[esi+2]
cmp byte ptr[edi+ebx],0
jnz @f
mov bl,byte ptr[esi+3]
cmp byte ptr[edi+ebx],0
jnz @f
invoke _setbuff,0,10
invoke _setbuff,1,0
jmp lp1
@@:
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -