我一直在这个项目上工作了一段时间,这对我来说是一种新的语言,但我有一个经验丰富的合作伙伴,他有点不屑于我。无论如何,现在我无法将文本从一个对象转移到另一个对象。我在游戏类中实例化一个对象,然后尝试获取它并将其保存到主类中的另一个对象,但是当我得到该对象时它是空的!我不知道这里发生了什么,我似乎无法弄清楚。值传递不正确?
,但不工作的部分是在显示方法,当我尝试绘制文本的问题:
drawText((WinWidth/2)-225, (WinHeight/2) - 90, curQuestion.question.c_str());
curQuestion在顶部创建,但在实例化的鼠标方法:
curQuestion = g.getQuestion(col,row);
,这里是游戏类(在Cc.h)
class Game {
public:
Game(bool);
void initQuestions();
Question getQuestion(int, int);
string getQuestionText(int, int);
private:
Question questions[5][5];
};
Game::Game(bool m)
{
mp = m;
initQuestions();
}
void Game::initQuestions()
{
bool hasDouble = false;
srand(time(NULL));
int blarg = rand() % 25 + 1;
fstream questionFile;
questionFile.open("questions.txt", ifstream::in);
int cur = 0;
for(int c = 0; c < 5; c++)
{
for(int r = 0; r < 5; r++)
{
char * q = new char[256];
char * a = new char[256];
questionFile.getline(q,256);
questionFile.getline(a,256);
questions[c][r] = Question(c,r, false, q, a);
cout << questions[c][r].question.c_str() << questions[c][r].answer.c_str();
}
}
questionFile.close();
}
Question Game::getQuestion(int c, int r)
{
return questions[c][r];
}
string Game::getQuestionText(int c, int r)
{
return questions[c][r].question;
}
注:所谓的T中的COUT他的游戏方法确实返回它应该!
问题类:
class Question {
public:
int col;
int row;
bool dailyDouble;
string question;
string answer;
int value;
Question();
Question(int, int, bool, string, string);
bool checkAnswer(string);
string getQuestion();
};
Question::Question() { }
Question::Question(int c, int r, bool d,string q, string a)
{
col = c; row = r; dailyDouble = d; question = q, answer = a;
cout << "TEST> Q: " << question << ", A: " << answer << endl;
if(d)
value = r * 200 * 2;
else
value = r * 200;
}
bool Question::checkAnswer(string answer)
{
if(answer.find("What is") && answer.find(answer))
return true;
return false;
}
string Question::getQuestion() {
return question;
}
我实在不明白这是怎么回事错在这里,任何帮助是极大的赞赏。我希望一旦我弄清楚发生了什么问题,我就可以自己完成!
Way.Too.Much.Code。永远记住[this](http://sscce.org)。 – Xeo 2011-05-18 00:49:32
对不起,我不确定是否有人试图帮助将需要所有..想要在安全的一面。我会砍掉它。 – CaffeinatedCM 2011-05-18 00:54:34
@Java:我们只需要知道错误的地方。其他一切只会分散注意力。 :) – Xeo 2011-05-18 00:58:08