Esempio n. 1
0
//Our main function sets up what it needs to set up, 
//it initializes curses, the dungeon, and runs the primary
//loop that defines the game, and then quits when we're done
int main(){
	//Declare our input character
	char c;
	//Set up curses
	initCurses();
	//Initialize the dungeon
	Dungeon dungeon;

	//Initialize five levels of the dungeon
	for(int i = 0; i < 5; i++){
		//Declare a new level
		Level* newLevel = new Level(generateLevel(36, 36, i));
		//Tell it what level it is
		newLevel->levelNumber = i;
		//Push it onto the dungeon's vector of levels
		dungeon.level.push_back(newLevel);
	}
	
	//The player starts on the first level
	player.currentLevel = dungeon.level[0];
	//Point the player to the dungeon
	player.dungeon = &dungeon;
	//Figure out what the player can see
	player.getLineOfSight();
	//Start the game
	dungeon.processTurn();

	cursesCleanup();
}
Esempio n. 2
0
Dungeon MazeGenerator::Generate()
{
    Dungeon d;

    d.SetCell(5,5,'@');


    return d;
}
Esempio n. 3
0
	Enemy::Enemy(Dungeon& dungeon)
		:je::Entity(&dungeon, "Enemy", sf::Vector2f(dungeon.getWidth() / 4, dungeon.getHeight() / 4), sf::Vector2i(32, 32), sf::Vector2i(-16, -16))
		, sprite(dungeon.getGame().getTexManager().get("enemy.png"))
		, bBox(this->getPos().x - 50, this->getPos().y - 100, 200, 200)
		, dungeon(dungeon)
		, enemyID(0)

