互连游戏的结构(红外线无线控制)

互连游戏的结构


我现在准备编红外互连游戏所以先介绍一下,希望有兴趣的朋友一起编
因为lava好像不支持call和poke所以现在就在basic上做,汇编我在学,
应该会有像样的游戏的
我也没什么经验,所以都是自己设计的框架,有更好的请大家指出一起分享


互连游戏的主要结构是一个完整的游戏代码和数据发送接受判断程序,
下面我就简单介绍一下
1.过程:
接受数据和发送数据不能同步进行的,所以有先后如
甲机:运行------等待连线------发送数据------接受数据-----运行
乙机:运行------等待连线------接受数据------发送数据-----运行
这样就完成了一个简单的数据交互过程
2.框架.
有人会想,这样不是要两个不同的程序??
其实不用,你只要设定机号就可以了,就像英雄坛说和我的豪斯网络版,首先要选择你做主机还是对方是,如
在我的豪斯里如果你在进入的时候选择了庄家,那么你的变量TAI就=0也就是说在接下去的程序运行中你都是先发送后接受,而如果你是选择闲家,那么你的变量TAI就=1也就是说你是先接受后发送

甲机 定义TAI值
甲机 运行-----ON TAI+1 GOTO 庄家,闲家
-----庄家 GOSUB 连线:GOSUB 发送:GOSUB 接受-----运行
-----闲家 GOSUB 连线:GOSUB 接受:GOSUB 发送-----运行
运行-------------
这样就分TAI值不同成了两个分区
如果乙机同时定义另外的TAI值就可以完成双机数据交换了!!!!

下面就是发送和接受等的代码:

1150 REM连线准备
1160 DATA 0,074,01,96,0,0,0,0,176,240,17,0,0
1170 FOR I=5880 TO 5892
1180 READ D
1190 POKE I,D
1200 NEXT I
1210 POKE 3840,176
1220 POKE 3841,240
1230 POKE 3842,017
1240 POKE 3843,000
1250 POKE 3844,000
1260 CALL 5880:S$="":P$=""

发送:

1350 SO=0:SCK$=" "
1351 FOR SB=1 TO SA
1352 SC=PEEK(59)/2
1353 IF INT(SC)=SC THEN GOTO 1356
1354 SCK$=RIGHT$(SCK$,2)+CHR$(PEEK(58))
1355 IF SCK$="RDY" THEN SO=1:SB=SA
1356 NEXT SB:RETURN
1400 REM发送等待
1410 CALL 5880
1420 SA=4000
1430 GOSUB 1350
1440 IF SO=0 THEN TITI$="双机发送失败":GOSUB 1100:A$=INKEY$:GOTO (主界面)

1445 RETURN


1110 CLS:LOCATE 3,5:PRINT TITI$:LOCATE 2,5:PRINT ""
1120 LOCATE 4,5:PRINT ""
1130 BOX 28,12,131,67:BOX 27,11,132,68
1140 RETURN

1280 FOR SZ=1 TO 95:NEXT SZ:RETURN
1290 SA=LEN(S$)
1291 FOR SB=1 TO SA
1292 POKE 58,ASC(MID$(S$,SB,1))
1293 FOR SC=1 TO 40
1294 NEXT SC:NEXT SB:POKE 58,0:RETURN
1300 REM发送过程
1301 CALL 5880
1310 GOSUB 1280
1320 S$="RDY"+P$
1330 GOSUB 1290
1340 RETURN
1350 SO=0:SCK$=" "
1351 FOR SB=1 TO SA
1352 SC=PEEK(59)/2
1353 IF INT(SC)=SC THEN GOTO 1356
1354 SCK$=RIGHT$(SCK$,2)+CHR$(PEEK(58))
1355 IF SCK$="RDY" THEN SO=1:SB=SA
1356 NEXT SB:RETURN

1449 FOR SZ=1 TO 95:NEXT SZ:RETURN
1450 POKE 58,82:GOSUB 1449
1451 POKE 58,68:GOSUB 1449
1452 POKE 58,89:RETURN
1500 REM接收等待
1510 SO=0:T=30
1520 WHILE T>0 AND SO=0
1530 CALL 5880
1535 GOSUB 1450
1540 CALL 5880
1550 SA=100
1560 GOSUB 1350
1570 T=T-1
1580 WEND
1590 IF SO<>1 THEN TITI$="双机接收失败":GOSUB 1100:A$=INKEY$:GOTO 340
1595 RETURN

