Beispiel #1
0
void	PuzzleWin::loadPic(std::list<sf::Sprite*> &_spr)
{
  DIR*	dir;
  struct dirent	*ent;
  struct stat	st;
  std::string	dos("./Ressources/Game/Puzzle/Pic/");
  std::string	name;
  std::string	fullName;
  sf::Texture*	pic;
  sf::Sprite*	spr;
  int	x = 25;
  int	y = 50;
  int	litX = getWindow().getSize().x / 4;
  int	litY = getWindow().getSize().y / 2;
  Button	*next;

  this->setType(GAME);
  dir = opendir("./Ressources/Game/Puzzle/Pic");
  if (dir != NULL)
    {
      while ((ent = readdir(dir)) != NULL)
	{
	  name = ent->d_name;
	  fullName = dos + name;
	  if (name[0] != '.' && stat(fullName.c_str(), &st) != -1)
            if ((st.st_mode & S_IFDIR) == false)
              if (name.rfind('.') != std::string::npos && name.substr(name.rfind('.')).compare(".jpg") == 0)
		{
		  pic = new sf::Texture;
		  if (pic->loadFromFile(fullName) == true)
		    {
		      next = new Button(x, y, x + 175, y + 175, name);
		      if (x == 25 && y == 50)
			{			
			  this->setPic(next->getContent());
			  next->setTarget(true);
			}
		      addButton(next);
		      this->setType(MENU);
		      next->setWin(this);
		      next->DrawContent(getWindow());
		      spr = new sf::Sprite;
		      spr->setTexture(*pic);
		      spr->setPosition(x, y+50);
		      spr->setScale(0.2f, 0.25f);
		      getWindow().draw(*spr);
		      _spr.push_front(spr);
		      x += 150 + 50;
		      if (x >= getWindow().getSize().x)
			{
			  x = 0;
			  y += 300;
			}

		    }
		}
	}
    }
}
Beispiel #2
0
void	initMenu(sf::RenderWindow& win, AWin &current)
{
  Button	*chooseGame;
  Button	*leaveGame;
  
  int	x2 = win.getSize().x / 2;
  int	y2 = win.getSize().y / 2;
  chooseGame = new Button(x2 - 150, y2 - 50, x2 + 150, y2 + 50, "Choose Game");
  chooseGame->setWin(new Choose(win));
  chooseGame->setTarget(true);
  chooseGame->DrawContent(win);
  current.addButton(chooseGame);
  leaveGame = new Button(x2 - 150, y2 + 100, x2 + 150, y2 + 200, "Leave");
  leaveGame->DrawContent(win);
  leaveGame->setWin(new Leave(win));
  current.addButton(leaveGame);
}