Пример #1
0
bool mazeMe(int row, int column, int plane)
{
  int nNewRow, nNewColumn, nNewPlane = 0;

  if (not mazeSolved())
  {
    for (int nIndex = 0; nIndex <= 26; nIndex++)
    {
      nNewRow = row + aMoves[nIndex].row;
      nNewColumn = column + aMoves[nIndex].column;
      nNewPlane = plane + aMoves[nIndex].plane;

      if (validMove(nNewRow, nNewColumn, nNewPlane))
      {
        aBoard[nNewRow][nNewColumn][nNewPlane].value = '-';
        objScreen.printChar('-',
                            aBoard[nNewRow][nNewColumn][nNewPlane].x,
                            aBoard[nNewRow][nNewColumn][nNewPlane].y,
                            32, 0, 0, 25000);

        if (not mazeMe(nNewRow, nNewColumn, nNewPlane))
        {
          aBoard[nNewRow][nNewColumn][nNewPlane].value = 'B';
          objScreen.printChar('B',
                              aBoard[nNewRow][nNewColumn][nNewPlane].x,
                              aBoard[nNewRow][nNewColumn][nNewPlane].y,
                              31, 0, 0, 25000);
        }
else	nIndex = 27;
      }
    }
  }

  return mazeSolved();
}
Пример #2
0
	// Function that displays a screen for the experience and levels
	// gained from the previous battle
	void reward()
	{
		display.Clear();
		cout << "Previous Level: " << Play1.level << " Previous XP: " << Play1.experience << endl;
		cout << "Gained " << Enem1.xpvalue << " experience!!!" << endl;
		Play1.setXP(Enem1.xpvalue);
		cout << endl << "Current Experience: " << Play1.experience << endl;
		display.pause();
	};