1600 REM接收过程
1610 S$=""
1620 IF PEEK(199)=241 THEN GOTO 1650
1630 SA=PEEK(59)/2:IF INT(SA)=SA THEN GOTO 1620
1640 SB=PEEK(58):IF SB=0 THEN GOTO 1660 ELSE S$=S$+CHR$(SB):GOTO 1620
1650 S$="":POKE 199,13
1660 RETURN

这样可能比较乱:

我就把我写的一段程序贴上来吧:

30 GRAPH:CLS:A$="对战":B$="豪斯"
35 FOR I=1 TO 5:CLS
40 LOCATE 3,I:PRINT A$:LOCATE 3,18-I:PRINT B$:FOR A=1 TO 100:NEXT A:NEXT I
45 X=80:Y=40
50 FOR I=1 TO 33 STEP 15
60 BOX 1,1,160,80,1,0:PRINT "";:LINE 35+I,40,79,I:LINE 80,I,125-I,40:LINE 35+I,40,79,80-I
70 LINE 80,80-I,125-I,40
80 FOR A=1 TO 80:NEXT A:NEXT I
90 LOCATE 3,10:PRINT "vs"
100 FOR I=30 TO 80
110 DRAW I,51:DRAW I,53:DRAW I,29:DRAW I,27
120 DRAW 160-I,51:DRAW 160-I,53:DRAW 160-I,29:DRAW 160-I,27:NEXT I
130 FOR I=1 TO 800:NEXT I
140 BOX 30,27,130,53,1,1
150 FOR I=1 TO 25 STEP 5
160 CLS:BOX 30+I,27-I/2,130-I,53-I,1,1:FOR A=1 TO 90:NEXT A:NEXT I
161 FOR I=1 TO 35 STEP 5
162 CLS:BOX 55-I,12,105+I,34,1,1:FOR A=1 TO 60:NEXT A:NEXT I
170 CLS:LOCATE 2,4:PRINT "对战豪斯网络版"
180 BOX 22,13,137,33:BOX 20,11,139,35:BOX 19,10,140,36:Z$(3)="账号通讯"
190 Z$(1)="进入游戏":Z$(2)="注册账号":Z$(4)="退出游戏":LOCATE 4,7:PRINT "进入游戏":Z=1
195 LINE 46,65,114,65:LINE 46,45,114,45
200 K=ASC(INKEY$)
210 IF K=20 THEN Z=Z-1 :GOTO 250
220 IF K=21 THEN Z=Z+1 :GOTO 250
230 IF K=13 THEN GOTO 300
240 BEEP:GOTO 200
250 IF Z>4 THEN Z=1 GOTO 270
260 IF Z<1 THEN Z=4 GOTO 270
270 FOR I=47 TO 63
280 LINE 48,I,112,I:NEXT I:FOR I=47 TO 63:LINE 48,I,112,I,0:FOR II=1 TO 10:NEXT II:NEXT I
290 LOCATE 4,7:PRINT Z$(Z):GOTO 200
300 ON Z GOTO 310,320,330,340
310 GOSUB 350:GOSUB 400:GOTO 450//进入游戏
320 GOTO 500://设账号
330 GOTO 1700://传
340 POKE 199,166:END
341 END
350 CLS:LOCATE 2,5:PRINT "账号:";:LOCATE 4,5:PRINT "密码:";
360 BOX 74,14,140,34:BOX 74,46,140,66:BOX 20,10,140,70:BOX 19,9,141,71
370 LOCATE 2,11:INPUT "*";NAME$:LOCATE 4,11:INPUT "*";WORD$
380 RETURN
400 REM密码
401 OPEN NAME$+"-hs" FOR RANDOM AS#1:CLOSE#1
410 IF LOF(1)<>0 THEN GOTO 420 ELSE 411
411 LOCATE 3,5:PRINT "账号不存在!!":A$=INKEY$:GOTO 170
420 OPEN NAME$+"-hs" FOR INPUT AS#1
430 INPUT#1,MIN$,MIM$,MONEY:CLOSE#1
440 IF MIM$<>WORD$ THEN LOCATE 3,5:PRINT "密码错误!!":A$=INKEY$:GOTO 170
445 RETURN
450 GOTO 600://进入
500 CLS:LOCATE 2,6:PRINT "*您的昵称*":BOX 30,12,130,65:BOX 35,45,125,65:BOX 29,11,131,66
505 LOCATE 4,6:INPUT "*";MIN$
510 GOSUB 350
520 OPEN NAME$+"-hs" FOR RANDOM AS#1:CLOSE#1
530 IF LOF(1)=0 THEN GOTO 550
540 LOCATE 3,5:PRINT "账号已存在!!":A$=INKEY$:GOTO 500
550 MONEY=2000:MIM$=WORD$:OPEN NAME$+"-hs" FOR OUTPUT AS#1
560 WRITE#1,MIN$,MIM$,MONEY:CLOSE#1
570 LOCATE 3,5:PRINT "新建成功!!":A$=INKEY$:CLS:CLEAR:GOTO 170
600 CLS:LOCATE 2,3:PRINT MIN$
610 LOCATE 3,3:PRINT "$";MONEY:BOX 10,12,90,50:BOX 9,11,91,51
620 LOCATE 3,15:PRINT "庄家":LOCATE 4,15:PRINT "闲家"
630 BOX 108,28,147,67:BOX 107,27,148,68:BOX 112,32,143,47,1,2:ZHU=0
640 K=ASC(INKEY$)
650 IF K=13 THEN GOTO 1000://主线
660 BOX 112,32,143,63,1,2:ZHU=ABS(ZHU-1):GOTO 640
1000 TAI=ZHU+1:TITI$="正在连线!..."
1010 GOSUB 1100:GOSUB 1150
1020 ON TAI GOTO 1030,1040
1030 REM庄家
1031 P$=MIN$:GOSUB 1400
1032 GOSUB 1300:P$=STR$(MONEY):GOSUB 1400:GOSUB 1300
1033 GOSUB 1500:GOSUB 1600:TMIN$=S$:GOSUB 1500:GOSUB 1600:TMONEY=VAL(S$):GOTO 2000
1040 REM闲家
1041 GOSUB 1500:GOSUB 1600:TMIN$=S$:GOSUB 1500:GOSUB 1600:TMONEY=VAL(S$)
1042 P$=MIN$:GOSUB 1400
1043 GOSUB 1300:P$=STR$(MONEY):GOSUB 1400:GOSUB 1300:GOTO 2000
1100 REM状态
1110 CLS:LOCATE 3,5:PRINT TITI$:LOCATE 2,5:PRINT ""
1120 LOCATE 4,5:PRINT ""
1130 BOX 28,12,131,67:BOX 27,11,132,68
1140 RETURN
1150 REM连线准备
1160 DATA 0,074,01,96,0,0,0,0,176,240,17,0,0
1170 FOR I=5880 TO 5892
1180 READ D
1190 POKE I,D
1200 NEXT I
1210 POKE 3840,176
1220 POKE 3841,240
1230 POKE 3842,017
1240 POKE 3843,000
1250 POKE 3844,000
1260 CALL 5880:S$="":P$=""
1270 RETURN
1280 FOR SZ=1 TO 95:NEXT SZ:RETURN
1290 SA=LEN(S$)
1291 FOR SB=1 TO SA
1292 POKE 58,ASC(MID$(S$,SB,1))
1293 FOR SC=1 TO 40
1294 NEXT SC:NEXT SB:POKE 58,0:RETURN
1300 REM发送过程
1301 CALL 5880
1310 GOSUB 1280
1320 S$="RDY"+P$
1330 GOSUB 1290
1340 RETURN
1350 SO=0:SCK$=" "
1351 FOR SB=1 TO SA
1352 SC=PEEK(59)/2
1353 IF INT(SC)=SC THEN GOTO 1356
1354 SCK$=RIGHT$(SCK$,2)+CHR$(PEEK(58))
1355 IF SCK$="RDY" THEN SO=1:SB=SA
1356 NEXT SB:RETURN
1400 REM发送等待
1410 CALL 5880
1420 SA=4000
1430 GOSUB 1350
1440 IF SO=0 THEN TITI$="双机发送失败":GOSUB 1100:A$=INKEY$:GOTO 340
1445 RETURN
1449 FOR SZ=1 TO 95:NEXT SZ:RETURN
1450 POKE 58,82:GOSUB 1449
1451 POKE 58,68:GOSUB 1449
1452 POKE 58,89:RETURN
1500 REM接收等待
1510 SO=0:T=30
1520 WHILE T>0 AND SO=0
1530 CALL 5880
1535 GOSUB 1450
1540 CALL 5880
1550 SA=100
1560 GOSUB 1350
1570 T=T-1
1580 WEND
1590 IF SO<>1 THEN TITI$="双机接收失败":GOSUB 1100:A$=INKEY$:GOTO 340
1595 RETURN
1600 REM接收过程
1610 S$=""
1620 IF PEEK(199)=241 THEN GOTO 1650
1630 SA=PEEK(59)/2:IF INT(SA)=SA THEN GOTO 1620
1640 SB=PEEK(58):IF SB=0 THEN GOTO 1660 ELSE S$=S$+CHR$(SB):GOTO 1620
1650 S$="":POKE 199,13
1660 RETURN
1700 CLS:LOCATE 2,5:PRINT " 操 作 选 择":LOCATE 4,7:PRINT "发送 接收":XUAN=0
1710 BOX 28,12,139,67:BOX 27,11,140,68:BOX 40,44,127,67:BOX 44,48,83,63,1,2
1720 K=ASC(INKEY$)
1730 IF K=13 THEN GOTO 1750
1740 XUAN=ABS(XUAN-1):BOX 44,48,123,63,1,2:GOTO 1720
1750 XXUAN=XUAN+1:GOSUB 1150
1760 ON XXUAN GOTO 1770,1810
1770 GOSUB 350:GOSUB 400:
1780 TITI$="账号发送!...":GOSUB 1100
1790 P$=NAME$:GOSUB 1400:GOSUB 1300:P$=MIN$:GOSUB 1400:GOSUB 1300
1795 P$=MIM$:GOSUB 1400:GOSUB 1300:P$=STR$(MONEY)
1800 GOSUB 1400:GOSUB 1300:TITI$="账号发送成功":GOSUB 1100:A$=INKEY$:GOTO 340
1810 TITI$="账号接收!...":GOSUB 1100
1820 GOSUB 1500:GOSUB 1600:NAME$=S$:GOSUB 1500:GOSUB 1600:MIN$=S$:GOSUB 1500:GOSUB 1600
1830 MIM$=S$:GOSUB 1500:GOSUB 1600:MONEY=VAL(S$)
1835 CALL 5880:FOR I=1 TO 500:NEXT I
1840 OPEN NAME$+"-hs" FOR RANDOM AS#1:CLOSE#1
1850 IF LOF(1)<>0 THEN GOTO 1890
1860 OPEN NAME$+"-hs" FOR OUTPUT AS#1
1870 WRITE#1,MIN$,MIM$,MONEY:CLOSE#1:TITI$="账号接收成功"
1880 A$=INKEY$:GOTO 340
1890 TITI$="覆盖原账号/Y":GOSUB 1100
1900 K$=INKEY$
1910 IF K$="y" THEN GOTO 1860
1920 TITI$="未覆盖原账号":GOSUB 1100:A$=INKY$:GOTO 340
2000 PRINT TMIN$,TMONEY,"vs",MIN$,MONEY

