- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我尝试运行代码时,总是出现在最后一行,因此我一直收到此错误。我正在尝试制作基于文本的冒险游戏。似乎(当我运行此命令时)这是我唯一的错误。但是,如果有更多人注意到您的帮助,将不胜感激。
所以我的问题是:(1)这到底是什么意思,(2)我如何解决它,以及(3)将来如何避免这种情况?
只是警告:此代码有800多行,因此请尽量采取。
编辑:好的,我已经从以前弄清楚了问题,但是,现在我类中的语句将不会输出。我类(class)中的“cout”语句(例如,fairy()类)以及房间标题和描述都将跳过。我将代码重新排列了一下。
//Chandler Witthaus
//Final Project- Text Adventure
//Professor Caleb Fowler
//17 December 2016
#include <iostream>
#include <string>
#include <stdlib.h>
int playerGold,
findDirect,
exitN,
exitS,
exitE,
exitW;
std::string start,
direction,
roomName,
roomDiscription;
using namespace std;
class Monster {
public:
void fairy() {
std::string monEncounter = "A fairy is stuck in a discarded can. You let her out and she rewards you with 5 gold.\n";
playerGold = playerGold + 5;
}
void unicorn() {
std::string monEncounter = "You see a unicorn frolicking in this room. The animal stares at you for a moment "
"before pointing its horn at a sack on the floor containing 20 gold.\n";
playerGold = playerGold + 20;
}
void nymph() {
std::string monEncounter = "A beautiful nymph approached you, she offers you 100 gold for a brief fling. You are "
"reminded of your college days but hastily accept.\n";
playerGold = playerGold + 100;
}
void imp() {
std::string monEncounter = "A little imp runs by, snatching 2 gold from your pouch. He disappears before you are able to catch him.\n";
playerGold = playerGold - 2;
}
void wisp() {
std::string monEncounter = "A will-o'-the-wisp entices you to follow it. You bang into a wall, dropping your gold pouch. You pick it back "
"up but are unable to find 10 pieces.\n";
playerGold = playerGold - 10;
}
void goblin() {
std::string monEncounter = "A greedy goblin ambushes you. You fight him off, but not before he takes 15 gold.\n";
playerGold = playerGold - 15;
}
void centaur() {
std::string monEncounter = "You encounter a wild centaur, who is bucking wildly. You try to sneak around him but are struck, losing 20 gold.";
playerGold = playerGold - 20;
}
void wraith() {
std::string monEncounter = "Upon entering you are confronted by a wraith. It throws a curse on you, but thinking fast, you "
"eat 50 gold pieces. This makes the wraith very uncomfortable, it quickly removes the curse and leaves without "
"making eye contact.\n";
playerGold = playerGold - 50;
}
void cyclops() {
std::string monEncounter = "You encounter a massive cyclops, he attempts to eat you. However, acting quickly, you make "
"a replica of yourself out of 80 gold pieces. The cyclops eats the replica and chokes to "
"death. You are not willing to recover the gold.\n";
playerGold = playerGold - 80;
}
void hydra() {
std::string monEncounter = "You encounter a massive hydra. He will let you pass for 15 gold, you begrudgingly agree. You begin "
"to walk past, but the other heads of the hydra demand their pay. The toll ends up costing 135 gold. You quietly curse the hydra.\n";
playerGold = playerGold - 135;
}
void bird() {
std::string monEncounter = "You see a bird, this must be the exit, but which way?\n";
}
};
class RandomSpawn {
public:
void spawnEnemy() {
int spawn = rand() % 10;
if (spawn <= 4) {
Monster objectImp;
objectImp.imp();
}
if (spawn == 5) {
Monster objectWisp;
objectWisp.wisp();
}
if (spawn == 6) {
Monster objectGoblin;
objectGoblin.goblin();
}
if (spawn == 7) {
Monster objectCentaur;
objectCentaur.centaur();
}
if (spawn == 8) {
Monster objectWraith;
objectWraith.wraith();
}
if (spawn == 9) {
Monster objectCyclops;
objectCyclops.cyclops();
}
if (spawn == 10) {
Monster objectHydra;
objectHydra.hydra();
}
}
};
class Treasure {
public:
void startChest() {
std::string chestType = "You find a beautiful chest. It is filled with 1000 gold. It makes you so excited that you don't even notice "
"as the entrance disappears. Looks like you will have to find your own way out.\n";
playerGold = 1000;
}
void smallChest() {
std::string chestType = "You find a small chest containing 150 gold. You feel a strong urge to shower in it, but you hold yourself back.\n";
playerGold = playerGold + 150;
}
void mediumChest() {
std::string chestType = "You find a chest with a pirate symbol on it. Ignoring it, you plunder 300 gold, feeling a thrill from the "
"steal. You think you may be a kleptomaniac.";
playerGold = playerGold + 300;
}
void largeChest() {
std::string chestType = "You find a large chest, no not that kind. You get 500 gold...dirty\n";
playerGold = playerGold + 500;
}
};
class Room {
public:
void room11() {
std::string roomName = "North-West corner";
std::string roomDiscription = "";
int roomId = 11;
Monster objectUnicorn;
objectUnicorn.unicorn();
int exitN = 0;
int exitS = 12;
int exitE = 21;
int exitW = 0;
}
void room21() {
std::string roomName = "Storage room";
std::string roomDiscription = "";
int roomId = 21;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 0;
int exitS = 22;
int exitE = 31;
int exitW = 11;
}
void room31() {
std::string roomName = "Grey room";
std::string roomDiscription = "";
int roomId = 31;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 0;
int exitS = 32;
int exitE = 41;
int exitW = 21;
}
void room41() {
std::string roomName = "Clock room";
std::string roomDiscription = "";
int roomId = 41;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 0;
int exitS = 42;
int exitE = 51;
int exitW = 31;
}
void room51() {
std::string roomName = "North-East corner";
std::string roomDiscription = "";
int roomId = 51;
Monster objectNymph;
objectNymph.nymph();
int exitN = 0;
int exitS = 52;
int exitE = 0;
int exitW = 41;
}
void room12() {
std::string roomName = "Chair room";
std::string roomDiscription = "";
int roomId = 12;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 11;
int exitS = 13;
int exitE = 22;
int exitW = 0;
}
void room22() {
std::string roomName = "Alchemy room";
std::string roomDiscription = "";
int roomId = 22;
Treasure objectLargeChest;
objectLargeChest.largeChest();
int exitN = 21;
int exitS = 23;
int exitE = 32;
int exitW = 12;
}
void room32() {
std::string roomName = "Sun room";
std::string roomDiscription = "";
int roomId = 32;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 32;
int exitS = 33;
int exitE = 42;
int exitW = 22;
}
void room42() {
std::string roomName = "Meaning of the universe room";
std::string roomDiscription = "";
int roomId = 42;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 41;
int exitS = 43;
int exitE = 52;
int exitW = 32;
}
void room52() {
std::string roomName = "Hallway";
std::string roomDiscription = "";
int roomId = 52;
Monster objectBird;
objectBird.bird();
int exitN = 51;
int exitS = 53;
int exitE = 62;
int exitW = 42;
}
void room13() {
std::string roomName = "Medical room";
std::string roomDiscription = "";
int roomId = 13;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 12;
int exitS = 13;
int exitE = 23;
int exitW = 0;
}
void room14() {
std::string roomName = "Guest bedroom";
std::string roomDiscription = "";
int roomId = 14;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 13;
int exitS = 15;
int exitE = 24;
int exitW = 0;
}
void room15() {
std::string roomName = "Guest kitchen";
std::string roomDiscription = "";
int roomId = 15;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 14;
int exitS = 16;
int exitE = 25;
int exitW = 0;
}
void room16() {
std::string roomName = "Storage room";
std::string roomDiscription = "";
int roomId = 16;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 15;
int exitS = 17;
int exitE = 26;
int exitW = 0;
}
void room17() {
std::string roomName = "Hallway";
std::string roomDiscription = "";
int roomId = 17;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 16;
int exitS = 18;
int exitE = 27;
int exitW = 0;
}
void room18() {
std::string roomName = "South-West Corner";
std::string roomDiscription = "";
int roomId = 18;
Treasure objectSmallChest;
objectSmallChest.smallChest();
Monster objectWraith;
objectWraith.wraith();
int exitN = 17;
int exitS = 0;
int exitE = 28;
int exitW = 0;
}
void room23() {
std::string roomName = "Library room";
std::string roomDiscription = "";
int roomId = 23;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 22;
int exitS = 24;
int exitE = 33;
int exitW = 13;
}
void room24() {
std::string roomName = "Washroom";
std::string roomDiscription = "";
int roomId = 24;
Treasure objectSmallChest;
objectSmallChest.smallChest();
int exitN = 23;
int exitS = 25;
int exitE = 34;
int exitW = 14;
}
void room25() {
std::string roomName = "Workshop";
std::string roomDiscription = "";
int roomId = 25;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 24;
int exitS = 26;
int exitE = 35;
int exitW = 15;
}
void room26() {
std::string roomName = "Courtyard";
std::string roomDiscription = "";
int roomId = 26;
Monster objectNymph;
objectNymph.nymph();
int exitN = 25;
int exitS = 27;
int exitE = 36;
int exitW = 16;
}
void room27() {
std::string roomName = "Garden";
std::string roomDiscription = "";
int roomId = 27;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 26;
int exitS = 28;
int exitE = 37;
int exitW = 17;
}
void room28() {
std::string roomName = "Chapel";
std::string roomDiscription = "";
int roomId = 28;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 27;
int exitS = 0;
int exitE = 38;
int exitW = 18;
}
void room33() {
std::string roomName = "Pantry";
std::string roomDiscription = "";
int roomId = 33;
Monster objectFairy;
objectFairy.fairy();
int exitN = 32;
int exitS = 34;
int exitE = 43;
int exitW = 23;
}
void room34() {
std::string roomName = "Master chambers";
std::string roomDiscription = "";
int roomId = 34;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 33;
int exitS = 35;
int exitE = 44;
int exitW = 24;
}
void room35() {
std::string roomName = "Guard house";
std::string roomDiscription = "";
int roomId = 35;
Monster objectFairy;
objectFairy.fairy();
int exitN = 34;
int exitS = 36;
int exitE = 45;
int exitW = 25;
}
void room36() {
std::string roomName = "Lavatory";
std::string roomDiscription = "";
int roomId = 36;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 35;
int exitS = 37;
int exitE = 46;
int exitW = 26;
}
void room37() {
std::string roomName = "Foyer";
std::string roomDiscription = "";
int roomId = 37;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 36;
int exitS = 38;
int exitE = 47;
int exitW = 27;
}
void room38() {
std::string roomName = "Gatehouse";
std::string roomDiscription = "";
int roomId = 38;
Treasure objectStarterChest;
objectStarterChest.startChest();
int exitN = 37;
int exitS = 0;
int exitE = 48;
int exitW = 28;
}
void room43() {
std::string roomName = "Walk-in closet";
std::string roomDiscription = "";
int roomId = 43;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 42;
int exitS = 44;
int exitE = 53;
int exitW = 33;
}
void room44() {
std::string roomName = "Sitting room";
std::string roomDiscription = "";
int roomId = 44;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 43;
int exitS = 45;
int exitE = 54;
int exitW = 34;
}
void room45() {
std::string roomName = "Great Hall";
std::string roomDiscription = "";
int roomId = 45;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 44;
int exitS = 46;
int exitE = 55;
int exitW = 35;
}
void room46() {
std::string roomName = "Kitchen";
std::string roomDiscription = "";
int roomId = 46;
Treasure objectSmallChest;
objectSmallChest.smallChest();
int exitN = 45;
int exitS = 47;
int exitE = 56;
int exitW = 36;
}
void room47() {
std::string roomName = "Buttery";
std::string roomDiscription = "";
int roomId = 47;
Monster objectUnicorn;
objectUnicorn.unicorn();
int exitN = 46;
int exitS = 48;
int exitE = 57;
int exitW = 37;
}
void room48() {
std::string roomName = "Storage room";
std::string roomDiscription = "";
int roomId = 48;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 47;
int exitS = 0;
int exitE = 58;
int exitW = 38;
}
void room53() {
std::string roomName = "Hallway";
std::string roomDiscription = "";
int roomId = 53;
Treasure objectMediumChest;
objectMediumChest.mediumChest();
int exitN = 52;
int exitS = 54;
int exitE = 0;
int exitW = 43;
}
void room54() {
std::string roomName = "Compost shed";
std::string roomDiscription = "";
int roomId = 54;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 53;
int exitS = 55;
int exitE = 0;
int exitW = 44;
}
void room55() {
std::string roomName = "Tool shed";
std::string roomDiscription = "";
int roomId = 55;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 54;
int exitS = 56;
int exitE = 0;
int exitW = 45;
}
void room56() {
std::string roomName = "Blacksmith";
std::string roomDiscription = "";
int roomId = 56;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 55;
int exitS = 57;
int exitE = 0;
int exitW = 46;
}
void room57() {
std::string roomName = "Guardroom";
std::string roomDiscription = "";
int roomId = 57;
Treasure objectMediumChest;
objectMediumChest.mediumChest();
Monster objectWisp;
objectWisp.wisp();
int exitN = 56;
int exitS = 58;
int exitE = 0;
int exitW = 47;
}
void room58() {
std::string roomName = "South-East corner";
std::string roomDiscription = "";
int roomId = 58;
RandomSpawn objectEnemy;
objectEnemy.spawnEnemy();
int exitN = 57;
int exitS = 0;
int exitE = 0;
int exitW = 48;
}
};
class Direction {
public:
void roomChanging() {
if (findDirect == 11) {
Room objectRoom11;
objectRoom11.room11();
}
if (findDirect == 12){
Room objectRoom12;
objectRoom12.room12();
}
if (findDirect == 13){
Room objectRoom13;
objectRoom13.room13();
}
if (findDirect == 14){
Room objectRoom14;
objectRoom14.room14();
}
if (findDirect == 15){
Room objectRoom15;
objectRoom15.room15();
}
if (findDirect == 16){
Room objectRoom16;
objectRoom16.room16();
}
if (findDirect == 17){
Room objectRoom17;
objectRoom17.room17();
}
if (findDirect == 18){
Room objectRoom18;
objectRoom18.room18();
}
if (findDirect == 21){
Room objectRoom21;
objectRoom21.room21();
}
if (findDirect == 22){
Room objectRoom22;
objectRoom22.room22();
}
if (findDirect == 23){
Room objectRoom23;
objectRoom23.room23();
}
if (findDirect == 24){
Room objectRoom24;
objectRoom24.room24();
}
if (findDirect == 25){
Room objectRoom25;
objectRoom25.room25();
}
if (findDirect == 26){
Room objectRoom26;
objectRoom26.room26();
}
if (findDirect == 27){
Room objectRoom27;
objectRoom27.room27();
}
if (findDirect == 28){
Room objectRoom28;
objectRoom28.room28();
}
if (findDirect == 31){
Room objectRoom31;
objectRoom31.room31();
}
if (findDirect == 32){
Room objectRoom32;
objectRoom32.room32();
}
if (findDirect == 33){
Room objectRoom33;
objectRoom33.room33();
}
if (findDirect == 34){
Room objectRoom34;
objectRoom34.room34();
}
if (findDirect == 35){
Room objectRoom35;
objectRoom35.room35();
}
if (findDirect == 36){
Room objectRoom36;
objectRoom36.room36();
}
if (findDirect == 37){
Room objectRoom37;
objectRoom37.room37();
}
if (findDirect == 38){
Room objectRoom38;
objectRoom38.room38();
}
if (findDirect == 41){
Room objectRoom41;
objectRoom41.room41();
}
if (findDirect == 42){
Room objectRoom42;
objectRoom42.room42();
}
if (findDirect == 43){
Room objectRoom43;
objectRoom43.room43();
}
if (findDirect == 44){
Room objectRoom44;
objectRoom44.room44();
}
if (findDirect == 45){
Room objectRoom45;
objectRoom45.room45();
}
if (findDirect == 46){
Room objectRoom46;
objectRoom46.room46();
}
if (findDirect == 47){
Room objectRoom47;
objectRoom47.room47();
}
if (findDirect == 48){
Room objectRoom48;
objectRoom48.room48();
}
if (findDirect == 51){
Room objectRoom51;
objectRoom51.room51();
}
if (findDirect == 52){
Room objectRoom52;
objectRoom52.room52();
}
if (findDirect == 53){
Room objectRoom53;
objectRoom53.room53();
}
if (findDirect == 54){
Room objectRoom54;
objectRoom54.room54();
}
if (findDirect == 55){
Room objectRoom55;
objectRoom55.room55();
}
if (findDirect == 56){
Room objectRoom56;
objectRoom56.room56();
}
if (findDirect == 57){
Room objectRoom57;
objectRoom57.room57();
}
if (findDirect == 58){
Room objectRoom58;
objectRoom58.room58();
}
}
};
int main()
{
cout << "Welcome\n\n";
cout << "You are playing 'Deep Delver'.\n\n";
cout << "The object of this game is to enter this old castle and emerge with as much gold as possible.\n\n";
cout << "If you lose all your gold, you lose.\n\n";
cout << "Here are the controls:\n Enter 'N', 'S', 'E', or 'W'. to go in that direction.\n";
cout << "To see the description of the room your in press 'L'.\n\nGood luck!\n\n";
cout << "Enter anything to start: ";
cin >> start;
Room objectStartingRoom;
objectStartingRoom.room38();
do {
cout << "\n\nWhich way would you like to go?\n\n";
stupid:
cout << "Cardnal direction: ";
cin >> direction;
cout << endl << endl;
if (direction == "W" || direction == "w")
findDirect = exitW;
else if (direction == "E" || direction == "e")
findDirect = exitE;
else if (direction == "N" || direction == "n")
findDirect = exitN;
else if (direction == "S" || direction == "s")
findDirect = exitS;
else if (findDirect == 0)
{
cout << "You bump into a wall...like an idiot. Go a different direction.\n\n";
goto stupid;
}
else
{
cout << "That is not a direction...stupid.\n\n";
goto stupid;
}
Direction objectDirection;
objectDirection.roomChanging();
cout << roomName << endl << endl;
cout << roomDiscription << endl << endl;
} while (exitE != 62);
cout << "\n\nCongradulations!!!\n\n";
cout << "You have found your way out with " << playerGold << " gold. Don't spend it all in one place!";
}
最佳答案
您缺少花括号。您永远不会关闭roomChanging()
函数。
关于c++ - 不断收到错误: expected unqualified id at end of input- C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41008257/
我有一个静态类。 static class AppDirectory { public static string PACSTEMP = Path.Combine(Path.GetTempPa
我已经设置了一个启用了推送通知的 iOS 应用。 我可以将消息推送到应用程序,例如角标(Badge)计数工作并相应更新。 但我从未在锁屏或其他地方看到标准的推送通知弹出窗口,但手机会振动,因此消息会通
我们有一个带有 Web 应用程序和一堆 Windows 服务的系统,它们在做一些后台工作。 每当我们需要对系统进行更实质性的更改时,我们最终不得不发出 IIS 重置,然后手动重新启动所有相关的 Win
我有以下几行 John SMith: A Pedro Smith: B Jonathan B: A John B: B Luis Diaz: A Scarlet Diaz: B 我需要获得所有获得
我正在编写一个 Java 客户端(在 weblogic 10.3 上)来调用一个安全的网络服务。我已获得安装在 cacerts、DemoIdentity.jks 和 DemoTrust,jks 中的客
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎偏离主题,因为它缺乏足够的信息来诊断问题。 更详细地描述您的问题或 include a mini
我正在尝试调用void方法addToList,该方法将通过用户传递给它的两个字符串除外。我检查了dataSource类,以确保它确实接受了那些作为参数。问题是我在该方法调用上始终收到标识符>预期错误,
我的任务:使用scanner方法从一行数据中提取字符串、 float 和整数。 数据格式为: Random String, 240.5 51603 Another String, 41.6 59087
这个问题已经有答案了: What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? (25 个回答)
首先我实例化一个游戏状态 class GameState extends state{ ArrayList levels; int currentLevelID; public GameState()
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
我有一个实现为单例的 Controller 对象,它有一个可以随时驱逐对象的缓存。当一个对象即将被删除时,我想通知任何使用此 Controller 的类,以便它们能够做出适当的响应。我对这种行为的第一
因此,我尝试跨集群发送消息,该消息将包含一个 User 对象,该对象是一个可序列化类。 当我发送 String 或 int 时,它工作正常,消息发送没有问题,并且集群上的所有 channel 都收到它
我试图创建的程序是一个基本游戏,用户输入网格大小,选择 block 接收增加分数的奖品、从分数中夺走分数的强盗或结束游戏的炸弹。我收到堆栈流错误,但我不明白为什么? 抱歉,代码量很大,我只是无法找到问
使用此代码我会得到什么ConcurrentModificationException?我有一个同步(监听器)锁。 private void notifyListeners(MediumRenditio
我想在捕获 DeadlineExceededError 后正确退出。我还剩下多少钱来清理? 例如, try: do_some_work() except DeadlineExceededError
我有 2 个 Intranet 站点: http://intranetv1/ http://intranetv2/ v1基于.NET 1.1,v2基于.NET 3.5 在 v1 上,我创建了一个网页,
我有一个在 Linux 3.12 上运行的 C 程序。该程序产生几个子进程。其中一个进程会生成一个线程,该线程运行一段时间然后终止。当该子进程运行时,它会执行 epoll_wait()。 epoll_
我能够将 APNS 集成到我的应用程序中。现在我想在用户点击它或用户在使用应用程序时收到通知时处理通知。我使用下面的代码在收到通知时显示警报对话框: func application(applicat
当我试图在浏览器上运行这段代码时,出现了以下错误。"错误响应错误代码:501消息:不支持的方法(“POST”)。错误码解释:501-服务器不支持该操作。" 浏览器控制台出现以下错误: "1.加载资源失
我是一名优秀的程序员,十分优秀!