Search code examples
pseudocode

A game I'm writing for my programming concepts class


The randomcoord function was given to me in the project. That's why it's not mentioned anywhere else. This is in pseudocode and I just wanted to check if there is anything wrong with it.

The program is supposed to be a game with a 10x10 grid where the player starts off in the middle and has to enter commands like up, down, left or right in order to find the antidote to the poison in 20 turns or you die.

That's the bare minimum, but I added a story and I also want to add walls somehow and I just want to know if there is anything wrong with what I have so far and if anyone is willing to help me create walls in this game.

The function of the walls would be if a player lands on that space the program would display something like "there's a wall here" and then put the player back onto the previous spot.

Can anyone help me please?

Declare Integer x
Declare Integer y
Declare String Decision
Declare String direction
Declare Integer turn
Set px = 5
Set py = 5
Call randomCoord
Call randomCoord
Set tx = randomCoord
Set ty = randomCoord
Declare Integer Map [10] [10]
    Function Integer moveUp
        If px+1>10then
            Display "there is a wall here"
        Else
            set px = px + 1
        End If
    End Function

    Function Integer moveDown
        If px-1<0 Then 
            Display "there is a wall here"
        Else
            set px = px - 1
        End If
    End Function

    Function Integer moveLeft
        If py-1<0 Then
            Display "there is a wall here"
        Else
            set py = py - 1
        End if
    End Function

    Function Integer moveRight
        If py+1>10 Then
            Display "there is a wall here"
        Else
            set py = py + 1
        End If
    End Function
Module Main ()

Do 
    Display "Your name is Vladsworn, you are a Powerful Necromancer.              During your travels you stumbled upon the town of Ascalon.  This town is full of theives, beggars, mages 
who practice blood magic, and a corrupted King.  Its getting dark out and it looks like its going to rain so you look for a place to stay, there is a run down inn with a giant
hole in the roof but you decide to check it out anyway.  You walk in and see the innkeeper at the desk and she is talking to an shady elf man.  He seems to be a ranger, he has a bow 
on his back along with a quiver, he has long blonde hair.  You walk up to the desk and ask the innkeeper for a room, she says that the only room left is on the top floor, right
under the hole,  Just then the elf says that you can stay in his place for the night if you need to, its in the forest surrounding the town high up in the trees.  Do you
want to stay at the inn? or take a chance staying with the elf man you just met?  please type either elf, or inn"



Do 
    Input decision 
    Display "You dont see anything like that around here, your only two choices are either the elf mans house in the trees or the run down inn in Ascalon"
Until  decision == elf or decision == inn


If  decision == elf  Then    
    Display "You decide to take a chance and stay with the elf man, he takes you to his house in the trees and on the way you talk to him and find out alittle about him, first 
    You find out his name is Adrian You find out that the reason he is in this shady town is that he has been looking for the blood mage who killed his mother, his sources say 
    that he still lives in this town and hes been here searching for him for months and didnt find anything on his wherabouts.  He asks you if you 
    would like to aid him on his quest and says that he will pay you greatly if you do so you decide to help him.  Finally you arrive at the Adrians treehouse, its much bigger than 
    you expected, its high above a huge redwood tree with stairs cut into the side of the tree.  you climb up the stairs and enter the house, its a nice little hut with a bedroom,
    a small kitchen and a trophy room with dragon heads on the walls.  Adrian hands you a bedroll and you are so tired you immediately lay down and fall asleep. 
    After a couple of hours of sleep you are woken up suddenly to a sharp pain in your neck and the sound of Adrian yelling and fighting someone.  you stand up and see Adrian 
    battling a mage, a blood mage but then he dissapears into black smoke.  Adrian explains to you that this was the blood mage he was looking for and he has realized he has been 
    followed.  also that he has injected you with a magic poison only he has the antidote to.  Adrian speculates you only have about 20 days to live unless you find the antidote
    so you and Adrian set off right away to find and kill the mage."
Else
    Display "You decide to stay in the inn despite the hole in the roof.  you dont know anything about this elf man and why he was so eager to have you stay with him, at least the innkeper
    isnt as shady as the elf.  its hard to sleep but you manage to go to sleep but after a couple of hours you awake to find your whole room is on fire, you see a dark 
    shadowy figure moving closer to you.  you try to cast a spell but he seems unnafected he keeps moving towards you until he stops suddenly right in front of you and stabs you
    right through the heart with his pointed staff.  You are dead"
End If

While decision == inn

Display "You and Adrian run into the town in search for the blood mage you start in the town square in the center of town, you can move up, down, left, or right. which way do 
you want to move"
Do
    Display "which way do you want to move now?"
    Input direction
    set turn=turn+1
        If direction == up or direction == Up Then
            Call moveUp
        Else
            If direction == down or direction == Down Then
                Call moveDown
            Else
                If direction == left or direction == Left Then
                    Call moveLeft
                Else
                    If direction == right or direction == Right Then
                        Call moveRight
                    Else 

                        Display "I dont understand"
                    End If
                End If
            End If
        End If
Until px==tx and py==ty or turn==20
If px==tx and py==ty Then
    Display "You found the antidote and are no longer effected by the poison!     now you must find and kill the blood mage.  To Be Continued"
Else 
    Display "You feel the poison slowly draining your life force, you fall dead on the ground"

Solution

  • Display "You and Adrian run into the town in search for the blood mage you start in the town square in the center of town, you can move up, down, left, or right. which way do you want to move"

    should be before while loop

    If direction == up or direction == Up Then
            Call moveUp
        Else
            If direction == down or direction == Down Then
                Call moveDown
            Else
                If direction == left or direction == Left Then
                    Call moveLeft
                Else
                    If direction == right or direction == Right Then
                        Call moveRight
                    Else 
                        Display "I dont understand"
                    End If
                End If
            End If
        End If
    

    use Switch statement if possible

    Record if movement is successful

    increment the turn at the end of the movement and only if the movement is successful