コード例 #1
0
ファイル: Game.cpp プロジェクト: Wullschi/sep
//------------------------------------------------------------------------------
void Game::findTeleportLocation(const string teleport_letter,
    const Coordinates& position, Coordinates& teleport_exit)
{
  int portal_x=0, portal_y=0;
  for (std::size_t y = 0; y < board_->size(); y++)
  {
    for (std::size_t x = 0; x < board_->at(y).size(); x++)
    {
      string symbol = board_->at(y).at(x)->getFieldSymbol(Field::FOR_GAME);
      
      // If the momentary field in this loop is not the one the player wants to
      // enter and if it has the same portal letter as the one he wants to enter
      // it must be the corresponding portal of that field.
      std::size_t player_x = position.getX();
      std::size_t player_y = position.getY();
      if (((x != player_x) || (y != player_y))
          && symbol == teleport_letter)
      {
        portal_x = static_cast<int>(x);
        portal_y = static_cast<int>(y);
      }
    }
  }

  teleport_exit.setX(portal_x);
  teleport_exit.setY(portal_y);
}
コード例 #2
0
ファイル: SVGLine.cpp プロジェクト: robinankele/SVG-Editor
//------------------------------------------------------------------------------
bool SVGLine::resize()
{
  signed int x, y;
  std::string str_value;
  Coordinates *coord = new Coordinates(0,0);
  
  std::cout << "id: " << id_ << std::endl;
  std::cout << "x2: " << coordinates_.back().getX() << std::endl;
  std::cout << "y2: " << coordinates_.back().getY() << std::endl;
  
  coordinates_.erase(coordinates_.begin()+1);
  while(true)
  {
    if(ui_->getParam("  x2? ", false, false, x, str_value, true))
      break;
  }
  coord->setX(x);
  
  while(true)
  {
    if(ui_->getParam("  y2? ", false, false, y, str_value, true))
      break;
  }
  coord->setY(y);
  coordinates_.push_back(*coord);
  delete coord;
  
  return true;
}
コード例 #3
0
ファイル: Entities.cpp プロジェクト: Feroxius/Projet-ift232
Coordinates Entities::getNewCoordinates(Source* source){
	Entity* entity = dynamic_cast<Entity*>(source);
	Coordinates newPosition = entity->getPosition();
	if (entity->getPosition().getX() > boundWidth - WIDTH_BORDER ){
		newPosition.setX(boundWidth - WIDTH_BORDER - POSITION_CORRECTION);
	}
	if (entity->getPosition().getX() < 0){
		newPosition.setX(POSITION_CORRECTION);
	}
	if (entity->getPosition().getY() > boundHeight - HEIGHT_BORDER){
		newPosition.setY(boundHeight - HEIGHT_BORDER - POSITION_CORRECTION);
	}
	if (entity->getPosition().getY() < 0){
		newPosition.setY(POSITION_CORRECTION);
	}

	return newPosition;
}
コード例 #4
0
//------------------------------------------------------------------------------
bool RectCommand::execute()
{
  signed int id, group_id, x, y, width, height, int_value;
  std::string fill, stroke, id_str, stroke_width;
  Coordinates *coord = new Coordinates(0,0);
  
  while(true)
  {
    while(true)
    {
      ui_->getParam("  id? ", false, false, int_value, id_str, false);
      if(!ui_->checkIfIdExists(id_str))
        break;
      error_->idAlreadyExist();
    }
    if(ui_->stringToSignedInt(id_str, id))
      break;
    error_->invalidParameter();
  }
  
  x = readParam("  x? ");
  coord->setX(x);
  
  y = readParam("  y? ");
  coord->setY(y);
  
  coordinates_.push_back(*coord);
  delete coord;
  
  width = readParam("  width? ");
  height = readParam("  height? ");
  ui_->getParam("  fill? ", false, false, int_value, fill, false);
  ui_->getParam("  stroke? ", false, false, int_value, stroke, false);
  ui_->getParam("  stroke-width? ", false, false, int_value, stroke_width,
                false);
  group_id = readParam("  group? ");

  try
  {
    SVGRect *rect = new SVGRect(ui_, db_, svgh_, id, group_id, coordinates_,
                                width, height, fill, stroke, stroke_width);
    db_->setSVGObject(rect);
    coordinates_.clear();
  }
  catch(std::bad_alloc& exception)
  {
    svgh_->setErrors(OUT_OF_MEMORY);
  }
  return true;
}
コード例 #5
0
/*************************************************************************
* Function name: placeShip
* The Input: ship type
* The output: -
* The Function operation: places a ship of the spec. type on the player's board
*************************************************************************/
void ComputerPlayer::placeShip(int shipType) {
	// Generate random coordinates and try to create a ship there
	int x = rand() % 10;
	int y = rand() % 10;
	Coordinates * coords = new Coordinates(x, y);
	Ship ship = Ship(shipType, *coords);

	// Try again until we find a suitable place on the board
	while (!canPlaceShip(ship)) {
		coords->setX(rand() % 10);
		coords->setY(rand() % 10);
		ship = Ship(shipType, *coords);
	}

	// Add the ship to the board
	board->addShip(shipType, coords);
}
コード例 #6
0
ファイル: SVGPolygon.cpp プロジェクト: robinankele/SVG-Editor
//------------------------------------------------------------------------------
bool SVGPolygon::resize()
{
  std::string str_value;
  unsigned int coord_count = 0;
  Coordinates *coord = new Coordinates(0,0);
  
  std::cout << "id: " << id_ << std::endl;
  for(std::vector<Coordinates>::iterator it = coordinates_.begin() + 1; 
      it != coordinates_.end(); ++it)
  {
    std::cout << "x: " << (*it).getX() << std::endl;
    std::cout << "y: " << (*it).getY() << std::endl;
  }
  
  coord_count = coordinates_.size();
  coordinates_.erase(coordinates_.begin()+1,coordinates_.end());

  signed int y = 0;
  signed int x = 0;
  for(unsigned int count = 0; count < coord_count - 1; count++)
  {
    while(true)
    {
      if(ui_->getParam("  x? ", false, false, x, str_value, true))
        break;
    }
    coord->setX(x);
    
    while(true)
    {
      if(ui_->getParam("  y? ", false, false, y, str_value, true))
        break;
    }
    coord->setY(y);
    coordinates_.push_back(*coord);
  }
  delete coord;
  
  return true;
}