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

📄 w_main.srw

📁 一个powerbuilder做的俄罗斯方块
💻 SRW
📖 第 1 页 / 共 3 页
字号:
long	ll_fkh
str_fk	lstr_fk_back[4]

lstr_fk_back  = istr_fk_last
Choose case il_fkh
	Case 1
		ll_fkh = 2
	Case 2
		ll_fkh = 3
	Case 3
		ll_fkh = 4
	Case 4
		ll_fkh = 1
End Choose

// 取将要旋转所的方块到istr_fk_last中
If wf_getfk(il_fkid,ll_fkh) = False Then
	messagebox('放置方块','取方块阵列出错。')
	Goto ExitFunction
End IF

// 开始判断是否可以旋转
integer	li_r,li_c
Long		ll_l
Boolean	lb_old
For li_r = 1 to 4
	If ii_CurrentY + li_r - 1 > 0 Then	// 在视线范围内的才要判断
		For li_c = 1 To 4
			Choose case li_c
				case 1
					ll_l = istr_fk_last[li_r].long1
					lb_old = (istr_fk_Current[li_r].long1 = ll_l)
				Case 2
					ll_l = istr_fk_last[li_r].long2
					lb_old = (istr_fk_Current[li_r].long2 = ll_l)
				Case 3
					ll_l = istr_fk_last[li_r].long3
					lb_old = (istr_fk_Current[li_r].long3 = ll_l)
				Case 4
					ll_l = istr_fk_last[li_r].long4
					lb_old = (istr_fk_Current[li_r].long4 = ll_l)
			End Choose
			If ll_l > 0 Then	// 有点
				If ii_CurrentX + li_c - 1 > 10 Then	// 超界,不能旋转
					Goto ExitFunction
				Else	// 看看是不是原来方块就有的点
					If lb_old = False Then	// 不是原来的点,则要看是否已有点在数据窗口中
						If dw_1.Object.data[li_r + ii_currentY -1,li_c + ii_CurrentX - 1] > 0 Then
							// 窗口上有重叠点,不能旋转
							Goto ExitFunction
						End If
					End If
				End If
			End If
		End For
	End If
End For
// 可以旋转
dw_1.SetRedraw(False)
wf_writeFk(dw_1,istr_fk_current,ii_currenty,ii_currentx,true)	// 消去原来的方块

il_fkh = ll_fkh			//  当前方块编号,方块号

istr_fk_current = istr_fk_last
wf_writeFk(dw_1,istr_fk_current,ii_currenty,ii_currentx,false) // 画上
dw_1.SetRedraw(True)


ExitFunction:
istr_fk_last = lstr_fk_back
Return

end subroutine

public subroutine wf_init_line (integer al_line);// 初始化初始行
If al_line <= 0 Or al_line >= 10 Then
	Return
End If
al_line --
Long	lla_c[9]
lla_c[1] = Rgb(0,0,0)
lla_c[2] = Rgb(255,0,0)
lla_c[3] = Rgb(255,128,064)
lla_c[4] = Rgb(0,0,255)
lla_c[5] = Rgb(0,255,255)
lla_c[6] = Rgb(0,255,0)
lla_c[7] = Rgb(192,192,192)
lla_c[8] = Rgb(255,0,255)
lla_c[9] = rgb(255,255,255)

Integer	li_r,li_c,li_rand
dw_1.SetRedraw(False)
For li_r = 21 To 21 - al_line Step -1
	For li_c = 1 To 10
		If Rand(3) = 1 Then
			dw_1.object.data[li_r,li_c] = 0
		Else
			li_rand = rand(4)
			dw_1.object.data[li_r,li_c] = lla_c[li_rand]
		End If
	End For
End For
dw_1.SetRedraw(True)
Return

end subroutine

public subroutine wf_new_fk ();Integer	li_row
li_row = dw_fklx.RowCount()
If li_row <= 0 Then
	Messagebox(this.title,'没有方块阵列,请先自定义方块。')
	Return
End If

istr_fk_Current = istr_fk_last
il_fkid = il_lastfkid
il_fkh = il_lastfkh

il_Lastfkid = dw_fklx.object.id[rand(li_row)]
il_Lastfkh = rand(4)
If wf_getfk(il_Lastfkid,il_lastfkh) = False Then
	messagebox(this.title,'取方块阵列出错。')
	Return
