News:

Welcome to RetroCoders Community

Main Menu

Snakes and Ladders

Started by johnno56, May 10, 2023, 09:07 PM

Previous topic - Next topic

johnno56

Do not get too excited!

This version is pure text! Aww...

This is NOT mine but I have made a few tweaks... The game is currently set to a maximum of 4 players. This can be changed. If changed then you will have to modify the "select case" to suite.

This game is NOT interactive, although it 'could' be... This is basically the core mechanics of the game.

I have based the game 'table' on a Snakes and Ladders game I made for sdlbasic... Yes, it was interactive with sprites and sound... I will not post an image of the board as I do not want to give you the impression that this version contains graphics... Moo Ha Ha Ha....

'// Rosetta Code problem: http://rosettacode.org/wiki/Snakes_and_Ladders
'// by Galileo, 04/2022

maxPlayers = 4

Dim table(100), player(maxPlayers)

'        Nine objects on the table. Five ladders and four snakes.
'        Each object reads a pair of numbers.
'        If the first number is smaller than the second, then that 
'        object is a ladder. If the first is larger than the second,
'        then that object is a snake.

'        eg: First pair: 8 and 31.
'                If the player lands on square 8, 8 is smaller than
'                31, then up the ladder to square 31.
'
'                Third pair: 24 and 1.
'                If the player lands on square 24, 24 is larger than 1,
'                then down the snake to square 1.
'

For n = 1 To 9: Read o, d: table(o) = d: Next

Data 8,31,15,97,24,1,42,81,55,13,66,87,71,29,88,67,99,6

for i = 1 to maxPlayers: player(i) = 1: next

turn = 1

Do
    steps = Int(Rnd * 6) + 1
    nextPos = player(turn) + steps
        
        select case turn
            case 1
                color 9
            case 2
                color 11
            case 3
                color 7
            case 4
                color 15
        end select                
        
    Print Using "Player # on square ### rolls a # "; turn; player(turn); steps;
    If Not (nextPos > 100) Then
        Print " and moves to square "; Str$(nextPos); "."
        player(turn) = nextPos
        If nextPos = 100 Then color 13: Print: Print "Player "; turn; " wins!": GoTo Done
        If table(nextPos) Then
            player(turn) = table(nextPos)
            If table(nextPos) > nextPos Then
                                color 10
                Print "Yay! Landed on a ladder. Climb up to ";
            Else
                                color 12
                Print "Oops! Landed on a snake. Slither down to ";
            End If
            Print Str$(player(turn)); "."
        End If
    Else
                color 14
        Print " but cannot move."
    End If

        turn = turn + 1: If turn > maxPlayers Then turn = 1

        _Delay 1
    Print
Loop

Done:
_delay 1
end

You cannot view this attachment.

WARNING: There is a one second delay between messages and some games can last quite a number of 'turns'. To help decrease the 'playing time' modify 'maxPlayers' to a lower value...

ps: Interactive with graphics or not? I wonder...
May your journey be free of incident.  Live long and prosper.

CharlieJV

I'm getting a major kick out of this.

johnno56

I was thinking about trying to include simple graphics to kind of replicate my sdlbasic version. I like interacting with the game, even though it is just to press a key to roll, and to watch the 'pieces' move up and down the board. To tell you the truth, just 'watching' a 'text based' version play until completion, can get a little boring after several games... lol... Although the 'mechanics' of the game is there, I think it needs to be improved, to make it more 'entertaining' to such a degree that the player will return to play again... Time to look through the archives, dust off the sdl version and try to think of ways to improve the BAM version....
May your journey be free of incident.  Live long and prosper.