Пример #3
0
void setDingy( screen &green_grid, screen &red_grid, bool ship_locations[4][4] ) {
	reset_locations( ship_locations );
	green_grid.clearGrid();
	unsigned char input_direction;					//var used to move ship on board
	unsigned char row, col;							//coordinate variables
	row = 0;
	col = 0;
	green_grid.addLight( row, col );		//lights up coordinate ( 1, A ) 
	while (  1 ) {
		input_direction = getInput( green_grid, red_grid );
		if ( input_direction == 0 && row != 0 ) {
			green_grid.subLight( row, col );
			row--;
		}
		else if ( input_direction == 1 && row != 3 ) {
			green_grid.subLight( row, col );
			row++;
		}
		else if ( input_direction == 2 && col != 0 ) {
			green_grid.subLight( row, col );
			col--;
		}
		else if ( input_direction == 3 && col != 3 ) {
			green_grid.subLight( row, col );
			col++;
		}
		if ( input_direction == 4 ) {
			ship_locations[row][col] = true;
			break;
		}
		green_grid.addLight( row, col );
		green_grid.flicker();
	}
}
Пример #4
0
void representation::draw(screen& pscreen, bool skip_take)
{
	if(visible && (skip_take || is_in_focus(pscreen.get_box())))
	{
		if(pscreen.has_camera())
		{
			pscreen.reset_clip();
		}

		pre_render_transform(pscreen.get_draw_info());
		do_draw();
	}

	//Es importante que esto siempre esté presente...
	glLoadIdentity();
}
Пример #5
0
void createLevel ()
{
        scrn.clearScreen();
		bricks.clear();
		enemies.clear();
		bombs.clear();

		for (int i = 0; i < 13; i++)
		{
			for (int j = 0; j < 15; j++)
			{
				switch ( lvls[NUM_LVL][i][j])
				{
					case 2:
					{
						bricks.push_back(brick (calculateCoordinates(j - 1), calculateCoordinates(j), calculateCoordinates(i-1), calculateCoordinates(i), scrn));
					}
					break;
					case 3:
					{
						enemies.push_back(enemy (calculateCoordinates(j - 1), calculateCoordinates(j), calculateCoordinates(i-1), calculateCoordinates(i), scrn));
					}
					break;
				}
			}
		}

		lvlup = portal (10, 50, 410, 450, scrn);
		Main = hero (scrn);
}
Пример #6
0
void representation::draw(screen& pscreen, const camera& pcamera, bool skip_take)
{
	if(visible && (skip_take || is_in_focus(pcamera.get_focus_box()))) 
	{
		pscreen.set_camera(pcamera);
		pre_render_transform(pcamera.get_draw_info());
		do_draw();
	}

	//Es importante que esto siempre esté presente...
	glLoadIdentity();
}
Пример #7
0
void eventsInGame(sf::Event &event, sf::RenderWindow &window)
{
	switch (event.type)
	{
	case sf::Event::Closed:
		{
			window.close();
		}
		break;
	//========================================================================================= Keyboard
	case sf::Event::KeyPressed:
		{
			switch (event.key.code)
			{
			case (sf::Keyboard::Left):
				Main.MoveL(scrn, lvlup);
				break;
			case (sf::Keyboard::Right):
				Main.MoveR(scrn, lvlup);
				break;
			case (sf::Keyboard::Up):
				Main.MoveU(scrn, lvlup);
				break;
			case (sf::Keyboard::Down):
				Main.MoveD(scrn, lvlup);
				break;
			case (sf::Keyboard::Space):
				bombs.push_back(bomb (Main.l, Main.r, Main.b, Main.t));
				break;
			case (sf::Keyboard::E):
			{
				scrn.print();
			}
			break;
			case (sf::Keyboard::Escape):
				{
					window.close();
				}
			break;
			case (sf::Keyboard::A):
			{
				//NUM_LVL++;
				enemies.clear();
				//scrn.clearScreen();
			}
			break;
			}
		}
	}
}
Пример #8
0
void printArray()
{
  for (int plane = 0; plane <= 4; plane++)
  {
    for (int row = 0; row <= 9; row++)
    {
      for (int column = 0; column <= 9; column++)
      {
        objScreen.printChar(aBoard[row][column][plane].value,
                            aBoard[row][column][plane].x,
                            aBoard[row][column][plane].y);
      }
    }
  }
}
Пример #9
0
void buildArray()
{
  ifstream is;
  char file[256];

  objScreen.printString("Please input file name: ", 1, 1, 25000);
  cin.get(file, 256);

  is.open(file);

  int x[5] = {20, 32, 44, 56, 68};
  int y[5] = {5, 6, 7, 8, 9};

  for (int plane = 0; plane <= 4; plane++)
  {
    for (int row = 0; row <= 9; row++)
    {
      for (int column = 0; column <= 10; column++)
      {
        aBoard[row][column][plane].value = is.get();
        aBoard[row][column][plane].x = x[plane] + column;
        aBoard[row][column][plane].y = y[plane] + row;
      }

      x[plane]--;
    }
  }

  is.close();

  int nIndex = 0;
  for (int i = -1; i <= 1; i++)
  {
    for (int j = -1; j <= 1; j++)
    {
      for (int k = -1; k <= 1; k++)
      {
        aMoves[nIndex].row = i;
        aMoves[nIndex].column = j;
        aMoves[nIndex].plane = k;
        nIndex++;
      }
    }
  }
}
Пример #10
0
int main()
{
  bool bCont = true;
  char strCont = 'y';

  while (bCont)
  {
    objScreen.clearScreen();
    objScreen.moveCursor(0, 0);
    cout.flush();

    buildArray();
    printArray();

    if (aBoard[0][0][0].value == ' ')
    {
      objScreen.printChar('-', aBoard[0][0][0].x, aBoard[0][0][0].y, 32, 0, 0, 25000);
    }

    if (mazeMe(0, 0, 0))
    {
      objScreen.printString("Puzzled Solved!", 1, 22, 25000);
    }
    else
    {
      objScreen.printString("Puzzle Unsolvable.", 1, 22, 25000);
    }

    objScreen.moveCursor(0, 23);
    cout.flush();

    objScreen.printString("Do you want to play another game (y/n)? ", 1, 23, 25000);
    cin >> strCont;

    if (strCont == 'n')
    {
      bCont = false;
    }

    cin.ignore(1000, '\n');
  }

  return 0;
}
Пример #11
0
void conn::game_thread(std::shared_ptr<tcp::socket> socket, bool &gameover, bots & bots, bot::team_id &id,
        boost::mutex & state_mutex, bot::field_size &field_width, bot::field_size &field_height,
        int &win_width, int &win_height, bool &connected) {

    superbots superbots(bots);

    boost::asio::streambuf buf;
    while(!gameover) {

        superbots.ejecutar(5);

        for(auto b : bots.team_bots(id)) {
            std::stringstream stream;
            stream << "move " << b->get_x() << " " << b->get_y() << " " << b->get_next_direction();
            send(*socket, stream.str());
        }

        read_until(*socket, buf, "\n");

        std::string data;
        std::istream is(&buf);
        std::getline(is, data);

        std::istringstream stream(data);

        std::string command;
        stream >> command;

        if(command == "welcome") {
            stream >> id;
            superbots.set_team(id);

            stream >> field_width;
            stream >> field_height;
            bots.set_size(field_width, field_height);
            MYscreen.set_screen(win_width, win_height, field_width, field_height);
            connected = true;
        }
        else if(command == "state") {
Пример #12
0
void eventsAfterWin(sf::Event &event, sf::RenderWindow &window, bool &in_menu, int x1, int y1, int x2, int y2)
{
	switch(event.type)
	{
	case sf::Event::MouseButtonPressed:
		{
			if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
			{
				sf::Vector2i mPos = sf::Mouse::getPosition(window);
				if ( mPos.x >= x1 && mPos.x <= 500 && mPos.y >= y1 && mPos.y <= y1 + 100 )
				{
					scrn.setRun(true);
					in_menu = true;
				}

				if ( mPos.x >= x2 && mPos.x <= 500 && mPos.y >= y2 && mPos.y <= y2 + 100)
				{
					window.close();
				}
			}
		}
	}
}
Пример #13
0
void eventsAfterLosing(sf::Event &event, sf::RenderWindow &window, bool &in_menu)
{
	switch(event.type)
	{
	case sf::Event::MouseButtonPressed:
		{
			if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
			{
				sf::Vector2i mPos = sf::Mouse::getPosition(window);
				if ( mPos.x >= 100 && mPos.x <= 200 && mPos.y >= 250 && mPos.y <= 350 )
				{
					scrn.setRun(true);
					in_menu = true;
				}

				if ( mPos.x >= 250 && mPos.x <= 350 && mPos.y >= 250 && mPos.y <= 300 )
				{
					window.close();
				}
			}
		}
	}
}
Пример #14
0
void setTriDingy( screen &green_grid, screen &red_grid, bool ship_locations[4][4] ) {
	unsigned char input_direction;							//var used to move ship on board
	unsigned char row, col;  								//coordinate variables
	row = 0;
	col = 0;
	green_grid.addLight( row, col );				//lights up coordinate ( 1, 1 )
	green_grid.addLight( row, col + 1 );			//lights up coordinate ( 2, 1 )
	green_grid.addLight( row, col + 2 );
	
	while ( 1 ) { 
		input_direction = getInput( green_grid, red_grid );
		if ( input_direction == 0 && row != 0 ) {
			green_grid.subLight( row, col );
			green_grid.subLight( row, col + 1 );
			green_grid.subLight( row, col + 2 );
			row--;
			green_grid.addLight( row, col );
			green_grid.addLight( row, col + 1 );
			green_grid.addLight( row, col + 2 );
		}
		else if ( input_direction == 1 && row != 3 ) {
			green_grid.subLight( row, col );
			green_grid.subLight( row, col + 1 );
			green_grid.subLight( row, col + 2 );
			row++;
			green_grid.addLight( row, col );
			green_grid.addLight( row, col + 1 );
			green_grid.addLight( row, col + 2 );
		}
		else if ( input_direction == 2 && col != 0 ) {
			green_grid.subLight( row, col + 2);
			col--;
			green_grid.addLight( row, col );
		}
		else if ( input_direction == 3 && col != 1 ) {
			green_grid.subLight( row, col );
			col++;
			green_grid.addLight( row, col + 2 );
		}
		else if ( input_direction == 4 ) {
			if ( green_grid.collisionCheck( 6 ) == false ) {
				ship_locations[row][col] = true;
				ship_locations[row][col + 1] = true;
				ship_locations[row][col + 2] = true;
				break;
			}
			else {
				setDingy( green_grid, red_grid, ship_locations );
				setDualDingy( green_grid, red_grid, ship_locations );
				row = 0;
				col = 0;
				green_grid.addLight( row, col );			//lights up coordinate ( 1, 1 )
				green_grid.addLight( row, col + 1 );		//lights up coordinate ( 2, 1 )
				green_grid.addLight( row, col + 2 );		//lights up coordinate ( 3, 1 )
			}
		}
		green_grid.flicker();
	}
}
Пример #15
0
int main ( int argc, char** argv)
{
	sf::RenderWindow window(sf::VideoMode(wW, wH), "MyDynablaster", sf::Style::Titlebar);

	sf::Clock clock;

	//==================================================================================================== Textures for objects
	
	sf::Texture texMainHero;
	texMainHero.loadFromFile("main_hero.png");
	sf::Sprite sprMainHero;
	sprMainHero.setTexture(texMainHero);

	sf::Texture texBrick;
	texBrick.loadFromFile("brick.png");
	sf::Sprite sprBrick;
	sprBrick.setTexture(texBrick);

	sf::Texture texEnemy;
	texEnemy.loadFromFile("enemy.png");
	sf::Sprite sprEnemy;
	sprEnemy.setTexture(texEnemy);

	sf::Texture texBomb;
	texBomb.loadFromFile("bomb.png");
	sf::Sprite sprBomb;
	sprBomb.setTexture(texBomb);

	sf::Texture texPortal;
	texPortal.loadFromFile("portal.png");
	sf::Sprite sprPortal;
	sprPortal.setTexture(texPortal);

	sf::Texture texFire;
	texFire.loadFromFile("fire.png");
	sf::Sprite sprFire;
	sprFire.setTexture(texFire);

	sf::Font font;
	if (!font.loadFromFile("font.ttf"))
	{
		return 3;
   	}

	
	//-----------------------------------------------------------------------------------------------Boolean variables	
	bool lvl_is_completed = false;
	bool in_menu = true;
	bool gamer_lose = false;
	// -----------------------------------------------------------------------------------------------Game
	while (window.isOpen())
    {
		sf::Event event;

		while ( in_menu)
		{
			window.clear(sf::Color::White);

			sf::Text txt1, txt2;
			const int txt1_x = 100, txt1_y=100;

			txt1.setFont(font);
			txt1.setString("Start game");
			txt1.setColor(sf::Color::Black);
			txt1.setPosition(txt1_x, txt1_y);
			txt1.setCharacterSize(72);
			window.draw(txt1);

			const int txt2_x = 100, txt2_y=180;
			txt2.setFont(font);
			txt2.setString("Exit");
			txt2.setColor(sf::Color::Black);
			txt2.setPosition(txt2_x,txt2_y);
			txt2.setCharacterSize(72);
			window.draw(txt2);

			window.display();
			while ( window.pollEvent(event))
			{
				eventsInMenu( event, window, in_menu, txt1_x, txt1_y, txt2_x, txt2_y);
			}
			
		}

		while ( window.pollEvent(event) )
		{
			if(scrn.getRun())
			{
				eventsInGame(event, window);
			}
			else
			{
				if(gamer_lose)
				{
					eventsAfterLosing (event, window, in_menu);
				}
				else
				{
					eventsAfterWin (event, window, in_menu, 100, 150, 100, 250);
				}
			}
		}

		//--------------------------------------------------------------------------------------------------------------------Draw
		window.clear(sf::Color::White);

		if (scrn.getRun() == true)
		{
			sprPortal.setPosition(sf::Vector2f(lvlup.l, lvlup.b));
			window.draw(sprPortal);

				if (! bricks.empty())
				{
					for (list<brick>::iterator i = bricks.begin(); i != bricks.end(); ++i)
					{
						sprBrick.setPosition(sf::Vector2f(i->l, i->b));
						window.draw(sprBrick);
					}
				}
				if (! enemies.empty())
				{

					sf::Time elapsed1 = clock.getElapsedTime();

					if (elapsed1.asSeconds() >= 0.5f)
					{
						for (list<enemy>::iterator i = enemies.begin(); i != enemies.end(); ++i)
						{

							i->motion(scrn, Main);
						}
						sf::Time elapsed1 = clock.restart();
					}
					for (list<enemy>::iterator i = enemies.begin(); i != enemies.end(); ++i)
					{	
						sprEnemy.setPosition(sf::Vector2f(i->l, i->b));
						window.draw(sprEnemy);
					}
				}
				if ( !bombs.empty())
				{
					for (list<bomb>::iterator i = bombs.begin(); i != bombs.end(); ++i)
					{
						sprBomb.setPosition(sf::Vector2f(i->l, i->b));

						if ( (i->clock).getElapsedTime().asSeconds() >= 3.0)
						{
							i->damage(window, sprFire);
							if ( (i->clock).getElapsedTime().asSeconds() > 5.0)
							{
								lst_iter.push_back(i);
							}

						}
						window.draw(sprBomb);
					}
				}
				sprMainHero.setPosition (sf::Vector2f (Main.l, Main.b));
				window.draw (sprMainHero);

				if ( enemies.empty() && Main.b == lvlup.b && Main.r ==lvlup.r)
				{
					std::cout<<NUM_LVL<<std::endl;
					if ( NUM_LVL < max_num_lvls -1)
					{
						levelUp();
					}
					else
					{
						std::cout<<"I'm here"<< std::endl;
						scrn.setRun(false); 
					}
				}
			}
			else
			{
				bricks.clear();
				bombs.clear();
				enemies.clear();
				scrn.clearScreen();
				scrn.setRun(false);

				sf::Text txt1, txt2, txt3, txt4;

				if ( NUM_LVL >= max_num_lvls - 1)
				{
					getText(txt1, font, "You Win!!", 100, 50, 72);
					window.draw(txt1);

					getText(txt2, font, "Back in menu", 100, 150, 72);
					window.draw(txt2);

					getText(txt3, font, "Exit", 100, 250, 72);
					window.draw(txt3);
				}
				else
				{
					gamer_lose = true;

					getText(txt1, font, "You lose", 100, 50, 72);
					window.draw(txt1);

					getText(txt2, font, "Try again?", 100, 150, 72);
					window.draw(txt2);

					getText(txt3, font, "Yes", 100, 250, 72);
					window.draw(txt3);

					getText(txt4, font, "No", 250, 250, 72);
					window.draw(txt4);
				}
			}

			window.display();
			
			if ( bombs.size() != 0)
			{ 
				for (list<list<bomb>::iterator>::iterator i = lst_iter.begin(); i != lst_iter.end(); ++i)
				{
					bombs.remove( *(*i));
				}
				lst_iter.clear();
			}
	} //while (window.isOpen())

    return 0;
}
Пример #16
0
//-----------------------------------
void bomb::damage(sf::RenderWindow& window, sf::Sprite& sprFire)
{

	if (scrn.getArrayElement(calculateIndex(b),calculateIndex(l)+1) != 4)
	{
		for (int i=0; i <= dst; ++i)
		{
			if (scrn.getArrayElement(calculateIndex(b), calculateIndex(l)+i) == 2 )
			{
				if (first)
				{
					bricks.remove(brick(l+i*step, r+(i*step), b, t, scrn));
					scrn.setArrayElement(0, calculateIndex(b), calculateIndex(l)+i);
				}
				break;
			}
			if (scrn.getArrayElement(calculateIndex(b), calculateIndex(l)+i) == 3)
			{
				enemies.remove( enemy ( l + i*step, r + i*step, b, t, scrn) );
				scrn.setArrayElement(0, calculateIndex(b), calculateIndex(l) + i);
			}
			sprFire.setPosition(sf::Vector2f(l + i*step, b));
			window.draw(sprFire);
		}
	}
	if (scrn.getArrayElement(calculateIndex(b), calculateIndex(l)-1) != 4)
	{
		for (int i=0; i <= dst; ++i)
		{
			if (scrn.getArrayElement(calculateIndex(b), calculateIndex(l) - i) == 2 && first)
			{
				if(first)
				{
					bricks.remove(brick( l - i*step, r - i*step, b, t, scrn));
					scrn.setArrayElement(0, calculateIndex(b), calculateIndex(l) - i);
				}
				break;
			}
			if (scrn.getArrayElement(calculateIndex(b), calculateIndex(l) - i - 1) == 3 )
			{
				enemies.remove( enemy (l-i*step, r-i*step, b, t, scrn) );
				scrn.setArrayElement(0, calculateIndex(b), calculateIndex(l) - i - 1);
			}
			sprFire.setPosition(sf::Vector2f(l- i*step, b));
			window.draw(sprFire);
		}
	}
	if (scrn.getArrayElement(calculateIndex(b)+1, calculateIndex(l)) != 4 )
	{
		for (int i=0; i <= dst; ++i)
		{
			if (scrn.getArrayElement(calculateIndex(b)+i, calculateIndex(l)) == 2  && first)
			{
				if(first)
				{
					bricks.remove(brick(l, r, b+i*step, t+i*step, scrn));
					scrn.setArrayElement(0, calculateIndex(b)+i, calculateIndex(l));
				}
				break;
			}
			if (scrn.getArrayElement(calculateIndex(b)+i, calculateIndex(l)) == 3)
			{
				enemies.remove( enemy (l, r, b+i*step, t+i*step, scrn) );
				scrn.setArrayElement(0, calculateIndex(b)+i, calculateIndex(l));
			}
			sprFire.setPosition(sf::Vector2f(l, b+ i*step));
			window.draw(sprFire);
		}
	}
	if (scrn.getArrayElement(calculateIndex(b)-1, calculateIndex(l)) != 4)
	{
		for (int i = 0; i <= dst; i++)
		{
			if (scrn.getArrayElement(calculateIndex(b)-i, calculateIndex(l)) == 2)
			{
				if (first)
				{
					bricks.remove(brick (l, r, b-i*step, t-i*step, scrn));
					scrn.setArrayElement(0, calculateIndex(b)-i, calculateIndex(l));
				}
				break;
			}
			if (scrn.getArrayElement(calculateIndex(b)-i, calculateIndex(l)) == 3)
			{
				enemies.remove (enemy (l, r, b-i*step, t-i*step, scrn));
				scrn.setArrayElement (0, calculateIndex(b)-i, calculateIndex(l));
			}
			sprFire.setPosition(sf::Vector2f(l , b - i*step));
			window.draw(sprFire);
		}
	}
	if (first)
	{
		first = false;
	}
	return;
}
Пример #17
0
void conn::conecta(std::string server,std::string port){
	bot::team_id id = 1000;

	boost::asio::io_service io_service;

	tcp::resolver resolver(io_service);
	auto endpoint_iterator = resolver.resolve({ server, port });

	std::shared_ptr<tcp::socket> socket(new tcp::socket(io_service));
	boost::asio::connect(*socket, endpoint_iterator);

	bot::field_size field_width;
	bot::field_size field_height;

	int win_width = 500;
	int win_height = 500;

	bots Mundo;

	boost::mutex state_mutex;

	SDL_Init(SDL_INIT_VIDEO);
	atexit(SDL_Quit);

	SDL_WM_SetCaption("Superbots", "Superbots");

	SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
	SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
	SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
	SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
	SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

	MYscreen.set_screen(win_width, win_height);

	SDL_Event event;
	bool gameover = false;

	bool connected = false;

	boost::thread t = boost::thread([this,socket, &state_mutex, &gameover, &connected, &Mundo, &id, &field_width, &field_height, &win_width, &win_height] () { game_thread(socket, gameover, Mundo, id, state_mutex, field_width, field_height, win_width, win_height, connected); } );

	while (!gameover) {
		if(connected) {
			if (SDL_PollEvent(&event)) {
				switch (event.type) {
					case SDL_QUIT:
						gameover = true;
						break;
					case SDL_KEYDOWN:
						switch (event.key.keysym.sym) {
							case SDLK_ESCAPE:
							case SDLK_q:
								gameover = true;
								break;
							default:
								break;
						}
						break;
					case SDL_VIDEORESIZE:
						win_width = event.resize.w;
						win_height = event.resize.h;
						MYscreen.set_screen(win_width, win_height, field_width, field_height);
						break;
					}
                }

				glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

                glMatrixMode(GL_MODELVIEW);

                {
                    boost::mutex::scoped_lock lock(state_mutex);
                    Mundo.for_each_bot([&Mundo] (const bot & the_bot) {
                    	auto t = the_bot.get_team() + 1;

                    	glColor3f(t * 0.2, 1 - t * 0.3, t * 0.1);

                    	const bot::position & pos = the_bot.get_position();

                    	glLoadIdentity();
                    	glTranslatef(pos.first, pos.second, 0);

                    	glBegin(GL_QUADS);
                    	glVertex3f(0.0f, 0.0f, 0.0f);
                    	glVertex3f(1.0f, 0.0f, 0.0f);
                    	glVertex3f(1.0f, 1.0f, 0.0f);
                    	glVertex3f(0.0f, 1.0f, 0.0f);
                    	glEnd();
                    });
                }
                SDL_GL_SwapBuffers();
            }
	}
        if(Mundo.bot_count().size() != 1) {
            std::cout << "Shit!" << std::endl;
        }
        else {
            for(auto inmortal : Mundo.bot_count()) {
                std::cout << inmortal.first << " se ha pulido a todos!" << std::endl;
            }
        }
    }
Пример #18
0
	// CurGame's primary method, this encapsulates the entire battle
	// routine, the routine ends as soon as the enemy or the player
	// reach 0 or less hit points. Returns a boolean to determine if
	// the player died during combat or an attempt to run away.
	bool battle()
	{
		// Initialize battle()'s variables to NULL
		// maxhp stores the players original max health so the value
		// can be restored if the player survives the encounter
		int select=0, maxhp=Play1.health;
		bool playDeath=false, enemDeath=false;
		
		// Keep fighting until the player runs or someone dies
		do
		{
			// Clear the display to draw the next frame
			display.Clear();
			
			// Display the battle screen
			select = battleMenu();
			
			// Check which option was chosen
			// The enemy is implemented without AI and will follow
			// suit with the player, a simple AI would evaluate 
			// which of its stats are greater than the player's
			switch( select )
			{
				// Strength based attack
				case 1:
					enemDeath = playAttRound(1);
					playDeath = enemAttRound(1);
					display.pause();
					break;
				// Dexterity based attack
				case 2:
					enemDeath = playAttRound(2);
					playDeath = enemAttRound(2);
					display.pause();
					break;
				// Spellcasting (Intelligence based attack)
				case 3:
					enemDeath = playAttRound(3);
					playDeath = enemAttRound(3);
					display.pause();
					break;
				// Attempt to run away from combat	
				case 4:
					// If they successfully run away
					if ( run() )
					{
						Enem1.xpvalue = 0;
						cout << "\nYou ran away successfully!!!\n";
						display.pause();
						return true;
					}
					// Or else the enemy gets a free attack on the player
					else
					{
						cout << "\nYou failed to get away, the enemy hits you!\n";
						playDeath = enemAttRound( randnum(3, 127) );
						display.pause();
					}
					break;
				// Let the user know their input is invalid	
				default:
					cout << "\nPlease enter a correct choice!!!\n";
                    display.pause();
					break;
			}

			// Check to see if either or both of our competitors have died
			if( playDeath && enemDeath )
			{
				cout << "\n\nYou simultaneously strike each other fatally!!! A true warrior's death...\n";
				display.pause();
				return false;
			}
			else if( playDeath && !enemDeath )
			{
				cout << "\n\nYou died!!!\n";
				display.pause();
				return false;
			}
			
			else if( enemDeath && !playDeath )
			{
				cout << "\n\nYou have slain the " << Enem1.ename << "!!!\n";
				// Reset the players health to maximum after combat
				Play1.health=maxhp;
				display.pause();
				return true;
			}
	
		}while( !playDeath && !enemDeath );
	};