End IF
wf_writeFk(dw_2,istr_fk_Current,1,1,True)
wf_writeFk(dw_2,istr_fk_last,1,1,False)
dw_2.SetRedraw(True)

ii_CurrentX = 5
ii_CurrentY = -3
wf_writeFk(dw_1,istr_fk_current,ii_CurrentY,ii_CurrentX,false)
dw_1.SetRedraw(True)
timing_1.Start(idec_timer)
Return

end subroutine

public function integer wf_del_line ();// 删除全填满的行
Integer	li_Count,li_r,li_c,li_bedel

li_Count = 0
// 计算可删除的行,并做上标记
For li_r = 1 To 21
	If dw_1.Object.col1[li_r] > 0 And dw_1.Object.col2[li_r] > 0 And &
		dw_1.Object.col3[li_r] > 0 And dw_1.Object.col4[li_r] > 0 And &
		dw_1.Object.col5[li_r] > 0 And dw_1.Object.col6[li_r] > 0 And &
		dw_1.Object.col7[li_r] > 0 And dw_1.Object.col8[li_r] > 0 And &
		dw_1.Object.col9[li_r] > 0 And dw_1.Object.col10[li_r] > 0 Then
		
		li_Count ++
		dw_1.Object.bedel[li_r] = 1
	End If
End For
If li_Count = 0 Then	// 没有可删除的行
	Return 0
End If

// 准备删除
For li_r = 21 to 1 Step -1
	If dw_1.Object.bedel[li_r] = 1 Then
		For li_c = 1 to 10
			dw_1.SetRedraw(False)
			dw_1.Object.data[li_r,li_c] = 0
			dw_1.SetRedraw(True)
		End For
	End If
End For

// 删除
li_r = 21
Do while li_r > 0
	If dw_1.Object.bedel[li_r] = 1 Then
		dw_1.SetRedraw(False)
		dw_1.DeleteRow(li_r)	// 删除
		// 重新加一行
		dw_1.insertRow(1)
		For li_c = 1 To 10
			dw_1.Object.Data[1,li_c] = 0
		End For
		dw_1.Object.bedel[1] = 0
		dw_1.SetRedraw(True)
	Else
		li_r --
	End If
Loop

il_zhs = il_zhs + li_Count
il_zfs = il_zfs + (5 * li_count) + (li_count -1) * (li_Count^2) * 5
st_zhs.Text = string(il_zhs) + '行'
st_zfs.text = string(il_zfs) + '分'

If il_zfs <= 500 Then
	If idec_timer < 1.0 Then
	Else
		idec_timer = 1.0
	End If
ElseIf il_zfs <= 1000 Then
	If idec_timer > 0.5 Then
		idec_timer = 0.5
	End If
ElseIf il_zfs <= 3000 Then
	If idec_timer > 0.1 Then
		idec_timer = 0.1
	End If
ElseIf il_zfs <= 6000 Then
	If idec_timer > 0.04 Then
		idec_timer = 0.04
	End If
Else
	idec_timer = 0.018
End If

Return li_Count

end function

public subroutine wf_keydown (keycode key);If ib_IsBegin = False Then
	Return
End If
If ib_IsStop Then
	Return
End If

ib_keydown = True
Choose Case key
	Case KeyLeftArrow!
		If wf_CanLeft(istr_fk_current,ii_currenty,ii_currentx) Then
			dw_1.SetRedraw(False)
			wf_writeFk(dw_1,istr_fk_current,ii_currenty,ii_currentx,true)
			ii_currentx --
			wf_writeFk(dw_1,istr_fk_current,ii_currenty,ii_currentx,false)
			dw_1.SetRedraw(True)
		End If
	Case KeyRightArrow!
		If wf_CanRight(istr_fk_current,ii_currenty,ii_currentx) Then
			dw_1.SetRedraw(False)
			wf_writeFk(dw_1,istr_fk_current,ii_currenty,ii_currentx,true)
			ii_currentx ++
			wf_writeFk(dw_1,istr_fk_current,ii_currenty,ii_currentx,false)
			dw_1.SetRedraw(True)
		End If
	Case keyDownArrow!
		timing_1.Stop()
		Do While wf_CanDown(istr_fk_current,ii_currenty,ii_currentx)
			dw_1.SetRedraw(False)
			wf_writeFk(dw_1,istr_fk_current,ii_currenty,ii_currentx,true)
			ii_currenty ++
			wf_writeFk(dw_1,istr_fk_current,ii_currenty,ii_currentx,false)
			dw_1.SetRedraw(True)
		Loop
		timing_1.Start(idec_timer)
	Case KeyUpArrow!
		wf_xz()
