Beispiel #1
0
/**
 * Moves the UFO to its destination.
 */
void Ufo::think()
{
	if (!isCrashed())
	{
		move();
		if (reachedDestination())
		{
			setSpeed(0);
		}
	}
}
Beispiel #2
0
/**
 * Changes the current altitude of the UFO.
 * @param altitude Altitude.
 */
void Ufo::setAltitude(const std::string &altitude)
{
	_altitude = altitude;
	if (_altitude != "STR_GROUND")
	{
		_status = FLYING;
	}
	else
	{
		_status = isCrashed() ? CRASHED : LANDED;
	}
}
Beispiel #3
0
/**
 * Returns the UFO's unique identifying name.
 * @param lang Language to get strings from.
 * @return Full name.
 */
std::wstring Ufo::getName(Language *lang) const
{
	std::wstringstream name;
	if (!isCrashed())
	{
		name << lang->getString("STR_UFO_") << _id;
	}
	else
	{
		name << lang->getString("STR_CRASH_SITE_") << _id;
	}
	return name.str();
}
Beispiel #4
0
/**
 * Moves the UFO to its destination.
 */
void Ufo::think()
{
	if (!isCrashed())
	{
		setLongitude(_lon + _speedLon);
		setLatitude(_lat + _speedLat);
		if (_dest != 0 && finishedRoute())
		{
			_lon = _dest->getLongitude();
			_lat = _dest->getLatitude();
			setSpeed(0);
		}
	}
}
Beispiel #5
0
/**
 * Returns the UFO's unique identifying name.
 * @param lang Language to get strings from.
 * @return Full name.
 */
