Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The World Prototype
#1
So, i made a progress with the codding, it is not so well so i was wondering if y'all got any proper fixes for it, let me share it

Code: (Select All)
Dim money As Integer
Dim strength As Integer
Dim speed As Integer
Dim babes As Integer
Dim balls As Integer
Dim cash As Integer
Dim directions As Integer
Dim knowledge As Integer


'intro
Screen 0
Color 4, 0
Locate 8, 37
Print "The World"
Sleep 5
Cls
Locate 8, 37
Print "Is Loading"
_Delay 5

'opening
Cls
Print "You finally got released from Prison at Kulai Headquarters"
Print "you looked at the sky and the people below it, you began"
Print "wondering, that you can become rich and powerfull"
Print "so you began your journey."
_Delay 10
MainPart


Sub MainPart
    Cls
    Print "Whats your name?"
    Input name$
    Sleep 2
    Cls
    MainPart2
End Sub


Sub MainPart2
    Print "You are outside of Kulai Headquarters,"
    Print "Where will you go?"
    Print "(N)"
    Print "(S)"
    Input x
    If x = N Then
        North
    End If
    If x = S Then
        South
    End If
End Sub


Sub South
    Cls
    Print "You found a Police Headquarters"
    Print "What will you do?"
    Print "Ask For Job"
    Print "Leave"
    _Delay 4
    Input x
    If x = 1 Then Police
    If x = 2 Then MainPart2
End Sub

Sub Police
    Print "You need at least 50iq and 20 strength"
    Print "50 stamina and 10 balls"
    Print "Do you have what it takes?"
    Input x
    If knowledge >= 50 And strength >= 20 And stamina >= 50 And balls >= 10 Then Police2
    If knowledge <= 50 And strength <= 20 And stamina <= 50 And balls <= 10 Then South
    If x = No Then South
End Sub


Sub Police2
    Print "Under Construction"
End Sub
Sub North
    Print "Under Construction"
End Sub
[Image: giphy.gif]
Reply
#2
You obviously didn't read what is wroted about sharing variables if you use SUB. That's why it can't work.

replace first rows as:

Dim Shared money As Integer
Dim Shared strength As Integer
Dim Shared speed As Integer
Dim Shared babes As Integer
Dim Shared balls As Integer
Dim Shared cash As Integer
Dim Shared directions As Integer
Dim Shared knowledge As Integer

and more and more next variables which you use in SUB: stamina, name (this can not be shared, rename "name" variable for example  as PlayerName variable...)

Is possible also easy defined this variable:

Dim Shared as Integer money, stenght, speed, babes, balls, cash, directions, knwoledge, stamina
Dim Shared as String PlayerName

is the same as previous rows in my example.

Sub MainPart2:

Input X is integer, not string, it can not be N or S. Replace it as X$


Reply
#3
i see i see, thanks sire
[Image: giphy.gif]
Reply
#4
I think i got a bit what you meant idk Big Grin but ty for teaching
[Image: giphy.gif]
Reply
#5
It doesn't work because you misspelled powerful.

Don't mind me, I'm just put out because your character has 10 balls. In my reply to Steve, I mentioned I have 9, but at least that's one better than Steve's 8-balls!

Pete  Big Grin

PS Where do the babes come in? After all, the bastard did just get out of prison.
Shoot first and shoot people who ask questions, later.
Reply
#6
If you want to create a text adventure the easiest way to do this in my opinion is to use a two dimensional array that can be navigated like a maze.

I whipped up the text adventure below to give you an idea of where to start. It's not a full game but simply allows you to navigate the game's world using basic commands.

Go East, Go North, Go South, Go West, Quit, Exit

(You can simply type east, west, north, or south as well)

Each grid in the two dimensional array contains its own descriptions that are displayed as you enter each one. The game ends either when you ask to quit or exit, something kills you, or you leave the world successfully.

Code: (Select All)
OPTION _EXPLICIT

