我正在为我的编程概念课编写的游戏

时间:2015-05-08 03:35:30

标签: pseudocode

在项目中给了我randomcoord函数。这就是为什么在其他任何地方都没有提到它。这是伪代码,我只想检查它是否有任何问题。

该程序应该是一个10x10网格的游戏,玩家在中间开始并且必须输入上,下,左或右的命令,以便在20回合中找到毒药的解毒剂或者你死。

这是最低限度,但我添加了一个故事,我也想以某种方式添加墙壁,我只是想知道我到目前为止是否有任何问题,如果有人愿意帮助我在这里创建墙壁游戏。

墙壁的功能是,如果玩家登陆该空间,程序会显示“这里有一堵墙”,然后将玩家放回原来的位置。

有人可以帮我吗?

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"

1 个答案:

答案 0 :(得分:0)

  

显示&#34;你和阿德里安跑进城里寻找你在镇中心城镇广场开始的血法师,你可以向上,向下,向左或向右移动。哪种方式   你想移动&#34;

应该在while循环之前

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

尽可能使用Switch语句

记录移动是否成功

在移动结束时增加转弯,并且仅在移动成功时

相关问题