Welcome to RetroCoders Community
Quote from: __blackjack__ on Jul 23, 2025, 08:47 PMThere is an array out of bounds error with `Cor`. Initialising this with -1 leads to `Cor` being 15 and then this value being used as index into the just 9 element long `CP_Cores` array.ah yeah `Cor` is to be intiialized with 1 not -1, i was puzzled since i couldnt see it here, but turns out i guess i copy pasted the code before fixing that xD
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
210 GUN(3)=1: IF BULLETS=2 THEN GUN(6)=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
10 DEFINT A-Z:DEF SEG=&HB800
20 CLS:FOR I=0 TO 15:FOR J=0 TO 15:POKE 160*I+J*2,I*16+J:NEXT:NEXT
30 WHILE INKEY$="":WEND
40 FOR I=0 TO 15:FOR J=0 TO 15:POKE 160*I+J*2+1,I*16+J:NEXT:NEXT
50 WHILE INKEY$="":WEND
10 DEFINT A-Z:RANDOMIZE TIMER:COLOR 2
20 PRINT"Ski Slope Challenge By electricwalrus (2022)":PRINT
30 PRINT"Use the arrow keys to move left or right down the slope":PRINT
40 PRINT"Press any key to begin!":WHILE INKEY$="":WEND
50 CLS:S=0:SX=40:PX=SX
60 PRINT"Get Ready!":T!=TIMER+5:WHILE TIMER<T!:WEND
70 ON INT(RND*2)+1 GOTO 80,100
80 IF SX>10 THEN SX=SX-1
90 GOTO 110
100 IF SX<70 THEN SX=SX+1
110 LOCATE 24,SX-9:COLOR 11:PRINT"* *";
120 K$=INKEY$:IF K$=CHR$(27) THEN END
130 IF K$=CHR$(0)+CHR$(75) THEN PX=PX-1:GOTO 150
140 IF K$=CHR$(0)+CHR$(77) THEN PX=PX+1
150 D=PX-SX:IF D<-8 OR D>6 THEN 190
160 LOCATE 24,PX:COLOR 10:PRINT"!!"
170 T!=TIMER+.3:WHILE TIMER<T!:WEND
180 S=S+1:GOTO 70
190 BEEP:T!=TIMER+1:WHILE TIMER<T!:WEND
200 CLS:COLOR 6:PRINT"You crashed on the ski-field":PRINT"Score:";S:PRINT
210 COLOR 15:PRINT"Try Again in 5 seconds":GOTO 50
SUB PrintTextFile(filename AS STRING)
DIM buffer AS STRING, handle AS LONG = FREEFILE
CLS
IF OPEN(filename FOR BINARY ACCESS READ AS #handle) THEN
PRINT "File could not be opened!"
ELSE
buffer = SPACE(LOF(handle))
IF LEN(buffer) = 0 THEN
PRINT "File is empty."
ELSE
GET #handle, 0, buffer
END IF
CLOSE #handle
PRINT buffer; ' Prints nothing if file was empty.
END IF
END SUB
switch (input)
{
case 1: result = message(BEG1, BEG2); break;
case 2: result = message(WORK1, WORK2); break;
case 3: result = message(PHONE1, PHONE2); break;
case 4: result = message(DRUGS1, DRUGS2); break;
}
static const char *MESSAGES[4][2] = {
{BEG1, BEG2}, {WORK1, WORK2}, {PHONE1, PHONE2}, {DRUGS1, DRUGS2}
};
...
result = message(MESSAGES[input - 1][0], MESSAGES[input - 1][1]);
result = message(MESSAGES[input - 1]);
int message(const char *messages[2])
{
int randon_number = rand() % 2;
puts(messages[randon_number]);
return randon_number + 1;
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define BEG1 "you have been begging all day for food and/or money but nothing"
#define BEG2 "you succeeded in getting some food and money from kind people"
#define WORK1 "you tried to find work but you where rejected everywhere you went"
#define WORK2 "you found work and after 2 weeks got your frist salery! you are off the streets! yay!"
#define PHONE1 "you phone family or friends you used to know but no one answers"
#define PHONE2 "you phone your parents - they come and get you and you are safe at home - you are off the streets - yay!"
#define DRUGS1 "you buy cheap alchohol and booze to try and forget your troubles, pass out and wake up at hospital"
#define DRUGS2 "you get OD from bad alchohol and drugs and you die on the streets - RIP :( GAME OVER"
static const char * const MESSAGES[][2] = {
{BEG1, BEG2}, {WORK1, WORK2}, {PHONE1, PHONE2}, {DRUGS1, DRUGS2}
};
void skip_to_end_of_line(void)
{
char ch;
while ((ch = getchar()) != '\n' && ch != EOF);
}
int main()
{
int days = 1, health = 50, money = 55;
int i, input, result;
srand((unsigned int) time(NULL));
while (health >= 0)
{
printf(
"\nyou are on the streets for %i days\n"
"you have %i health, %i money\n",
days, health, money
);
puts(
"choose what to do:\n"
"1. beg for money or food\n"
"2. try to find work or a job\n"
"3. phone someone for help\n"
"4. buy some street drugs/alcohol to forget your troubles"
);
/*
* TODO This still accepts input like "3some stuff thats not digits" by
* simply ignoring the part where the digits stop up to the end of
* the line.
*/
for (;;)
{
i = scanf("%d", &input);
skip_to_end_of_line();
if (i == 1 && input >=1 && input <= 4)
{
break;
}
puts("Error! Wrong input. Try again.");
}
result = rand() % 2;
puts(MESSAGES[input - 1][result]);
if (result == 1)
{
if (input != 1)
{
break;
}
health += 25;
money += 30;
}
else
{
health -= 5;
money -= 10;
}
days++;
skip_to_end_of_line();
}
skip_to_end_of_line();
return 0;
}
Randomize Timer
Dim Messages(..., ...) As Const String = { _
{"you have been begging all day for food and/or money but nothing", _
"you succeeded in getting some food and money from kind people"}, _
{"you tried to find work but you where rejected everywhere you went", _
"you found work and after 2 weeks got your frist salery! you are off the streets! yay!"}, _
{"you phone family or friends you used to know but no one answers", _
"you phone your parents - they come and get you and you are safe at home - you are off the streets - yay!"}, _
{"you buy cheap alchohol and booze to try and forget your troubles, pass out and wake up at hospital", _
"you get OD from bad alchohol and drugs and you die on the streets - RIP :( GAME OVER"}}
Dim days As Integer = 1, health As Integer = 50, money As Integer = 55
Dim answer As Integer, result As Integer
Do While health >= 0
Print
Print "you are on the streets for"; days; " days"
Print "you have"; health; " health,"; money; " money"
Print "choose what to do:"
Print "1. beg for money or food"
Print "2. try to find work or a job"
Print "3. phone someone for help"
Print "4. buy some street drugs/alcohol to forget your troubles"
Do
Input answer
If answer >= 1 And answer <= 4 Then Exit Do
Print "Error! Wrong input. Try again."
Loop
result = Int(Rnd * 2)
Print Messages(answer - 1, result)
If result = 1 Then
If answer <> 1 Then Exit Do
health += 25: money -= 30
Else
health -= 5: money -= 10
End If
days += 1
GetKey
Loop
GetKey
Randomize Timer
Const MaxGuessCount = 7
Dim number As Const Byte = Int(Rnd * 100) + 1
Dim guess As Byte
Cls
Print "Welcome to the Guessing Game!"
Print
Print "I am thinking of a number between 1 and 100."
Print "Can you guess my number?"
For guessCount As Byte = MaxGuessCount To 1 Step -1
Print
Input "Your guess: ", guess
If guess = number Then Print "Well done! You guessed my number.": End
Print IIf(guess < number, "Higher...", "Lower...")
Print "You have"; guessCount - 1; " guesses remaining..."
Next
Print "You have guessed"; MaxGuessCount; " times... Not good enough. You have no more guesses."
Print "Game over."
Randomize Timer
Const ChamberCount = 6
Dim clicksTillBoom As Integer = Int(Rnd * ChamberCount)
Print "Spinning the cylinder with"; ChamberCount; " chambers and one cartridge."
Do
Print "ESCape or any other key to pull trigger..."
If GetKey = 27 Then Print "Coward!": End
If clicksTillBoom = 0 Then
Print "Boom! The gun went off.": End
Else
Print "Click.": clicksTillBoom = clicksTillBoom - 1
End If
Loop
Randomize Timer
Screen 17 ' Ideal Screen Size (80x25 characters)
' Welcome
Color 2
Print "Ski Slope Challenge! By electricwalrus (2022)"
Print "Try to last on this slope as long as possible"
Print
Print "Use the arrow keys to move left and right down the slope"
Print
Print "Press any key to begin!"
Sleep
Dim score As Integer, x As Integer, player As Integer
Do
Cls
Print "Get Ready!"
Sleep 1000, 1
score = 0: x = 40: player = x
Do
Select Case Int(Rnd * 2)
Case 0: If x > 10 Then x = x - 1
Case 1: If x < 70 Then x = x + 1
End Select
Locate 25, x - 9: Color 11: Print "* *";
If MultiKey(1) Then End
If MultiKey(75) Then player = player - 1
If MultiKey(77) Then player = player + 1
Select Case player - x
Case Is < -8, Is > 6: Exit Do
End Select
Locate 25, player: Color 10: Print "!!"
Sleep 100, 1
score = score + 1
Loop
Beep
Sleep 1000, 1
Cls
Locate 1, 1
Color 6
Print "You crashed on the ski-field!"
Print "Score:"; score
Print
Color 15
Print "Try Again in 5 seconds"
Sleep 5000, 1
Loop