News:

Welcome to RetroCoders Community

Main Menu

Ski Slope by electricwalrus (2022)

Started by electricwalrus, Sep 12, 2022, 06:46 AM

Previous topic - Next topic

__blackjack__

It's easy to get rid of the GOTOs.  The one for the `start:` label is just a DO ... LOOP around the code and the other two are an EXIT DO to exit the game loop.

And the game just needs three variables.  The others can be removed.  `i` isn't needed when the value is checked with a SELECT CASE statement.  The expression defining `x2` can be inserted in the only place where `x2` is used.  `a` is for a loop that can be replaced by a LOCATE.  And for `check` we can use SELECT CASE again.

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
Two is the oddest prime.

__blackjack__

There's a type in line 130: T1 instead of T!.

In line 200 there's the `;` missing at the end of the print.  This leads to printing the slope and the player every other line instead of printing both on every line.

Line 70 isn't the best way to translate the original because that doesn't wait for any key but for the enter key.  A loop with INKEY$ would be better.

Just like in the original the FOR loop printing single spaces can be replaced by LOCATE.

All variables without a type suffix can be declared as integer instead of floating point.

Somehow the COLORs from the FreeBASIC version was missing. Easy to add back because GW-BASIC the same COLOR command with the same color values.

It was custom to pack more than one statement into a line.  Yes that makes the code more dense and thus sometimes harder to read, on the other hand the code now fits onto the 80x24 lines visible on screen when listed in GW-BASIC.
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
Two is the oddest prime.