菜鸟的问题 在线等

zhaoyangqing 2004-03-09 03:52:30
为什么我无法在Game中调用Scorer??
#include<iostream>
#define min(a, b) (((a) < (b)) ? (a) : (b))
using namespace std;

//////////////////////////////////////////////////////////////////////////////////////////////
//
//
/////////////////////////////////////////////////////////////////////////////////////////////
class Game
{
public:
Game();
public:
int score();
void add(int );
int scoreForFrame(int );
private:
void adjustCurrentFrame(int );
bool lastBallInFrame(int );
bool strike(int );
void advanceFrame();
private:
int itsCurrentFrame;
bool firstThrowInFrame;
Scorer itsScorer;//problem?
};
Game::Game()
{
itsCurrentFrame = 0;
firstThrowInFrame = true;
}
int Game::score()
{
return scoreForFrame(itsCurrentFrame);
}
void Game::add(int pins)
{
itsScorer.addThrow(pins);
adjustCurrentFrame(pins);
}
int Game::scoreForFrame(int theFrame)
{
return itsScorer.scoreForFrame(theFrame);
}
void Game::adjustCurrentFrame(int pins)
{
if (lastBallInFrame(pins))
advanceFrame();
else
firstThrowInFrame = false;

}
bool Game::lastBallInFrame(int pins)
{
return strike(pins) || !firstThrowInFrame;
}
bool Game::strike(int pins)
{
return (firstThrowInFrame && pins == 10);
}
void Game::advanceFrame()
{
itsCurrentFrame = min(10, itsCurrentFrame + 1);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
//
//
//////////////////////////////////////////////////////////////////////////////////////////////////
class Scorer
{
public:
Scorer();
public:
void addThrow(int);
int scoreForFrame(int);
private:
bool strike();
bool spare();
int nextTwoBallsForStrike();
int nextBallForSpare();
int twoBallsInFrame();
private:
int ball;
int itsThrows[21];
int itsCurrentThrow ;
};
Scorer::Scorer()
{
itsCurrentThrow = 0;
}
void Scorer::addThrow(int pins)
{
itsThrows[itsCurrentThrow++] = pins;
}
int Scorer::scoreForFrame(int theFrame)
{
ball = 0;
int score=0;
for (int currentFrame = 0;
currentFrame < theFrame;
currentFrame++)
{
if (strike())
{
score += 10 + nextTwoBallsForStrike();
ball++;
}
else if ( spare() )
{
score += 10 + nextBallForSpare();
ball+=2;
}
else
{
score += twoBallsInFrame();
ball+=2;
}
}

return score;
}

bool Scorer::strike()
{
return itsThrows[ball] == 10;
}

bool Scorer::spare()
{
return (itsThrows[ball] + itsThrows[ball+1]) == 10;
}

int Scorer::nextTwoBallsForStrike()
{
return itsThrows[ball+1] + itsThrows[ball+2];
}

int Scorer::nextBallForSpare()
{
return itsThrows[ball+2];
}

int Scorer::twoBallsInFrame()
{
return itsThrows[ball] + itsThrows[ball+1];
}

void main(void)
{
cout<<"JUVENTUS VIVA" << endl;
}

...全文
42 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

64,643

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