End Choose
ib_keydown = False
Return

end subroutine

public subroutine wf_new ();Integer	li_r,li_c
// 初始化大方块数据窗口
this.SetRedraw(False)
dw_1.Reset()
For li_r = 1 To 21
	dw_1.InsertRow(0)
	For li_c = 1 To 10
		dw_1.SetItem(li_r,li_c,0)
	End For
	dw_1.object.bedel[li_r] = 0
End For
dw_1.Object.Datawindow.readonly = True

// 初始化小方块数据窗口
dw_2.Reset()
For li_r = 1 To 4
	dw_2.InsertRow(0)
	For li_c = 1 To 4
		dw_2.SetItem(li_r,li_c,0)
	End For
End For

this.SetRedraw(True)

li_r = dw_fklx.RowCount()
If li_r <= 0 Then
	Messagebox(this.title,'没有方块阵列,请先自定义方块。')
	Return
End If

il_Lastfkid = dw_fklx.object.id[rand(li_r)]
il_Lastfkh = rand(4)
If wf_getfk(il_Lastfkid,il_Lastfkh) = False Then
	messagebox(this.title,'取方块阵列出错。')
	Return
End IF
wf_writeFk(dw_2,istr_fk_last,1,1,False)
dw_2.SetRedraw(True)

st_Over.Visible = False
ib_IsBegin = True
ib_IsStop = False
pb_4.pictureName = pb_stop.picturename

il_zhs= 0;il_zfs=0	// 总行数,总分数
st_zhs.text = '行'
st_zfs.text = '分'

Choose Case il_dj
	Case 1
		idec_timer = 1.0
	Case 2
		idec_timer = 0.50
	Case 3
		idec_timer = 0.10
	case 4
		idec_timer = 0.04
	Case 5
		idec_timer = 0.018
End choose

isi_cont = 0

timing_1.Stop()
timing_2.stop()

wf_Init_Line(il_line)
wf_new_fk()
Return

end subroutine

public subroutine wf_edit ();If ib_IsBegin Then
	If ib_IsStop = False Then
		w_main.pb_4.triggerEvent('Clicked')
	End If
End If
open(w_edit)
If ib_IsBegin And ib_IsStop Then
	pb_4.Post Event Clicked()
End If
Return

end subroutine
on w_main.create
if this.MenuName = "m_main" then this.MenuID = create m_main
this.mdi_1=create mdi_1
this.st_14=create st_14
this.st_13=create st_13
this.st_12=create st_12
this.st_8=create st_8
this.dw_fklx=create dw_fklx
this.st_zfs=create st_zfs
this.st_10=create st_10
this.st_9=create st_9
this.st_zhs=create st_zhs
this.st_7=create st_7
this.st_6=create st_6
this.st_5=create st_5
this.st_4=create st_4
this.st_2=create st_2
this.st_1=create st_1
this.pb_start=create pb_start
this.pb_stop=create pb_stop
this.pb_5=create pb_5
this.pb_4=create pb_4
this.pb_3=create pb_3
this.pb_2=create pb_2
this.pb_1=create pb_1
this.st_over=create st_over
this.dw_2=create dw_2
this.dw_1=create dw_1
this.st_3=create st_3
this.timing_2=create timing_2
this.timing_1=create timing_1
this.Control[]={this.mdi_1,&
this.st_14,&
this.st_13,&
this.st_12,&
this.st_8,&
this.dw_fklx,&
this.st_zfs,&
this.st_10,&
this.st_9,&
this.st_zhs,&
this.st_7,&
this.st_6,&
this.st_5,&
this.st_4,&
this.st_2,&
this.st_1,&
this.pb_start,&
this.pb_stop,&
this.pb_5,&
this.pb_4,&
this.pb_3,&
this.pb_2,&
this.pb_1,&
this.st_over,&
this.dw_2,&
this.dw_1,&
this.st_3}
end on

