我一直在這個項目上工作了一段時間,這對我來說是一種新的語言,但我有一個經驗豐富的合作伙伴,他有點不屑於我。無論如何,現在我無法將文本從一個對象轉移到另一個對象。我在遊戲類中實例化一個對象,然後嘗試獲取它並將其保存到主類中的另一個對象,但是當我得到該對象時它是空的!我不知道這裏發生了什麼,我似乎無法弄清楚。值傳遞不正確?
,但不工作的部分是在顯示方法,當我嘗試繪製文本的問題:
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