gpt4 book ai didi

c++ - 返回到 C++ 中的上一个 if 语句

转载 作者:行者123 更新时间:2023-11-28 02:57:34 25 4
gpt4 key购买 nike

<分区>

这是我用 C++ 编写的冒险游戏。我一直在尝试新事物来提高它的效率。我想知道是否有更有效的设置级别的方法?截至目前,我只是将级别定义为字符串,这似乎比需要的效率低得多。特别是对于 if 语句,它们是聚集的。

#include <iostream>
using namespace std;

int main(int argc, const char * argv[])
{
string name;
short choice;
string choice2;

int health = 100;

// handling errors
string nope = "Are you H@CK3R, that command does not exist";

// handling directions
string west = "You went West. ";
string east = "You went East. ";
string south = "You went South. ";
string north = "Your went North. ";

// Handles the areas of the map

// Level 1
string north1 = "You are now standing in an empty clearing. There is a path going North, East, and West.";
string south1 = "You are now back where you started.";
string east1 = "There is nothing of significance this way.";
string west1 = "You see smoke off farther west. There is also a path to your North.";

// level 2
string north2 = "You have continued North, the trees are getting more thick. There is no longer a trail to the East and West.";
string south2 = "You are now back in the empty clearing.";
string east2 = "You cannot go this way.";
string west2 = "You cannot go this way.";

// level 3

// level 4

// level 5

// level 6

// level 7

// level 8

// level 9

// level 10

system("clear");
std::cout << "Please enter your name.\n";
cin >> name;
cout << "Welcome " << name << " to the [place holder]" << endl;
cout << "Type 1 to start, press 2 for credits, press 3 to quit." << endl;
std::cin >> choice;

// main game block
switch (choice) {
system("clear");
case 1:
system("clear");
while(1) {
cout << "You wake up on a beach, there are trees to your North, and open beach to your East and West." << endl;
cin >> choice2;
if (choice2 == "north") {
system("clear");
while(2) {
cout << north << north1 << endl;
cin >> choice2;
if(choice2 == "north"){
system("clear");
cout << north << north2 << endl;
cin >> choice2;
} else if("south") {
cout << south << south2 << endl;
break;
} else if("east") {
cout << east << east2 << endl;
break;
} else if("west") {
cout << west << west2 << endl;
break;
} else {
system("clear");
cout << nope << endl;
}
}
break;
}else if (choice2 == "south") {
system("clear");
cout << south << south1 << endl;
cin >> choice2;
break;
}else if (choice2 == "east") {
system("clear");
cout << east << east1 << endl;
cin >> choice2;
break;
}else if (choice2 == "west") {
system("clear");
cout << west << west1 << endl;
cin >> choice2;
break;
} else if (choice2 == "hacker") {
system("clear");
cout << "nope";
break;
}else {
system("clear");
cout << nope << endl;
}
}
break;

case 2:
system("clear");
cout << "The Village Part 2" << endl;
cout << "Coded ----- Kyle Sherman" << endl;
cout << "Coded ----- Phillip Noble" << endl;
cout << "Story ----- Pillip Noble" << endl;
cout << "Story ----- Kyle Sherman" << endl;
break;

case 3:
break;
}
cout << endl;
/**
// Handles displaying the stats and help
if(choice2 == "help") {
cout << "List of commands" << endl;
cout << "stats ----- Display the stats" << endl;
cout << "clear ----- Clears the screen" << endl;
cout << "north ----- Goes North" << endl;
cout << "south ----- Goes South" << endl;
cout << "east ------ Goes East" << endl;
cout << "west ------ Goes West" << endl;
}else if(choice2 == "stats") {
system("clear");
cout << name << "'s health: " << health << endl;
}else if(choice2 == "clear") {
system("clear");
}
**/
return 0;
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com