on w_main.destroy
if IsValid(MenuID) then destroy(MenuID)
destroy(this.mdi_1)
destroy(this.st_14)
destroy(this.st_13)
destroy(this.st_12)
destroy(this.st_8)
destroy(this.dw_fklx)
destroy(this.st_zfs)
destroy(this.st_10)
destroy(this.st_9)
destroy(this.st_zhs)
destroy(this.st_7)
destroy(this.st_6)
destroy(this.st_5)
destroy(this.st_4)
destroy(this.st_2)
destroy(this.st_1)
destroy(this.pb_start)
destroy(this.pb_stop)
destroy(this.pb_5)
destroy(this.pb_4)
destroy(this.pb_3)
destroy(this.pb_2)
destroy(this.pb_1)
destroy(this.st_over)
destroy(this.dw_2)
destroy(this.dw_1)
destroy(this.st_3)
destroy(this.timing_2)
destroy(this.timing_1)
end on

event open;Integer	li_r,li_c
// 初始化大方块数据窗口
For li_r = 1 To 21
	dw_1.InsertRow(0)
	For li_c = 1 To 10
		dw_1.SetItem(li_r,li_c,0)
	End For
	dw_1.object.bedel[li_r] = 0
End For
dw_1.Object.Datawindow.readonly = True

// 初始化空方块结构及初始化小方块数据窗口
dw_2.object.col5.x = 400
For li_r = 1 To 4
	dw_2.InsertRow(0)
	For li_c = 1 To 4
		dw_2.SetItem(li_r,li_c,0)
	End For
	istr_fk_null[li_r].long1 = 0
	istr_fk_null[li_r].long2 = 0
	istr_fk_null[li_r].long3 = 0
	istr_fk_null[li_r].long4 = 0
End For

dw_fklx.ImportFile('fklx.dbf')
w_main.dw_fklx.SetSort('id a')
w_main.dw_fklx.sort()

string ls_pathfile
integer li_filenum
ls_pathFile = GetApplication().className() + '.ini'
If FileExists(ls_PathFile) = False Then
	// 若是文件没有建立,则建立它
	li_FileNum = FileOpen(ls_PathFile,StreamMode!, Write!, LockWrite!, Replace!)
	FileWrite(li_FileNum,'Rem 系统配置文件')
	FileClose(li_FileNum)
End If

//Long	il_dj,il_line	// 等级,底行数
il_dj = Long(ProfileString(ls_pathFile, "System","Dj", "1"))
il_Line = Long(ProfileString(ls_pathFile, "System","Line", "0"))

m_main lm
lm = this.menuid
Choose Case il_dj
	Case 1
		lm.m_s.m_sl.m_l1.checked = True
		idec_timer = 1.0
	Case 2
		lm.m_s.m_sl.m_l2.checked = True
		idec_timer = 0.50
	Case 3
		lm.m_s.m_sl.m_l3.checked = True
		idec_timer = 0.10
	case 4
		lm.m_s.m_sl.m_l4.checked = True
		idec_timer = 0.04
	Case 5
		lm.m_s.m_sl.m_l5.checked = True
		idec_timer = 0.018
End choose
Choose Case il_line
	Case 0
		lm.m_s.m_si.m_i0.checked = True
	Case 1
		lm.m_s.m_si.m_i1.checked = True
	Case 2
		lm.m_s.m_si.m_i2.checked = True
	Case 3
		lm.m_s.m_si.m_i3.checked = True
	Case 4
		lm.m_s.m_si.m_i4.checked = True
	Case 5
		lm.m_s.m_si.m_i5.checked = True
	Case 6
		lm.m_s.m_si.m_i6.checked = True
	Case 7
		lm.m_s.m_si.m_i7.checked = True
	Case 8
		lm.m_s.m_si.m_i8.checked = True
	Case 9
		lm.m_s.m_si.m_i9.checked = True
End Choose

st_zhs.text = '行'
st_zfs.text = '分'

Return

end event

event close;timing_1.Stop()
Return

end event

⌨️ 快捷键说明

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