예제 #1
0
bool Airport::At(Plane &plane)
{
    int x, y;
    plane.GetPosition(x, y);
    if ( x == position.x && y == position.y)
        if (plane.GetHeading() == (heading ^ 4))
            if (plane.GetAltitude() == 0)
                return true;
    return false;
}
예제 #2
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;
}
예제 #3
0
bool Fix::At(Plane &plane)
{
    int x, y;
    plane.GetPosition(x, y);
    return (x == position.x || y == position.y) && plane.GetAltitude() >= 5 && (heading ^ 4) == plane.GetHeading();
}