我已经完成了这个任务,但我只想有人检查一下,以确保它是正确的。以下说明:
创建伪代码或流程图,逻辑上勾勒出允许玩家在房间之间移动的步骤,使用命令向北、南、东和西移动。确保解决以下问题:
,
,
,
这是我的密码:
START
currentRm=’Foyer’
PRINT ‘You are in the Foyer
BEGIN LOOP
INPUT ‘Which direction do you want to go?’
IF currentRm IS ‘Foyer’
IF direction IS ‘East’
currentRm = ‘Kitchen’
OUTPUT ‘You are in the Kitchen’
ELSE
OUTPUT ‘Invalid Direction. Try again’
ELIF currentRm IS ‘Kitchen’
INPUT ‘Where do you want to go?’
IF direction IS ‘North’
currentRm = ‘Living Room’
OUTPUT’You are in the Living Room’
ELIF direction IS ‘South’
currentRm = ‘Dining Room’
OUTPUT’You are in the Dining Room’
ELIF direction IS ‘East’
currentRm = ‘Bedroom’
OUTPUT ‘You are in the Bedroom’
ELIF direction IS ‘West’
currentRm = ‘Foyer’
OUTPUT ‘You are in the Foyer’
ELSE
OUTPUT ‘Invalid Direction. Try again’
ELIF currentRM IS ‘Living Room’
INPUT ‘Where do you want to go?’
IF direction IS ‘East’
currentRm = ‘Gaming Room’
PRINT ‘You are in the Gaming Room’
ELIF direction IS ‘South’
currentRm = ‘Kitchen’
OUTPUT ‘You are in the Kitchen’
ELSE
OUTPUT ‘Invalid Direction. Try again’
ELIF currentRm IS ‘Gaming Room’
INPUT ‘Where do you want to go?’
IF direction IS ‘West’
currentRm = ‘Living Room’
OUTPUT ‘You are in the Living Room’
ELSE
OUTPUT ‘Invalid Direction. Try again’
ELIF currentRm IS ‘Dining Room’
INPUT ‘Where do you want to go?’
IF direction IS ‘North’
currentRm = ‘Kitchen’
OUTPUT ’You are in the Kitchen’
ELIF direction IS ‘East’
currentRm = ‘Garage’
OUTPUT ‘You are in the Garage’
ELSE
OUTPUT ‘Invalid Direction. Try again’
ELIF currentRm IS ‘Garage’
INPUT ‘Where do you want to go?’
IF direction IS ‘West’
currentRm = ‘Dining Room’
OUTPUT ‘You are in the Dining Room’
ELSE
OUTPUT ‘Invalid Direction. Try again’
ELIF currentRm IS ‘Bedroom’
INPUT ‘Where do you want to go?’
IF direction IS ‘West’
currentRm = ‘Kitchen’
OUTPUT ‘You are in the Kitchen’
ELIF direction IS ‘North’
currentRm = ‘Bathroom’
OUTPUT ‘You are in the Bathroom’
ELSE
OUTPUT ‘Invalid Direction. Try again’
ELIF currentRm IS ‘Bathroom’
INPUT ‘Where do you want to go?’
IF direction is ‘South’
currentRm = ‘Bedroom’
OUTPUT ‘You are in the Bedroom’
ELSE
OUTPUT ‘Invalid Direction. Try again’
END LOOP
IF currentRm = ‘Gaming Room’
OUTPUT ‘Game Over’
发布于 2022-06-05 15:01:54
几点意见:
“你想往哪个方向走?”“你想去哪里?”
这是不对的。第一个问题是不管你住在哪个房间,也不应该问特定房间的第二个问题。因此,从所有这些INPUT
块中删除该ELIF
语句.
如果currentRm =“游戏室”输出“游戏结束”
如果打算在用户进入游戏厅时显示该输出,并且程序可能应该结束,则需要在循环中移动这段代码,在该循环中,您已经检测到用户进入了该房间:
如果方向是‘东方’currentRm =‘游戏室’打印‘你是在游戏室’输出‘游戏超过’退出循环‘
PRINT ‘You are in the ’, currentRm
组合PRINT ‘You are in the Kitchen’
的所有变体,并将该语句移动到对所有情况都执行该语句的位置。在实际编程语言中,
IF..ELIF
块。该数据结构的外观将取决于编程语言.IF
或ELIF
语句之后代码更缩进(4个空格是一个很好的标准),并且作为该块一部分的所有语句都在相同的缩进级别上。https://stackoverflow.com/questions/72508235
复制相似问题