{
	sprite.setOrigin(16, 16);

}
Esempio n. 4
0
int main()
{
	Dungeon level;

	mt19937 mt;
	mt.seed( time(NULL));

	level.createLevel(mt);
	level.outputLevel();

	return 0;
}
Esempio n. 5
0
void runGame() {
    bool win = false;
    string strbuff;
    char race;
    cout<<"What race do you want to start with? ";
    cin>>race;                               //gets the race
    if (race != 'h'&&race != 'o'&&race != 'e'&&race != 'd') {
        race='h';                            //by default human
    }
    Dungeon *d = new Dungeon(race);
    d->readMap("default.dat");               //initializes Dungeon
    d->print();
    while (!win&&(strbuff!="q")&&!cin.eof()) {
        cin>>strbuff;                       //gets input
        if (strbuff == "r") {
            d->deleteDungeon();
            runGame();
        }
        if  (strbuff == "no" || strbuff == "so"||strbuff == "ea"||
             strbuff == "we"||strbuff == "ne"||strbuff == "nw"||
             strbuff == "se"||strbuff == "sw") {                             //case move
            win = d->movePlayer(strbuff);
        }
        else if (strbuff == "a"){
            cin>>strbuff;
            win = d->attack(strbuff);               //be sure to include the a in front of all the directions
        }
        else if (strbuff == "u"){
Esempio n. 6
0
int main( int /*argc*/, const char** /*argv*/ )
{
	Dungeon dungeon;
	bool done = false;
	char buf[ 256 ];

	while ( !done ) {
		dungeon.Print();
		printf( "\n# # to move, q to quit, r to redraw, d to toggle doors, t for touched\n" );
		//gets( buf );
		//printf( "\n" );

		std::cin.getline( buf, 256 );

		if ( *buf )
		{
			if ( buf[0] == 'q' ) {
				done = true;
			}
			else if ( buf[0] == 'd' ) {
				dungeon.ToggleDoor();
				dungeon.ClearPath();
			}
			else if ( buf[0] == 't' ) {
				dungeon.ToggleTouched();   
			}    
			else if ( buf[0] == 'r' ) {
				dungeon.ClearPath();
			}
			else if ( isdigit( buf[0] ) ) {
				int x, y;
				sscanf( buf, "%d %d", &x, &y );	// sleazy, I know
				dungeon.SetPos( x, y );
			} 
		}
		else
		{				
			dungeon.ClearPath();
		}
	}
	return 0;
}
// Creates a new creature and places it in the maze
void Creature::CBIRTH(dodBYTE typ)
{
	int			u, maz_idx;
	RowCol		rndcell;
	dodBYTE		rw, cl;
	int			TCBindex;

	u = -1;
	do
	{
		++u;
	} while (CCBLND[u].P_CCUSE != 0);
	--CCBLND[u].P_CCUSE;

	CCBLND[u].creature_id = typ;
	CCBLND[u].P_CCPOW = CDBTAB[typ].P_CDPOW;
	CCBLND[u].P_CCMGO = CDBTAB[typ].P_CDMGO;
	CCBLND[u].P_CCMGD = CDBTAB[typ].P_CDMGD;
	CCBLND[u].P_CCPHO = CDBTAB[typ].P_CDPHO;
	CCBLND[u].P_CCPHD = CDBTAB[typ].P_CDPHD;
	CCBLND[u].P_CCTMV = CDBTAB[typ].P_CDTMV;
	CCBLND[u].P_CCTAT = CDBTAB[typ].P_CDTAT;

	do
	{
		do
		{
			cl = (rng.RANDOM() & 31);
			rw = (rng.RANDOM() & 31);
			//printf("          %02X, %02X = %02X\n", rw, cl, dungeon.MAZLND[dungeon.RC2IDX(rw, cl)]);
			rndcell.setRC(rw, cl);
			maz_idx = dungeon.RC2IDX(rw, cl);
		} while (dungeon.MAZLND[maz_idx] == 0xFF);
	} while (CFIND(rw, cl) == false);
	
	//printf("----- %02X: %02X, %02X -----\n", typ, rw, cl);
	CCBLND[u].P_CCROW = rw;
	CCBLND[u].P_CCCOL = cl;

	TCBindex = scheduler.GETTCB();
	scheduler.TCBLND[TCBindex].data = u;
	scheduler.TCBLND[TCBindex].type = Scheduler::TID_CRTMOVE;
	scheduler.TCBLND[TCBindex].frequency = CCBLND[u].P_CCTMV;
}
Esempio n. 8
0
void MazeGenerator::GenerateRooms(Dungeon& d)
{
    vector<Room> rooms;
    int numberOfRooms = (rand() % 10) + 1;
    for(int i = 0; i < numberOfRooms; ++i)
    {
        int height = (rand() % 10) + 1;
        int width = (rand() % 10) + 1;
        int topX = (rand() % d.GetWidth());
        int topY = (rand() % d.GetHeight());

        if(topX + width > d.GetWidth())
        {
            width = d.GetWidth() - topX;
        }

        if(topY + height > d.GetHeight())
        {
            width = d.GetWidth() - topX;
        }

        Room r;
        r.topX = topX;
        r.topY = topY;
        r.bottomX = topX + width;
        r.bottomY = topY + height;

        for(vector<Room>::iterator it = rooms.begin(); it != rooms.end(); it++)
        {
            if((*it).IsOverlapping(r))
            {
                --i;
            }
            else
            {
                rooms.push_back(r);
            }
        }
    }
}
bool display_movement_choices(Player& playerA, Dungeon& dunA)
{
    string user_input;
    bool exit = false;
    bool wrong_input = false;
    system("cls");
    cin.ignore();

    do{//while(exit != true);
    wrong_input = false;//reseting bool
    cout << dunA << endl; //***Display Player Map

    cout << "To move please type correct Letter.______ \n";
    cout << "Move Up   = 'W'  Move Left  = 'A'  |  W  |\n";
    cout << "Move Down = 'S'  Move Right = 'D'  |A S D|\n";
    cout << "To exit type 'Y'. Your Choice: ";
    getline( cin, user_input );
    cout << endl;

    if(user_input == "y" || user_input == "Y")
    {
        exit = true;
    }
    else if(user_input == "W" || user_input == "w" || user_input == "A" || user_input == "a" ||
            user_input == "S" || user_input == "s" || user_input == "D" || user_input == "d")
    {
        system("cls");
        //**** playerA(user_input);//Making movement
        //**********************The below code will make so they see there move and pause then exit out
        //***Display Player Map //playerA;
        Room* currentRoom = dunA.getCurrentRoom();
        int roomNumber = 0;
        if(user_input == "W" || user_input == "w")
        {
            roomNumber = currentRoom->get_north();
            currentRoom = dunA.move(roomNumber);
        }
        if(user_input == "S" || user_input == "s")
        {
            roomNumber = currentRoom->get_south();
            currentRoom = dunA.move(roomNumber);
        }
        if(user_input == "D" || user_input == "d")
        {
            roomNumber = currentRoom->get_east();
            currentRoom = dunA.move(roomNumber);
        }
        if(user_input == "A" || user_input == "a")
        {
            roomNumber = currentRoom->get_west();
            currentRoom = dunA.move(roomNumber);
        }
        cout << dunA << endl; //***Display Player Map
        cout << "To move please type correct Letter.______ \n";
        cout << "Move Up   = 'W'  Move Left  = 'A'  |  W  |\n";
        cout << "Move Down = 'S'  Move Right = 'D'  |A S D|\n";
        cout << "To exit type 'Y'. Your Choice: \n";
        system("PAUSE");

        if(roomNumber == 53)
        {
            system("cls");
            cout << "\nAt long last, you gaze upon the room of treasure you were seeking.\n";
            cout << "Amidst the gold and jewels, you find the legendary Sword Of A Thousand Spoofs.\n";
            cout << "With this sword in your hands, nothing will stand in your way ever again!\n";
            cout << "Congratulations!\n\n";

            system("PAUSE");

            int randNum = rand()%2;
            if(randNum == 0)
            {
                system("cls");
                cout << "\nAs you stand basking in your glory...\n";
                cout << "~~~~~A WILD HOOLIGAN APPEARS!~~~~~\n";
                cout << "Hooligan uses \"stab you in the back\" \nand runs off with the Sword Of A Thousand Spoofs.\n";
                cout << "Next time try a different path to shake off that stupid bandit following you.\n";
                system("PAUSE");
                display_gameover();
            }
            return false;
        }
        if(currentRoom->get_enemy())
        {
            bool cont;
            cont = combat(playerA, roomNumber);
            if(cont == false)
            {
                display_gameover();
                return false;
            }
        }
        if(currentRoom->get_item())
        {

            system("cls");
            cout << "\nYou found an item in this room!\n";
            playerA.addToInventory(pickRandItem());
            system("PAUSE");
        }

        exit = true; // I might need to make a system pause so once
    }
    else
        wrong_input = true;

    system("cls");
    if(wrong_input == true)
        cout << "*~Did not select a valid number~* \n";

    }while(exit != true);
    return true; //game is still running
}
Esempio n. 10
0
int main( int argc, const char* argv[] )
{
	Dungeon dungeon;

	const int NUM_TEST = 389;
	
	int		indexArray[ NUM_TEST ];	// a bunch of locations to go from-to
	float	costArray[ NUM_TEST ];
	int64_t timeArray[ NUM_TEST ];
	int		resultArray[ NUM_TEST ];

	bool useBinaryHash = false;
	bool useList = false;
	bool debug = false;

	#ifdef DEBUG
	debug = true;
	#endif
	#ifdef USE_BINARY_HASH
	useBinaryHash = true;
	#endif
	#ifdef USE_LIST
	useList = true;
	#endif 
	
	printf( "SpeedTest binaryHash=%s list=%s debug=%s\n",
			useBinaryHash ? "true" : "false",
			useList ? "true" : "false",
			debug ? "true" : "false" );
					
	// Set up the test locations, making sure they
	// are all valid.
	for (int i = 0; i < NUM_TEST; ++i) {
		indexArray[i] = (MAPX*MAPY) * i / NUM_TEST;
		costArray[i] = 0.0f;

		int y = indexArray[i] / MAPX;
		int x = indexArray[i] - MAPX*y;
		while (!dungeon.Passable(x, y)) {
			indexArray[i] += 1;
			y = indexArray[i] / MAPX;
			x = indexArray[i] - MAPX*y;
		}
	}
	// Randomize the locations.
	for (int i = 0; i < NUM_TEST; ++i)
	{
		int swapWith = rand() % NUM_TEST;
		int temp = indexArray[i];
		indexArray[i] = indexArray[swapWith];
		indexArray[swapWith] = temp;
	}

	int64_t compositeScore = 0;
	for ( int numDir=4; numDir<=8; numDir+=4 )
	{
		dungeon.maxDir = numDir;
		dungeon.aStar->Reset();

		static const int SHORT_PATH = 0;
		static const int MED_PATH	= 1;
		static const int LONG_PATH  = 2;
		static const int FAIL_SHORT = 3;
		static const int FAIL_LONG  = 4;

		for( int reset=0; reset<=1; ++reset )
		{
			TimePoint clockStart = FastTime();
			for( int i=0; i<NUM_TEST; ++i ) 
			{
				if ( reset )
					dungeon.aStar->Reset();
				
				int startState = indexArray[i];
				int endState = indexArray[ (i==(NUM_TEST-1)) ? 0 : i+1];

				TimePoint start = FastTime();
				resultArray[i] = dungeon.aStar->Solve( (void*)startState, (void*)endState, &dungeon.path, &costArray[i] );
				TimePoint end = FastTime();

				timeArray[i] = Nanoseconds(start, end);
				MPASSERT(timeArray[i]);
			}
			TimePoint clockEnd = FastTime();

			#ifndef PROFILING_RUN
			// -------- Results ------------ //
			const float shortPath = (float)(MAPX / 4);
			const float medPath = (float)(MAPX / 2 );

			int count[5] = { 0 };	// short, med, long, fail short, fail long
			int64_t time[5] = { 0 };

			for(int i=0; i<NUM_TEST; ++i )
			{
				int idx = 0;
				if ( resultArray[i] == MicroPather::SOLVED ) {
					if ( costArray[i] < shortPath ) {
						idx = SHORT_PATH;
					}
					else if ( costArray[i] < medPath ) {
						idx = MED_PATH;
					}
					else {
						idx = LONG_PATH;
					}
				}
				else if ( resultArray[i] == MicroPather::NO_SOLUTION ) {
					int startState = indexArray[i];
					int endState = indexArray[ (i==(NUM_TEST-1)) ? 0 : i+1];
					int startX, startY, endX, endY;
					dungeon.NodeToXY( (void*)startState, &startX, &startY );
					dungeon.NodeToXY( (void*)endState, &endX, &endY );

					int distance = abs( startX - endX ) + abs( startY - endY );

					if ( distance < shortPath ) {
						idx = FAIL_SHORT;
					}
					else {
						idx = FAIL_LONG;
					}
				}
				count[idx] += 1;
				time[idx] += timeArray[i];
			}

			printf( "Average of %d runs. Reset=%s. Dir=%d.\n",
					NUM_TEST, reset ? "true" : "false", numDir );
			printf( "short(%4d)       = %7.2f\n", count[0],	double(time[0]) / count[0] * 0.001 );
			printf( "med  (%4d)       = %7.2f\n", count[1],	double(time[1]) / count[1] * 0.001 );
			printf( "long (%4d)       = %7.2f\n", count[2],	double(time[2]) / count[2] * 0.001 );
			printf( "fail short (%4d) = %7.2f\n", count[3],	double(time[3]) / count[3] * 0.001 );
			printf( "fail long  (%4d) = %7.2f\n", count[4],	double(time[4]) / count[4] * 0.001 );

			int64_t totalTime = 0;
			int totalCount = 0;
			for( int k=0; k<5; ++k ) {
				totalTime += time[k];
				totalCount += count[k];
			}	
			printf( "Average           = %7.2f\n", double(totalTime) / totalCount * 0.001 );
			compositeScore += totalTime / totalCount;
			#endif
		}
	}
	printf( "Composite average = %7.2f\n", double(compositeScore) / 4 * 0.001);

	return 0;
}
Esempio n. 11
0
// This routine creates a new dungeon level,
// filling it with objects and creatures.  It
// should probably be moved to the Dungeon class.
void Creature::NEWLVL()
{
	dodBYTE	a, b;
	int		u, idx, tmp;

	CMXPTR = game.LEVEL * CTYPES;
	dungeon.CalcVFI();
	for (tmp = 0; tmp < 32; ++tmp)
	{
		CCBLND[tmp].clear();
	}
	scheduler.SYSTCB();
	dungeon.DGNGEN();
	u = CMXPTR;
	a = CTYPES - 1;
	do
	{
		b = CMXLND[u + a];
		if (b != 0)
		{
			do
			{
				CBIRTH(a);
				--b;
			} while (b != 0);
		}
		--a;
	} while (a != 0xFF);

	u = -1;
	object.OFINDF = 0;
	do
	{
		idx = object.FNDOBJ();
		if (idx == -1)
		{
			break;
		}
		if (object.OCBLND[idx].P_OCOWN == 0xFF)
		{
			do
			{
				++u;
				if (u == 32)
				{
					u = 0;
				}
				if (CCBLND[u].P_CCUSE != 0)
				{
					tmp = CCBLND[u].P_CCOBJ;
					CCBLND[u].P_CCOBJ = idx;
					object.OCBLND[idx].P_OCPTR = tmp;
					break;
				}
			} while (true);
		}
	} while (true);

	// Determine video invert Setting
	viewer.setVidInv((game.LEVEL % 2) ?true: false);
}
Esempio n. 12
0
void
TownGenerator::Generate ()
{
	// STODO: have two options for building symmetry: symmetrical section placement and centered section placement.
	uint32 worldSize = WorldGeneratorAPI ()->GetWorldSize ();	
	uint32 numTownsLeft = 3; //(worldSize / (SECTOR_BLENGTH * 2)) + 1; // STODO: change this in future for larger maps
	uint32 numDungeonsLeft = 1;
	townSupportingAreas_ = WorldGeneratorAPI ()->GetTownSupportingAreas ();
	for( uint32 i = 0; i < townSupportingAreas_->GetCount(); ++i )
	{
		isSmoothedTownSupportingAreas_.InsertBack(false); // this ensures terrain is smoothed in a zone only once
	}

	// STODO: use this to shift the bounds of a town/dungeon away from sector borders
	townSupportingAreasSparseArray_ = WorldGeneratorAPI ()->GetTownSupportingAreasSparseArray (); 

	uint32 unsuccessfulAddCount = 0;
	while (numTownsLeft > 0 || numDungeonsLeft > 0)
	{
		if (townSupportingAreas_->GetCount () == 0)
			break;

		uint32 randIndex = rand () % townSupportingAreas_->GetCount ();

		// check if town is to be placed
		uint32 xMin = (townSupportingAreas_->GetElement (randIndex) % (worldSize / SECTOR_BLENGTH)) * SECTOR_BLENGTH;
		uint32 yMin = (townSupportingAreas_->GetElement (randIndex) / (worldSize / SECTOR_BLENGTH)) * SECTOR_BLENGTH;
		bool doLevelTerrain = !isSmoothedTownSupportingAreas_[randIndex];

		if (rand () % 2 == 0 && numDungeonsLeft > 0)
		{
			Dungeon* dungeon = new Dungeon (xMin, yMin, doLevelTerrain);
			isSmoothedTownSupportingAreas_[randIndex] = true;
			if (dungeon->PlaceBuildings ())
			{
				dungeon->Build ();
				dungeons_.InsertBack (dungeon);
				townSupportingAreas_->Remove (randIndex);
				isSmoothedTownSupportingAreas_.Remove( randIndex );
				--numDungeonsLeft;
			}
			else
			{
				delete dungeon;
				++unsuccessfulAddCount;
			}
		}
		else if (numTownsLeft > 0)
		{
			Town* town = new Town (xMin, yMin, doLevelTerrain);
			isSmoothedTownSupportingAreas_[randIndex] = true;
			if (town->PlaceBuildings ())
			{
				town->Build ();
				towns_.InsertBack (town);
				townSupportingAreas_->Remove (randIndex);
				isSmoothedTownSupportingAreas_.Remove( randIndex );
				--numTownsLeft;
			}
			else
			{
				delete town;
				++unsuccessfulAddCount;
			}
		}

		if (unsuccessfulAddCount > 25)
			break;
	}

	// STODO: this is preliminary code:
	// connect roads between town
	GetWorld()->BeginModify();
	RoadGenerator rGen;
	Vector<BaseArea*> areas;
	for( uint32 i = 0; i < towns_.GetCount(); ++i )
	{
		areas.InsertBack( towns_[i] );
	}
	for( uint32 i = 0; i < dungeons_.GetCount(); ++i )
	{
		areas.InsertBack( dungeons_[i] );
	}
	if( towns_.GetCount() >= 2 )
	{
		rGen.ConnectZones(ROAD_PRIMARY, towns_[0], towns_[1], 1.0f, &areas); // STODO: add avoidance points for all zones as well
		if( towns_.GetCount() >= 3 )
		{
			rGen.ConnectZones(ROAD_PRIMARY, towns_[0], towns_[2], 1.0f, &areas);
			rGen.ConnectZones(ROAD_PRIMARY, towns_[1], towns_[2], 1.0f, &areas);
		}
	}
	GetWorld()->EndModify();

	// DEBUG_TOWNGENERATOR:
	/*
	GetWorld()->BeginModify();
	AStar3D search;
	search.AllocMem( 150, 150, 120 );
	
	// note: make goal.z unreachable and time it
	for (uint32 i = 0; i < 1; ++i)
	{
		UPoint3D start = dungeons_.GetBack()->GetBuilding(0)->GetRoom(dungeons_.GetBack()->GetBuilding(0)->GetNumRooms() - 1)->GetCenterPoint();
		start.z = dungeons_.GetBack()->GetBuilding(0)->GetRoom(dungeons_.GetBack()->GetBuilding(0)->GetNumRooms() - 1)->GetMinZ() + 1;
		UPoint3D goal = towns_.GetFront()->GetBuilding(0)->GetRoom(towns_.GetFront()->GetBuilding(0)->GetNumRooms() - 1)->GetCenterPoint();
		goal.z = towns_.GetFront()->GetBuilding(0)->GetRoom(towns_.GetFront()->GetBuilding(0)->GetNumRooms() - 1)->GetMinZ() + 1;

		if( search.Search( start, goal, 2, 1.0f ) )
		{
			Vector<UPoint3D>* lastPath = search.GetLastPath();
			
			// DEBUG_ASTAR3D: show path
			for (uint32 i = 0; i < lastPath->GetCount(); ++i)
			{
				UPoint3D& point = lastPath->GetElement( i );
				uint32 sCubeBuf = 0;
				SetSCubeTerrainType (&sCubeBuf, TERRA_LAVA);
				GetWorld()->SetSCube  (point.x, point.y, point.z, sCubeBuf);
			}
		}
		search.ClearMem();
	}
	
	search.FreeMem();
	GetWorld()->EndModify();
	*/
	// DEBUG_ASTAR3D: end test search

}
Esempio n. 13
0
void GenLagoonZone::placeDungeon(dungeonType type)
{	
	int screenNumber = 0;

	int screensPerRow = overworld->getWorldSizeW() / SCREEN_WIDTH;
	int tilesPerRow = screensPerRow*SCREEN_WIDTH;
	// Pantalla de comienzo del gusano
	// por ahora se elige una al azar y creo que se va a quedar así
	int tile;

	if(type == NORMAL)
	{
		if ( screenList->size() != 0 )
		{

			int iniTile = getTileOfScreen(screenNumber);
			tile = iniTile;
			bool placed = false;
			short range = 20;
			short tries = 0;
		
			while (!placed){
				if (tile < (int)overworld->mapTileMatrix->size() &&
					overworld->mapTileMatrix->at(tile)->getZoneNumber() == this->zoneNumber && 
					overworld->mapTileMatrix->at(tile)->getSolid() > 0 ){
					if ( !isFrontierNear(tile, range) && (screenNumber != (overworld->getWorldSizeW()*overworld->getWorldSizeH())/2)){
						placed = true;
						dungEntranceTile = tile;
						dungEntranceScreenN = screenNumber;
						// Aqui se hara el new Dungeon tal tal
						// new Dungeon (bla bla); 
					}
					else{
						iniTile = getTileOfScreen(screenNumber);
						tile = iniTile;
					}
				}
				else{
					iniTile = getTileOfScreen(screenNumber);
					tile = iniTile;
				}
				tries++;

				if (tries == 10 || tries == 20 || tries == 30)
					range -=5;
				else if (tries == 40)
					range = 2;
				else if (tries == 50)
					range = 0;
			}
		}
	}
	/*else
	{
		//la ponemos en medio del mundo
		screenNumber = (overworld->getWorldSizeW()/2)+(overworld->getWorldSizeW()*(overworld->getWorldSizeH()/2));
		dungEntranceTile = (((screenNumber % overworld->getWorldSizeW())*SCREEN_WIDTH)+SCREEN_WIDTH/2)+(((screenNumber / overworld->getWorldSizeW())*SCREEN_HEIGHT)+SCREEN_HEIGHT/2);
	}*/

	int tileX, tileY, screenTileX, screenTileY;
	int screenX, screenY;
	int dunScreenX, dunScreenY, dunTileX, dunTileY;
	
	if(type == NORMAL)
	{
		//coordenadas de la screenN dentro del mundo.
		screenX = screenNumber % overworld->getWorldSizeW(); // % screensPerRow
		screenY = screenNumber / overworld->getWorldSizeW();

		//introducimos en el mundo, la posición de la nueva dungeon:
		GPoint p;
		p.x = screenX;
		p.y = screenY;
		overworld->dungeonScreenPoints.push_back(p);

		screenTileX = (dungEntranceTile % overworld->getTileWorldSizeW()) % SCREEN_WIDTH; // % tilesPerRow
		screenTileY = (dungEntranceTile / overworld->getTileWorldSizeW()) % SCREEN_HEIGHT;
	
	
		// el tile dentro del mapa de tiles grande.
		//int tile = (tileY * overworld->getTileWorldSizeW()) + tileX;

		DungeonPos dp;
		dp.screenX = screenX;
		dp.screenY = screenY;
		dp.tileX = screenTileX; 
		dp.tileY = screenTileY+1; //No queremos aparecer encima de la teleportacíon de la mazmorra!

		Dungeon* newDungeon = genDungeon->createDungeon(zone, gameDifficulty, numDungeon, ratioDungeon, idTool, keyObj, dp/*Posición de la mazmorra*/, myDB);

		dunScreenX = newDungeon->getIniDScreenX();
		dunScreenY = newDungeon->getIniDScreenY();
		dunTileX = newDungeon->getIniDTileX();
		dunTileY = newDungeon->getIniDTileY();

		EntityTeleporter* e = new EntityTeleporter(TELEPORTATOR, screenTileX, screenTileY, -1/*idCollectable*/, -1/*linkedTo*/, numDungeon/*idMap*/, dunScreenX, dunScreenY, dunTileX, dunTileY);
		overworld->screenList->at(screenNumber)->getEntities()->push_back(e);

	}
	else //ESTAMOS CON LA MAZMORRA FINAL
	{
		screenTileX = SCREEN_WIDTH/2;
		screenTileY = SCREEN_HEIGHT/2;
		screenX = overworld->getWorldSizeW()/2;
		screenY = overworld->getWorldSizeH()/2;

		//introducimos en el mundo, la posición de la nueva dungeon:
		GPoint p;
		p.x = screenX;
		p.y = screenY;
		overworld->dungeonScreenPoints.push_back(p);

		DungeonPos dp;
		dp.screenX = screenX;
		dp.screenY = screenY;
		dp.tileX = screenTileX; 
		dp.tileY = screenTileY+1; //No queremos aparecer encima de la teleportacíon de la mazmorra!

		Dungeon* newDungeon = genDungeon->createFinalDungeon(zone, gameDifficulty, numDungeon+1, ratioDungeon, idTool, keyObj, dp/*Posición de la mazmorra*/, myDB);

		dunScreenX = newDungeon->getIniDScreenX();
		dunScreenY = newDungeon->getIniDScreenY();
		dunTileX = newDungeon->getIniDTileX();
		dunTileY = newDungeon->getIniDTileY();

		EntityTeleporter* e = new EntityTeleporter(TELEPORTATOR, screenTileX, screenTileY, -1/*idCollectable*/, -1/*linkedTo*/, numDungeon+1/*idMap*/, dunScreenX, dunScreenY, dunTileX, dunTileY);
		overworld->screenList->at((screenY*overworld->getWorldSizeW())+screenX)->getEntities()->push_back(e);

		//PARA QUE QUEDE BONITO PONEMOS SU ENTRADA:
		tileX = screenX*SCREEN_WIDTH + screenTileX;
		tileY = screenY*SCREEN_HEIGHT + screenTileY;
		tile = (tileY * overworld->getTileWorldSizeW()) + tileX;
		placeEntrance(tile);

	}
	overworld->dungeonTilesPoints.push_back(tile);
	//////////////////////////////////////////////////// DEBUG!!
	// Aparecemos en la última mazmorra creada por el generador
	//overworld->screenList->at(screenNumber)->setPosIni(tileX + tilesPerRow, tileY);
	//overworld->setStartLocation(screenX, screenY);
}
Esempio n. 14
0
int main( int argc, char *argv[] ){
	Dungeon game;
	return game.exec();
}
Esempio n. 15
0
int main( int /*argc*/, const char** /*argv*/ )
{
	{
		// Run the test code.
		Dungeon test;

		const int NUM_TEST = 5;
		int tx[NUM_TEST]	= {	24,	25,	10,	6,	0	};	// x of test
		int ty[NUM_TEST]	= {	9,	9,	5,	5,	0	};	// y of test
		int door[NUM_TEST]	= {	0,	0,	0,	1,	0	};	// toggle door? (before move)
		int result[NUM_TEST]= { MicroPather::SOLVED, MicroPather::SOLVED, MicroPather::NO_SOLUTION,
								MicroPather::SOLVED, MicroPather::SOLVED };
		unsigned check[NUM_TEST]	= { 139640, 884, 0, 129313, 2914 };

		for( int i=0; i<NUM_TEST; ++i )
		{
			if ( door[i] )
				test.ToggleDoor();
			int _result = test.SetPos( tx[i], ty[i] );

			if ( _result == result[i] )	{
				// result good.
				if ( _result == MicroPather::SOLVED ) {
					if ( test.Checksum() == check[i] )
						printf( ">> Test %d to (%d,%d) ok\n", i, tx[i], ty[i] );
					else
						printf( ">> Test %d to (%d,%d) BAD CHECKSUM\n", i, tx[i], ty[i] );
				}
				else {
					printf( ">> Test %d to (%d,%d) ok\n", i, tx[i], ty[i] );
				}
			}
			else {
				printf( ">> Test %d to (%d,%d) BAD RESULT\n", i, tx[i], ty[i] );
			}
		}
	}


	Dungeon dungeon;
	bool done = false;
	char buf[ 256 ];

	while ( !done ) {
		dungeon.Print();
		printf( "\n# # to move, q to quit, r to redraw, d to toggle doors, t for touched\n" );
		//gets( buf );
		//printf( "\n" );

		std::cin.getline( buf, 256 );

		if ( *buf )
		{
			if ( buf[0] == 'q' ) {
				done = true;
			}
			else if ( buf[0] == 'd' ) {
				dungeon.ToggleDoor();
				dungeon.ClearPath();
			}
			else if ( buf[0] == 't' ) {
				dungeon.ToggleTouched();   
			}    
			else if ( buf[0] == 'r' ) {
				dungeon.ClearPath();
			}
			else if ( isdigit( buf[0] ) ) {
				int x, y;
				sscanf( buf, "%d %d", &x, &y );	// sleazy, I know
				dungeon.SetPos( x, y );
			} 
		}
		else
		{				
			dungeon.ClearPath();
		}
	}
	return 0;
}