这是画面的代码:

1 TAI=1:XI=2:MIN$="信志":MONEY=2000:TMIN$="雨晴":TMONEY=2000
10 GRAPH:PRINT "XIPAI"
20 DIM PAI$(52),HUA$(52)
30 OPEN "hssysa" FOR INPUT AS#1
40 FOR I=1 TO 52
50 INPUT#1,PAI$(I),HUA$(I):NEXT I
59 PRINT "QUPAI"
60 FOR I=1 TO 10
70 PAIA(I)=INT(RND(1)*100)
80 IF PAIA(I)<1 OR PAIA(I)>52 THEN GOTO 70
90 IF I>1 THEN GOTO 100 ELSE 130
100 FOR S=1 TO I-1
110 IF PAIA(I)=PAIA(S)THEN GOTO 70
120 NEXT S
130 NEXT I
140 FOR I=1 TO 10:PRINT PAI$(PAIA(I));HUA$(PAIA(I));",";
150 NEXT I
160 A$=INKEY$:CLS
161 PS=1:RO=1:ON TAI GOTO 162,165:
162 GOSUB 250:GOSUB 300:LOCATE 4,6:PRINT WP$(RO):LOCATE 5,6:PRINT WH$(RO);
163 BOX 38,48,58,80:GOSUB 240:BOX 38,0,58,31:GOSUB 240:GOTO 170
165 GOSUB 300:GOSUB 250:BOX 38,0,58,31:GOSUB 240:LOCATE 4,6:PRINT WP$(RO)
166 LOCATE 5,6:PRINT WH$(RO);:BOX 38,48,58,80:GOSUB 240:GOTO 170
170 PS=3:FOR ROUND=2 TO 5
180 ON TAI GOTO 184,190
181 GOSUB 240:NEXT ROUND:A$=INKEY$:CLS:GOTO 60
184 RO=ROUND:HH=(RO+1)*3:GOSUB 250:GOSUB 300:GOSUB 500
185 LOCATE 4,HH:PRINT WP$(RO)
186 LOCATE 5,HH:PRINT WH$(RO);:GOSUB 540:GOSUB 240:LOCATE 1,HH:PRINT TP$(RO)
187 LOCATE 2,HH:PRINT TH$(RO):GOSUB 520:BOX XX,48,XX+20,80
188 GOTO 181
190 RO=ROUND:HH=(RO+1)*3:GOSUB 300:GOSUB 250:GOSUB 500
191 LOCATE 1,HH:PRINT TP$(RO)
192 LOCATE 2,HH:PRINT TH$(RO);:GOSUB 520:GOSUB 240:LOCATE 4,HH:PRINT WP$(RO)
193 LOCATE 5,HH:PRINT WH$(RO);:GOSUB 540:BOX XX,0,XX+20,31
194 GOTO 181
240 FOR I=1 TO 500:NEXT I:RETURN
250 REM定我牌
260 WP$(RO)=PAI$(PAIA(PS)):WH$(RO)=HUA$(PAIA(PS)):WP(RO)=PAIA(PS):PS=PS+1
270 RETURN
300 REM定他牌
310 TP$(RO)=PAI$(PAIA(PS)):TH$(RO)=HUA$(PAIA(PS)):TP(RO)=PAIA(PS):PS=PS+1
320 RETURN
498 SWAP TAI,XI
499 RETURN
500 IF PAIA(PS-2)<PAIA(PS-1)THEN GOSUB 498
510 RETURN
520 REM上边框
530 FOR I=1 TO RO-1:XX=((I+1)*3-1)*8-2:BOX XX,0,XX+20,31:BOX XX,48,XX+20,80:NEXT I:
535 XX=((RO+1)*3-1)*8-2:BOX XX,0,XX+20,31
536 RETURN
540 REM下边框
550 FOR I=1 TO RO-1:XX=((I+1)*3-1)*8-2:BOX XX,0,XX+20,31:BOX XX,48,XX+20,80:NEXT I:
555 XX=((RO+1)*3-1)*8-2:BOX XX,48,XX+20,80
560 RETURN


这是data文件的代码:

10 REM牌面
20 DATA 2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8
30 DATA 9,9,9,9,10,10,10,10,J,J,J,J,Q,Q,Q,Q,K,K,K,K,A,A,A,A
40 REM花色
50 DATA,,,,,,,,,,,,,,,,,,,,,,,,,,,
60 DATA,,,,,,,,,,,,,,,,,,,,,,,,,,,
70 DIM PAI$(52),HUA$(52):FOR I=1 TO 52
80 READ A$:PAI$(I)=A$
90 NEXT I
100 FOR I=1 TO 52
110 READ A$:HUA$(I)=A$
120 NEXT I
130 OPEN "hssysa" FOR OUTPUT AS#1
140 FOR I=1 TO 52
150 WRITE#1,PAI$(I),HUA$(I)
160 NEXT I
170 CLOSE#1


花色显示不出来,我放附件里吧!!在楼上!!!!!!!!!!!!!
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值