Exemplo n.º 1
0
int                main               (int                 argc,
                                       char               *argv[])
 {
  bool                                 Result;
  char                                *ModelFileName;
  unsigned int                         RepeatCount;
  bool                                 ShowHelp;

  Result = ParseArgs(&ModelFileName,&RepeatCount,&ShowHelp,argc,argv);

  if (Result)
   {
    if (ShowHelp)
     {
      ShowHelpMessage();
     }
    else
     {
      Result = MakeShot(ModelFileName,RepeatCount);
     }
   }

  if (Result)
   {
    return(0);
   }
  else
   {
    return(1);
   }
 }
Exemplo n.º 2
0
void BattleField::DrownShip(int index) 
{
    int dirs[8][2] = {
        { -1, -1 }, { 0, -1 }, { 1, -1 }, { -1, 0 }, { 1, 0 }, { -1, 1 }, { 0, 1 }, { 1, 1 }
    };
    int x = m_ships[index].x;
    int y = m_ships[index].y;
    int orient  = m_ships[index].orient;
    for (int i = 0; i < m_ships[index].kind; i ++, ++ (orient == SHIP_ORIENTATION_HORZ ? x : y)) 
    {
        for (int n = 0; n < 8; ++n) 
        {
            if (CheckCanMakeShot(x + dirs[n][0], y + dirs[n][1])) 
                MakeShot(x + dirs[n][0], y + dirs[n][1]);
        }
    }
}
Exemplo n.º 3
0
////////////////////////////////////////////////////////////////
// Main battle method, emulation of tanks battle, finding who winner
void CBattleField::Battle(std::istream& _is)
{
	Time_t time;;
	_is >> time;
		
	while (!IsGameOver())
	{
		if (!time && _commandsCount != 0)
		{
			_is >> time;	
		}
		
		////////////////////////////////////////////
		// Loop getting command at this time momment
		// Like: 
		// 25 A SHOOT
		// 25 A MOVE
		// 25 A STOP
		while (time == _time && _commandsCount != 0)
		{
			_commandsCount--;
			time = 0;
			PointName_t name;
			CommandName_t cmd;
			Angle_t angle;
			
			//Read tank name
			_is >> name;
			
			_is >> cmd;

			if (cmd == g_commandTurn)
			{
				//if command "turn" need read angle, for correct input
				_is >> angle;
			}

			Point_t tank = GetTankByName(name);

			// If tank exist recive command, else if not exist ignore command 
			if (tank != 0)
			{
				if (cmd == g_commandTurn)
				{
					//Tank recive command "TURN"
					tank->SetNewAngle(angle);
				}
				else if (cmd == g_commandStop)
				{
					//Tank recive command "STOP"
					tank->Stop();
				}
				else if (cmd == g_commandShoot)
				{
					//Tank recive command "SHOOT"
					//BOOOOOOOOOOM! :-)
					MakeShot(tank->GetX(), tank->GetY(), tank->GetAngle());
				}
				else if (cmd == g_commandMove)
				{
					//Tank recive command "MOVE"
					tank->Move();
				}
				else
				{
					//Wrong command name
					throw CError(ERR_WRONG_COMMAND);
				}
			}

			if (_commandsCount)
			{
				_is >> time;
			}
		}