示例#1
0
int
main(int argc, char **argv)
{
	bool noheader = FALSE;	/* set if don't want header */
	bool headeronly = FALSE; /* set if only want header */
	bool examine = FALSE;	/* set if examine a character */
	time_t seconds;		/* for time of day */
	double dtemp;		/* for temporary calculations */

	initialstate();		/* init globals */

	/* process arguments */
	while (--argc && (*++argv)[0] == '-')
		switch ((*argv)[1]) {
		case 's':	/* short */
			noheader = TRUE;
			break;

		case 'H':	/* Header */
			headeronly = TRUE;
			break;

		case 'a':	/* all users */
			activelist();
			cleanup(TRUE);
			/* NOTREACHED */

		case 'p':	/* purge old players */
			purgeoldplayers();
			cleanup(TRUE);
			/* NOTREACHED */

		case 'S':	/* set 'Wizard' */
			Wizard = !getuid();
			break;

		case 'x':	/* examine */
			examine = TRUE;
			break;

		case 'm':	/* monsters */
			monstlist();
			cleanup(TRUE);
			/* NOTREACHED */

		case 'b':	/* scoreboard */
			scorelist();
			cleanup(TRUE);
			/* NOTREACHED */
		}

	if (!isatty(0))		/* don't let non-tty's play */
		cleanup(TRUE);
	/* NOTREACHED */

	playinit();		/* set up to catch signals, init curses */

	if (examine) {
		changestats(FALSE);
		cleanup(TRUE);
		/* NOTREACHED */
	}

	if (!noheader) {
		titlelist();
		purgeoldplayers();	/* clean up old characters */
	}

	if (headeronly)
		cleanup(TRUE);
	/* NOTREACHED */

	do {
		/* get the player structure filled */
		Fileloc = -1L;

		mvaddstr(22, 17, "Do you have a character to run [Q = Quit] ? ");

		switch (getanswer("NYQ", FALSE)) {
		case 'Y':
			Fileloc = recallplayer();
			break;

		case 'Q':
			cleanup(TRUE);
			/* NOTREACHED */

		default:
			Fileloc = rollnewplayer();
			break;
		}
		clear();
	} while (Fileloc < 0L);

	if (Player.p_level > 5.0)
		/* low level players have long timeout */
		Timeout = TRUE;

	/* update some important player statistics */
	strcpy(Player.p_login, Login);
	time(&seconds);
	Player.p_lastused = localtime(&seconds)->tm_yday;
	Player.p_status = S_PLAYING;
	writerecord(&Player, Fileloc);

	Statptr = &Stattable[Player.p_type];	/* initialize pointer */

	/* catch interrupts */
#ifdef  BSD41
	sigset(SIGINT, interrupt);
#endif
#ifdef  BSD42
	signal(SIGINT, interrupt);
#endif
#ifdef  SYS3
	signal(SIGINT, interrupt);
#endif
#ifdef  SYS5
	signal(SIGINT, interrupt);
#endif

	altercoordinates(Player.p_x, Player.p_y, A_FORCED);	/* set some flags */

	clear();

	for (;;) {
		/* loop forever, processing input */

		adjuststats();	/* cleanup stats */

		if (Throne && Player.p_crowns == 0 && Player.p_specialtype != SC_KING) {
			/* not allowed on throne -- move */
			mvaddstr(5, 0, "You're not allowed in the Lord's Chamber without a crown.\n");
			altercoordinates(0.0, 0.0, A_NEAR);
		}

		checktampered();	/* check for energy voids, etc. */

		if (Player.p_status != S_CLOAKED
		/* not cloaked */
		    && (dtemp = fabs(Player.p_x)) == fabs(Player.p_y)
		/* |x| = |y| */
		    && !Throne) {
			/* not on throne */
			dtemp = sqrt(dtemp / 100.0);
			if (floor(dtemp) == dtemp) {
				/* |x| / 100 == n*n; at a trading post */
				tradingpost();
				clear();
			}
		}

		checkbattle();	/* check for player to player battle */
		neatstuff();	/* gurus, medics, etc. */

		if (Player.p_status == S_CLOAKED) {
			/* costs 3 mana per turn to be cloaked */
			if (Player.p_mana > 3.0)
				Player.p_mana -= 3.0;
			else {
				/* ran out of mana, uncloak */
				Player.p_status = S_PLAYING;
				Changed = TRUE;
			}
		}

		if (Player.p_status != S_PLAYING && Player.p_status != S_CLOAKED) {
			/* change status back to S_PLAYING */
			Player.p_status = S_PLAYING;
			Changed = TRUE;
		}

		if (Changed) {
			/* update file only if important stuff has changed */
			writerecord(&Player, Fileloc);
			Changed = FALSE;
			continue;
		}

		readmessage();	/* read message, if any */

		displaystats();	/* print statistics */

		move(6, 0);

		if (Throne)
			/* maybe make king, print prompt, etc. */
			throneroom();

		/* print status line */
		addstr("1:Move  2:Players  3:Talk  4:Stats  5:Quit  ");
		if (Player.p_level >= MEL_CLOAK && Player.p_magiclvl >= ML_CLOAK)
			addstr("6:Cloak  ");
		if (Player.p_level >= MEL_TELEPORT && Player.p_magiclvl >= ML_TELEPORT)
			addstr("7:Teleport  ");
		if (Player.p_specialtype >= SC_COUNCIL || Wizard)
			addstr("8:Intervene  ");

		procmain();	/* process input */
	}
}
示例#2
0
void location::roommenu(player &mainchar, map &maplocation)
{
	if (mainchar.alive == false)
	{
		return;
	}
	
	bool validinput = false;
	
	while(validinput == false)
	{
		if((mainchar.gethealth() + 5) < mainchar.gethealthcap())
		{
			mainchar.sethealth(mainchar.gethealth() + 5);
		}
		if((mainchar.getmana() + 5) < mainchar.getmanacap())
		{
			mainchar.setmana(mainchar.getmana() + 5);
		}
		cout<<"The Menu:"<<endl;
		if(goN == true)
		{
			cout<<"(N) Go North"<<endl;
		}
		if(goS == true)
		{
			cout<<"(S) Go South"<<endl;
		}
		if(goE == true)
		{
			cout<<"(E) Go East"<<endl;
		}
		if(goW == true)
		{
			cout<<"(W) Go West"<<endl;
		}
		
		cout<<"(1) Inventory"<<endl;
		cout<<"(2) Stats"<<endl;
		cout<<"(3) Equip Weapon"<<endl;
		char input;
		cin>>input;
		switch(input)
		{
		case 'n':
		case 'N':
			if(goN == true)
			{
				maplocation.goN();
				validinput = true;
			}
			else
			{
				cout<<"Invalid Input.  Try Again."<<endl;
			}
			break;
		case 's':
		case 'S':
			if(goS == true)
			{
				maplocation.goS();
				validinput = true;
			}
			else
			{
				cout<<"Invalid Input.  Try Again."<<endl;
			}
			break;
		case 'e':
		case 'E':
			if(goE == true)
			{
				maplocation.goE();
				validinput = true;
			}
			else
			{
				cout<<"Invalid Input.  Try Again."<<endl;
			}
			break;
		case 'w':
		case 'W':
			if(goW == true)
			{
				maplocation.goW();
				validinput = true;
			}
			else
			{
				cout<<"Invalid Input.  Try Again."<<endl;
			}
			break;
		case '1':
			mainchar.displayinv();
			break;
		case '2':
			displaystats();
			break;
		case '3':
			mainchar.displayinv();
			cout<<"Which item would you like to equip (inventory slot number)?"<<endl;
			cin>>input;
			input -= 48;
			mainchar.equipweapon(input - 1);
			validinput = true;
			break;
		default:
			cout<<"Invalid Input.  Try Again."<<endl<<endl;
		}
	}
	}