' Quick demonstration of using a two-dimensional array as a map for a text adventure.
'
' Valid commands are: north, south, east, west, quit, exit
'
' You can enter commands such as:
' - I want to quit
' - Exit game
' - or simply quit or exit
' - go east
' - go south
' - go north
' - go west
' - or simply enter the direction you wish to go
'
'  ------------------------
' | The game's maze design |
'  ------------------------
'
' The game is made up of a 5x5 grid. An asterisk (*) indicates a grid square can be entered.
'
'                          NORTH
'
'        +-------+-------+-------+-------+-------+           +----  1  ----+
'        |   *   |       |       |   *   |       |           |             |    Room exits can have the following values:
'        |  1,1  |  2,1  |  3,1  |  4,1  |  5,1  |           |  All doors  |
'        |       |       |       |       |       |             are present       0 - no doors present
'+-------+--   --+-------+-------+--   --+-------+           8             2     1 - North door present
'|   *   |   *   |   *   |   *   |   *   |   *   |                               2 - East door present
'|  0,2 --> 1,2     2,2     3,2     4,2     5,2  |           |  1+2+4+8=15 |     3 - North & East doors present
'| ENTER |       |       |       |       |       |           |             |     4 - South door present
'+-------+--   --+-------+-------+-------+-------+           +----  4  ----+     5 - North & South doors present
'        |   *   |       |   *   |   *   |   *   |                               6 - East & South doors present
'  WEST  |  1,3  |  2,3  |  3,3     4,3     5,3  |  EAST     +----  1  ----+     7 - North & East & South doors present
'        |       |       |       |       |       |           |             |     8 - West door present
'        +--   --+-------+--   --+-------+--   --+           | Only North  |     9 - North & West doors present
'        |   *   |   *   |   *   |       |   *   |           | and East         10 - East & West doors present
'        |  1,4     2,4  |  3,4  |  4,4  |  5,4 --> EXIT     | are present 2    11 - North & East & West doors present
'        |       |       |       |       |       |           |                  12 - South & West doors present
'        +-------+--   --+--   --+-------+--   --+           |    1+2=3    |    13 - North & South & West doors present
'        |       |   *   |   *   |       |   *   |           |             |    14 - East & South & West doors present
'        |  1,5  |  2,5     3,5  |  4,5  |  5,5  |           +-------------+    15 - All doors present
'        |       |       |       |       |       |
'        +-------+-------+-------+-------+-------+
'
'                          SOUTH

CONST FALSE = 0 '           truth detector
CONST TRUE = NOT FALSE '    truth detector
CONST NORTHDOOR = 1 '       north door value
CONST EASTDOOR = 2 '        east door value
CONST SOUTHDOOR = 4 '       south door value
CONST WESTDOOR = 8 '        west door value
CONST MAZEWIDTH = 5 '       width of game maze
CONST MAZEHEIGHT = 5 '      height of game maze

TYPE TYPE_ROOM '            ROOM DEFINITIONS
    Description AS STRING ' room description
    Door AS INTEGER '       doors that exist (1 through 15, see explanation above)
    North AS STRING '       description of north door
    East AS STRING '        description of east door
    South AS STRING '       description of south door
    West AS STRING '        description of west door
END TYPE

DIM Room(MAZEWIDTH, MAZEHEIGHT) AS TYPE_ROOM ' create the game maze playing field
DIM px AS INTEGER '                            player's x location in maze (horizontal)
DIM py AS INTEGER '                            player's y location in maze (vertical)
DIM Response AS STRING '                       player's next response
DIM Valid AS INTEGER '                         did player give a valid response? (TRUE or FALSE)
DIM North AS INTEGER '                         north is a valid direction (TRUE or FALSE)
DIM East AS INTEGER '                          east  is a valid direction (TRUE or FALSE)
DIM South AS INTEGER '                         south is a valid direction (TRUE or FALSE)
DIM West AS INTEGER '                          west  is a valid direction (TRUE or FALSE


'  -----------------------
' | Set up the ENTER room |
'  -----------------------

Room(0, 2).Description = "You are standing outside of a dark sinister looking building."
Room(0, 2).North = "you see a scary forest."
Room(0, 2).East = "is an entrance into the building."
Room(0, 2).South = "you see a swamp."
Room(0, 2).West = "you see a pack of hungry wild dogs."
Room(0, 2).Door = 15 ' all exits exist

'  -----------------------
' | Set up the maze rooms |
'  -----------------------

Room(1, 1).Description = "This walls in this room have an odd glow to them."
Room(1, 1).South = "you see a passage way."
Room(1, 1).Door = 4 ' only exit is to the SOUTH

Room(4, 1).Description = "This room gives you a feeling of dread!"
Room(4, 1).South = "you see an unlocked door."
Room(4, 1).Door = 4 ' only exit is to the SOUTH

Room(1, 2).Description = "You are standing in the lobby of the sinister building."
Room(1, 2).North = "you see a dimly lit passage way."
Room(1, 2).East = "you see a long hallway."
Room(1, 2).South = "you hear sounds coming from a passage way."
Room(1, 2).West = "you see an exit to the oustide world."
Room(1, 2).Door = 15 ' all exits exist

