这里是一些代码:
void main()
{
GameEngine ge("phil", "anotherguy");
string response;
do {
ge.playGame();
cout << endl << "Do you want to (r)eplay the same battle, (s)tart a new battle, or (q)uit? ";
cin >> response;
} while(response == "r" || response == "R" || response == "s" || response == "S" );
}
GameEngine::GameEngine(string name1, string name2)
{
p1Name = name1;
p2Name = name2;
}
void GameEngine::playGame()
{
cout << "PLAY GAME" << endl;
Army p1, p2;
Battlefield testField;
RuleSet rs;
int xSize = 13; // Number of rows
int ySize = 13; // Number of columns
loadData(p1, p2, testField, rs, xSize, ySize);
...
}
void GameEngine::loadData(Army& p1, Army& p2, Battlefield& testField, RuleSet& rs, int& xSize, int& ySize)
{
string terrain = BattlefieldUtils::pickTerrain();
string armySplit[14];//id index 1
string ruleSplit[19];//in index 7
string armyP1, armyP2, ruleSet;
Skill p1Skills[8];
Skill p2Skills[8];
CreatureStack p1Stacks[20];
CreatureStack p2Stacks[20];
...
}
CreatureStack(){quantity = 0; isLive = false; id = -1;};
Army(){};
Battlefield(){};
RuleSet(){};
我已经发布了每一行代码,直到程序崩溃。这段代码长时间运行正常,我添加了一些在这里发布的代码之后才执行的东西,然后就出现了堆栈溢出,发生在
GameEngine::loadData()
的CreatureStack p2Stacks[20];
行。我做错了什么?这是栈可以处理的全部吗?我增加了Visual Studio中的堆栈大小,使错误消失,但这会严重减慢速度,那么如何找到问题的根源并解决它呢?
loadData()
(或playGame()
)吗? - sth