原創 文曲星GVB 俄羅斯方塊

2021-08-29 06:00:03 字數 4727 閱讀 1554

好久沒寫gvb了,都快忘記了,

上一段時間抽空寫了個俄羅斯方塊的gvb程式,

發來給大家看看。

第一遍寫完後,慢的無法忍受。

已經優化過兩次演算法,但還是很慢,權當乙個樣品吧。

使用了鍵盤對映,是nc1020的,nc系列應該差不多。

以下內容為程式**:

10 clear:graph:locate 3,6:print "loading...":dim a(22,12),p(6,3,3),q(6,3,3):restore

20 for i=0 to 6:for j=0 to 3:for l=1 to 3:read p(i,j,l):read q(i,j,l):next:next:next

30 for i=0 to 10:a(21,i)=1:a(i,0)=1:a(i+11,0)=1:a(i,11)=1:a(i+11,11)=1:next

40 v=0:u=1:d=21:lvl=0:spd=9:scr=0:cls:locate 3,1:print "level:0","speed:9","score:0";

50 line 111,0,111,80:line 152,0,152,80:line 159,0,159,80:box 88,0,111,23

100 gosub 4400:gosub 4350:gosub 4100:s$="ready":gosub 4300:gosub 4600

500 b=0:s=ns:t=nt:gosub 4100:box 92,4,107,19,1,0

510 swap s,ns:swap t,nt:o=1:r=3:c=-3:gosub 4010:swap s,ns:swap t,nt

520 o=1:r=1:c=5:gosub 4010

1100 tt=t:rr=r:cc=c:k=peek(199):if k=141 or k=148 or k=160 or k=157 then poke 199,0

1200 if k<>141 then 1300 else s$="pause":gosub 4300:gosub 4600

1300 if k=157 then 10

2000 if k=148 then tt=t+u:tt=tt+(tt<0)*4-(tt>3)*4:gosub 4200:if z>0 then 1100

2100 i=peek(188):i=(i=247)-(i=127)

2110 if i<>0 then cc=c+i:gosub 4200:if z>0 then poke 188,255:1100

2300 if k=160 then z=0:while z=0:rr=rr+1:gosub 4200:wend:rr=rr-1:gosub 4000:goto 2500

2400 b=b+1:if b>=9-spd then b=0:rr=r+1 else rr=r+(peek(192)=247)

2410 if rr=r then 3000 else gosub 4200:if z=0 then 3000

2420 tt=t:cc=c:gosub 4200:if z=0 then 3000 else rr=r

2500 rl=0:for i=0 to 3:a(r+p(s,t,i),c+q(s,t,i))=1:next

2505 if d>r+p(s,t,3)then d=r+p(s,t,3):gosub 4450

2510 for i=r+p(s,t,1)to r+p(s,t,3)step-1:if i>20 then 2550

2520 j=1:while j<11 and a(i,j):j=j+1:wend:if j=11 then rl=rl+1:2550

2530 if rl=0 then 2550

2540 for j=1 to 10 :a(i+rl,j)=a(i,j):next

2550 next:if rl=0 then 2590

2555 for i=r+p(s,t,3)-1 to d step-1:for j=1 to 10:a(i+rl,j)=a(i,j):next:next

2560 box 112,d*4-4,151,(d+rl)*4-5,1,0

2565 for i=d+rl to r+p(s,t,1):for j=1 to 10:o=a(i,j):nr=i:nc=j:gosub 4050:next:next

2570 for i=d to d+rl-1:for j=1 to 10:a(i,j)=0:next:next:d=d+rl:gosub 4450

2580 scr=scr+(rl=1)+(rl=2)*3+(rl=3)*7+(rl=4)*13:gosub 4330:v=+1:if v=20 then v=0:gosub 4310

2590 if d>1 then 500

2600 for i=1 to 4:box 112,0,151,79,1,2:for j=1 to 800:next:next

2610 poke 199,0:s$="over!":gosub 4300:gosub 4500:goto 10

3000 if tt<>t or rr<>r or cc<>c then gosub 4000

3100 goto 1100

4000 o=0:gosub 4010:t=tt:r=rr:c=cc:o=1:gosub 4010:return

4010 for i=0 to 3:nc=c+q(s,t,i):nr=r+p(s,t,i):gosub 4050:next:return

4020 if a(i+rl,j)<>a(i,j)then a(i+rl,j)=a(i,j):o=a(i,j):nr=i+rl:nc=j

