News:

Welcome to RetroCoders Community

Main Menu

Gw Basic Game - Russian Roulette

Started by ron77, Nov 20, 2023, 02:41 PM

Previous topic - Next topic

ron77

10 REM RUSSIAN ROULETTE GAME IN GW BASIC
20 REM BY RON77 (SOLO88) 2023
30 REM INITIALIZE VARIABLES
40 DIM GUN(6): USER1$="": USER2$="": S$="": ROW=0: RANDOMIZE TIMER: B=0
50 FOR I = 1 TO 6: GUN(I) = 0: NEXT I
60 REM INTRO
65 GOSUB 1200 REM SCREEN 0: REM COLOR 15,0:REM CLS
70 S$ = "RUSSIAN ROULETTE": ROW = 3: GOSUB 1000
80 S$ = "BY RON77 (SOLO88)": ROW = 5: GOSUB 1000
90 WHILE INKEY$ = "": WEND: BEEP
100 GOSUB 1300
110 S$="RUSSIAN ROULETTE": ROW=3: GOSUB 1000
120 S$="BY RON77 (SOLO88)": ROW=5: GOSUB 1000
130 WHILE INKEY$="": WEND: GOSUB 1200
140 REM START OG GAME LOOP
150 INPUT "PLAYER 1 NAME: ", USER1$
160 INPUT "PLAYER 2 NAME: ", USER2$
170 CLS
180 PRINT USER$;"ONE OR TWO BULLETS IN THE REVOLVER?"
190 INPUT "ENTER 1 OR 2: ", BULLETS
200 IF BULLETS = 1 THEN GOTO 220 ELSE IF BULLETS = 2 THEN GOTO 230

220 REM ONE BULLET IN THE REVOLVER
221 GUN(3) = 1
222 GOTO 240

230 REM TWO BULLETS IN THE REVOLVER
231 GUN(3) = 1: GUN(6) = 1
232 GOTO 240

240 REM START OF GAME LOOP
250 REM PLAYER 1 TURN
255 GOSUB 1200: PRINT USER1$;" TURN"
260 PRINT "1, ROLL THE CYLINDER"
270 PRINT "2, PULL THE TRIGGER"
280 PRINT "3, QUIT"
290 INPUT "ENTER 1, 2, OR 3: ", CHOICE
295 IF CHOICE < 1 OR CHOICE > 3 THEN GOTO 290
300 ON CHOICE GOTO 400, 500, 600

320 REM PLAYER 2 TURN
325 GOSUB 1200: PRINT USER2$;" TURN"
330 PRINT "1, ROLL THE CYLINDER"
340 PRINT "2, PULL THE TRIGGER"
350 PRINT "3, QUIT"
360 INPUT "ENTER 1, 2, OR 3: ", CHOICE
365 IF CHOICE < 1 OR CHOICE > 3 THEN GOTO 360
370 ON CHOICE GOTO 450, 550, 650

400 REM ROLL THE CYLINDER PLATER 1
415 FOR I = 1 TO 6
420 B = INT(RND*7)
422 NEXT I
425 GOSUB 50600
430 GOTO 240

450 REM ROLL THE CYLINDER PLAYER 2
455 FOR I = 1 TO 6
460 B = INT(RND*7)
462 NEXT I
465 GOSUB 50600
470 GOTO 320


500 REM PULL THE TRIGGER PLATER 1
505 IF GUN(B) = 1 THEN GOSUB 1300: BEEP: ROW=4:S$=USER1$+" YOU DIED!":GOSUB 1000: END
510 IF GUN(B) = 0 THEN GOSUB 1200: BEEP: ROW=4:S$=USER1$+" YOU LIVE!":GOSUB 1000: T!=TIMER +3:WHILE TIMER <T!:WEND:GOTO 320

550 REM PULL THE TRIGGER PLAYER 2
555 IF GUN(B) = 1 THEN GOSUB 1300: BEEP: ROW=4:S$=USER2$+" YOU DIED!":GOSUB 1000: END
560 IF GUN(B) = 0 THEN GOSUB 1200: BEEP: ROW=4:S$=USER2$+" YOU LIVE!":GOSUB 1000: T!=TIMER +3:WHILE TIMER <T!:WEND: GOTO 240

600 REM QUIT PLAYER 1
605 GOSUB 1200: ROW=4:S$=USER1$+" QUIT!":GOSUB 1000: END

650 REM QUIT PLAYER 2
655 GOSUB 1200: ROW=4:S$=USER2$+" QUIT!":GOSUB 1000: END

1000 REM PRINT STRING
1010 LOCATE ROW, (80 - LEN(S$))/2: PRINT S$
1020 RETURN

1200 REM SCREEN INIT
1210 SCREEN 0: COLOR 15,0: CLS
1220 RETURN

1300 REM SCREEN RED COLOR
1310 SCREEN 0: COLOR 4,0: CLS
1320 RETURN

50600 FOR I = 1 TO 50
50700    J=RND(I)*10000
50800    IF J<37 THEN 51100
50900    PLAY "mb"
51000    SOUND J,.5
51100 NEXT I
51200 RETURN

