N: TCP Game Example: Reversi - FujiNetWIFI/fujinet-firmware GitHub Wiki
This game implements a full version of Reversi, that can be played by two players over a network. TCP port 6502 is used.
8 TRAP 3000
9 GRAPHICS 0
10 GOTO 500
18 LOCATE X,Y-1,C:COLOR C:PLOT X,Y:PLOT X+1,Y:RETURN
19 LOCATE X-1,Y-1,C:GOTO 30
20 LOCATE X-1,Y,CC:IF C=CC THEN C=0
30 COLOR C:PLOT X,Y:PLOT X+1,Y:GOTO 60
40 LOCATE X-1,Y,Z:IF Z=C THEN RETURN
45 COLOR C:FOR I=X-1 TO X+2:FOR J=Y-1 TO Y+1
50 PLOT I,J:NEXT J:NEXT I:SOUND 0,C*25,10,8
60 FOR V=0 TO 10:NEXT V
61 STATUS #2,A:IF PEEK(746)>0 THEN GOSUB 18:INPUT #2,X,Y,TRIG:IF TRIG=0 THEN 1700
70 SOUND 0,0,0,0:RETURN
500 DIM A$(8),B$(8),F(1),S(1,9),H$(64),D$(64)
501 LS=0
520 OPEN #1,4,0,"K"
530 POSITION 10,1:? " FUJINET REVERSI ":?
531 ? "BE SURE TO FORWARD TCP PORT 6502.":?
540 PRINT "HOSTNAME OR RETURN TO LISTEN"
550 INPUT #16,H$
560 IF H$="" THEN LS=1
570 D$="N:TCP://":D$(LEN(D$)+1)=H$:D$(LEN(D$)+1)=":6502/"
571 OPEN #2,12,0,D$
572 IF NOT LS THEN 600
580 STATUS #2,A:IF NOT PEEK(748) THEN 580
581 ? "ACCEPTING CONNECTION.":XIO 65,#2,12,0,"N:"
582 GOTO 600
600 GC=0:GRAPHICS O:POSITION 5,8:? "Type name, press RETURN"
601 IF NOT LS THEN 620
610 ? :? "Player 1";:INPUT A$:IF A$="" THEN 610
611 PRINT #2;A$:INPUT #2,B$
612 GOTO 700
620 ? :? "Player 2";:INPUT B$:IF B$="" THEN 620
621 PRINT #2;B$:INPUT #2,A$
622 GOTO 700
625 F(0)=0:F(1)=0
630 IF A$="COMPUTER" THEN F(0)=1
640 IF B$="COMPUTER" THEN F(1)=1
700 GRAPHICS 5:POKE 752,1
710 SETCOLOR 4,13,6:SETCOLOR 2,13,2
720 SETCOLOR 0,0,0:SETCOLOR 1,0,15
750 COLOR 3:FOR Y=1 TO 37
770 PLOT 17,Y:PLOT 18,Y:PLOT 19,Y
780 FOR X=20 TO 60 STEP 5:PLOT X,Y:NEXT X
790 PLOT 61,Y:PLOT 62,Y:PLOT 63,Y:NEXT Y
800 FOR X=17 TO 60
810 PLOT X,1:PLOT X,2
820 FOR Y=3 TO 35 STEP 4:PLOT X,Y:NEXT Y
830 PLOT X,36:PLOT X,37:NEXT X
850 FOR L=1 TO 6:READ X,Y,C:GOSUB 40:NEXT L:RESTORE
855 DATA 10,36,1,37,17,1,42,21,1,72,36,2,42,17,2,37,21,2
990 P=2
1000 P=3-P:POKE 764,255
1010 A=0:B=0:FOR M=22 TO 57 STEP 5:FOR N=5 TO 33 STEP 4
1020 LOCATE M,N,C:IF C=1 THEN A=A+1
1030 IF C=2 THEN B=B+1
1040 IF C=0 THEN X=M:Y=N
1050 NEXT N:NEXT M
1055 POKE 656,1:POKE 657,3:? A$;:POKE 657,28:? B$:? " ";A;" ";:POKE 657,30:? B;" "
1070 IF A+B=64 THEN 2000
1110 IF F(P-1)=0 THEN GOTO 1500
1120 GOSUB 5000
1130 IF Q>0 THEN 1730
1140 FOR L=0 TO 20:POKE 656,1:POKE 657,15
1143 ? "I PASS";:POKE 657,15:GOSUB 60:? " ";:NEXT L:GOTO 1000
1500 C=P:GOSUB 20:GOSUB 20:GOSUB 19
1510 N=PEEK(764):POKE 764,255:TRIG=STRIG(0):JS=STICK(0)
1511 IF LS=0 AND P=1 THEN 1500
1512 IF LS=1 AND P=2 THEN 1500
1520 IF N=255 AND TRIG=1 AND JS=15 THEN 1500
1530 POKE 77,0:IF N=33 OR N=12 OR TRIG=0 THEN 1698
1540 IF N=30 THEN C=2:GOSUB 40:GOTO 1500
1550 IF N=31 THEN C=1:GOSUB 40:GOTO 1500
1560 IF N=10 THEN 1630
1570 X=X+5*((N=7 OR JS=7) AND X<57)-5*((N=6 OR JS=11) AND X>22)
1580 Y=Y+4*((N=15 OR JS=13) AND Y<33)-4*((N=14 OR JS=14) AND Y>5)
1581 IF N=33 OR N=12 THEN TRIG=0
1582 ? #2;X;",";Y;",";TRIG
1590 SOUND 0,(P+1)*40,10,8:GOTO 1500
1630 GOSUB 19:GOSUB 5000:IF Q=0 THEN 1000
1655 FOR I=0 TO 20:POKE 656,1:POKE 657,12
1656 ? " INVALID MOVE";:SOUND 0,180,10,10:GOSUB 60:POKE 657,12:? " ";
1657 NEXT I:GOTO 1010
1698 IF N=33 OR N=12 THEN TRIG=0
1699 PRINT #2;X;",";Y;",";TRIG
1700 G=0:GOSUB 4000:IF R=0 THEN GOSUB 19:GOTO 1655
1730 G=1:GOSUB 4000
1780 GOTO 1000
2000 ? "To see scoreboard, press any key":GET #1,N
2040 S(0,GC)=A:S(1,GC)=B
2050 GRAPHICS O:POSITION 1,10:? "GAME":POSITION 1,12:? A$:POSITION 1,14:? B$
2060 FOR X=0 TO GC:N=X*3+10:POSITION N,10:? X+1;:POSITION N,12:? S(0,X);:POSITION N,14:? S(1,X);:NEXT X
2100 ? :? :? "Same players go again? (Y-N)";:GET #1,N
2120 IF GC>7 AND N=89 THEN ? :? "You have already played 9 games.";:FOR X=1 TO 999:NEXT X:GOTO 600
2130 IF N=89 THEN GC=GC+1:GOTO 700
2135 IF N<>78 THEN 2100
2140 GOTO 600
3000 GRAPHICS 0:? "DISCONNECTED.":CLOSE #1:CLOSE #2:END
4000 R=0:SX=X:SY=Y
4005 LOCATE X-1,Y,C:IF C<>0 THEN RETURN
4010 FOR DX=-1 TO 1:FOR DY=-1 TO 1
4020 IF DX=0 AND DY=0 THEN 4130
4030 TR=0:X=SX:Y=SY
4050 X=X+DX*5:Y=Y+DY*4:LOCATE X,Y,C
4060 IF C=3-P THEN TR=TR+1:GOTO 4050
4070 IF C=P THEN R=R+TR:IF G=1 THEN 4100
4080 GOTO 4130
4100 X=X-DX*5:Y=Y-DY*4:C=P:GOSUB 40
4110 IF NOT (X=SX AND Y=SY) THEN 4100
4130 NEXT DY:NEXT DX:X=SX:Y=SY:RETURN
5000 Q=0:QX=0:QY=0:FOR M=0 TO 7:FOR N=0 TO 7
5020 X=M*5+22:Y=N*4+5
5030 LOCATE X,Y,C:IF C<>0 THEN 5090
5035 C=P:GOSUB 20:GOSUB 19
5040 G=0:GOSUB 4000
5080 IF R>Q THEN Q=R:QX=X:QY=Y
5090 NEXT N:NEXT M:X=QX:Y=QY:RETURN
7005 FOR X=0 TO 8:S(0,X)=0:S(1,X)=0:NEXT X
9999 GOTO 9999