示例#1
0
bool placevalid(int x, int y, bool is_vertical, int length, char ** board)
{
   
    if (is_vertical)
    {
        for (int ii=x; ii<x+length; ii++)
        { if (OutofBounds(ii, y))
            {
                return false;
            }
            if (board[y][ii]!='-')
            return false;
        }
    }
    if (!is_vertical)
    {
        for (int ii=y; ii<y+length; ii++)
        {
            if (OutofBounds(x,ii))
            {
                return false;
            }
            if (board[ii][x]!='-')
            return false;
        }
    }
    return true;
}
示例#2
0
文件: FMain.cpp 项目: bjonke/Golf
//void FireGolfBall(bool &set,int &x2,int &y2,int &isp,GolfClub &golfclub,Bools &bo, float &value,Pos &windPos,Pos &WPos)
void FireGolfBall(bool &set,int &x2,int &y2,int &isp,GolfClub &golfclub, float &value,Pos &windPos,Pos &WPos)
{
	static float tempX,tempY,atX,atY;

	if(set)
	{	
		atX=  ((x2-(isplaying[isp].ball.x-bredd1))/(sqrtf(powf(abs(x2-(isplaying[isp].ball.x-bredd1)),2)+powf(abs(y2-(isplaying[isp].ball.y-hojd1)),2))));
		atY=  ((y2-(isplaying[isp].ball.y-hojd1))/(sqrtf(powf(abs(x2-(isplaying[isp].ball.x-bredd1)),2)+powf(abs(y2-(isplaying[isp].ball.y-hojd1)),2))));
		set=false;
		if(golfclub.height == 0)
		{
			snd.Putter();
		}
		else
		{
			snd.Driver();
		}
	}

	tempX= isplaying[isp].ball.distance*atX;
	tempY= isplaying[isp].ball.distance*atY;
	
	if(isplaying[isp].ball.height>0)
	{
		UseWind(FirstShot,windPos,WPos);
	}
	
	Direction x=CompPosX(bredd1,isplaying[isp].ball.x+tempX+windPos.x);
	Direction y=CompPosY(hojd1,isplaying[isp].ball.y+tempY+windPos.y);			
	

	if(bredd1+tempX+windPos.x < ((bredd-16)*50) && bredd1+tempX+windPos.x >0)
	{
		if((tempX+windPos.x > 0 && x==Right) || (tempX+windPos.x < 0 && x==Left) )
		{
			bredd1+= tempX+windPos.x;
		}
	}
	
	if(hojd1+tempY+windPos.y < ((hojd-12)*50) && hojd1+tempY+windPos.y > 0 )
	{
		if((tempY+windPos.y > 0 && y==Down) || (tempY+windPos.y < 0 && y==Up))
		{
			hojd1+= tempY+windPos.y;
		}
	}
	
	isplaying[isp].ball.x+=tempX;
	isplaying[isp].ball.x+=windPos.x;
	isplaying[isp].ball.y+=tempY;
	isplaying[isp].ball.y+=windPos.y;

	if(isplaying[isp].ball.x<bredd*50)
	{
		FireGolfBall=Skjut(isplaying[isp],isplaying[isp].ball,windPos,atX,atY,Ground);
	}
	if(FireGolfBall)
	{
		FireGolfBall=OutofBounds(isplaying[isp].ball,tempX+windPos.x,tempY+windPos.y);
	}
	if(isplaying[isp].BallInHole)
	{
		FireGolfBall=false;
	}
	
	if(FireGolfBall==false)
	{
		PickGolfClub=true;
		Ground=true;
		SetValue=true;
		Power=true;
		value=0;
		FirstShot=true;
		isplaying[isp].BallLanded=true;
		UseWind(FirstShot,windPos,WPos);		
	}
}
void GameManager::UpdateGameObjects(int fElapsed)
{
    if(mGameState != GameState::GAMEPLAY)
        return;

    mCurrentTime = glutGet(GLUT_ELAPSED_TIME);

    for(unsigned int i = 0; i < GameObjects.size(); i++)
    {
        GameObject* obj = GameObjects[i];

        obj->Update(fElapsed);

        if(obj->GetType() == GameObjectType::BULLET)
        {
            if(OutofBounds(obj->GetPosition()))
                GameObjects.erase(GameObjects.begin() + i);
            else
            {
                for(GameObject* object : GameObjects)
                {
                    if(EnemyShip* enemy = dynamic_cast<EnemyShip*>(object))
                    {
                        if(Distance(enemy->GetPosition(), obj->GetPosition()) < 40)
                        {
                            GameObjects.erase(GameObjects.begin() + i);
                            enemy->SetDying(true);
                            UpdateScore();
                            break;
                        }

                    }
                }
            }
        }

        if(obj->GetType() == GameObjectType::ENEMY_SHIP)
        {
            if(dynamic_cast<EnemyShip*>(obj)->GetTimer() <= 0)
                GameObjects.erase(GameObjects.begin() + i);

            if(Distance(obj->GetPosition(), mPlayerShip->GetPosition()) < 40)
            {
                PlayerShip *playerShip = dynamic_cast<PlayerShip *>(mPlayerShip);
                if (NULL != playerShip)
                {
                    playerShip->SetDying(true);
                }
            }
        }

        if(obj->GetType() == GameObjectType::PLAYER_SHIP)
        {
            if(dynamic_cast<PlayerShip*>(obj)->GetTimer() <= 0)
                mGameState = GameState::GAMEOVER;
        }
    }

    mPreviousTime = mCurrentTime;

    //Update Game Objects as fast as the frame-rate.
    //glutTimerFunc(1000.f/60.f, UpdateGameObjects, 0);
}