'Battleships on two computers: 'requires pc with TTY console on serial port 1 or 2 'TTY settings: 'CR->CR/NL: incoming 'local echo: on 'Rules: 'Set up fleet on field using a1..cnn coordinates 'and North, East, South or West heading 'Attack enemy fleet using a1..cnn coordintes 'program does not check valid input! '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 'Begin Configurable Part 'Communication characteristics '----------------------------- communication$ = "com1: 9600, E, 7, 1" 'TTY communications maxLine% = 22 'TTY display 'Zone characteristics '-------------------- ZoneWidth% = 10 'max 18 on 80 cols screen ZoneHeight% = 10 'max 16 on 22 lines screen Front% = 2 'free space between zones 'Target characteristics '---------------------- TargetNum% = 9 'min 1 max 9 'Number of Targets: DIM TargetLen%(TargetNum%) TargetLen%(1) = 4 'Length of Target 1 TargetLen%(2) = 3 'Length of Target 2 TargetLen%(3) = 3 'Length of Target 3 TargetLen%(4) = 2 'Length of Target 4 TargetLen%(5) = 2 'Length of Target 5 TargetLen%(6) = 2 'Length of Target 6 TargetLen%(7) = 1 'Length of Target 7 TargetLen%(8) = 1 'Length of Target 8 TargetLen%(9) = 1 'Length of Target 9 'End Configurable Part '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ DIM LocalTargetLen%(TargetNum%) DIM RemoteTargetLen%(TargetNum%) FOR i% = 1 TO TargetNum% LocalTargetLen%(i%) = TargetLen%(i%) RemoteTargetLen%(i%) = TargetLen%(i%) NEXT i% Turn$ = "local" InPlace% = 1 Action$ = "target" Battle% = 1 LocalStatusLine$ = "" RemoteStatusLine$ = "" DIM TargetID$(TargetNum%) FOR i% = 1 TO TargetNum% TargetID$(i%) = LTRIM$(STR$(i%)) NEXT i% DIM SecretLocalZone$(ZoneWidth% * ZoneHeight%) DIM PublicLocalZone$(ZoneWidth% * ZoneHeight%) DIM SecretRemoteZone$(ZoneWidth% * ZoneHeight%) DIM PublicRemoteZone$(ZoneWidth% * ZoneHeight%) 'Creating empty zones FOR i% = 1 TO (ZoneWidth% * ZoneHeight%) SecretLocalZone$(i%) = "-" PublicLocalZone$(i%) = "." SecretRemoteZone$(i%) = "-" PublicRemoteZone$(i%) = "." NEXT i% DIM Coor%(2) DIM LocalLine$(maxLine%) DIM RemoteLine$(maxLine%) 'unrem for two console mode OPEN communication$ FOR RANDOM AS #1 ' DO WHILE Battle% = 1 'Creating the lines to display on local and remote consoles '*** line 1 LocalLine$(1) = "BattleZones by TTY 1998 /ipenburg@xs4all.nl" RemoteLine$(1) = LocalLine$(1) '*** line 2 Indent% = 4 LocalLine$(2) = SPACE$(Indent%) FOR i% = 1 TO ZoneWidth% LocalLine$(2) = LocalLine$(2) + CHR$(i% + 64) + SPACE$(1) NEXT i% LocalLine$(2) = LocalLine$(2) + SPACE$(Front% + Indent%) FOR i% = 1 TO ZoneWidth% LocalLine$(2) = LocalLine$(2) + CHR$(i% + 64) + SPACE$(1) NEXT i% RemoteLine$(2) = LocalLine$(2) '*** line 3/ZoneHeight+2 FOR j% = 1 TO ZoneHeight% IF j% < 10 THEN Indent% = 1 ELSE Indent% = 0 LocalLine$(j% + 2) = SPACE$(Indent%) + STR$(j%) + SPACE$(1) FOR i% = 1 TO ZoneWidth% LocalLine$(j% + 2) = LocalLine$(j% + 2) + SecretLocalZone$(i% + (ZoneWidth% * (j% - 1))) + SPACE$(1) NEXT i% LocalLine$(j% + 2) = LocalLine$(j% + 2) + SPACE$(Front%) + SPACE$(Indent%) + STR$(j%) + SPACE$(1) FOR i% = 1 TO ZoneWidth% LocalLine$(j% + 2) = LocalLine$(j% + 2) + PublicRemoteZone$(i% + (ZoneWidth% * (j% - 1))) + SPACE$(1) NEXT i% NEXT j% FOR j% = 1 TO ZoneHeight% IF j% < 10 THEN Indent% = 1 ELSE Indent% = 0 RemoteLine$(j% + 2) = SPACE$(Indent%) + STR$(j%) + SPACE$(1) FOR i% = 1 TO ZoneWidth% RemoteLine$(j% + 2) = RemoteLine$(j% + 2) + SecretRemoteZone$(i% + (ZoneWidth% * (j% - 1))) + SPACE$(1) NEXT i% RemoteLine$(j% + 2) = RemoteLine$(j% + 2) + SPACE$(Front%) + SPACE$(Indent%) + STR$(j%) + SPACE$(1) FOR i% = 1 TO ZoneWidth% RemoteLine$(j% + 2) = RemoteLine$(j% + 2) + PublicLocalZone$(i% + (ZoneWidth% * (j% - 1))) + SPACE$(1) NEXT i% NEXT j% '*** line ZoneHeight+3 Indent% = INT(((ZoneWidth% * 2) - 12) / 2) IF Indent% < 0 THEN Indent% = 0 LocalLine$(ZoneHeight% + 3) = SPACE$(Indent%) + " Your Fleet " + SPACE$(Front%) + SPACE$(2 * Indent%) + "The Enemies Fleet" RemoteLine$(ZoneHeight% + 3) = LocalLine$(ZoneHeight% + 3) '*** line ZoneHeight+4+n FOR i% = (ZoneHeight% + 4) TO maxLine% LocalLine$(i%) = "" RemoteLine$(i%) = "" NEXT i% '*** Action dependent lines IF (Turn$ = "local") THEN IF mess$ <> "" THEN LocalLine$(ZoneHeight% + 5) = "The enemy says:" + SPACE$(1) + mess$ LocalLine$(ZoneHeight% + 4) = LocalStatusLine$ RemoteLine$(ZoneHeight% + 4) = RemoteStatusLine$ SELECT CASE Action$ CASE IS = "target" RemoteLine$(ZoneHeight% + 6) = "Please wait while the enemies targets are placed..." LocalLine$(ZoneHeight% + 6) = "It's your turn to place your targets:" LocalLine$(ZoneHeight% + 7) = "Coordinates for Target" + SPACE$(0) + STR$(InPlace%) + SPACE$(0) + ":" CASE IS = "heading" RemoteLine$(ZoneHeight% + 6) = "Please wait while the enemies targets are placed..." LocalLine$(ZoneHeight% + 6) = "It's your turn to place your targets:" LocalLine$(ZoneHeight% + 7) = "Heading for Target" + SPACE$(0) + STR$(InPlace%) + SPACE$(0) + "(n,e,s,w):" CASE IS = "coor" RemoteLine$(ZoneHeight% + 6) = "Please wait while the enemy attacks..." LocalLine$(ZoneHeight% + 6) = "It's your turn to attack:" LocalLine$(ZoneHeight% + 7) = "Coordinates to Attack:" CASE IS = "mess" RemoteLine$(ZoneHeight% + 6) = "Scanning for enemy messages..." LocalLine$(ZoneHeight% + 6) = "Message to send to enemy?" END SELECT ELSE IF mess$ <> "" THEN RemoteLine$(ZoneHeight% + 5) = "The enemy says:" + SPACE$(1) + mess$ LocalLine$(ZoneHeight% + 4) = LocalStatusLine$ RemoteLine$(ZoneHeight% + 4) = RemoteStatusLine$ SELECT CASE Action$ CASE IS = "target" LocalLine$(ZoneHeight% + 6) = "Please wait while the enemies targets are placed..." RemoteLine$(ZoneHeight% + 6) = "It's your turn to place your targets:" RemoteLine$(ZoneHeight% + 7) = "Coordinates for Target" + SPACE$(0) + STR$(InPlace%) + SPACE$(0) + ":" CASE IS = "heading" LocalLine$(ZoneHeight% + 6) = "Please wait while the enemies targets are placed..." RemoteLine$(ZoneHeight% + 6) = "It's your turn to place your targets:" RemoteLine$(ZoneHeight% + 7) = "Heading for Target" + SPACE$(0) + STR$(InPlace%) + SPACE$(0) + "(N,E,S,W):" CASE IS = "coor" LocalLine$(ZoneHeight% + 6) = "Please wait while the enemy attacks..." RemoteLine$(ZoneHeight% + 6) = "It's your turn to attack:" RemoteLine$(ZoneHeight% + 7) = "Coordinates to Attack:" CASE IS = "mess" LocalLine$(ZoneHeight% + 6) = "Scanning for enemy messages..." RemoteLine$(ZoneHeight% + 6) = "Message to send to enemy?" END SELECT END IF 'Sending lines to the displays CLS FOR i% = 1 TO maxLine% PRINT LocalLine$(i%) PRINT #1, RemoteLine$(i%) NEXT i% 'handle actions IF Turn$ = "local" THEN SELECT CASE Action$ CASE IS = "target" INPUT Coor$ Coor%(1) = ASC(UCASE$(Coor$)) - 64 Coor%(2) = VAL(MID$(Coor$, 2, (LEN(Coor$) - 1))) - 1 Index% = Coor%(1) + (Coor%(2) * ZoneWidth%) SecretLocalZone$(Index%) = TargetID$(InPlace%) IF TargetLen%(InPlace%) > 1 THEN Action$ = "heading" ELSE InPlace% = InPlace% + 1 IF (InPlace% = TargetNum% + 1) THEN InPlace% = 1 Turn$ = "remote" END IF END IF CASE IS = "heading" INPUT Head$ SELECT CASE UCASE$(Head$) CASE IS = "N" FOR i% = 1 TO TargetLen%(InPlace%) SecretLocalZone$(Index% - (ZoneWidth% * (i% - 1))) = TargetID$(InPlace%) NEXT i% CASE IS = "E" FOR i% = 1 TO TargetLen%(InPlace%) SecretLocalZone$(Index% + (i% - 1)) = TargetID$(InPlace%) NEXT i% CASE IS = "S" FOR i% = 1 TO TargetLen%(InPlace%) SecretLocalZone$(Index% + (ZoneWidth% * (i% - 1))) = TargetID$(InPlace%) NEXT i% CASE IS = "W" FOR i% = 1 TO TargetLen%(InPlace%) SecretLocalZone$(Index% - (i% - 1)) = TargetID$(InPlace%) NEXT i% CASE ELSE LocalStatusLine$ = "Error in heading for Local Target" + SPACE$(1) + TargetID$(InPlace%) RemoteStatusLine$ = LocalStatusLine$ END SELECT Action$ = "target" InPlace% = InPlace% + 1 IF (InPlace% = TargetNum% + 1) THEN InPlace% = 1 Turn$ = "remote" END IF CASE IS = "coor" INPUT Coor$ IF Coor$ = "0" THEN END Coor%(1) = ASC(UCASE$(Coor$)) - 64 Coor%(2) = VAL(MID$(Coor$, 2, (LEN(Coor$) - 1))) - 1 Index% = Coor%(1) + (Coor%(2) * ZoneWidth%) IF ((Index% < 1) OR (Index% > (ZoneWidth% * ZoneHeight%))) THEN LocalStatusLine$ = "Invalid attack on Remote Zone!" RemoteStatusLine$ = LocalStatusLine$ END IF SELECT CASE SecretRemoteZone$(Index%) CASE IS = "1", "2", "3", "4", "5", "6", "7", "8", "9" LocalStatusLine$ = "Kaboom! You hit a target!" RemoteStatusLine$ = "Kaboom! You are hit!" RemoteTargetLen%(VAL(SecretRemoteZone$(Index%))) = RemoteTargetLen%(VAL(SecretRemoteZone$(Index%))) - 1 IF RemoteTargetLen%(VAL(SecretRemoteZone$(Index%))) = 0 THEN LocalStatusLine$ = "BlubBlub! You sunk a target!" RemoteStatusLine$ = "BlubBlub! You lost one!" END IF PublicRemoteZone$(Index%) = "#" SecretRemoteZone$(Index%) = "x" CASE IS = "-" LocalStatusLine$ = "Splash! You missed!" RemoteStatusLine$ = "Splash! It missed!" PublicRemoteZone$(Index%) = "x" SecretRemoteZone$(Index%) = "x" CASE IS = "x", "#" LocalStatusLine$ = "Duh! You already attacked those coordinates..." RemoteStatusLine$ = "Duh! The enemy is confused..." CASE ELSE LocalStatusLine$ = "Error detecting impact in Remote Zone!" RemoteStatusLine$ = LocalStatusLine$ END SELECT Targetleft% = 0 FOR i% = 1 TO TargetNum% Targetleft% = RemoteTargetLen%(i%) + Targetleft% NEXT i% IF Targetleft% = 0 THEN Battle% = 0 Action$ = "mess" CASE IS = "mess" INPUT mess$ Turn$ = "remote" Action$ = "coor" END SELECT ELSE SELECT CASE Action$ CASE IS = "target" INPUT #1, Coor$ Coor%(1) = ASC(UCASE$(Coor$)) - 64 Coor%(2) = VAL(MID$(Coor$, 2, (LEN(Coor$) - 1))) - 1 Index% = Coor%(1) + (Coor%(2) * ZoneWidth%) SecretRemoteZone$(Index%) = TargetID$(InPlace%) IF TargetLen%(InPlace%) > 1 THEN Action$ = "heading" ELSE InPlace% = InPlace% + 1 IF (InPlace% = TargetNum% + 1) THEN InPlace% = 1 Turn$ = "local" Action$ = "coor" END IF END IF CASE IS = "heading" INPUT #1, Head$ SELECT CASE UCASE$(Head$) CASE IS = "N" FOR i% = 1 TO TargetLen%(InPlace%) SecretRemoteZone$(Index% - (ZoneWidth% * (i% - 1))) = TargetID$(InPlace%) NEXT i% CASE IS = "E" FOR i% = 1 TO TargetLen%(InPlace%) SecretRemoteZone$(Index% + (i% - 1)) = TargetID$(InPlace%) NEXT i% CASE IS = "S" FOR i% = 1 TO TargetLen%(InPlace%) SecretRemoteZone$(Index% + (ZoneWidth% * (i% - 1))) = TargetID$(InPlace%) NEXT i% CASE IS = "W" FOR i% = 1 TO TargetLen%(InPlace%) SecretRemoteZone$(Index% - (i% - 1)) = TargetID$(InPlace%) NEXT i% CASE ELSE RemoteStatusLine$ = "Error in heading Remote Target" + SPACE$(1) + TargetID$(InPlace%) LocalStatusLine$ = RemoteStatusLine$ END SELECT Action$ = "target" InPlace% = InPlace% + 1 IF InPlace% = TargetNum% + 1 THEN InPlace% = 1 Turn$ = "local" Action$ = "coor" END IF CASE IS = "coor" INPUT #1, Coor$ IF Coor$ = "0" THEN END Coor%(1) = ASC(UCASE$(Coor$)) - 64 Coor%(2) = VAL(MID$(Coor$, 2, (LEN(Coor$) - 1))) - 1 Index% = Coor%(1) + (Coor%(2) * ZoneWidth%) IF ((Index% < 1) OR (Index% > (ZoneWidth% * ZoneHeight%))) THEN RemoteStatusLine$ = "Invalid target!" LocalStatusLine$ = RemoteStatusLine$ END IF SELECT CASE SecretLocalZone$(Index%) CASE IS = "1", "2", "3", "4", "5", "6", "7", "8", "9" RemoteStatusLine$ = "Kaboom! You hit a target!" LocalStatusLine$ = "Kaboom! You are hit!" LocalTargetLen%(VAL(SecretLocalZone$(Index%))) = LocalTargetLen%(VAL(SecretLocalZone$(Index%))) - 1 IF LocalTargetLen%(VAL(SecretLocalZone$(Index%))) = 0 THEN RemoteStatusLine$ = "BlubBlub! You sunk a target!" LocalStatusLine$ = "BlubBlub! You lost one!" END IF PublicLocalZone$(Index%) = "#" SecretLocalZone$(Index%) = "x" CASE IS = "-" RemoteStatusLine$ = "Splash! You missed!" LocalStatusLine$ = "Splash! It missed!" PublicLocalZone$(Index%) = "x" SecretLocalZone$(Index%) = "x" CASE IS = "x", "#" RemoteStatusLine$ = "Duh! You already attacked those coordinates..." LocalStatusLine$ = "Duh! The enemy is confused..." CASE ELSE RemoteStatusLine$ = "Error detecting targets in Local Zone!" LocalStatusLine$ = RemoteStatusLine$ END SELECT Targetleft% = 0 FOR i% = 1 TO TargetNum% Targetleft% = LocalTargetLen%(i%) + Targetleft% NEXT i% IF Targetleft% = 0 THEN Battle% = 0 Action$ = "mess" CASE IS = "mess" INPUT #1, mess$ Turn$ = "local" Action$ = "coor" END SELECT END IF LOOP 'Creating the lines to display on local and remote consoles after victory '*** line 1 LocalLine$(1) = "BattleZones by TTY 1998 /ipenburg@xs4all.nl" RemoteLine$(1) = LocalLine$(1) '*** line 2 Indent% = 4 LocalLine$(2) = SPACE$(Indent%) FOR i% = 1 TO ZoneWidth% LocalLine$(2) = LocalLine$(2) + CHR$(i% + 64) + SPACE$(1) NEXT i% LocalLine$(2) = LocalLine$(2) + SPACE$(Front% + Indent%) FOR i% = 1 TO ZoneWidth% LocalLine$(2) = LocalLine$(2) + CHR$(i% + 64) + SPACE$(1) NEXT i% RemoteLine$(2) = LocalLine$(2) '*** line 3/ZoneHeight+2 FOR j% = 1 TO ZoneHeight% IF j% < 10 THEN Indent% = 1 ELSE Indent% = 0 LocalLine$(j% + 2) = SPACE$(Indent%) + STR$(j%) + SPACE$(1) FOR i% = 1 TO ZoneWidth% LocalLine$(j% + 2) = LocalLine$(j% + 2) + SecretLocalZone$(i% + (ZoneWidth% * (j% - 1))) + SPACE$(1) NEXT i% LocalLine$(j% + 2) = LocalLine$(j% + 2) + SPACE$(Front%) + SPACE$(Indent%) + STR$(j%) + SPACE$(1) FOR i% = 1 TO ZoneWidth% LocalLine$(j% + 2) = LocalLine$(j% + 2) + PublicRemoteZone$(i% + (ZoneWidth% * (j% - 1))) + SPACE$(1) NEXT i% NEXT j% FOR j% = 1 TO ZoneHeight% IF j% < 10 THEN Indent% = 1 ELSE Indent% = 0 RemoteLine$(j% + 2) = SPACE$(Indent%) + STR$(j%) + SPACE$(1) FOR i% = 1 TO ZoneWidth% RemoteLine$(j% + 2) = RemoteLine$(j% + 2) + SecretRemoteZone$(i% + (ZoneWidth% * (j% - 1))) + SPACE$(1) NEXT i% RemoteLine$(j% + 2) = RemoteLine$(j% + 2) + SPACE$(Front%) + SPACE$(Indent%) + STR$(j%) + SPACE$(1) FOR i% = 1 TO ZoneWidth% RemoteLine$(j% + 2) = RemoteLine$(j% + 2) + PublicLocalZone$(i% + (ZoneWidth% * (j% - 1))) + SPACE$(1) NEXT i% NEXT j% '*** line ZoneHeight+3 Indent% = INT(((ZoneWidth% * 2) - 12) / 2) IF Indent% < 0 THEN Indent% = 0 LocalLine$(ZoneHeight% + 3) = SPACE$(Indent%) + " Your Fleet " + SPACE$(Front%) + SPACE$(2 * Indent%) + "The Enemies Fleet" RemoteLine$(ZoneHeight% + 3) = LocalLine$(ZoneHeight% + 3) '*** line ZoneHeight+4 FOR i% = (ZoneHeight% + 4) TO maxLine% LocalLine$(i%) = "" RemoteLine$(i%) = "" NEXT i% IF (Turn$ = "local") THEN LocalLine$(maxLine%) = "Game Over... You won!" RemoteLine$(maxLine%) = "Game Over... You lost!" ELSE LocalLine$(maxLine%) = "Game Over... You lost!" RemoteLine$(maxLine%) = "Game Over... You won!" END IF 'Sending lines to the displays CLS FOR i% = 1 TO maxLine% PRINT LocalLine$(i%) PRINT #1, RemoteLine$(i%) NEXT i% CLOSE END