Rock Paper Scissors:

Click Here for the TIFILES version

1 REM Rock Paper Scissors
2 REM Demo program for using TipiVariables in BASIC
3 REM 2018 ElectricLab.com
5 CALL CLEAR
6 T$=CHR$(30)
9 PROG$="ELRPS"
10 PRINT "Rock Paper Scissors!"
11 PRINT ""
12 OPEN #1:"PI.VARS",DISPLAY ,VARIABLE 254,SEQUENTIAL,UPDATE
14 PRINT #1:"GLOBAL";T$;;T$;"RS";T$;;T$;;T$;"SESSION_ID"
16 INPUT #1:SESSION_ID$
18 REM PRINT "session_id: ";SESSION_ID$
19 IF LEN(SESSION_ID$)THEN 20 ELSE 28
20 PRINT #1:"GLOBAL";T$;T$;"T";T$;;T$;"NEW_SESSION_ID";T$;"ACTION";T$;"AUTHSESSID";T$;"SESSION_ID";T$;SESSION_ID$
21 PRINT #1:"GLOBAL";T$;T$;"RS";T$;;T$;;T$;"NEW_SESSION_ID"
22 INPUT #1:NEW_SESSION_ID$
23 IF NEW_SESSION_ID$="ERROR" THEN 24 ELSE 90
24 PRINT "Please Login to myTI99.com:"
25 REM Read: REMOTE_HOST
26 PRINT #1:"GLOBAL";T$;T$;"RS";T$;;T$;;T$;"REMOTE_HOST"
27 INPUT #1:REMOTE_HOST$
28 IF REMOTE_HOST$="ERROR" THEN 29 ELSE 30
29 REMOTE_HOST$=""
30 PRINT "REMOTE_HOST: ";REMOTE_HOST$;" (ent=keep)"
31 INPUT "REMOTE_HOST? ":RH$
32 IF LEN(RH$)>0 THEN 33 ELSE 45
33 REMOTE_HOST$=RH$
34 PRINT #1:"GLOBAL";T$;;T$;"W";T$;;T$;;T$;"REMOTE_HOST";T$;REMOTE_HOST$
45 REM Read: REMOTE_PORT
46 PRINT #1:"GLOBAL";T$;T$;"RS";T$;;T$;;T$;"REMOTE_PORT"
47 INPUT #1:REMOTE_PORT$
48 IF REMOTE_PORT$="ERROR" THEN 49 ELSE 50
49 REMOTE_PORT$=""
50 PRINT "REMOTE_PORT: ";REMOTE_PORT$;" (ent=keep)"
51 INPUT "REMOTE_PORT? ":RP$
52 IF LEN(RP$)>0 THEN 53 ELSE 65
53 REMOTE_PORT$=RP$
54 PRINT #1:"GLOBAL";T$;;T$;"W";T$;;T$;;T$;"REMOTE_PORT";T$;REMOTE_PORT$
65 REM Read: MY_SCREENNAME
66 PRINT #1:"GLOBAL";T$;T$;"RS";T$;;T$;;T$;"MY_SCREENNAME"
67 INPUT #1:MY_SCREENNAME$
68 IF MY_SCREENNAME$="ERROR" THEN 69 ELSE 70
69 MY_SCREENNAME$=""
70 PRINT "MY_SCREENNAME: ";MY_SCREENNAME$;" (ent=keep)"
71 INPUT "MY_SCREENNAME? ":MS$
72 IF LEN(MS$)>0 THEN 73 ELSE 75
73 MY_SCREENNAME$=MS$
74 PRINT #1:"GLOBAL";T$;;T$;"W";T$;;T$;;T$;"MY_SCREENNAME";T$;MY_SCREENNAME$
75 INPUT "  Password: ":PW$
79 PRINT #1:"GLOBAL";T$;T$;"T";T$;;T$;"SESSION_ID";T$;"ACTION";T$;"AUTHUSER";T$;"MY_SCREENNAME";T$;MY_SCREENNAME$;T$;"PASSWORD";T$;PW$
80 PRINT #1:"GLOBAL";T$;T$;"RS";T$;;T$;;T$;"SESSION_ID"
81 INPUT #1:SESSION_ID$
82 REM PRINT "SESSION_ID: ";SESSION_ID$
83 IF SESSION_ID$="ERROR" THEN 84 ELSE 86
84 PRINT "Invalid ScreenName or Passwd"
85 GOTO 24
86 PRINT #1:"GLOBAL";T$;T$;"W";T$;;T$;;T$;"SESSION_ID";T$;SESSION_ID$
90 PRINT #1:"GLOBAL";T$;T$;"RS";T$;;T$;;T$;"MY_SCREENNAME"
91 INPUT #1:MY_SCREENNAME$
92 PRINT "Logged in as: ";MY_SCREENNAME$
93 PRINT "(C)reate game   (J)oin game"
94 CALL KEY(0,KP,S)
95 IF KP=67 THEN 1270
96 IF KP=74 THEN 97 ELSE 94
97 INPUT "Game Name: ":GAME_NAME$
98 IF LEN(GAME_NAME$)=0 THEN 97
99 REM OPEN #1:"PI.VARS",DISPLAY,VARIABLE 254,SEQUENTIAL,UPDATE
100 REM Let's check for an open game called GAME_NAME$ with GAME_STATUS='OPEN'
101 PRINT #1:PROG$;T$;GAME_NAME$;T$;"T";T$;;T$;"GAME_STATUS";T$;"ACTION";T$;"READ_VAR";T$;"VAR_NAME";T$;"GAME_STATUS"
103 INPUT #1:GAME_STATUS$
104 GAME_STATUS$=SEG$(GAME_STATUS$,3,LEN(GAME_STATUS$)-2)
105 IF LEN(GAME_STATUS$)>0 THEN 110
106 PRINT "That game doesn't exist"
107 GOTO 92
110 IF GAME_STATUS$="UNDERWAY" THEN 111 ELSE 113
111 PRINT "That game is already underway"
112 GOTO 92
113 IF GAME_STATUS$="COMPLETE" THEN 114 ELSE 116
114 PRINT "That game is over"
115 GOTO 112
116 PRINT "Joining game: ";GAME_NAME$
117 PRINT #1:PROG$;T$;GAME_NAME$;T$;"T";T$;;T$;"P1_NAME";T$;"ACTION";T$;"READ_VAR";T$;"VAR_NAME";T$;"P1_NAME"
118 INPUT #1:P1_NAME$
119 P1_NAME$=SEG$(P1_NAME$,3,LEN(P1_NAME$)-2)
120 P2_NAME$=MY_SCREENNAME$
124 IF LEN(P1_NAME$)>0 THEN 127
125 PRINT "ERROR reading P1_NAME!"
126 END 
127 PRINT #1:PROG$;T$;GAME_NAME$;T$;"T";T$;;T$;"P1_MOVE";T$;"ACTION";T$;"READ_VAR";T$;"VAR_NAME";T$;"P1_MOVE"
128 INPUT #1:P1_MOVE$
129 P1_MOVE$=SEG$(P1_MOVE$,3,LEN(P1_MOVE$)-2)
130 IF LEN(P1_MOVE$)>0 THEN 134
131 PRINT "ERROR reading p1_move!"
132 END 
134 REM Add me as player 2 and mark this game as underway:
135 PRINT #1:PROG$;T$;GAME_NAME$;T$;"T";T$;;T$;;T$;"ACTION";T$;"WRITE_VAR";T$;"P2_NAME";T$;MY_SCREENNAME$;T$;"GAME_STATUS";T$;"UNDERWAY"
136 PRINT "Playing against: ";P1_NAME$
170 PRINT "Your Move? (R, P, S) "
180 CALL KEY(0,KP,S)
190 IF KP=82 THEN 220
200 IF KP=80 THEN 220
210 IF KP=83 THEN 220 ELSE 180
220 P2_MOVE$=CHR$(KP)
225 PRINT "Sending Move: ";P2_MOVE$
230 PRINT #1:PROG$;T$;GAME_NAME$;T$;"T";T$;;T$;;T$;"ACTION";T$;"WRITE_VAR";T$;"P2_MOVE";T$;P2_MOVE$
235 PRINT "Their move: ";P1_MOVE$
240 IF P2_MOVE$="R" THEN 250 ELSE 300
250 IF P1_MOVE$="R" THEN 252 ELSE 260
252 PRINT "It's a TIE!"
253 PRINT #1:PROG$;T$;GAME_NAME$;T$;"T";T$;;T$;;T$;"ACTION";T$;"WRITE_VAR";T$;"GAME_STATUS";T$;"COMPLETE";T$;"WINNER";T$;"NONE: TIE";T$;"P1_MESSAGE";T$;"It's a TIE!"
255 GOTO 92
260 IF P1_MOVE$="P" THEN 262 ELSE 270
262 PRINT "Paper covers Rock"
263 PRINT "You lose!"
264 PRINT #1:PROG$;T$;GAME_NAME$;T$;"T";T$;;T$;;T$;"ACTION";T$;"WRITE_VAR";T$;"GAME_STATUS";T$;"COMPLETE";T$;"WINNER";T$;P1_NAME$;T$;"P1_MESSAGE";T$;"Paper covers Rock"
265 GOTO 92 
270 IF P1_MOVE$="S" THEN 272 ELSE 300
272 PRINT "Rock beats Scissors"
273 PRINT "You WIN!"
274 PRINT #1:PROG$;T$;GAME_NAME$;T$;"T";T$;;T$;;T$;"ACTION";T$;"WRITE_VAR";T$;"GAME_STATUS";T$;"COMPLETE";T$;"WINNER";T$;P2_NAME$;T$;"P1_MESSAGE";T$;"Rock beats Scissors"
275 GOTO 92
300 IF P2_MOVE$="P" THEN 310 ELSE 400
310 IF P1_MOVE$="P" THEN 312 ELSE 320
312 PRINT "It's a TIE!"
313 PRINT #1:PROG$;T$;GAME_NAME$;T$;"T";T$;;T$;;T$;"ACTION";T$;"WRITE_VAR";T$;"GAME_STATUS";T$;"COMPLETE";T$;"WINNER";T$;"NONE: TIE";T$;"P1_MESSAGE";T$;"It's a TIE!"
314 GOTO 92 
320 IF P1_MOVE$="R" THEN 322 ELSE 330
322 PRINT "Paper covers Rock"
323 PRINT "You WIN!"
324 PRINT #1:PROG$;T$;GAME_NAME$;T$;"T";T$;;T$;;T$;"ACTION";T$;"WRITE_VAR";T$;"GAME_STATUS";T$;"COMPLETE";T$;"WINNER";T$;P2_NAME$;T$;"P1_MESSAGE";T$;"Paper covers Rock"
325 GOTO 92 
330 IF P1_MOVE$="S" THEN 332 ELSE 400
332 PRINT "Scissors cut Paper"
333 PRINT "You lose!"
334 PRINT #1:PROG$;T$;GAME_NAME$;T$;"T";T$;;T$;;T$;"ACTION";T$;"WRITE_VAR";T$;"GAME_STATUS";T$;"COMPLETE";T$;"WINNER";T$;P1_NAME$;T$;"P1_MESSAGE";T$;"Scissors cut Paper"
335 GOTO 92 
400 IF P2_MOVE$="S" THEN 410 ELSE 500
410 IF P1_MOVE$="S" THEN 412 ELSE 420
412 PRINT "It's a TIE!"
413 PRINT #1:PROG$;T$;GAME_NAME$;T$;"T";T$;;T$;;T$;"ACTION";T$;"WRITE_VAR";T$;"GAME_STATUS";T$;"COMPLETE";T$;"WINNER";T$;"NONE: TIE";T$;"P1_MESSAGE";T$;"It's a TIE!"
414 GOTO 92 
420 IF P1_MOVE$="P" THEN 422 ELSE 430
422 PRINT "Scissors cut Paper"
423 PRINT "You WIN!"
424 PRINT #1:PROG$;T$;GAME_NAME$;T$;"T";T$;;T$;;T$;"ACTION";T$;"WRITE_VAR";T$;"GAME_STATUS";T$;"COMPLETE";T$;"WINNER";T$;P2_NAME$;T$;"P1_MESSAGE";T$;"Scissors cut Paper"
425 GOTO 92 
430 IF P1_MOVE$="R" THEN 432 ELSE 500
432 PRINT "Rock beats Scissors"
433 PRINT "You lose!"
434 PRINT #1:PROG$;T$;GAME_NAME$;T$;"T";T$;;T$;;T$;"ACTION";T$;"WRITE_VAR";T$;"GAME_STATUS";T$;"COMPLETE";T$;"WINNER";T$;P1_NAME$;T$;"P1_MESSAGE";T$;"Rock beats Scissors"
435 GOTO 92 
500 PRINT "I shouldn't be here!"
510 END 
1270 REM Create a New Game
1290 PRINT "Creating a new game"
1300 INPUT "Enter a game name: ":GAME_NAME$
1310 REM GAME_NAME$=SEG$(GAME_NAME$, 1, LEN(GAME_NAME$)-1)
1320 IF LEN(GAME_NAME$)=0 THEN 1300
1330 REM Check to see if a game of this name
1331 REM exists that is OPEN or UNDERWAY:
1334 PRINT #1:PROG$;T$;GAME_NAME$;T$;"T";T$;;T$;"GAME_STATUS";T$;"ACTION";T$;"READ_VAR";T$;"VAR_NAME";T$;"GAME_STATUS"
1336 INPUT #1:GAME_STATUS$
1337 GAME_STATUS$=SEG$(GAME_STATUS$,3,LEN(GAME_STATUS$)-2)
1338 IF GAME_STATUS$="OPEN" THEN 1340 ELSE 1343
1340 PRINT "That game already exists,"
1341 PRINT "Pick a different name."
1342 GOTO 1290
1343 IF GAME_STATUS$="UNDERWAY" THEN 1344 ELSE 1350
1344 PRINT "That game is underway,"
1345 PRINT "Pick a different name."
1346 GOTO 1290
1350 PRINT "Your Move? (R, P, S) "
1360 CALL KEY(0,KP,S)
1370 IF KP=82 THEN 1400
1380 IF KP=80 THEN 1400
1390 IF KP=83 THEN 1400 ELSE 1360
1400 P1_MOVE$=CHR$(KP)
1410 PRINT "Sending Move: ";P1_MOVE$
1500 PRINT #1:PROG$;T$;GAME_NAME$;T$;"T";T$;;T$;;T$;"ACTION";T$;"WRITE_VAR";T$;"GAME_NAME";T$;GAME_NAME$;T$;"GAME_STATUS";T$;"OPEN";T$;"P1_NAME";T$;MY_SCREENNAME$
1510 PRINT #1:PROG$;T$;GAME_NAME$;T$;"T";T$;;T$;;T$;"ACTION";T$;"WRITE_VAR";T$;"P1_MOVE";T$;P1_MOVE$
1515 REM Clear stale vars:
1520 PRINT #1:PROG$;T$;GAME_NAME$;T$;"T";T$;;T$;;T$;"ACTION";T$;"WRITE_VAR";T$;"P2_NAME";T$;"";T$;"P2_MOVE";T$;""
1530 PRINT #1:PROG$;T$;GAME_NAME$;T$;"T";T$;;T$;;T$;"ACTION";T$;"WRITE_VAR";T$;"P1_MESSAGE";T$;"";T$;"WINNER";T$;""
1600 PRINT GAME_NAME$;": AWAITING PLAYER 2"
1620 PRINT #1:PROG$;T$;GAME_NAME$;T$;"T";T$;;T$;"P2_MOVE";T$;"ACTION";T$;"READ_VAR";T$;"VAR_NAME";T$;"P2_MOVE"
1640 INPUT #1:P2_MOVE$
1800 P2_MOVE$=SEG$(P2_MOVE$,3,LEN(P2_MOVE$)-2)
1900 IF LEN(P2_MOVE$)>0 THEN 2000
1920 FOR LOOP=1 TO 2002
1930 NEXT LOOP
1940 GOTO 1620
2000 REM PRINT "2) P2_MOVE: --";P2_MOVE$;"--"
2100 PRINT #1:PROG$;T$;GAME_NAME$;T$;"T";T$;;T$;"P2_NAME";T$;"ACTION";T$;"READ_VAR";T$;"VAR_NAME";T$;"P2_NAME"
2200 INPUT #1:P2_NAME$
2210 P2_NAME$=SEG$(P2_NAME$,3,LEN(P2_NAME$)-2)
2300 PRINT "Playing against: ";P2_NAME$
2305 PRINT "Their move: ";P2_MOVE$
2400 PRINT #1:PROG$;T$;GAME_NAME$;T$;"T";T$;;T$;"P2_NAME";T$;"ACTION";T$;"READ_VAR";T$;"VAR_NAME";T$;"P1_MESSAGE"
2410 INPUT #1:P1_MESSAGE$
2420 P1_MESSAGE$=SEG$(P1_MESSAGE$,3,LEN(P1_MESSAGE$)-2)
2430 PRINT #1:PROG$;T$;GAME_NAME$;T$;"T";T$;;T$;"P2_NAME";T$;"ACTION";T$;"READ_VAR";T$;"VAR_NAME";T$;"WINNER"
2440 INPUT #1:WINNER$
2450 WINNER$=SEG$(WINNER$,3,LEN(WINNER$)-2)
2460 PRINT P1_MESSAGE$
2470 IF WINNER$=MY_SCREENNAME$ THEN 2480 ELSE 2490
2480 PRINT "You WON!"
2485 GOTO 92 
2490 PRINT "You lose."
2500 GOTO 92