N: TCP Game Example: Light Cycles - FujiNetWIFI/fujinet-firmware GitHub Wiki

This game implements the classic snake/light cycles game using two networked players, over TCP port 6502.

0 GOTO 3000
1 IF D=14 THEN CX=X:CY=Y-1
2 IF D=13 THEN CX=X:CY=Y+1
3 IF D=11 THEN CX=X-1:CY=Y
4 IF D=7 THEN CX=X+1:CY=Y
5 LOCATE CX,CY,CC
6 RETURN 
7 IF LD=14 THEN LY=LY-1
8 IF LD=13 THEN LY=LY+1
9 IF LD=11 THEN LX=LX-1
10 IF LD=7 THEN LX=LX+1
11 IF RD=14 THEN RY=RY-1
12 IF RD=13 THEN RY=RY+1
13 IF RD=11 THEN RX=RX-1
14 IF RD=7 THEN RX=RX+1
15 RETURN 
16 PD=15:IF STICK(0)<>15 THEN PD=STICK(0):? #1;PD
17 STATUS #1,A:ND=15:IF PEEK(746)>0 THEN INPUT #1,ND
18 IF ND<>15 AND LS THEN RD=ND
19 IF ND<>15 AND  NOT LS THEN LD=ND
20 IF PD<>15 AND LS THEN LD=PD
21 IF PD<>15 AND  NOT LS THEN RD=PD
22 SOUND 0,48+PD,6,10:SOUND 1,54+ND,6,10
23 RETURN 
100 GOSUB 1000
110 GOSUB 1100
111 POKE 656,1:POKE 657,INT((20/2)-(LEN(A$)/2)):? A$
112 POKE 656,1:POKE 657,INT((20/2)-(LEN(B$)/2)+18):? B$
113 POKE 656,2:POKE 657,INT((20/2)-(LEN(STR$(A))/2)):? A
114 POKE 656,2:POKE 657,INT((20/2)-(LEN(STR$(B))/2)+18):? B
115 FOR DE=1 TO 500:NEXT DE
120 COLOR 1:PLOT LX,LY
130 COLOR 2:PLOT RX,RY
140 X=LX:Y=LY:D=LD:GOSUB 1:LC=CC
150 X=RX:Y=RY:D=RD:GOSUB 1:RC=CC
160 IF LC<>0 AND RC<>0 THEN 1200
170 IF LC<>0 THEN 1300
180 IF RC<>0 THEN 1400
190 GOSUB 16:GOSUB 7
200 GOTO 120
999 END 
1000 GRAPHICS 3:COLOR 3:PLOT 0,0:DRAWTO 39,0:DRAWTO 39,19:DRAWTO 0,19:DRAWTO 0,0:RETURN 
1100 LX=4:RX=35:LY=9:RY=9:LD=7:RD=11
1199 RETURN 
1200 M$="DRAW":GOSUB 2000:GOTO 2200
1300 M$=A$:M$(LEN(M$)+1)=" WINS":GOSUB 2000:GOTO 2200
1400 M$=B$:M$(LEN(M$)+1)=" WINS":GOSUB 2000:GOTO 2200
2000 SOUND 0,0,0,0:SOUND 1,0,0,0:FOR N=1 TO LEN(M$):N$(N,N)=" ":NEXT N
2010 FOR N=1 TO 16
2020 POKE 656,2:POKE 657,INT((38/2)-(LEN(M$)/2)):? M$
2030 SOUND 0,32,10,10
2040 POKE 656,2:POKE 657,INT((38/2)-(LEN(N$)/2)):? N$
2050 SOUND 0,0,0,0
2060 NEXT N
2070 RETURN 
2100 TRAP 2130:IF LS THEN ? #1;A$:INPUT #1,B$
2110 IF  NOT LS THEN ? #1;B$:INPUT #1,A$
2120 RETURN 
2130 ? "DISCONNECTED.":END 
2200 ? "":? "PLAY AGAIN";:INPUT Q$
2210 IF Q$(1,1)="Y" THEN GOSUB 2100:GOTO 100
2220 IF Q$(1,1)="N" THEN 2130
2230 GOTO 2200
3000 ? "":DIM H$(64),D$(64),A$(8),B$(8),Q$(8),M$(40),N$(40)
3010 ? "         FUJINET LIGHT CYCLES       ":? 
3020 ? "ENTER HOST NAME OR  RETURN  TO LISTEN":INPUT #16,H$
3030 D$="N:TCP://":D$(LEN(D$)+1)=H$:D$(LEN(D$)+1)=":6502/"
3040 OPEN #1,12,0,D$:IF H$="" THEN LS=1
3050 IF LS=0 THEN PRINT "PLAYER 2 NAME";:INPUT B$:GOSUB 2100:GOTO 100
3051 ? "PLAYER 1 NAME";:INPUT A$
3060 PRINT "WAITING FOR CONNECTION..."
3070 STATUS #1,A:IF  NOT PEEK(748) THEN 3070
3080 XIO 65,#1,12,0,"N:"
3090 GOSUB 2100
3099 GOTO 100
⚠️ **GitHub.com Fallback** ⚠️