Exemplo n.º 1
0
VOID Player::turn(ProgramManager &rProgramManager, GameInfo &rGameInfo)
{
	if(rGameInfo.first == first_)
	{
		if(rGameInfo.scoredEight) rProgramManager.endGame(name_ + L" выиграл со счЄтом: " + getScoreWStr());
		else if(rGameInfo.scoredZero)
		{ 
			rGameInfo.scoredZero = FALSE;
			rGameInfo.drawCue    = FALSE;
			rGameInfo.turn       = Turns::SetZeroPos;

			rProgramManager.updateZero();
		}
		else if(rGameInfo.scoredWrong)
		{
			rGameInfo.scoredWrong = FALSE;
			rGameInfo.drawCue     = FALSE;
			rGameInfo.turn        = Turns::SetPos;
		}

		if(!copied_) 
		{
			memcpy(tmpBallsStatus_, rProgramManager.getScored(), sizeof(tmpBallsStatus_));
			memcpy(tmpBallsPos_, rProgramManager.getPoints(), sizeof(tmpBallsPos_));

			copied_ = !copied_;
		}

		if(rGameInfo.turn == Turns::SetZeroPos)
		{ 
			rProgramManager.setBallCoords(rProgramManager.getMousePos());

			rProgramManager.work(textToDraw(), PointF(0, 0), static_cast<ARGB>(Color::LightGreen), FALSE);

			if(Key(VK_END)) 
			{
				rGameInfo.turn = Turns::Blow;

				rGameInfo.drawCue = TRUE;
			}
		}
		else if(rGameInfo.turn == Turns::SetPos)
		{
			rProgramManager.setBallCoords(rProgramManager.getMousePos(), rGameInfo.wrongBall);
			rProgramManager.work(textToDraw(), PointF(0, 0), static_cast<ARGB>(Color::LightGreen), FALSE);
			
			if(Key(VK_END)) 
			{
				rGameInfo.turn = Turns::Blow;

				rGameInfo.drawCue = TRUE;
			}
		}
		else if(rGameInfo.turn == Turns::Blow) 
		{	
			if(Key(VK_SPACE))
			{
				POINT cursor = { 0, 0 };
				GetCursorPos(&cursor);		

				rProgramManager.nextMove();
				rGameInfo.turn = Turns::Step;
			}
			else rProgramManager.work(textToDraw());
		}
		else if(rGameInfo.turn == Turns::Step)
		{
			if(!rProgramManager.stopBalls()) rProgramManager.work(textToDraw());
			else
			{
				updateScore(checkScored(rProgramManager, rGameInfo));
				if(!checkPoints(rProgramManager)) if(score_ != 0) score_--;
				resetValues();
				rGameInfo.resetToNext(); 
			}		
		}
	}
	else rProgramManager.work(textToDraw(), PointF(static_cast<REAL>(rProgramManager.getMemDCWindow().width - 6 * sizestenaRIGHT), 0), static_cast<ARGB>(Color::Red), rGameInfo.drawCue);
}
Exemplo n.º 2
0
WORD Player::checkScored(ProgramManager &rProgramManager, GameInfo &rGameInfo)
{
	WORD ret_val = 0;
	for(size_t i = 0; i < NUMBER_OF_BALLS; i++)
		if(tmpBallsStatus_[i] != rProgramManager.getScored()[i])
		{
			BallType ballType = getBallType(static_cast<Balls::Ball>(i));
			
			if(!rGameInfo.firstScore && ballType != BallType::Zero) 
			{
				rGameInfo.firstScore = !rGameInfo.firstScore;
				ballType_ = ballType;

				rGameInfo.ballType2 = (ballType_ == BallType::Solid)? BallType::Striped : BallType::Solid;
			}
			else if(ballType_ == BallType::NoType && rGameInfo.firstScore) ballType_ = rGameInfo.ballType2;
				 
			switch(ballType)
			{
			case BallType::Zero:
				rProgramManager.updateZero();
				rGameInfo.scoredZero = TRUE;
				if(score_ != 0) score_--;
				break;
			case BallType::Solid: 
				if(i == Balls::Ball::eighth)
				{
					rGameInfo.scoredEight = TRUE;
					score_ = 0;

					return FALSE;
				}
				else
				{
					if(ballType_ == BallType::Solid) 
					{
						rGameInfo.scored = TRUE;
						ret_val++;
					}
					else 
					{
						rGameInfo.scoredWrong = TRUE;
						rGameInfo.wrongBall = static_cast<Balls::Ball>(i);
						if(score_ != 0) score_--;
					}
				}
				break;
			case BallType::Striped: 
				if(ballType_ == BallType::Striped) ret_val++;
				else 
				{
					rGameInfo.scoredWrong = TRUE;
					rGameInfo.wrongBall = static_cast<Balls::Ball>(i);
					if(score_ != 0) score_--;
				}
				break;
			default: PostQuitMessage(-999);
			}			
		}
	
	return ret_val;
}