int main()
{
    if(!initialize())    return 1;
    int spawn, lastspawn=-1,spawnbomb,lastspawnbomb=-1;
    if(!loadplayer()) {
        set_gfx_mode(GFX_TEXT,0,0,0,0);
        allegro_message("Can't load tarma");
        return 1;
    }
    if(!loadenemy()){
        set_gfx_mode(GFX_TEXT,0,0,0,0);
        allegro_message("Can't load bulldogs");
        return 1;
    }
    if(!loadpistol()){
        set_gfx_mode(GFX_TEXT,0,0,0,0);
        allegro_message("Can't load pistols");
        return 1;
    }
    if(!loadbomber()){
        set_gfx_mode(GFX_TEXT,0,0,0,0);
        allegro_message("Can't load bomber");
        return 1;
    }
    if(!loadbomb()){
        set_gfx_mode(GFX_TEXT,0,0,0,0);
        allegro_message("Can't load bomb");
        return 1;
    }

    /*if(!loadgun()){
        set_gfx_mode(GFX_TEXT,0,0,0,0);
        allegro_message("Can't load guns");
        return 1;
    }*/
    /*if(!loadboss()){
        set_gfx_mode(GFX_TEXT,0,0,0,0);
        allegro_message("Can't load boss");
        return 1;
    }*/
    //int volume=250,pan=128,pitch=1000;
    //play_sample(level1,volume,pan,pitch,TRUE);
    int intro=0,exits=0;
    while(!exits){
         intro=counter;
         while(counter-intro<2)
        blit(welcome,screen,0,0,0,0,WIDTH,HEIGHT);
        intro=counter;
        while(counter-intro<2)
        blit(instruction1,screen,0,0,0,0,WIDTH,HEIGHT);
        intro=counter;
        while(counter-intro<2)
        blit(instruction2,screen,0,0,0,0,WIDTH,HEIGHT);
        intro=counter;

        while(counter-intro<2)
        blit(instruction3,screen,0,0,0,0,WIDTH,HEIGHT);
        intro=counter;
        gameover=0;
        loadplayer();
        loadenemy();
        loadbomber();
        loadpistol();
        loadbomb();

        while(!key[KEY_ESC] && !gameover){
       // clear_bitmap(buffer);

        if(mils-lastinput>2) inputflag=1;
        if(inputflag)   checkinputs();

        updatehero();
        if(gameover==1) break;
        if((tarma.x%(640*2))<5 && lastspawn!=tarma.x/(640*2)){
            spawn=1;
            lastspawn=tarma.x/(640*2);
        }
         if((tarma.x%(640*5))<5 && lastspawnbomb!=tarma.x/(640*5)){
            spawnbomb=1;
            lastspawnbomb=tarma.x/(640*5);
        }


        updateenemy(spawn);
        updatebombers(spawnbomb);
        updatedeaths();
        updatebullets();
        updatebombs();
        displaystats();
        acquire_screen();
        blit(buffer,screen,0,0,0,0,WIDTH,HEIGHT);
        release_screen();
        ticks++;
        rest(DELAY);
    }
    intro=counter;
    while(counter-intro<2)
        blit(gameoverscreen,screen,0,0,0,0,WIDTH,HEIGHT);
    if(key[KEY_ESC])     exits=1;

    }

     destroy_sample(level1);
     remove_sound();
    remove_int(timer1);
    destroy_bitmap(buffer);
    destroy_bitmap(welcome);
    destroy_bitmap(instruction1);
    destroy_bitmap(instruction2);
    destroy_bitmap(instruction3);
    destroy_bitmap(gameoverscreen);
    delete []bulldogs;
    delete []pistols;
    delete gun;
    delete []bomb;
    delete []bombman;
    delete rocket;
     for(int i=0;i<6;i++)
                for(int j=0;j<TARMAMAX[i];j++)
                    destroy_bitmap(tarma.heroimg[i][j]);
     for(int i=2;i<5;i++)
                for(int j=0;j<REBELMAX[i];j++)
                destroy_bitmap(enemypics.enemyimg[i][j]);
    for(int i=0;i<4;i++)
                destroy_bitmap(bulletpics.bullets[i]);
    for(int i=0;i<14;i++)
        destroy_bitmap(bomberpics.bomber[i]);

    MapFreeMem();
    allegro_exit();
    return 0;
}