Room(2, 2).Description = "You are in a hallway and hear faint voices."
Room(2, 2).East = "you see the hallway continuing on."
Room(2, 2).West = "you see the hallway continuing on."
Room(2, 2).Door = 10 ' only exits are EAST and WEST

Room(3, 2).Description = "You are in a hallway. The voices are louder."
Room(3, 2).East = "you see the hallway continuing on."
Room(3, 2).West = "you see the hallway continuing on."
Room(3, 2).Door = 10 ' only exits are EAST and WEST

Room(4, 2).Description = "There is a walkie talkie on the ground. You smell something foul."
Room(4, 2).North = "you see an unlocked door."
Room(4, 2).East = "you see the hallway continuing on."
Room(4, 2).West = "you see the hallway continuing on."
Room(4, 2).Door = 11 ' only exits are NORTH, EAST, and WEST

Room(5, 2).Description = "There is a dead security guard laying here!"
Room(5, 2).West = "you see a long hallway."
Room(5, 2).Door = 8 ' only exit is to the WEST

Room(1, 3).Description = "A television is playing a movie in the corner of the room."
Room(1, 3).North = "you see a passage way leading to the building's lobby."
Room(1, 3).South = "you see mist entering from a passage way."
Room(1, 3).Door = 5 ' only exits are NORTH and SOUTH

Room(3, 3).Description = "There appears to be blood smeared on the walls!"
Room(3, 3).East = "you see an open door leading to dark hallway."
Room(3, 3).South = "you see a passage way with a flickering light."
Room(3, 3).Door = 6 ' only exits are EAST and SOUTH

Room(4, 3).Description = "You are in a dark hallway. Once again you feel watched."
Room(4, 3).East = "you see an open door leading to a room lit in red."
Room(4, 3).West = "you see an open door."
Room(4, 3).Door = 10 ' only exits are EAST and WEST

Room(5, 3).Description = "You are in a red room with portraits you swear are watching you!"
Room(5, 3).South = "you see a passage way to escape through."
Room(5, 3).West = "you see a dark hallway."
Room(5, 3).Door = 12 ' only exists are SOUTH and WEST

Room(1, 4).Description = "You feel as though you are being watched through the mist in this room."
Room(1, 4).North = "you see a room with flickering light."
Room(1, 4).East = "you see mist entering through a passage way."
Room(1, 4).Door = 3 ' only exits are NORTH and EAST

Room(2, 4).Description = "Blood appears to be seeping from the north wall!"
Room(2, 4).South = "you see flickering light coming from a passge way."
Room(2, 4).West = "you see mist entering from a passage way."
Room(2, 4).Door = 12 ' only exits are SOUTH and WEST

Room(3, 4).Description = "There is a table against the west wall with candles burning."
Room(3, 4).North = "you see a passage way."
Room(3, 4).South = "you seen an unlocked door."
Room(3, 4).Door = 5 ' only exits are NORTH and SOUTH

Room(5, 4).Description = "You here chains rattling in the distance."
Room(5, 4).North = "you see a passage way to a dimly lit room in red."
Room(5, 4).East = "you see a doorway with sunlight shining in."
Room(5, 4).South = "you see a staircase leading down."
Room(5, 4).Door = 7 ' only exits are NORTH, EAST, and SOUTH

Room(2, 5).Description = "There is a pentagram on the floor surrounded by burning candles."
Room(2, 5).North = "you see a passage way."
Room(2, 5).East = "you see a salt trail leading through a doorway."
Room(2, 5).Door = 3 ' only exits are NORTH and EAST

Room(3, 5).Description = "A dead goat and chicken lie on the floor. The goat is staring at you."
Room(3, 5).North = "you see a passage way with a flickering light."
Room(3, 5).West = "you see a salt trail leading through a doorway."
Room(3, 5).Door = 9 ' only exits are NORTH and WEST

Room(5, 5).Description = "A rotting corpse is chained to the south wall. It's moving!"
Room(5, 5).North = "you see a staircase leading up."
Room(5, 5).Door = 1 ' only exist is NORTH

'  -----------------
' | Begin game here |
'  -----------------

px = 0 ' player's x starting location
py = 2 ' player's y starting location

CLS
PRINT
PRINT " You awaken to find yourself in a strange place. How did I get here?"
PRINT " There is a dark sinister looking building surrounded by a forest and"
PRINT " misty swamp land. You hear dogs barking in the distance."
PRINT