4050 x=nc*4+108:y=nr*4-4:if y>=0 and y<80 then box x,y,x+3,y+3,0,o:line x+1,y+1,x+2,y+2,o

4060 return

4100 i=rnd(1)*7:ns=(i>1)+(i>2)+(i>3)+(i>4)+(i>5)+(i>6):i=rnd(1)*4:nt=(i>1)+(i>2)+(i>3)

4110 return

4200 z=0:for i=0 to 3:nc=cc+q(s,tt,i):nr=rr+p(s,tt,i):z=z+a(nr,nc):next:return

4300 gosub 4350 :locate 1,2:print s$:gosub 4350

4305 for i=1 to 4:for j=1 to 800:next:gosub 4350 :next:return

4310 lvl=lvl+(lvl<9):spd=spd+(spd>0):gosub 4350:locate 3,7:print lvl:gosub 4350

4320 gosub 4350:locate 4,7:print spd:gosub 4350:return

4330 gosub 4350:locate 5,7:print scr;:gosub 4350:return

4350 box 1,0,55,16:box 3,2,53,14,1,2:return

4400 box 92,26,108,44,1,0:circle 100,38,8:box 100+u*2,30,100+u*8,40,1,0

4410 line 100-u*2,26,100+u*2,30:line 100-u*2,34,100+u*2,30:return

4450 box 154,0,157,80,1,0:box 154,d*4-4*(d>0),157,80,1,1:return

4500 poke 199,0:z=asc(inkey$):if z=27 then poke 199,155 else if z=29 then 10

4510 return

4600 gosub 4500:if z=20 then u=-u:gosub 4400

4610 if z=22 or z=23 then spd=spd+(z=22)*(spd<9)-(z=23)*(spd>0):gosub 4320

4620 if s$<>"ready" or(z=19)*(d>11)+(z=14)*(d<21)=0 then 4640

4630 d=d-(z=19):l=(int(d/2)=d/2):j=l:for i=1 to 10:j=(j=0)*(z=19):a(d,i)=j:o=j

4635 nr=d:nc=i:gosub 4050:next:d=d+(z=14):gosub 4450

4640 if z<>13 then 4600

4650 s$="start":gosub 4300:return

5000 data 0,2,0,1,0,-1,2,0,1,0,-1,0,0,2,0,1,0,-1,2,0,1,0,-1,0

5010 data 1,0,0,1,0,-1,1,0,0,-1,-1,0,0,1,0,-1,-1,0,1,0,0,1,-1,0

5020 data 1,1,1,0,-1,0,1,-1,0,1,0,-1,1,0,-1,0,-1,-1,0,1,0,-1,-1,1

5030 data 1,0,1,-1,-1,0,0,1,0,-1,-1,-1,1,0,-1,0,-1,1,1,1,0,1,0,-1

5040 data 1,1,1,0,0,-1,1,-1,0,-1,-1,0,1,1,1,0,0,-1,1,-1,0,-1,-1,0

5050 data 1,0,1,-1,0,1,1,1,0,1,-1,0,1,0,1,-1,0,1,1,1,0,1,-1,0

5060 data 1,1,1,0,0,1,1,1,1,0,0,1,1,1,1,0,0,1,1,1,1,0,0,1

俄羅斯方塊高階 AI俄羅斯方塊

前文回顧 致青春 python實現俄羅斯方塊 人工智慧大火的今天,如果還是自己玩俄羅斯方塊未免顯得太low,為什麼不對遊戲公升級,讓機器自己去玩俄羅斯方塊呢?有了這個想法之後利用週六週日兩天的時間去蒐集了大量的資料,在電腦宕機好多次之後終於將ai俄羅斯方塊實現了。所謂讓機器自己去玩俄羅斯方塊,就是讓...

俄羅斯方塊

俄羅斯方塊 tetris,俄文 是一款風靡全球的電視遊戲機 和掌上遊戲機遊戲,它由俄羅斯人阿列克謝 帕基特諾夫 發明,故得此名。俄羅斯方塊的基本規則是移動 旋轉和擺放遊戲自動輸出的各種方塊,使之排列成完整的一行或多行並且消除得分。由於上手簡單 老少皆宜,從而家喻戶曉,風靡世界。俄羅斯方塊的開發者是阿...

俄羅斯方塊

include include include include includeusing namespace std include include define mem a,b memset a,b,sizeof a const int sudu 40 const int dir 4 2 cons...