std::wstring Ufo::getName(Language *lang) const
{
	std::wstringstream name;
	if (!isCrashed())
	{
		// apparently this string is never actually used ingame??
		//if (_altitude == "STR_GROUND")
		//	name << lang->getString("STR_LANDING_SITE_") << _id;
		//else
		name << lang->getString("STR_UFO_") << _id;
	}
	else
	{
		name << lang->getString("STR_CRASH_SITE_") << _id;
	}
	return name.str();
}
Beispiel #6
0
void StepComp()
{
    int x = 0, y = 0;

    if((igra->last_hit_x != -1) && (igra->last_hit_y != -1))
        ChooseWay();
    else
    {
        if(igra->difficultly_level == HARD)
        {
            x = qrand() % SIZE_FIELD_SQUARE;
            y = 4 - ((x + 1) % 4) + (qrand() % 3) * 4;                  //smart rand
            if(y > 9)
                y %= 4;

            int k = 0;
            while((MyField[y][x] == MISS) || (MyField[y][x] == HIT))
            {
                if (k < 500)
                {
                    x = qrand() % SIZE_FIELD_SQUARE;
                    y = 4 - ((x + 1) % 4) + (qrand() % 3) * 4;
                    if(y > 9)
                        y %= 4;
                    k++;
                }
                else
                {
                    igra->difficultly_level = MEDIUM;
                    break;
                }
            }
        }
        if(igra->difficultly_level == MEDIUM)
        {
            x = qrand() % SIZE_FIELD_SQUARE;
            y = 4 - ((x + 3) % 4) + (qrand() % 3) * 4;                  //smart rand
            if(y > 9)
                y %= 4;

            int k = 0;
            while((MyField[y][x] == MISS) || (MyField[y][x] == HIT))
            {
                if(k < 500)
                {
                    x = qrand() % SIZE_FIELD_SQUARE;
                    y = 4 - ((x + 3) % 4) + (qrand() % 3) * 4;
                    if(y > 9)
                        y %= 4;
                    k++;
                }
                else
                {
                    igra->difficultly_level = EASY;
                    break;
                }
            }
        }
        if(igra->difficultly_level == EASY)
        {
            x = qrand() % SIZE_FIELD_SQUARE;
            y = qrand() % SIZE_FIELD_SQUARE;
            int k = 0;
            while(((MyField[y][x] == MISS) || (MyField[y][x] == HIT)) && (k < 500))
            {
                x = qrand() % SIZE_FIELD_SQUARE;
                y = qrand() % SIZE_FIELD_SQUARE;
                k++;
            }
            if(k == 500)
            {
                for(int i(0); i < SIZE_FIELD_SQUARE; i++)
                    for(int j(0); j < SIZE_FIELD_SQUARE; j++)
                    {
                        if((MyField[i][j] == EMPTY) || (MyField[i][j] == BUSY))
                        {
                            x = j;
                            y = i;
                        }
                    }
            }
        }

        if(MyField[y][x] == EMPTY)
        {
            MyField[y][x] = MISS;
            addCell(x, y, igra->scene1);
            igra->miss->play();
            while(!igra->miss->isFinished())
                Delay();
            igra->currentMove = true;
        }

        if(MyField[y][x] == BUSY)
        {
            MyField[y][x] = HIT;
            igra->last_hit_x = x;
            igra->last_hit_y = y;
            addCell(x, y, igra->scene1);
            if(isCrashed(x, y, MyField, igra->scene1))
                igra->kill->play();
            else
                igra->hit->play();
            while((!igra->hit->isFinished()) || (!igra->kill->isFinished()))
                Delay();
            igra->comp_win++;

            if(isCrashed(x, y, MyField, igra->scene1))
            {
                igra->last_hit_x = -1;
                igra->last_hit_y = -1;
            }
            StepComp();
        }
    }

    if(igra->comp_win == 20)    //if computer won
    {
        QSound *lose = new QSound("music/lose.wav");
        lose->play();
        QMessageBox::information(0, "Result", "You lose!");
        while(!lose->isFinished())
            Delay();
        igra->currentMove = true;
        //igra->comp_win++;
        igra->finish = true;
    }
}
Beispiel #7
0
int Kill(int Way)
{
    int x = igra->last_hit_x;
    int y = igra->last_hit_y;

    switch (Way)
    {
    case 0:
        while((x > 0) && (MyField[y][--x] != MISS) && (MyField[y][x] != HIT))
        {
            MyField[y][x] += MISS - EMPTY;
            addCell(x, y, igra->scene1);
            if(MyField[y][x] == HIT)
            {
                if(isCrashed(x, y, MyField, igra->scene1))
                    igra->kill->play();
                else
                    igra->hit->play();
                while((!igra->hit->isFinished()) || (!igra->kill->isFinished()))
                    Delay();
                igra->comp_win++;
            }
            if(MyField[y][x] == MISS)
            {
                igra->miss->play();
                while(!igra->miss->isFinished())
                    Delay();
            }
            if(isCrashed(igra->last_hit_x, igra->last_hit_y, MyField, igra->scene1))
                return 1;
            if(((MyField[y][x] == MISS) || (x == 0)) && (igra->last_hit_x - x > 1))
                return 2;
            else if(MyField[y][x] == MISS)
                return 0;
        }
        break;
    case 1:
        while((y > 0) && (MyField[--y][x] != MISS) && (MyField[y][x] != HIT))
        {
            Delay();
            MyField[y][x] += MISS - EMPTY;
            addCell(x, y, igra->scene1);
            if(MyField[y][x] == HIT)
            {
                if(isCrashed(x, y, MyField, igra->scene1))
                    igra->kill->play();
                else
                    igra->hit->play();
                while((!igra->hit->isFinished()) || (!igra->kill->isFinished()))
                    Delay();
                igra->comp_win++;
            }
            if(MyField[y][x] == MISS)
            {
                igra->miss->play();
                while(!igra->miss->isFinished())
                    Delay();
            }
            if(isCrashed(igra->last_hit_x, igra->last_hit_y, MyField, igra->scene1))
                return 1;
            if(((MyField[y][x] == MISS) || (y == 0)) && (igra->last_hit_y - y > 1))
                return 2;
            else if(MyField[y][x] == MISS)
                return 0;
        }
        break;
    case 2:
        while((x < SIZE_FIELD_SQUARE - 1) && (MyField[y][++x] != MISS) && (MyField[y][x] != HIT))
        {
            Delay();
            MyField[y][x] += MISS - EMPTY;
            addCell(x, y, igra->scene1);
            if(MyField[y][x] == HIT)
            {
                if(isCrashed(x, y, MyField, igra->scene1))
                    igra->kill->play();
                else
                    igra->hit->play();
                while((!igra->hit->isFinished()) || (!igra->kill->isFinished()))
                    Delay();
                igra->comp_win++;
            }
            if(MyField[y][x] == MISS)
            {
                igra->miss->play();
                while(!igra->miss->isFinished())
                    Delay();
            }
            if(isCrashed(igra->last_hit_x, igra->last_hit_y, MyField, igra->scene1))
                return 1;
            if(((MyField[y][x] == MISS) || (x == SIZE_FIELD_SQUARE - 1)) && (x - igra->last_hit_x > 1))
                return 2;
            else if(MyField[y][x] == MISS)
                return 0;
        }
        break;
    case 3:
        while((y < SIZE_FIELD_SQUARE - 1) && (MyField[++y][x] != MISS) && (MyField[y][x] != HIT))
        {
            Delay();
            MyField[y][x] += MISS - EMPTY;
            addCell(x, y, igra->scene1);
            if(MyField[y][x] == HIT)
            {
                if(isCrashed(x, y, MyField, igra->scene1))
                    igra->kill->play();
                else
                    igra->hit->play();
                while((!igra->hit->isFinished()) || (!igra->kill->isFinished()))
                    Delay();
                igra->comp_win++;
            }
            if(MyField[y][x] == MISS)
            {
                igra->miss->play();
                while(!igra->miss->isFinished())
                    Delay();
            }
            if(isCrashed(igra->last_hit_x, igra->last_hit_y, MyField, igra->scene1))
                return 1;
            if(((MyField[y][x] == MISS) || (y == SIZE_FIELD_SQUARE - 1)) && (y - igra->last_hit_y > 1))
                return 2;
            else if(MyField[y][x] == MISS)
                return 0;
        }
        break;
    default:
        break;
    }
    return 3;
}