DO '                                                                                             begin main game loop
    DO '                                                                                         begin player response loop
        North = FALSE: East = FALSE: South = FALSE: West = FALSE '                               reset valid directions
        PRINT " ------------------------------------------------------------------------------"
        COLOR 15, 0 '                                                                            bright white on black text
        PRINT " "; Room(px, py).Description '                                                    print current room description
        COLOR 7, 0 '                                                                             white on black text
        IF (Room(px, py).Door AND NORTHDOOR) = NORTHDOOR THEN '                                  is there a door to the north?
            PRINT " - To the north "; Room(px, py).North '                                       yes, print its description
            North = TRUE '                                                                       north is a valid move
        END IF
        IF (Room(px, py).Door AND EASTDOOR) = EASTDOOR THEN '                                    is there a door to the east?
            PRINT " - To the east "; Room(px, py).East '                                         yes, print its description
            East = TRUE '                                                                        east is a valid move
        END IF
        IF (Room(px, py).Door AND SOUTHDOOR) = SOUTHDOOR THEN '                                  is there a door to the south?
            PRINT " - To the south "; Room(px, py).South '                                       yes, print its description
            South = TRUE '                                                                       south is a valid move
        END IF
        IF (Room(px, py).Door AND WESTDOOR) = WESTDOOR THEN '                                    is there a door to the west?
            PRINT " - To the west "; Room(px, py).West '                                         yes, print its description
            West = TRUE '                                                                        west is a valid move
        END IF
        PRINT " ------------------------------------------------------------------------------"
        LINE INPUT " What next? > "; Response '                                                  ask player for input
        PRINT
        Valid = TRUE '                                                                           assume player's input is valid
        Response = UCASE$(Response) '                                                            capitalize player's input
        IF INSTR(Response, "QUIT") OR INSTR(Response, "EXIT") THEN SYSTEM '                      leave game if player wishes
        IF INSTR(Response, "NORTH") AND North THEN '                                             is north a valid move?
            py = py - 1 '                                                                        yes, move player's position up in maze
        ELSEIF INSTR(Response, "EAST") AND East THEN '                                           is east a valid move?
            px = px + 1 '                                                                        yes, move player's position to the right in maze
        ELSEIF INSTR(Response, "SOUTH") AND South THEN '                                         is south a valid move?
            py = py + 1 '                                                                        yes, move player's position down in maze
        ELSEIF INSTR(Response, "WEST") AND West THEN '                                           is west a valid move?
            px = px - 1 '                                                                        yes, move player's position to the left in maze
        ELSE '                                                                                   player entered invalid input
            COLOR 15, 0 '                                                                        bright white on black text
            PRINT " You can't go in that direction." '                                           inform player of error
            COLOR 7, 0 '                                                                         white on black text
            Valid = FALSE '                                                                      player's input was invalid
        END IF
    LOOP UNTIL Valid = TRUE '                                                                    loop back until player enters valid input

    IF px < 1 THEN '                                                                             is player to the left of maze?
        COLOR 15, 0 '                                                                            yes, bright white on black text
        IF py = 1 THEN '                                                                         player went north into the forest
            PRINT " You wander around in the forest for days and die from dehydration." '        player is dead
        ELSEIF py = 3 THEN '                                                                     player went south into the swamp
            PRINT " You enter the swamp and get eaten by an alligator." '                        player is dead
        ELSEIF px = -1 THEN '                                                                    player went west into the dogs
            PRINT " The hungry wild dogs feast on your bones for days." '                        player is dead
        END IF
        END '                                                                                    end the game
    ELSEIF px > 5 THEN '                                                                         no, is player to the right of maze?
        PRINT " ------------------------------------------------------------------------------"
        COLOR 15, 0 '                                                                            yes, bright white on black text
        PRINT " You exit the building wondering what in the hell all that was about?" '          inform player success through maze
        COLOR 7, 0 '                                                                             white on black text
        PRINT " ------------------------------------------------------------------------------"
        END '                                                                                    end game
    END IF
LOOP '                                                                                           loop back to display new room
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#7
Terry could add to that a Vote for Democrats option... Oh wait, my bad... Terry already has the 'Go South' option, sorry for the Duplicate Definition!

Terry gave you a really great sample of how these types of maze/action-adventure/role-player games are generally made, but your method is less complicated and is certainly doable. Now if Terry's method is something you get and can run with, you will be better off when you are well into this project, but if not, just ask yourself if you are okay with the extra overhead not using arrays will bring you. It's a text game, so no worries about speed, either way.

Pete

- My 2-cents and a bag of 8066 chips.
Shoot first and shoot people who ask questions, later.
Reply




Users browsing this thread: 4 Guest(s)