Example #1
0
  void createRooms(bsp *n){
    if(n->leftNode != nullptr || n->rightNode != nullptr){
      if(n->leftNode != nullptr){
	createRooms(n->leftNode);
      }

      if(n->rightNode != nullptr){
	createRooms(n->rightNode);
      }
    
    }
    else{
      
      P roomSize = P(Rng::randInt(3, n->w - 2),
		     Rng::randInt(3, n->h - 2));

      P roomPos = P(Rng::randInt(1, n->w - roomSize.x - 1),
		    Rng::randInt(1, n->h - roomSize.y - 1));
    
      R *tempRoom = new R(n->x + roomPos.x, n->y + roomPos.y, n->x + roomPos.x + roomSize.x,
			  n->y + roomPos.y + roomSize.y);
           
      mapGen::rooms.push_back(tempRoom);
    }      
  
  }
Example #2
0
AMenu	*JoinRoomMenu::myUpdate(sf::Event *event, std::map <std::string, bool>	&state, CommandHandler	*comhandler, 
				  std::vector<std::string> *availlablerooms, Room	*room)
{
	if (event && event->type == sf::Event::KeyPressed)
	{
		int	tmp = leftOrRight;
		int	keyCode = event->key.code;
		if (keyCode == sf::Keyboard::Left)
			leftOrRight = 4;
		if (keyCode == sf::Keyboard::Right)
			leftOrRight = 6;
		if (leftOrRight != tmp)
		{
			if (Menu.size() > 0)
				Menu[selected]->setSelected(false);
			std::vector<HudWindow *>	vectTmp = Hud;
			Hud = Menu;
			Menu = vectTmp;
			selected = 0;
			if (Menu.size() > 0)
				Menu[selected]->setSelected(true);			
		}
	}
	if (inLoading == false)
		return (NULL);
	if (state["Pending"] == false)
	{
		inLoading = false;
		return (createRooms(availlablerooms));
	}
	return (NULL);
}
Example #3
0
void	Dungeon::initDungeon(TileMap *destination, int width, int height, bool create = false){

	if (width > MAP_WIDTH || height > MAP_HEIGHT)
		return;

	destMap = destination;
	TileMap *dungeonMap = new TileMap(width, height);

	if (create){
		createRooms( MAX_ROOMS, ROOM_MIN_SIZE, ROOM_MAX_SIZE, dungeonMap);
		connectRooms(dungeonMap);

		destMap->importMap(dungeonMap);
	}
}
Example #4
0
SharedStack_t*
SharedStack_Alloc(int doubleProcess, int stackletSize, int globalLocSize,
	int rootLocSize, int objSize, int segmentSize, int backObjSize,
	int backLocSize)
{
	SharedStack_t *ss = (SharedStack_t *) malloc(sizeof(SharedStack_t));
	ss->doubleProcess = doubleProcess;
	init_localWork(&ss->work, objSize, segmentSize, globalLocSize,
		rootLocSize, stackletSize, objSize, backLocSize);
	ss->numLocalStack = 0;
	ss->threeRoom = createRooms(3);
	/* check if stack empty in push room */
	assignExitCode(ss->threeRoom, 1, &finalizer, (void *) ss);
	ss->numPush = ss->numPop = 0;
	return ss;
}
Example #5
0
bool DungeonTest::init()
{
	if ( !Layer::init() )
	{
		return false;
	}
	srand((int)time(0));
	_drawnode = DrawNode::create();
	addChild(_drawnode);
	
	auto winSize = Director::getInstance()->getWinSize();
	_width = (int)winSize.width / TILED_WIDTH - 1;
	_height = (int)winSize.height / TILED_WIDTH - 1;
	
	//memory
	_blocks = new int*[_width];
	for (int i = 0 ; i < _width ; i++)
	{
		_blocks[i] = new int[_height];
		for (int j = 0 ; j < _height ; j++)
		{
			_blocks[i][j] = BLOCK_BLANK;
		}
	}

	createRooms();
	createCorridors();
	connect();
	removeDeadEnds();

	renderScene();

	int a = _regionRoomMax;
	int b = _regionCorridorMax;

	return true;
}
Example #6
0
 /**
  * Create the game and initialise its internal map.
  */
 Game::Game() 
 {
     createRooms();
     parser = new Parser();
 }
