如何用vb設定拼圖遊戲啊,如何用vb設定乙個拼圖遊戲啊

時間 2022-03-08 09:45:16

1樓:匿名使用者

public a, b

private sub form_load()

a = 2

b = 2

end sub

private sub command1_click(index as integer)

if (command1(index).left / 1500 - a) ^ 2 + (command1(index).top / 1500 - b) ^ 2 = 1 then

tempa = command1(index).left / 1500

tempb = command1(index).top / 1500

command1(index).left = a * 1500

command1(index).top = b * 1500

a = tempa

b = tempb

else

msgbox "周圍沒有空格"

end if

end sub

這是個簡單的例子。建立8個按鈕組(可以根據需要修改為**等),例子中按鈕的left和top屬性都是1500的整數倍。

然後建立a\b兩個公共變數儲存空白區域的位置。

按鈕功能主要是監測臨近是否有空白區域,有空白就換位置,沒有彈出提示。看下是否能滿足你的要求。

2樓:匿名使用者

我有使用vb6.0做的拼圖遊戲。

如何用vb寫乙個這樣的小遊戲 5

3樓:浥鮫綃透

把**複製到空窗體中按f5執行即可。

option explicit

private withevents timer1 as timer

private withevents label1 as label

dim gfangxiang as boolean

dim hwb as single

dim she() as shenti

dim x as long, y as long

dim zhuangtai(23, 23) as long

private type shenti

f as long

x as long

y as long

end type

private sub form_keydown(keycode as integer, shift as integer)

dim c as long

if keycode = 27 then end

if keycode = 32 then

if timer1.enabled = true then

timer1.enabled = false

label1.visible = true

else

timer1.enabled = true

label1.visible = false

end if

end if

c = ubound(she)

if gfangxiang = true then exit sub

select case keycode

case 37

if she(c).f = 2 then exit sub

she(c).f = 0

gfangxiang = true

case 38

if she(c).f = 3 then exit sub

she(c).f = 1

gfangxiang = true

case 39

if she(c).f = 0 then exit sub

she(c).f = 2

gfangxiang = true

case 40

if she(c).f = 1 then exit sub

she(c).f = 3

gfangxiang = true

end select

end sub

private sub form_load()

me.autoredraw = true

me.backcolor = hc000

me.fillcolor = 255

me.fillstyle = 0

me.scalewidth = 24

me.scaleheight = 24

me.windowstate = 2

set timer1 = controls.add(;vb.timer;, ;timer1;)

set label1 = controls.add(;vb.label;, ;label1;)

label1.autosize = true

label1.backstyle = 0

label1 = ;暫停;

label1.forecolor = rgb(255, 255, 0)

label1.fontsize = 50

chushihua

end sub

private sub form_resize()

on error goto 1:

with me

if .windowstate lt;; 1 then

.cls

.scalemode = 3

hwb = .scaleheight / .scalewidth

.scalewidth = 24

.scaleheight = 24

label1.move (me.scalewidth - label1.width) / 2, (me.scaleheight - label1.height) / 2

huatu

me.line (x, y)-(x + 1, y + 1), rgb(255, 255, 0), bf

end if

end with

1: end sub

private sub timer1_timer()

dim c as long, i as long

on error goto 2:

qingchu

c = ubound(she)

select case she(c).f

case 0

if zhuangtai(she(c).x - 1, she(c).y) = 2 then

c = c + 1

redim preserve she(c)

she(c).f = she(c - 1).f

she(c).x = she(c - 1).x - 1

she(c).y = she(c - 1).y

chanshengshiwu

goto 1:

elseif zhuangtai(she(c).x - 1, she(c).y) = 1 then

goto 2:

end if

case 1

if zhuangtai(she(c).x, she(c).y - 1) = 2 then

c = c + 1

redim preserve she(c)

she(c).f = she(c - 1).f

she(c).x = she(c - 1).x

she(c).y = she(c - 1).y - 1

chanshengshiwu

goto 1:

elseif zhuangtai(she(c).x, she(c).y - 1) = 1 then