__blackjack__

That's an interesting revolver: with *7* chambers!  I'm pretty sure that wasn't the intend, given line 50 that just "empties" 6 of the chambers and that traditionally most revolvers have 6 chambers.  So B must be initialised with 1 and the random number assigned later must be in the range 1 to 6, not 0 to 6.  Also it doesn't make sense to roll the dice 6 times instead of just one.

And then there is the fact that the cylinder doesn't advance to the next chamber when pulling the trigger.  And at the start of the game the cylinder isn't rolled. That doesn't make sense for Russian roulette.

In line 180 there is a USER$ printed that isn't defined anywhere, so that's the empty string and has no effect.

It doesn't make much sense to initialise variables to values that are not used anywhere in the program.

The answer for number of bullets isn't validated.

GOTOs to the very next line number are unnecessary.

The two "blocks" of code when loading the revolver with either 1 or 2 bullets repeats some code.  It would be much shorter to load one bullet and then just check if a second one is needed.  So instead of:

220 REM ONE BULLET IN THE REVOLVER
221 GUN(3)=1
222 GOTO 240

230 REM TWO BULLETS IN THE REVOLVER
231 GUN(3)=1: GUN(6)=1
232 GOTO 240

Just:

210 GUN(3)=1: IF BULLETS=2 THEN GUN(6)=1

There are *two* REMs saying ,,start of game loop" but just one actually *is* the start of the game loop.  Well sort of because the code does jump there only when player 2 was active.  This is one of the uses of GOTO that make code harder to follow than necessary.  Instead of GOTO somewhere at the end of each action for each player, it would be better to code the actions as subroutines that end with a RETURN and have one clear main loop with one GOTO that jumps back to the start.

Then comes all the duplicated code for player 1 and player 2.  As the names in USER1$ and USER2$ are never used together somewhere in the main loop, the easiest way to get rid of half the action code is to just put the player names into an array and swap the two each loop iteration and leave just the code for player 1.

10 REM RUSSIAN ROULETTE GAME IN GW BASIC
20 REM BY RON77 (SOLO88) 2023
30 REM INITIALIZE VARIABLES
40 RANDOMIZE TIMER: DIM GUN(6),USERS$(2)

60 REM INTRO
65 FOR I=1 TO 2: ON I GOSUB 1200,1300
70 S$="RUSSIAN ROULETTE": ROW=3: GOSUB 1000
80 S$="BY RON77 (SOLO88)": ROW=5: GOSUB 1000
90 WHILE INKEY$="": WEND: IF I=1 THEN BEEP
100 NEXT: GOSUB 1200

150 FOR I=1 TO 2: PRINT "PLAYER";I;"NAME: ";: INPUT "",USERS$(I): NEXT
170 CLS
180 PRINT "ONE OR TWO BULLETS IN THE REVOLVER?"
190 INPUT "ENTER 1 OR 2: ",BULLETS
200 IF BULLETS<1 OR BULLETS>2 THEN 190
210 GUN(3)=1: IF BULLETS=2 THEN GUN(6)=1
220 GOSUB 400

240 REM START OF GAME LOOP
255 GOSUB 1200: PRINT USERS$(1);" TURN"
260 PRINT "1. ROLL THE CYLINDER"
270 PRINT "2. PULL THE TRIGGER"
280 PRINT "3. QUIT"
290 INPUT "ENTER 1, 2, OR 3: ",CHOICE
295 IF CHOICE<1 OR CHOICE>3 THEN 290
300 ON CHOICE GOSUB 400,500,600
310 SWAP USERS$(1),USERS$(2): GOTO 240

400 REM ROLL THE CYLINDER
420 B=INT(RND*6)+1: GOSUB 5060: RETURN

500 REM PULL THE TRIGGER (ADVANCES THE CYLINDER)
510 B=B+1: IF B>6 THEN B=1
520 ON GUN(B)+1 GOTO 530,540
530 GOSUB 1200: S$="LIVE": GOTO 550
540 GOSUB 1300: S$="DIED": GOSUB 550: END
550 BEEP: S$=USERS$(1)+" YOU "+S$+"!": ROW=4: GOSUB 1000
560 T!=TIMER+3: WHILE TIMER<T!: WEND: RETURN

600 REM QUIT
610 GOSUB 1200: S$=USERS$(1)+" QUIT!": ROW=4: GOSUB 1000: END

1000 REM PRINT STRING CENTERED
1010 LOCATE ROW,(80-LEN(S$))\2: PRINT S$: RETURN

1200 REM SCREEN INIT
1210 COLOR 15,0: CLS: RETURN

1300 REM SCREEN RED COLOR
1310 COLOR 4,0: CLS: RETURN

5060 FOR I=1 TO 50
5070   J=RND(I)*10000: IF J>=37 THEN PLAY "mb": SOUND J,.5
5110 NEXT: RETURN

It's not necessary by the way to model the revolver as array with six elements when distributing the bullet(s) evenly into the chambers.  Then it is enough to keep track how many trigger pulls till a bullet is reached and the possible maximum of this value for rolling the cylinder.
Two is the oddest prime.