Example #7
0
  void init(){

    // clear all stuff
    for (std::vector<R*>::iterator it = rooms.begin() ; it != rooms.end(); ++it){
      delete (*it);
    } 
    rooms.clear();

    while(!nodes.empty()) delete nodes.front(), nodes.pop_front();
    
    
    player_p = P(0,0);
    
    bsp* root = new bsp(1,1,g::MAP_WIDTH, g::MAP_HEIGHT);

    nodes.push_back(root);
    
    bool didSplit = true;

    while(didSplit){

      didSplit = false;

      for(auto& i : nodes){

	if(i->leftNode == nullptr && i->rightNode == nullptr){
	  if(i->w > MAX_NODE_SIZE || i->h > MAX_NODE_SIZE || Rng::randInt(0,100) > 25){

	    if(i->split()){
	      nodes.push_back(i->leftNode);
	      nodes.push_back(i->rightNode);
	      didSplit = true;
	    }

	  }
	
	}
      
      }
      
    }
    // These functions will create the actual map in the _map array.
    fillRect(R(P(0,0), P(g::MAP_WIDTH, g::MAP_HEIGHT)), '#');
    createRooms(root);  // Creates the rooms within the bsp nodes
    createConnection(); // Draws connections from each room
    for(auto i : rooms){
      fillRect(*i, '.');
    }

    // Add some monsters
    for(unsigned int i = 0; i < rooms.size(); ++i){
      addMonster(rooms[i]->center());
    }
    
    // add player in a random room
    int pStartRoom = 0;
    while(pStartRoom == 0){
      pStartRoom = Rng::randInt(1,rooms.size());
      player_p = rooms[pStartRoom]->center();
    }
    _map[player_p.x][player_p.y] = '@';

    // Add Doors
    addDoors();

    // add stair to next level
    bool stairsAdded = false;
    while(!stairsAdded){
      int roomId = Rng::randInt(0, rooms.size());
      if(_map[rooms[roomId]->center().x][rooms[roomId]->center().y] != '@'){
	_map[rooms[roomId]->center().x][rooms[roomId]->center().y] = '<';
	stairs_p = rooms[roomId]->center();
	stairsAdded = true;
      }
    }
    
    // Throw in some random items
    for(unsigned int i = 0; i < rooms.size(); ++i){
      if(Rng::randInt(0,100) < 20){
	addItem(rooms[i]->randPoint());
      }
    }
    
    if(Debug::debugEnabled)
      drawMap();

    if(!isMapGood())
      init();
    
  } // init
Gameplay::Gameplay()
{
    createRooms();
}
Example #9
0
int
main(void) {

	struct room *start_room;	/* store start room */
	struct room *goal_room;		/* store goal room */

	int numRooms;
	int numDoors;
	char input_name[21];
	int input_doughnuts;
	int intput_milkshakes;
	char start[21];
	char goal[21];
	

	/*scan number of rooms from input and check if valid */
	scanf("\n%d", &numRooms);
	if(numRooms<=0){
		printf("\nerror");
		return -1;
	}

	base = (struct list *)malloc(sizeof(struct list));
	createRooms(numRooms);
	/*
	//loop that creates new room 
	for(int i=1; i<= numRooms;i++){
		scanf("\n%20s %d %d, &input_name, &input_doughnuts);
	}
	*/
	
	/*scan number of doors from input and check if valid */
	scanf("\n%d", &numDoors);
	if(numDoors<=0){
		printf("\nerror");
		return -1;
	}
	createDoors(numDoors);

	/* scan START and GOAL rooms */
	scanf("\n%s %s",&start, &goal);
	start_room = find_room(start, base);
	goal_room = find_room(goal, base);
	if(start_room == NULL || goal_room == NULL){
		printf("\nerror");
		return -1;
	}

	pointer = start_room;

	while(scanf("\n%c", &move)!=EOF){
			command();
			if(pointer == NULL){
				return -1;
			}
			else if(pointer == goal_room){
				printf("\nwon");
				return 0;
			}
			else{
				printf("\n %s %d %d %d %d", pointer->name, pointer->num_doughnuts, pointer->num_milkshakes, player_doughnuts, player_milkshakes);
			}
	}

	delete_rooms(base);
	return 0;
}