goto 2:

end if

case 2

if zhuangtai(she(c).x + 1, she(c).y) = 2 then

c = c + 1

redim preserve she(c)

she(c).f = she(c - 1).f

she(c).x = she(c - 1).x + 1

she(c).y = she(c - 1).y

chanshengshiwu

goto 1:

elseif zhuangtai(she(c).x + 1, she(c).y) = 1 then

goto 2:

end if

case 3

if zhuangtai(she(c).x, she(c).y + 1) = 2 then

c = c + 1

redim preserve she(c)

she(c).f = she(c - 1).f

she(c).x = she(c - 1).x

she(c).y = she(c - 1).y + 1

chanshengshiwu

goto 1:

elseif zhuangtai(she(c).x, she(c).y + 1) = 1 then

goto 2:

end if

end select

zhuangtai(she(0).x, she(0).y) = 0

for i = 0 to c

select case she(i).f

case 0

she(i).x = she(i).x - 1

case 1

she(i).y = she(i).y - 1

case 2

she(i).x = she(i).x + 1

case 3

she(i).y = she(i).y + 1

end select

next

tiaozheng

1: gfangxiang = false

zhuangtai(she(c).x, she(c).y) = 1

huatu

exit sub

2: if msgbox(;遊戲結束,點「是」重新開始遊戲,點「否」;, vbyesno, ;貪吃蛇;) = vbyes then

chushihua

else

endend if

end sub

private sub chushihua()

me.cls

timer1.enabled = true

timer1.interval = 200

erase zhuangtai

redim she(2)

she(0).f = 2

she(0).x = 9

she(0).y = 11

zhuangtai(9, 11) = 1

she(1).f = 2

she(1).x = 10

she(1).y = 11

zhuangtai(10, 11) = 1

she(2).f = 2

she(2).x = 11

she(2).y = 11

zhuangtai(11, 11) = 1

huatu

chanshengshiwu

end sub

private sub qingchu()

dim i as long

for i = 0 to ubound(she)

me.line (she(i).x, she(i).y)-(she(i).x + 1, she(i).y + 1), me.backcolor, bf

next

end sub

private sub huatu()

dim i as long

for i = 0 to ubound(she)

me.circle (she(i).x + 0.5, she(i).y + 0.5), 0.49, rgb(255, 255, 0), , , hwb

next

end sub

private sub tiaozheng()

dim i as long

for i = 0 to ubound(she) - 1

she(i).f = she(i + 1).f

next

end sub

private sub chanshengshiwu()

randomize timer

1: x = int(rnd * 24)

y = int(rnd * 24)

if zhuangtai(x, y) ; 0 then goto 1:

zhuangtai(x, y) = 2

me.line (x, y)-(x + 1, y + 1), rgb(255, 255, 0), bf

end sub

應該就是這個了

VB如何得到CPU溫度呢,如何用VB Net進行CPU溫度讀取

微軟的mvp說到了,如果主機板提供了api並註冊到了系統wmi下,那就可以在.net下呼叫,從而讀取cpu的溫度資訊.否則的話,就無法通過簡單的方法來實現cpu溫度的讀取.更何況有些主機板根本就不有溫度探頭,沒有辦法的。如何用vb.net進行cpu溫度讀取 這個要使用api進行讀取cpu溫度的。我估...

vb如何外部開啟檔案,如何用VB呼叫乙個外部EXE程式

是的 樓主你好 完整的程式是這樣的 private declare function shellexecute lib shell32.dll alias shellexecutea byval hwnd as long,byval lpoperation as string,byval lpfil...

如何用瑞星設定上網首頁

開啟卡卡安全助手,ie防護 ie主頁保護的 修改設定 填入需要設定的主頁,最後 確定 即可。 旋風 很簡單啊開啟卡卡安全助手,ie防護,ie主頁保護的 修改設定 打入要設定的主頁,最後 確定 你只裝瑞星防毒軟體或全功能安全軟體的話,是無法設定上網首頁的。你可以裝瑞星卡卡安全助手,在ie防護可以設定。...