Exemplo n.º 1
0
void Board::CommandPlane(int index, enum Command command, int modifier)
{
    for (std::set<Plane *>::iterator it = planesIn.begin(); it != planesIn.end(); ++it)
    {
        Plane *plane = *it;
        if (plane->GetName() == index + 'A')
        {
            if (command == CircleNavaid)
            {
                int x,y;
                navAids[0]->GetPosition(x,y);
                int n1 = plane->dist(x, y);
                navAids[1]->GetPosition(x,y);
                int n2 = plane->dist(x,y);
                if (n1 < n2)
                {
                    navAids[0]->GetPosition(x,y);
                }
                plane->Circle(x, y);
            }
            else
            {
                plane->CommandPlane(command, modifier);
            }
            break;
        }
    }
}
Exemplo n.º 2
0
std::string Board::GetDisplayString(int index)
{
    for (std::set<Plane *>::iterator it = planesIn.begin(); it != planesIn.end(); ++it)
    {
        Plane *plane = *it;
        if (index == plane->GetName() - 'A')
            return GetDisplayString(plane);
    }
    return "";
}
Exemplo n.º 3
0
void perform(HWND hDlg, HWND hList, HWND hEditList,Plane::PlaneDirection direction
			 //,CountPlanesFunc cpf,LandOrLiftPlanesFunc lolpf,
			 )
{
	Plane * plane = gestor->criarAviaoPara(direction);
	ListBox_AddString(hList,plane->GetName());
	//_itot_s(cpf(),buffer,sizeof(_TCHAR)*MAX_BUFFER,10);
	loadIntoBufferPlanesCount(direction);
	
	Edit_SetText(hEditList,buffer);
	
	plane = executeLandOrListFunction(direction);
	
	EnterCriticalSection(&csDelFromLB);
	ListBox_DeleteString(hList,ListBox_FindStringExact(hList,0,plane->GetName()));
	LeaveCriticalSection(&csDelFromLB);

	//_itot_s(cpf(),buffer,sizeof(_TCHAR)*MAX_BUFFER,10);
	loadIntoBufferPlanesCount(direction);
	Edit_SetText(hEditList,buffer);

	if(!(plane->terminateQuickly()))
	{
		INT * animationEditTexts = getAnimationEditText(plane->_idLane);
		if(plane->GetDirection()==Plane::LAND)
		{
			for (int i=0; i < 26; ++i) {
				doAnimation(plane,hDlg,animationEditTexts[i]);
			}
		}
		else if(plane->GetDirection()==Plane::LIFTOFF)
		{
			for(int i = 25; i>=0;--i)
			{
				doAnimation(plane,hDlg,animationEditTexts[i]);
			}
		}
		gestor->libertarPista(plane);
	}
}
Exemplo n.º 4
0
int Board::GetPlaneIndex(int x, int y)
{
    x = x/TextWidth;
    y = y/TextHeight;
    for (std::set<Plane *>::iterator it = planesIn.begin(); it != planesIn.end(); ++it)
    {
        int x1, y1;
        Plane *plane = *it;
        plane->GetPosition(x1, y1);
        if (x1 == x && y1 == y)
            return plane->GetName() - 'A';
    }
    return -1;
}
Exemplo n.º 5
0
std::string Board::Timed()
{
    std::string rv;
    In();
    for (std::set<Plane *>::iterator it = planesIn.begin(); it != planesIn.end();)
    {
        Plane *plane = *it;
        int n = plane->GetDestination();
        bool atFix; 
        if (n >= 10)
        {
            navAids[n-10]->At(*plane);
            atFix = airports[n-10]->At(*plane);
            if (atFix)
            {
                if (plane->GetHeading() == airports[n-10]->GetHeading() ^ 4)
                {
                    it = planesIn.erase(it);
                    planesDone.insert(plane);
                    continue;
                }
            }
        }
        else
        {
            atFix = fixes[n]->At(*plane);
        }
        if (plane->GetAltitude() == 0)
        {
            bool at = false;
            int x, y;
            int x1, y1;
            plane->GetPosition(x, y);
            airports[0]->GetPosition(x1,y1);
            if (x == x1 && y == y1)
                at = true;
            airports[1]->GetPosition(x1,y1);
            if (x == x1 && y == y1)
                at = true;
            if (at)
            {
                rv = "Skimmed airport without landing!";
            }
        }
        if (plane->Move(time))
        {
            if (atFix && plane->OffBoard())
            {
                it = planesIn.erase(it);
                planesDone.insert(plane);
                continue;
            }
            else if (plane->OffBoard())
            {
                // game over, exit in wrong place
                if (plane->GetAltitude() < 5)
                    rv = std::string(plane->GetName()) + " left control area at wrong altitude";
                else 
                {   
                    if ((plane->GetDestination() < 10 && plane->GetHeading() != (fixes[plane->GetDestination()]->GetHeading() ^ 4)) ||
                        (plane->GetDestination() >9 && plane->GetHeading() != (airports[plane->GetDestination()-10]->GetHeading() ^ 4)))
                        rv = std::string(plane->GetName()) + " left control area at wrong heading";
                    else
                        rv = std::string(plane->GetName()) + " left control area at wrong place";
                }
            }
        }
        ++it;
    }
    for (std::set<Plane *>::iterator it = planesDisplay.begin(); it != planesDisplay.end();)
    {
        Plane *plane = *it;
        if (plane->GetStartTime() <= time)
        {
            it = planesDisplay.erase(it);
            planesIn.insert(plane);
            continue;
        }
        ++it;
    }
    if (rv == "")
    {
        for (std::set<Plane *>::iterator it1 = planesIn.begin(); rv == "" && it1 != planesIn.end(); ++it1)
        {
            Plane *left = *it1;
            for (std::set<Plane *>::iterator it2 = it1; rv == "" && it2 != planesIn.end(); ++it2)
            {
                Plane *right = *it2;
                if (it1 != it2)
                {
                    if (left->GetAltitude() == right->GetAltitude())
                    {
                        int x,y;
                        right->GetPosition(x, y);
                        if (left->dist(x, y) < 4)
                            rv = std::string("Conflict between ") + left->GetName() + " and " + right->GetName();
                    }
                }
            }
        }
    }
    if (rv == "")
    {
        for (std::set<Plane *>::iterator it = planesIn.begin(); rv == "" && it != planesIn.end(); ++it)
        {
            Plane *plane = *it;
            if (plane->GetFuel() < 0)
            {
                rv = std::string(plane->GetName()) + " out of fuel!";
            }
        }
    }
    // game over, they win!
    if (rv == "" && planesIn.size() == 0 && planesOut.size() ==0 && planesDisplay.size() == 0)
        rv = "You Won!";
    // game over, timeout
    if (rv == "" && ++time >= maxTime)
        rv = "Time is up!";
    return rv;
}