示例#1
0
void KJezzball::createLevel( int level )
{
    // destroy old game
    if ( m_gameWidget ) delete m_gameWidget;

    // create new game widget
    if ( m_showBackground )
        m_background = getBackgroundPixmap();
    else
        m_background = QPixmap();

    m_gameWidget = new JezzGame( m_background, level+1, m_view, "m_gameWidget" );
    m_gameWidget->setSound(m_soundAction->isChecked());

    m_gameWidget->show();
    m_layout->addWidget( m_gameWidget, 0, 0 );
    connect( m_gameWidget, SIGNAL(died()), this, SLOT(died()) );
    connect( m_gameWidget, SIGNAL(newPercent(int)), this, SLOT(newPercent(int)) );
    connect( m_soundAction, SIGNAL(toggled(bool)), m_gameWidget, SLOT(setSound(bool)) );

    // update displays
    m_level.lifes = level+1;
    m_lifesLCD->display( m_level.lifes );
    m_percentLCD->display( 0 );

    m_level.time = (level+2)*30;
    m_timeLCD->display( m_level.time );

    m_level.score = 0;
}
示例#2
0
void oelevator(int dir)
{
	if (dir==1) { 
		if (level == 0) {
			lprcat(",\nunfortunately, it is out of order.");
			return;
		}
		playerx = rnd(MAXX-2);	
		playery = rnd(MAXY-2);
		nap(2000);
		newcavelevel(rund(level));
	}
	else {
		if (level==DBOTTOM || level==VBOTTOM) {
			nap(2000);
			lprcat("\nand it leads straight to HELL!");
			beep();
			lflush();
			nap(3000);
			died(287);
		}
		playerx = rnd(MAXX-2);	
		playery = rnd(MAXY-2);
		nap(2000);
	    	newcavelevel(level + rnd(DBOTTOM - level));
	}
	positionplayer();
	draws(0,MAXX,0,MAXY); 
	bot_linex();
}
示例#3
0
/*
 *	subroutine to save the game if a hangup signal
 */
static void
sgam(void)
{
	savegame(savefilename);
	wizard = 1;
	died(-257);		/* hangup signal */
}
示例#4
0
/*
	*********
	OTELEPORT
	*********

	subroutine to handle a teleport trap +/- 1 level maximum
 */
void oteleport(int err)
{
	int tmp;

	if (err) if (rnd(151)<3)  died(264);  /* stuck in a rock */

	/*show ?? on bottomline if been teleported	*/
	if (!wizard) c[TELEFLAG]=1;	

	if (level==0) 
		tmp=0;
	else if (level <= DBOTTOM) { 	/* in dungeon */
		tmp=rnd(5)+level-3; 
		if (tmp>DBOTTOM)
			tmp=DBOTTOM;
		if (tmp<0) 
			tmp=0; 
	}
	else { 				/* in volcano */
		tmp=rnd(4)+level-2; 
		if (tmp>=VBOTTOM)
			tmp=VBOTTOM;
		if (tmp<DBOTTOM+1)
			tmp=0;  /* back to surface */
	}
	playerx = rnd(MAXX-2);
	playery = rnd(MAXY-2);
	if (level != tmp)
		newcavelevel(tmp);  
	positionplayer();
	draws(0,MAXX,0,MAXY); 
	bot_linex();
}
示例#5
0
/* Subroutine to save the game if a hangup signal */
static void sgam()
{
    savegame(savefilename);
    wizard = 1;

    /* Hangup signal */
    died(-257);
}
示例#6
0
void obottomless()
{
	lprcat("\nYou fell into a pit leading straight to HELL!");  
	beep(); 
	lflush();
	nap(3000);  
	died(262);
}
示例#7
0
文件: bird.cpp 项目: youngjeff/qt
void Bird::CollisionToDeath()
{
    m_timer->stop();
    m_checkTimer->stop();
    status = 3;
    this->scene()->views().value(0)->repaint();
    m_anim.stop();
    m_anim.setDuration(DEATH_TIME);
    m_anim.setStartValue(this->pos());
    m_anim.setEndValue(this->pos()+QPoint(0,600));
    m_anim.start();
    isDied = true;
    emit died();
}
示例#8
0
文件: widget.cpp 项目: youngjeff/qt
Widget::Widget(QWidget *parent) :
    QGraphicsView(parent),
    ui(new Ui::Widget)
{

    ui->setupUi(this);
    m_scene = new QGraphicsScene;
    setScene(m_scene);
    m_scene->setSceneRect(3-width()/2,3-height()/2,width()-6,height()-6);

    m_bird = new bird();
    m_scene->addItem(m_bird);
    m_bird->setPos(0,0);

    m_edge_1 = new edge();
    m_scene->addItem(m_edge_1);
    m_edge_1->setPos(m_edge_1->boundingRect().width()/4,-height()/2+7);

    m_edge_2 = new edge();
    m_scene->addItem(m_edge_2);
    m_edge_2->setPos(m_edge_2->boundingRect().width()/4,height()/2-7);
    m_edge_1->BeginMove();
    m_edge_2->BeginMove();

    hideButton();
    m_timer = new QTimer(this);
    connect(m_timer,SIGNAL(timeout()),this,SLOT(beginBarrier()));//barrier

    connect(m_bird,SIGNAL(died()),this,SLOT(onBirdDied()));

    for(int i =0;i<BARRIER_NUM;i++)
    {
        m_barr[i] = new barrier();
        m_scene->addItem(m_barr[i]);
    }
    initBarrier();

    num = 0;
    QTimer::singleShot(1000,this,SLOT(Scoring()));

    score = 0;
    ScoringTimer = new QTimer(this);

    connect(ScoringTimer,SIGNAL(timeout()),this,SLOT(Scoring()));

    settings = new QSettings("score.ini",QSettings::IniFormat);

//    setWindowFlags(Qt::FramelessWindowHint);
}
示例#9
0
void Health::hit(int damage)
{
	if(!invincible())
	{
		m_clock.restart();
		hits -= damage;

		hurt();

		if (hits < 0)
		{
			died();
		}
	}
}
示例#10
0
void PlayerServer::dying(PlayerServer *killer)
{
	TRIEV(t_PreDying);
	if (!isDying())
		return;
	int pos = game->currentPosition;
	do 
	{
		PlayerServer* player = static_cast<PlayerServer*>(game->players[pos]);
		if (player->alive) {
			bool canSave = true;
			player->TRIEV(t_CanSave, &canSave, this);
			if (canSave) {
				while (isDying()) {
					unique_ptr<Card> card;
					if (player == this)
						card = move(player->needUseCard(CardProperty_Tao | CardProperty_Jiu));
					else
						card = move(player->needUseCard(CardProperty_Tao));
					if (card) {
						int addhp = 1;
						TRIEV(t_AddHpPoint, &addhp, &card, &player);
						setHp(hp + addhp);
						GAME->addToDeadwood(card);
						if (!isDying()) {
							return;
						}
					}
					else
						break;
				}
			}
		}
		pos++;
		if (pos > (int)game->players.size()) {
			pos = 0;
		}
	} while (pos!=game->currentPosition);
	died(killer);
}
示例#11
0
文件: action.c 项目: HunterZ/larn
/*
    Code to perform the action of drinking at a fountian.  Assumes that
    cursors() has already been called, and that a check has been made that
    the player is actually standing at a live fountain.
*/
void act_drink_fountain(void)
{
    int x ;

    if (rnd(1501)<2)
        {
        lprcat("\nOops!  You seem to have caught the dreadful sleep!");
        lflush();  
        nap(3000);  
        died(280); 
        return;
        }

    x = rnd(100);
    if (x<7)
        {
        c[HALFDAM] += 200 + rnd(200);
        lprcat("\nYou feel a sickness coming on");
        }

    else if (x < 13)
        quaffpotion(23, FALSE ); /* see invisible,but don't know the potion */

    else if (x < 45)
        lprcat("\nnothing seems to have happened");

    else if (rnd(3) != 2)
        fntchange(1);   /*  change char levels upward   */

    else
        fntchange(-1);  /*  change char levels downward */

    if (rnd(12)<3)
        {
        lprcat("\nThe fountains bubbling slowly quiets");
        item[playerx][playery]=ODEADFOUNTAIN; /* dead fountain */
        know[playerx][playery]=0;
        }
    return;
}
示例#12
0
文件: wall.cpp 项目: KDE/kbounce
void KBounceWall::collide( KBounceCollision collision )
{
    if ( !isVisible() )
        return;

    foreach( const KBounceHit &hit, collision ) {
        switch (hit.type) {
            case ALL:
                break;
            case TILE:
                finish();
                break;
            case BALL:
                if (safeEdgeHit(hit.boundingRect)) {
                    KBounceVector normal = hit.normal;
                    if (qAbs(normal.x) < qAbs(normal.y)) { // vertical
                        if (m_dir == Up || m_dir == Down) {
                            finish( true, m_dir );
                        }
                    }
                    else if (m_dir == Left || m_dir == Right) {
                        finish( true, m_dir );
                    }
                } else {
                    emit died();
                    hide();
                }
                break;
            case WALL:
                if (safeEdgeHit(hit.boundingRect)) {
                    finish();
                }
                break;
        }
    }
}
示例#13
0
void ohome()
{
	int i;

	nosignal = 1;	/* disable signals */
	for (i=0; i<IVENSIZE; i++) 
		/* remove the potion of cure dianthroritis from inventory */
		if (iven[i]==OPOTION) 
			if (ivenarg[i]==21) {   
				iven[i]=0;	
				clear(); 
				lprcat("Congratulations.  You found the potion of cure "
					   "dianthroritis!\n");
				lprcat("\nFrankly, No one thought you could do it.");
				lprcat("  Boy!  Did you surprise them!\n");
				nap(1000);
				if (gtime>TIMELIMIT) {
					lprcat("\nHowever... the doctor has the sad duty to "
						   "inform you that your daughter has\n");
					lprcat("died! You didn't make it in time.  In your agony, "
						   "you kill the doctor,\nyour ");
					if (sex == 1)
						lprcat("wife");
					else
						lprcat("husband");
					lprcat(" and yourself!  Too bad...\n");
					nap(5000); 
					died(269);
				}
				else {
					lprcat("\nThe doctor is now administering the potion and, "
						   "in a few moments,\n");
					lprcat("your daughter should be well on her way to "
						   "recovery.\n");
					nap(6000);
					lprcat("\nThe potion is."); 
					nap(1000); 
					lprcat(".");
					nap(1000); 
					lprcat(".");
					nap(1000); 
					lprcat(" working!  The doctor thinks that\n");
					lprcat("your daughter will recover in a few days.  "
						   "Congratulations!");
					beep(); 
					nap(5000); 
					died(263);
				}
			}

	while (1) {
		clear();
		lprintf("Welcome home %s.",logname);
		lprcat("  Latest word from the doctor is not good.\n");

		if (gtime>TIMELIMIT) {
			lprcat("\nThe doctor has the sad duty to inform you that your "
				   "daughter has died!\n");
			lprcat("You didn't make it in time.");
			lprcat("In your agony, you kill the doctor,\nyour ");
			if (sex == 1)
				lprcat("wife");
			else
				lprcat("husband");
			lprcat(" and yourself!  Too bad...");
			nap(5000); 
			died(269);
		}

		lprcat("\nThe diagnosis is confirmed as dianthroritis.  "
			   "He guesses that\n");
		lprintf("your daughter has only %d mobuls left in this world.  "
				"It's up to you,\n",(long)((TIMELIMIT-gtime+99)/100));
		lprintf("%s, to find the only hope for your daughter, the very rare\n",
				logname);
		lprcat("potion of cure dianthroritis.  It is rumored that only deep "
			   "in the\n");
		lprcat("depths of the caves can this potion be found.\n\n\n");
		lprcat("\n     ----- press "); 
		ularn_standout("return");
		lprcat(" to continue, "); 
		ularn_standout("escape");
		lprcat(" to leave ----- ");
		i=getcharacter();  
		while (i!=ESC && i!='\n') 
			i=getcharacter();
		if (i==ESC) { 
			drawscreen(); 
			nosignal = 0; /* enable signals */

			return; 
		}
	}
}
示例#14
0
文件: object.c 项目: davidpeng/ularn
/* =============================================================================
 * FUNCTION: lookforobject
 */
void lookforobject(void)
{
  int i;
  int dx, dy;

  /* can't find objects is time is stopped */
  if (c[TIMESTOP]) return;

  i=item[playerx][playery];
  if (i == ONOTHING) return;

  showcell(playerx,playery);
  yrepcount=0;

  switch (i)
  {
    case OGOLDPILE:
    case OMAXGOLD:
    case OKGOLD:
    case ODGOLD:
      ogold(i);
      break;

    case OPOTION:
      Print("You find a magic potion");
      i = iarg[playerx][playery];
      if (potionknown[i]) Printf(" of %s",&potionname[i][1]);
      Print(".");
	  add_option('d', "Drink", "");
	  add_option('t', "Take", "");
      break;

    case OSCROLL:
      Print("You find a magic scroll");
      i = iarg[playerx][playery];
      if (scrollknown[i]) Printf(" of %s",&scrollname[i][1]);
      Print(".");
	  if (c[BLINDCOUNT] == 0)
	    add_option('r', "Read", "");
	  add_option('t', "Take", "");
      break;

    case OALTAR:
      if (nearbymonst()) return;
      Print("There is a holy altar here.");
	  set_callback("act_on_object");
	  add_option('p', "Pray", "");
	  add_option('d', "Desecrate", "");
	  add_option('i', "Ignore", "");
      break;

    case OBOOK:
      Print("You find a book.");
	  if (c[BLINDCOUNT] == 0)
	    add_option('r', "Read", "");
	  add_option('t', "Take", "");
      break;

    case OCOOKIE:
      Print("You find a fortune cookie.");
	  add_option('e', "Eat", "");
	  add_option('t', "Take", "");
      break;

    case OTHRONE:
    case OTHRONE2:
      if (nearbymonst()) return;
      Printf("There is %s here.", objectname[i]);
	  add_option('p', "Pry Jewels", "");
	  add_option('s', "Sit", "");
      break;

    case ODEADTHRONE:
      Printf("There is %s here.", objectname[i]);
	  add_option('s', "Sit", "");
      break;

    case OORB:
      if (nearbymonst()) return;
      finditem(i);
      break;

    case OBRASSLAMP:
      Print("You find a brass lamp.");
	  add_option('r', "Rub", "");
	  add_option('t', "Take", "");
      return;

    case OWWAND:
      if (nearbymonst()) return;
      finditem(i);
      break;

    case OHANDofFEAR:
      if (nearbymonst()) return;
      finditem(i);
      break;

    case OPIT:
      Print("You're standing at the top of a pit.");
      opit();
      break;

    case OSTAIRSUP:
      Print("There is a circular staircase here.");
	  add_option('u', "Up", "");
      break;

    case OELEVATORUP:
      Print("You have found an express elevator going up.");
      oelevator(1);  /*  up  */
      break;

    case OELEVATORDOWN:
      Print("You have found an express elevator going down.");
      oelevator(-1);  /*  down  */
      break;

    case OFOUNTAIN:
      if (nearbymonst()) return;
      Print("There is a fountain here.");
	  add_option('d', "Drink", "");
	  add_option('w', "Wash Yourself", "");
      break;

    case OSTATUE:
      if (nearbymonst()) return;
      Print("You stand before a statue.");
      ostatue();
      break;

    case OCHEST:
      Print("There is a chest here.");
	  add_option('t', "Take", "");
	  add_option('o', "Open", "");
      break;

    case OIVTELETRAP:
      if (rnd(11)<6) return;
      item[playerx][playery] = OTELEPORTER;

    case OTELEPORTER:
      /*
       * The player is being teleported, so obviously the player gets
       * to know that a teleport trap is here.
       * oteleport forces a screen redraw, so don't bother display anything
       * here.
       */
      know[playerx][playery] = item[playerx][playery];
      Print("Zaaaappp!  You've been teleported!");
      UlarnBeep();
      nap(3000);
      oteleport(0);
      break;

    case OSCHOOL:
      if (nearbymonst()) return;
      Print("You have found the College of Ularn.");
	  add_option('g', "Go in", "");
      break;

    case OMIRROR:
      if (nearbymonst()) return;
      Print("There is a mirror here.");
      omirror();
      break;

    case OBANK2:
    case OBANK:
      if (nearbymonst()) return;
      if (i==OBANK)
      {
        Print("You have found the bank of Ularn.");
      }
      else
      {
        Print("You have found a branch office of the bank of Ularn.");
      }
	  add_option('g', "Go in", "");
      break;

    case ODEADFOUNTAIN:
      if (nearbymonst()) return;
      Print("There is a dead fountain here.");
      break;

    case ODNDSTORE:
      if (nearbymonst()) return;
      Print("There is a DND store here.");
	  add_option('g', "Go in", "");
      break;

    case OSTAIRSDOWN:
      Print("There is a circular staircase here.");
	  add_option('d', "Down", "");
      break;

    case OOPENDOOR:
      Print("There is an open door here.");
      break;

    case OCLOSEDDOOR:
      
      /* can't move objects if time is stopped */
      if (c[TIMESTOP]) return;

      dx = playerx;
      dy = playery;

      if (dropflag)
        return;
      Printf("You find %s",objectname[i]);
	  set_callback("act_on_object");
	  add_option('o', "Open", "");
	  add_option('i', "Ignore", "");
      break;

    case OENTRANCE:
      Print("You have found ");
      Print(objectname[OENTRANCE]);
	  add_option('g', "Go in", "");
      break;

    case OVOLDOWN:
      Print("You have found ");
      Print(objectname[OVOLDOWN]);
	  add_option('c', "Climb down", "");
      return;

    case OVOLUP:
      Print("You have found ");
      Print(objectname[OVOLUP]);
	  add_option('c', "Climb up", "");
      return;

    case OTRAPARROWIV:
      if (rnd(17)<13) return; /* for an arrow trap */
      item[playerx][playery] = OTRAPARROW;
    case OTRAPARROW:
      Print("You are hit by an arrow!");
      UlarnBeep(); /* for an arrow trap */

      losehp(DIED_SHOT_BY_ARROW, rnd(10)+level);
      UpdateStatus();
      return;

    case OIVDARTRAP:
      if (rnd(17)<13) return;   /* for a dart trap */
      item[playerx][playery] = ODARTRAP;
    case ODARTRAP:
      Print("You are hit by a dart!");
      UlarnBeep(); /* for a dart trap */
      
      losehp(DIED_HIT_BY_DART, rnd(5));
      if ((--c[STRENGTH]) < 3) c[STRENGTH] = 3;
      UpdateStatus();
      return;

    case OIVTRAPDOOR:
      if (rnd(17)<13) return;   /* for a trap door */
      item[playerx][playery] = OTRAPDOOR;
    case OTRAPDOOR:
      for (i=0;i<IVENSIZE;i++)
      {
        if (iven[i]==OWWAND)
        {
          Print("You escape a trap door.");
          return;
        }
      }
      if ((level==DBOTTOM)||(level==VBOTTOM))
      {
        Print("You fall through a trap door leading straight to HELL!");
        UlarnBeep();
        nap(3000);
        died(DIED_FELL_THROUGH_BOTTOMLESS_TRAPDOOR, 0);
      }
      Print("You fall through a trap door!");
      UlarnBeep();
      losehp(DIED_FELL_THROUGH_TRAPDOOR, rnd(5+level));
      nap(2000);
      newcavelevel(level+1);
      draws(0,MAXX,0,MAXY);
      UpdateStatusAndEffects();
      return;

    case OTRADEPOST:
      if (nearbymonst()) return;
      Print("You have found the Ularn trading Post.");
	  add_option('g', "Go in", "");
      return;

    case OHOME:
      if (nearbymonst()) return;
      Print("You have found your way home.");
	  add_option('g', "Go in", "");
      return;

    case OPAD:
      if (nearbymonst()) return;
      Print("You have found Dealer McDope's Hideout!");
	  add_option('g', "Go in", "");
      return;

    case OSPEED:
      Print("You find some speed.");
	  add_option('s', "Snort", "");
	  add_option('t', "Take", "");
      break;

    case OSHROOMS:
      Print("You find some magic mushrooms.");
	  add_option('e', "Eat", "");
	  add_option('t', "Take", "");
      break;

    case OACID:
      Print("You find some LSD.");
	  add_option('e', "Eat", "");
	  add_option('t', "Take", "");
      break;

    case OHASH:
      Print("You find some hashish.");
	  add_option('s', "Smoke", "");
	  add_option('t', "Take", "");
      break;

    case OCOKE:
      Print("You find some cocaine.");
	  add_option('s', "Snort", "");
	  add_option('t', "Take", "");
      break;

    case OWALL:
      break;

    case OANNIHILATION:
      if (player_has_item(OSPHTALISMAN))
      {
        Print("The Talisman of the Sphere protects you from annihilation!");
        return;
      }
      
      /* annihilated by sphere of annihilation */
      died(DIED_SPHERE_ANNIHILATION, 0);
      return;

    case OLRS:
      if (nearbymonst()) return;
      Print("There is an LRS office here.");
	  add_option('g', "Go in", "");
      break;

    default:
	  finditem(i);
      break;
  }
}
示例#15
0
/*
	***************
	LOOK_FOR_OBJECT
	***************

	subroutine to look for an object and give the player his options
	if an object was found.
 */
lookforobject()
{
register int i,j;
if (c[TIMESTOP])  return;	/* can't find objects is time is stopped	*/
i=item[playerx][playery];	if (i==0) return;
showcell(playerx,playery);  cursors();  yrepcount=0;
switch(i)
	{
	case OGOLDPILE:	case OMAXGOLD:
	case OKGOLD:	case ODGOLD:	lprcat("\n\nYou have found some gold!");	ogold(i);	break;

	case OPOTION:	lprcat("\n\nYou have found a magic potion");
				i = iarg[playerx][playery];
				if (potionname[i][0]) lprintf(" of %s",&potionname[i][1]);  opotion(i);  break;

	case OSCROLL:	lprcat("\n\nYou have found a magic scroll");
				i = iarg[playerx][playery];
				if (scrollname[i][0])	lprintf(" of %s",&scrollname[i][1]);
				oscroll(i);  break;

	case OALTAR:	if (nearbymonst()) return;
					lprcat("\n\nThere is a Holy Altar here!"); oaltar(); break;

	case OBOOK:	lprcat("\n\nYou have found a book."); obook(); break;

	case OCOOKIE:	lprcat("\n\nYou have found a fortune cookie."); ocookie(); break;

	case OTHRONE:	if (nearbymonst()) return;
					lprintf("\n\nThere is %s here!",objectname[i]); othrone(0); break;

	case OTHRONE2:	if (nearbymonst()) return;
					lprintf("\n\nThere is %s here!",objectname[i]); othrone(1); break;

	case ODEADTHRONE: lprintf("\n\nThere is %s here!",objectname[i]); odeadthrone(); break;

	case OORB:		lprcat("\n\nYou have found the Orb!!!!!"); oorb(); break;

	case OPIT:		lprcat("\n\nYou're standing at the top of a pit."); opit(); break;

	case OSTAIRSUP:		lprcat("\n\nThere is a circular staircase here"); ostairs(1);  /* up */ break;

	case OELEVATORUP:	lprcat("\n\nYou feel heavy for a moment, but the feeling disappears");
				oelevator(1);  /*  up  */  break;

	case OFOUNTAIN:	if (nearbymonst()) return;
					lprcat("\n\nThere is a fountain here"); ofountain(); break;

	case OSTATUE:	if (nearbymonst()) return;
					lprcat("\n\nYou are standing in front of a statue"); ostatue(); break;

	case OCHEST:	lprcat("\n\nThere is a chest here");  ochest();  break;

	case OIVTELETRAP:	if (rnd(11)<6) return;
						item[playerx][playery] = OTELEPORTER;
						know[playerx][playery] = 1;

	case OTELEPORTER:	lprcat("\nZaaaappp!  You've been teleported!\n");
						beep(); nap(3000); oteleport(0);
						break; 

	case OSCHOOL:	if (nearbymonst()) return;
				lprcat("\n\nYou have found the College of Larn.");
				lprcat("\nDo you (g) go inside, or (i) stay here? ");
				i=0; while ((i!='g') && (i!='i') && (i!='\33')) i=getchar();
				if (i == 'g') { oschool();  /*	the college of larn	*/ }
				else	lprcat(" stay here");
				break;

	case OMIRROR:	if (nearbymonst()) return;
					lprcat("\n\nThere is a mirror here");	omirror();	break;

	case OBANK2:
	case OBANK:	if (nearbymonst()) return;
				if (i==OBANK) lprcat("\n\nYou have found the bank of Larn.");
				else lprcat("\n\nYou have found a branch office of the bank of Larn.");
				lprcat("\nDo you (g) go inside, or (i) stay here? ");
				j=0; while ((j!='g') && (j!='i') && (j!='\33')) j=getchar();
				if (j == 'g') {  if (i==OBANK) obank(); else obank2(); /*  the bank of larn  */  }
				else   lprcat(" stay here");
				break;

	case ODEADFOUNTAIN:	if (nearbymonst()) return;
						lprcat("\n\nThere is a dead fountain here"); break;

	case ODNDSTORE:	if (nearbymonst()) return;
					lprcat("\n\nThere is a DND store here.");
					lprcat("\nDo you (g) go inside, or (i) stay here? ");
					i=0; while ((i!='g') && (i!='i') && (i!='\33')) i=getchar();
					if (i == 'g')
						dndstore();  /*  the dnd adventurers store  */
					else  lprcat(" stay here");
					break;

	case OSTAIRSDOWN:	lprcat("\n\nThere is a circular staircase here"); ostairs(-1); /* down */ break;

	case OELEVATORDOWN:	lprcat("\n\nYou feel light for a moment, but the feeling disappears");
				oelevator(-1);	/*	down	*/
				break;

	case OOPENDOOR:		lprintf("\n\nYou have found %s",objectname[i]);
						lprcat("\nDo you (c) close it"); iopts();
						i=0; while ((i!='c') && (i!='i') && (i!='\33')) i=getchar();
						if ((i=='\33') || (i=='i')) { ignore();  break; }
						lprcat("close");  forget();
						item[playerx][playery]=OCLOSEDDOOR;
						iarg[playerx][playery]=0;
						playerx = lastpx;  playery = lastpy;
						break;

	case OCLOSEDDOOR:	lprintf("\n\nYou have found %s",objectname[i]);
						lprcat("\nDo you (o) try to open it"); iopts();
						i=0; while ((i!='o') && (i!='i') && (i!='\33')) i=getchar();
						if ((i=='\33') || (i=='i'))
							{ ignore();  playerx = lastpx;
							playery = lastpy; break; }
						else
						{
						lprcat("open");
						if (rnd(11)<7)
						  {
						  switch(iarg[playerx][playery])
							{
							case 6: c[AGGRAVATE] += rnd(400);	break;

							case 7:	lprcat("\nYou are jolted by an electric shock "); 
									lastnum=274; losehp(rnd(20));  bottomline();  break;

							case 8:	loselevel();  break;

							case 9:	lprcat("\nYou suddenly feel weaker ");
									if (c[STRENGTH]>3) c[STRENGTH]--;
									bottomline();  break;

							default:	break;
							}
						  playerx = lastpx;  playery = lastpy;
						  }
						else
						  {
						  forget();  item[playerx][playery]=OOPENDOOR;
						  }
						}
						break;

	case OENTRANCE:	lprcat("\nYou have found "); lprcat(objectname[OENTRANCE]);
					lprcat("\nDo you (g) go inside"); iopts();
					i=0; while ((i!='g') && (i!='i') && (i!='\33')) i=getchar();
					if (i == 'g')
						{
						newcavelevel(1); playerx=33; playery=MAXY-2;
						item[33][MAXY-1]=know[33][MAXY-1]=mitem[33][MAXY-1]=0;
						draws(0,MAXX,0,MAXY); bot_linex(); return;
						}
					else   ignore();
					break;

	case OVOLDOWN:	lprcat("\nYou have found "); lprcat(objectname[OVOLDOWN]);
						lprcat("\nDo you (c) climb down"); iopts();
						i=0; while ((i!='c') && (i!='i') && (i!='\33')) i=getchar();
						if ((i=='\33') || (i=='i')) { ignore();  break; }
					if (level!=0) { lprcat("\nThe shaft only extends 5 feet downward!"); return; }
					if (packweight() > 45+3*(c[STRENGTH]+c[STREXTRA])) { lprcat("\nYou slip and fall down the shaft"); beep();
											  lastnum=275;  losehp(30+rnd(20)); bottomhp(); }
					
					else lprcat("climb down");  nap(3000);  newcavelevel(MAXLEVEL);
					for (i=0; i<MAXY; i++)  for (j=0; j<MAXX; j++) /* put player near volcano shaft */
						if (item[j][i]==OVOLUP) { playerx=j; playery=i; j=MAXX; i=MAXY; positionplayer(); }
					draws(0,MAXX,0,MAXY); bot_linex(); return;

	case OVOLUP:	lprcat("\nYou have found "); lprcat(objectname[OVOLUP]);
						lprcat("\nDo you (c) climb up"); iopts();
						i=0; while ((i!='c') && (i!='i') && (i!='\33')) i=getchar();
						if ((i=='\33') || (i=='i')) { ignore();  break; }
					if (level!=11) { lprcat("\nThe shaft only extends 8 feet upwards before you find a blockage!"); return; }
					if (packweight() > 45+5*(c[STRENGTH]+c[STREXTRA])) { lprcat("\nYou slip and fall down the shaft"); beep();
											  lastnum=275; losehp(15+rnd(20)); bottomhp(); return; }
					lprcat("climb up"); lflush(); nap(3000); newcavelevel(0);
					for (i=0; i<MAXY; i++)  for (j=0; j<MAXX; j++) /* put player near volcano shaft */
						if (item[j][i]==OVOLDOWN) { playerx=j; playery=i; j=MAXX; i=MAXY; positionplayer(); }
					draws(0,MAXX,0,MAXY); bot_linex(); return;

	case OTRAPARROWIV:	if (rnd(17)<13) return;	/* for an arrow trap */
						item[playerx][playery] = OTRAPARROW;
						know[playerx][playery] = 0;

	case OTRAPARROW:	lprcat("\nYou are hit by an arrow"); beep();	/* for an arrow trap */
						lastnum=259;	losehp(rnd(10)+level);
						bottomhp();	return;

	case OIVDARTRAP:	if (rnd(17)<13) return;		/* for a dart trap */
						item[playerx][playery] = ODARTRAP;
						know[playerx][playery] = 0;

	case ODARTRAP:		lprcat("\nYou are hit by a dart"); beep();	/* for a dart trap */
						lastnum=260;	losehp(rnd(5));
						if ((--c[STRENGTH]) < 3) c[STRENGTH] = 3;
						bottomline();	return;

	case OIVTRAPDOOR:	if (rnd(17)<13) return;		/* for a trap door */
						item[playerx][playery] = OTRAPDOOR;
						know[playerx][playery] = 1;

	case OTRAPDOOR:		lastnum = 272; /* a trap door */
						if ((level==MAXLEVEL-1) || (level==MAXLEVEL+MAXVLEVEL-1))
							{ lprcat("\nYou fell through a bottomless trap door!"); beep();  nap(3000);  died(271); }
						lprcat("\nYou fall through a trap door!"); beep();	/* for a trap door */
						losehp(rnd(5+level));
						nap(2000);  newcavelevel(level+1);  draws(0,MAXX,0,MAXY); bot_linex();
						return;


	case OTRADEPOST:	if (nearbymonst()) return;
				lprcat("\nYou have found the Larn trading Post.");
				lprcat("\nDo you (g) go inside, or (i) stay here? ");
				i=0; while ((i!='g') && (i!='i') && (i!='\33')) i=getchar();
				if (i == 'g')  otradepost();  else  lprcat("stay here");
				return;

	case OHOME:	if (nearbymonst()) return;
				lprcat("\nYou have found your way home.");
				lprcat("\nDo you (g) go inside, or (i) stay here? ");
				i=0; while ((i!='g') && (i!='i') && (i!='\33')) i=getchar();
				if (i == 'g')  ohome();  else  lprcat("stay here");
				return;

	case OWALL:	break;

	case OANNIHILATION:	died(283); return; 	/* annihilated by sphere of annihilation */

	case OLRS:	if (nearbymonst()) return;
				lprcat("\n\nThere is an LRS office here.");
				lprcat("\nDo you (g) go inside, or (i) stay here? ");
				i=0; while ((i!='g') && (i!='i') && (i!='\33')) i=getchar();
				if (i == 'g')
					olrs();  /*  the larn revenue service */
				else  lprcat(" stay here");
				break;

	default:	finditem(i); break;
	};
}
示例#16
0
/*
 *	*********
 *	OFOUNTAIN
 *	*********
 */
void ofountain()
{
	int x;

	cursors();
	lprcat("\nDo you (d) drink, (w) wash yourself"); 
	iopts();
	while (1) switch(getcharacter()) {
	case 'd':	
		lprcat("drink");
		if (rnd(1501)<4) {
		lprcat("\nOH MY GOD!! You have caught the *dreadful sleep*!");
			beep(); 
			lflush();  
			sleep(3);  
			died(280); 
			return;
		}
		x = rnd(100);
		if (x==1) raiselevel();
		else if (x < 11) { 	
			x=rnd((level<<2)+2);
			lprintf("\nBleah! The water tasted like stale gatorade!  "
					"You lose %d hit point%s!", (long)x, x==1?"":"s");
			lastnum=273; 
			losehp(x); 
			bottomline();  
			cursors();
		}
		else if (x<14) { 	
			c[HALFDAM] += 200+rnd(200);
			lprcat("\nThe water makes you vomit.");
		}
		else if (x<17) 
			quaffpotion(17); /* giant strength */
		else if (x < 45)
			lprcat("\nNothing seems to have happened.");
		else if (rnd(3) != 2)
			fntchange(1);	/*change char levels upward*/
		else
			fntchange(-1);	/*change char levels downward*/
		if (rnd(12)<3) {      
			lprcat("\nThe fountains bubbling slowly quietens.");
			/* dead fountain */
			item[playerx][playery]=ODEADFOUNTAIN; 
			know[playerx][playery]=0;
		}
		return;

	case 'i':	
	case ESC:
		ignore();  
		return;
	case 'w':	
		lprcat("wash yourself.");
		if (rnd(100) < 11) { 	
			x=rnd((level<<2)+2);
			lprintf("\nThe water burns like acid!  You lose %d hit point%s!",
					(long)x, x==1?"":"s");
			lastnum=273; 
			losehp(x); 
			bottomline();  
			cursors();
		}
		else if (rnd(100) < 29)
			lprcat("\nYou are now clean.");
		else if (rnd(100) < 31)
		  lprcat("\nThis water needs soap -- the dirt didn't come off.");
		else if (rnd(100) < 34)
			createmonster(WATERLORD); 
		else lprcat("\nNothing seems to have happened.");
		return;
	}
}
示例#17
0
文件: object.c 项目: davidpeng/ularn
void act_on_object(int ans)
{
  int i, j;
  int dx, dy;

  /* can't find objects is time is stopped */
  if (c[TIMESTOP]) return;

  i=item[playerx][playery];
  if (i == ONOTHING) return;

  showcell(playerx,playery);
  yrepcount=0;

  switch (i)
  {
    case OPOTION:
      i = iarg[playerx][playery];
      opotion(i, ans);
      break;

    case OSCROLL:
      i = iarg[playerx][playery];
      oscroll(i, ans);
      break;

    case OALTAR:
      oaltar(ans);
      move_world(0);
      break;

    case OBOOK:
      obook(ans);
      break;

    case OCOOKIE:
      ocookie(ans);
      break;

    case OTHRONE:
      othrone(0, ans);
      break;

    case OTHRONE2:
      othrone(1, ans);
      break;

    case ODEADTHRONE:
      odeadthrone(ans);
      break;

    case OORB:
      take_item(ans);
      break;

    case OBRASSLAMP:
      if (ans=='r')
      {
        i=rnd(100);
        if (i>90)
        {
          Print("The magic genie was very upset at being disturbed!");
      
          losehp(DIED_ANNOYED_GENIE, (int)c[HP]/2+1);
          UlarnBeep();
        }

        /* higher level, better chance of spell */
        else if ( (rnd(100)+c[LEVEL]/2) > 80)
        {
		  j = 0;
		  for (i = 0; i < SPELL_COUNT; i++)
		  {
			if (!spelknow[i])
			{
			  add_option(i, spelname[i], "");
			  j++;
			}
		  }
		  if (j > 0)
		  {
			  print_header("A magic genie appears!  What spell would you like?");
			  set_callback("obrasslamp");
			  break;
		  }
		  else
			  Print("A magic genie appears!  The genie has no new spells to teach you.");
        }
        else
        {
          Print("Nothing happened.");
        }

        if (rnd(100) < 15)
        {
          Print("The genie prefers not to be disturbed again!");
          forget();
          c[LAMP]=0;  /* chance of finding lamp again */
        }

        UpdateStatus();
      }
      else if (ans=='t')
      {
        if (take(OBRASSLAMP,0)==0)
          forget();
      }
      return;

    case OWWAND:
      take_item(ans);
      break;

    case OHANDofFEAR:
      take_item(ans);
      break;

    case OSTAIRSUP:
      ostairs(1, ans);  /* up */
      break;

    case OFOUNTAIN:
      ofountain(ans);
      break;

    case OCHEST:
      ochest(ans);
      break;

    case OSCHOOL:
      if (ans == 'g')
      {
		  oschool();
      }
      break;

    case OBANK2:
    case OBANK:
      if (ans == 'g')
      {
        if (i==OBANK)
			obank();
        else
			obank2();
      }
      break;

    case ODNDSTORE:
      if (ans == 'g')
		  dndstore();
      break;

    case OSTAIRSDOWN:
      ostairs(-1, ans); /* down */
      break;

    case OCLOSEDDOOR:
      
      /* can't move objects if time is stopped */
      if (c[TIMESTOP]) return;

      dx = playerx;
      dy = playery;

      if (dropflag)
        return;

      if ((ans==ESC) || (ans=='i'))
      {
        playerx = lastpx;
        playery = lastpy;
        lastpx = (char) dx;
        lastpy = (char) dy;
        break;
      }
      else
      {
        /* Try and open the door that is here */
        oopendoor(playerx, playery);

        if (item[playerx][playery] == OCLOSEDDOOR)
        {
          /*
           * Door didn't open.
           * Move the player back where they came from.
           */

          playerx = lastpx;
          playery = lastpy;
          lastpx = (char) dx;
          lastpy = (char) dy;
        }
        
        move_world(0);
      }
      break;

    case OENTRANCE:
      if (ans == 'g')
      {
        newcavelevel(1);
        playerx = 33;
        playery = MAXY - 2;

        /* Make sure the entrance to the dungeon is clear */
        item[33][MAXY-1] = ONOTHING;
        mitem[33][MAXY-1].mon = MONST_NONE;

        draws(0,MAXX,0,MAXY);
        UpdateStatusAndEffects();
        return;
      }
      break;

    case OVOLDOWN:
      if ((ans==ESC) || (ans=='i'))
      {
        break;
      }
      if (level!=0)
      {
        Print("The shaft only extends 5 feet downward!");
        return;
      }
      if (packweight() > 45+3*(c[STRENGTH]+c[STREXTRA]))
      {
        Print("You slip and fall down the shaft.");
        UlarnBeep();
        
        losehp(DIED_SLIPPED_VOLCANO_SHAFT, 30+rnd(20));
        UpdateStatus();
      }
      nap(3000);
      newcavelevel(DBOTTOM+1); /* down to V1 */
      playerx = (char) rnd(MAXX-2);
      playery = (char) rnd(MAXY-2);
      positionplayer();
      draws(0,MAXX,0,MAXY);
      UpdateStatusAndEffects();
      return;

    case OVOLUP:
      if ((ans==ESC) || (ans=='i'))
      {
        break;
      }
      if (packweight() > 40+5*(c[DEXTERITY]+c[STRENGTH]+c[STREXTRA]))
      {
        Print("You slip and fall down the shaft.");
        UlarnBeep();
        
        losehp(DIED_SLIPPED_VOLCANO_SHAFT, 15+rnd(20));
        UpdateStatus();
        return;
      }

      nap(3000);
      newcavelevel(0);
      for (i=0; i<MAXY; i++)  for (j=0; j<MAXX; j++)
      {
        /* put player near volcano shaft */
        if (item[j][i]==OVOLDOWN)
        {
          playerx = (char) j;
          playery = (char) i;
          j=MAXX;
          i=MAXY;
          positionplayer();
        }
      }
      draws(0,MAXX,0,MAXY);
      UpdateStatusAndEffects();
      return;

    case OTRADEPOST:
      if (ans == 'g')
      {
		  otradepost();
      }
      return;

    case OHOME:
      if (ans == 'g')
      {
        ohome();
      }
      return;

    case OPAD:
      if (ans == 'c')
      {
		  opad();
      }
      return;

    case OSPEED:
      if (ans=='s')
      {
        Print("Ohwowmanlikethingstotallyseemtoslowdown!");
        c[HASTESELF] += 200 + c[LEVEL];
        c[HALFDAM] += 300 + rnd(200);
        adjust_ability(INTELLIGENCE, -2);
        adjust_ability(WISDOM, -2);
        adjust_ability(CONSTITUTION, -2);
        adjust_ability(DEXTERITY, -2);
        adjust_ability(STRENGTH, -2);
        forget();
        UpdateStatus();
      }
      else if (ans=='t')
      {
        if (take(OSPEED,0)==0) forget();
      }
      break;

    case OSHROOMS:
      if (ans=='e')
      {
        Print("Things start to get real spacey...");
        c[HASTEMONST] += rnd(75) + 25;
        c[CONFUSE] += 30+rnd(10);
        adjust_ability(WISDOM, 2);
        adjust_ability(CHARISMA, 2);
        forget();
        UpdateStatus();
      }
      else if (ans=='t')
      {
        if (take(OSHROOMS,0)==0) forget();
      }
      break;

    case OACID:
      if (ans=='e')
      {
        Print("You are now frying your ass off!");
        c[CONFUSE] += 30 + rnd(10);
        adjust_ability(WISDOM, 2);
        adjust_ability(INTELLIGENCE, 2);
        c[AWARENESS] += 1500;
        c[AGGRAVATE] += 1500;
        {
          int j, k; /* heal monsters */
          for(j = 0 ; j < MAXY ; j++)
          {
            for(k = 0 ; k < MAXX ; k++)
            {
              if (mitem[k][j].mon)
              {
                hitp[k][j] = monster[(int) mitem[k][j].mon].hitpoints;
              }
            }
          }
        }
        forget();
        UpdateStatus();
      }
      else if (ans=='t')
      {
        if (take(OACID,0)==0) forget();
      }
      break;

    case OHASH:
      if (ans=='s')
      {
        Print("WOW! You feel stooooooned...");
        c[HASTEMONST] += rnd(75)+25;
        adjust_ability(INTELLIGENCE, 2);
        adjust_ability(WISDOM, 2);
        adjust_ability(CONSTITUTION, -2);
        adjust_ability(DEXTERITY, -2);
        c[HALFDAM] += 300+rnd(200);
        c[CLUMSINESS] += rnd(1800)+200;
        forget();
        UpdateStatus();
      }
      else if (ans=='t')
      {
        if (take(OHASH,0)==0) forget();
      }
      break;

    case OCOKE:
      if (ans=='s')
      {
        Print("Your nose begins to bleed!");
        adjust_ability(DEXTERITY, -2);
        adjust_ability(CONSTITUTION, -2);
        adjust_ability(CHARISMA, 3);

        for(i = ABILITY_FIRST ; i <= ABILITY_LAST ; i++)
        {
          adjust_ability(i, 33);
        }
        c[COKED] += 10;
        forget();
        UpdateStatus();
      }
      else if (ans=='t')
      {
        if (take(OCOKE, 0) == 0) forget();
      }
      break;

    case OWALL:
      break;

    case OANNIHILATION:
      if (player_has_item(OSPHTALISMAN))
      {
        Print("The Talisman of the Sphere protects you from annihilation!");
        return;
      }
      
      /* annihilated by sphere of annihilation */
      died(DIED_SPHERE_ANNIHILATION, 0);
      return;

    case OLRS:
      if (nearbymonst()) return;

      if (ans == 'g')
      {
		  olrs();
      }
      break;

    default:
	  if (ans == 't')
	  {
		  if (take(i, iarg[playerx][playery]) == 0)
			  forget();
	  }
      break;
  }
}
示例#18
0
/*
	lexical analyzer for larn
 */
int
yylex(void)
{
	char cc;
	int ic;
	if (hit2flag) {
		hit2flag = 0;
		yrepcount = 0;
		return (' ');
	}
	if (yrepcount > 0) {
		--yrepcount;
		return (lastok);
	} else
		yrepcount = 0;
	if (yrepcount == 0) {
		bottomdo();
		showplayer();
	}			/* show where the player is */
	lflush();
	while (1) {
		c[BYTESIN]++;
		/* check for periodic checkpointing */
		if (ckpflag)
			if ((c[BYTESIN] % CHECKPOINT_INTERVAL) == 0) {
#ifndef DOCHECKPOINTS
				savegame(ckpfile);
#else
				wait(0);	/* wait for other forks to finish */
				if (fork() == 0) {
					savegame(ckpfile);
					exit(0);
				}
#endif
#ifdef TIMECHECK
				if (dayplay == 0)
					if (playable()) {
						cursor(1, 19);
						lprcat("\nSorry, but it is now time for work.  Your game has been saved.\n");
						beep();
						lflush();
						savegame(savefilename);
						wizard = nomove = 1;
						sleep(4);
						died(-257);
					}
#endif /* TIMECHECK */
			}

		do {		/* if keyboard input buffer is too big, flush some of it */
			ioctl(0, FIONREAD, &ic);
			if (ic > flushno)
				read(0, &cc, 1);
		} while (ic > flushno);

		if (read(0, &cc, 1) != 1)
			return (lastok = -1);

		if (cc == 'Y' - 64) {	/* control Y -- shell escape */
			resetscroll();
			clear();	/* scrolling region, home, clear, no attributes */
			if ((ic = fork()) == 0) {	/* child */
				/* revoke */
				setgid(getgid());
				execl("/bin/csh", "csh", NULL);
				exit(1);
			}
			wait(0);
			if (ic < 0) {	/* error */
				write(2, "Can't fork off a shell!\n", 25);
				sleep(2);
			}

			setscroll();
			return (lastok = 'L' - 64);	/* redisplay screen */
		}

		if ((cc <= '9') && (cc >= '0')) {
			yrepcount = yrepcount * 10 + cc - '0';
		} else {
			if (yrepcount > 0)
				--yrepcount;
			return (lastok = cc);
		}
	}
}
示例#19
0
文件: object.c 项目: ethandicks/ularn
/*
	***************
	LOOK_FOR_OBJECT
	***************

	subroutine to look for an object and give the player his options
	if an object was found.
 */
lookforobject()
{
	int i,j;

	/* can't find objects is time is stopped*/
	if (c[TIMESTOP])  return;	

	i=item[playerx][playery];	
	if (i==0) return;

	showcell(playerx,playery);  
	cursors();  
	yrepcount=0;

	switch(i) {
	case OGOLDPILE:	
	case OMAXGOLD:
	case OKGOLD:	
	case ODGOLD:	
		ogold(i);	
		break;

	case OPOTION:	
		lprcat("\n\nYou find a magic potion");
		i = iarg[playerx][playery];
		if (potionknown[i]) lprintf(" of %s",&potionname[i][1]);
		lprcat(".");
		opotion(i);  
		break;

	case OSCROLL:	
		lprcat("\n\nYou find a magic scroll");
		i = iarg[playerx][playery];
		if (scrollknown[i]) lprintf(" of %s",&scrollname[i][1]);
		lprcat(".");
		oscroll(i);  
		break;

	case OALTAR:	
		if (nearbymonst()) return;
		lprcat("\n\nThere is a holy altar here.");
		oaltar(); 
		break;

	case OBOOK:	
		lprcat("\n\nYou find a book.");
		obook(); 
		break;

	case OCOOKIE:	
		lprcat("\n\nYou find a fortune cookie.");
		ocookie(); 
		break;

	case OTHRONE:	
		if (nearbymonst()) return;
		lprintf("\n\nThere is %s here.",objectname[i]);
		othrone(0); 
		break;

	case OTHRONE2:	
		if (nearbymonst()) return;
		lprintf("\n\nThere is %s here.",objectname[i]);
		othrone(1); 
		break;

	case ODEADTHRONE: 
		lprintf("\n\nThere is %s here.",objectname[i]);
		odeadthrone(); 
		break;

	case OORB:	
		if (nearbymonst()) return;
		finditem(i);
		break;

	case OBRASSLAMP: 
		lprcat("\nYou find a brass lamp.");
	lprcat("\nDo you want to (r) rub it, (t) take it, or (i) ignore it? ");
		i=0;
		while ((i!='r') && (i!='i') && (i!='t') && (i!=ESC)) 
			i=getcharacter();
		if (i=='r') {
			i=rnd(100);
			if (i>90) {
		lprcat("\nThe magic genie was very upset at being disturbed!");
				lastnum = 286;
				losehp((int)c[HP]/2+1);
				beep();
			}
			/* higher level, better chance of spell */
			else if ( (rnd(100)+c[LEVEL]/2) > 80) {
				int a,b,d;
				lprcat("\nA magic genie appears!");
				cursors();
				lprcat("\n  What spell would you like? : ");
				while ((a=getcharacter())=='D') { 	
					seemagic(99);
					cursors();  
					lprcat("\n  What spell would you like? : ");
				}
				/* to escape casting a spell	*/
				if (a==ESC) goto over; 	
				if ((b=getcharacter())==ESC) 
					goto over;
				if ((d=getcharacter())==ESC) { 
over: 
					lprcat("aborted"); 
					return;
				}
				lprc('\n');
				for (i=0; i<SPNUM; i++)
					if ((spelcode[i][0]==a) 
					    && (spelcode[i][1]==b) 
					    && (spelcode[i][2]==d)) {
						spelknow[i]=1;
						lprintf("\nSpell \"%s\":  %s\n%s",spelcode[i],
								spelname[i],speldescript[i]); 
						lprcat("\nThe genie prefers not to be disturbed "
							   "again.");
						forget();
						bottomline();
						return;
					}
				lprcat("\nThe genie has never heard of such a spell!");
				lprcat("\nThe genie prefers not to be disturbed again.");
				forget();
				bottomline();
				return;
			}
			else lprcat("\nnothing happened.");
			if (rnd(100) < 15) {
				lprcat("\nThe genie prefers not to be disturbed again!");
				forget();
				c[LAMP]=0;  /* chance of finding lamp again */
			}
			bottomline();
		}
		else if (i=='t') {
			lprcat("take.");
			if (take(OBRASSLAMP,0)==0) 
				forget();
		}
		else lprcat("ignore.");
		return;

	case OWWAND:
		if (nearbymonst()) return;
		finditem(i);
		break;

	case OHANDofFEAR:
		if (nearbymonst()) return;
		finditem(i);
		break;

	case OPIT:	
		lprcat("\n\nYou're standing at the top of a pit."); 
		opit(); 
		break;

	case OSTAIRSUP:	
		lprcat("\n\nThere is a circular staircase here."); 
		ostairs(1);  /* up */
		break;

	case OELEVATORUP:
		lprcat("\n\nYou have found an express elevator going up.");
		oelevator(1);  /*  up  */
		break;

	case OELEVATORDOWN:	
		lprcat("\n\nYou have found an express elevator going down.");
		oelevator(-1);	/*	down	*/
		break;

	case OFOUNTAIN:	
		if (nearbymonst()) return;
		lprcat("\n\nThere is a fountain here."); 
		ofountain(); 
		break;

	case OSTATUE:	
		if (nearbymonst()) return;
		lprcat("\n\nYou stand before a statue."); 
		ostatue(); 
		break;

	case OCHEST:	
		lprcat("\n\nThere is a chest here.");  
		ochest();  
		break;

	case OIVTELETRAP:	
		if (rnd(11)<6) return;
		item[playerx][playery] = OTELEPORTER;
		know[playerx][playery] = 1;

	case OTELEPORTER:
		lprcat("\nZaaaappp!  You've been teleported!\n");
		beep(); 
		nap(3000); 
		oteleport(0);
		break; 

	case OSCHOOL:	
		if (nearbymonst()) return;
		lprcat("\n\nYou have found the College of Ularn.");
		lprcat("\nDo you (g) go inside, or (i) stay here? ");
		i=0; 
		while ((i!='g') && (i!='i') && (i!=ESC)) i=getcharacter();
		if (i == 'g') { 
			oschool();  /*	the college of larn	*/
		}
		else	lprcat(" stay here.");
		break;

	case OMIRROR:	
		if (nearbymonst()) return;
		lprcat("\n\nThere is a mirror here.");
		omirror();	
		break;

	case OBANK2:
	case OBANK:	
		if (nearbymonst()) return;
		if (i==OBANK) 
			lprcat("\n\nYou have found the bank of Ularn.");
		else 
		    lprcat("\n\nYou have found a branch office of the bank of Ularn.");
		lprcat("\nDo you (g) go inside, or (i) stay here? ");
		j=0; 
		while ((j!='g') && (j!='i') && (j!=ESC)) 
			j=getcharacter();
		if (j == 'g') {  
			if (i==OBANK) 
				obank(); 
			else 
			    obank2(); /*  the bank of larn  */

		}
		else   
			lprcat(" stay here.");
		break;

	case ODEADFOUNTAIN:	
		if (nearbymonst()) return;
		lprcat("\n\nThere is a dead fountain here.");
		break;

	case ODNDSTORE:	
		if (nearbymonst()) 
			return;
		lprcat("\n\nThere is a DND store here.");
		lprcat("\nDo you (g) go inside, or (i) stay here? ");
		i=0; 
		while ((i!='g') && (i!='i') && (i!=ESC)) i=getcharacter();
		if (i == 'g')
			dndstore();  /*  the dnd adventurers store  */
		else  
			lprcat(" stay here.");
		break;

	case OSTAIRSDOWN:
		lprcat("\n\nThere is a circular staircase here.");
		ostairs(-1); /* down */
		break;

	case OOPENDOOR:		
		lprcat("\nThere is an open door here.");
		break;


	case OCLOSEDDOOR:
		if (dropflag)
			return;
		lprintf("\n\nYou find %s",objectname[i]);
		lprcat("\nDo you (o) try to open it"); 
		iopts();
		i=0; 
		while ((i!='o') && (i!='i') && (i!=ESC)) i=getcharacter();
		if ((i==ESC) || (i=='i')) { 
			ignore();  
			playerx = lastpx;
			playery = lastpy; 
			break; 
		}
		else {
			lprcat("open.");
			if (rnd(11)<7) {
				switch(iarg[playerx][playery]) {
				case 6: 
					c[AGGRAVATE] += rnd(400);	
					break;

				case 7:	
				case 8:
					lprcat("\nYou are jolted by an electric shock!");
					lastnum=274; 
					losehp(rnd(20));  
					bottomline();  
					break;

/* Losing a level is just too harsh... */
/*				case 8:	
					loselevel();  
					break;
*/
				case 9:	
					lprcat("\nYou suddenly feel weaker!");
					if (c[STRENGTH]>3) c[STRENGTH]--;
					bottomline();  
					break;

				default:	
					break;
				}
				playerx = lastpx;  
				playery = lastpy;
			}
			else {
				forget();  
				item[playerx][playery]=OOPENDOOR;
			}
		}
		break;

	case OENTRANCE:	
		lprcat("\nYou have found ");
		lprcat(objectname[OENTRANCE]);
		lprcat("\nDo you (g) go inside"); 
		iopts();
		i=0; 
		while ((i!='g') && (i!='i') && (i!=ESC)) i=getcharacter();
		if (i == 'g')
		{
			newcavelevel(1); 
			playerx=33; 
			playery=MAXY-2;
			item[33][MAXY-1]=know[33][MAXY-1]=mitem[33][MAXY-1].mon=0;
			draws(0,MAXX,0,MAXY); 
			bot_linex(); 
			return;
		}
		else   ignore();
		break;

	case OVOLDOWN:	
		lprcat("\nYou have found "); 
		lprcat(objectname[OVOLDOWN]);
		lprcat("\nDo you (c) climb down"); 
		iopts();
		i=0; 
		while ((i!='c') && (i!='i') && (i!=ESC)) 
			i=getcharacter();
		if ((i==ESC) || (i=='i')) { 
			ignore();  
			break; 
		}
		if (level!=0) { 
			lprcat("\nThe shaft only extends 5 feet downward!"); 
			return; 
		}
		if (packweight() > 45+3*(c[STRENGTH]+c[STREXTRA])) { 
			lprcat("\nYou slip and fall down the shaft.");
			beep();
			lastnum=275;  
			losehp(30+rnd(20)); 
			bottomhp(); 
		}
		else lprcat("climb down.");
		nap(3000); 
		newcavelevel(DBOTTOM+1); /* down to V1 */
		playerx = rnd(MAXX-2);
		playery = rnd(MAXY-2);
		positionplayer(); 
		draws(0,MAXX,0,MAXY); 
		bot_linex(); 
		return;

	case OVOLUP:	
		lprcat("\nYou have found "); 
		lprcat(objectname[OVOLUP]);
		lprcat("\nDo you (c) climb up"); 
		iopts();
		i=0; 
		while ((i!='c') && (i!='i') && (i!=ESC)) i=getcharacter();
		if ((i==ESC) || (i=='i')) { 
			ignore();  
			break; 
		}
	if (packweight() > 40+5*(c[DEXTERITY]+c[STRENGTH]+c[STREXTRA])) { 
			lprcat("\nYou slip and fall down the shaft.");
			beep();
			lastnum=275; 
			losehp(15+rnd(20)); 
			bottomhp(); 
			return; 
		}
		lprcat("climb up.");
		lflush(); 
		nap(3000); 
		newcavelevel(0);
		for (i=0; i<MAXY; i++)  for (j=0; j<MAXX; j++) /* put player near volcano shaft */
			if (item[j][i]==OVOLDOWN) { 
				playerx=j; 
				playery=i; 
				j=MAXX; 
				i=MAXY; 
				positionplayer(); 
			}
		draws(0,MAXX,0,MAXY); 
		bot_linex(); 
		return;

	case OTRAPARROWIV:	
		if (rnd(17)<13) return;	/* for an arrow trap */
		item[playerx][playery] = OTRAPARROW;
		know[playerx][playery] = 0;
	case OTRAPARROW:	
		lprcat("\nYou are hit by an arrow!");
		beep();	/* for an arrow trap */
		lastnum=259;	
		losehp(rnd(10)+level);
		bottomhp();	
		return;

	case OIVDARTRAP:	
		if (rnd(17)<13) 
			return;		/* for a dart trap */
		item[playerx][playery] = ODARTRAP;
		know[playerx][playery] = 0;
	case ODARTRAP:		
		lprcat("\nYou are hit by a dart!");
		beep();	/* for a dart trap */
		lastnum=260;	
		losehp(rnd(5));
		if ((--c[STRENGTH]) < 3) c[STRENGTH] = 3;
		bottomline();	
		return;

	case OIVTRAPDOOR:	
		if (rnd(17)<13) 
			return;		/* for a trap door */
		item[playerx][playery] = OTRAPDOOR;
		know[playerx][playery] = 1;
	case OTRAPDOOR:		
		lastnum = 272; /* a trap door */
		for (i=0;i<IVENSIZE;i++)
			if (iven[i]==OWWAND) {
				lprcat("\nYou escape a trap door.");
				return;
			}
		if ((level==DBOTTOM)||(level==VBOTTOM)) { 
			lprcat("\nYou fall through a trap door leading straight to HELL!");
			beep();
			lflush();
			nap(3000);
			died(271); 
		}
		lprcat("\nYou fall through a trap door!");
		beep();	
		lflush();
		losehp(rnd(5+level));
		nap(2000);
		newcavelevel(level+1);  
		draws(0,MAXX,0,MAXY); 
		bot_linex();
		return;

	case OTRADEPOST:
		if (nearbymonst()) return;
		lprcat("\nYou have found the Ularn trading Post.");
		lprcat("\nDo you (g) go inside, or (i) stay here? ");
		i=0; 
		while ((i!='g') && (i!='i') && (i!=ESC)) i=getcharacter();
		if (i == 'g')  otradepost();  
		else  lprcat("stay here.");
		return;

	case OHOME:	
		if (nearbymonst()) return;
		lprcat("\nYou have found your way home.");
		lprcat("\nDo you (g) go inside, or (i) stay here? ");
		i=0; 
		while ((i!='g') && (i!='i') && (i!=ESC)) 
			i=getcharacter();
		if (i == 'g')  
			ohome();  
		else  lprcat("stay here.");
		return;
	case OPAD:	
		if (nearbymonst()) return;
		lprcat("\nYou have found Dealer McDope's Hideout!");
		lprcat("\nDo you (c) check it out, or (i) ignore it? ");
		i=0;
		while ((i!='c') && (i!='i') && (i!=ESC)) 
			i=getcharacter();
		if (i == 'c')  
			opad();
		else  lprcat("forget it.");
		return;

	case OSPEED:   	
		lprcat("\nYou find some speed.");
		lprcat("\nDo you (s) snort it, (t) take it, or (i) ignore it? ");
		i=0; 
		while ((i!='s') && (i!='i') && (i!='t') && (i!=ESC)) 
			i=getcharacter();
		if (i=='s') {
			lprcat("snort!");
			lprcat("\nOhwowmanlikethingstotallyseemtoslowdown!");
			c[HASTESELF] += 200 + c[LEVEL];
			c[HALFDAM] += 300 + rnd(200);
			if ((c[INTELLIGENCE]-=2) < 3)
				c[INTELLIGENCE]=3;
			if ((c[WISDOM]-=2) < 3)
				c[WISDOM]=3;
			if ((c[CONSTITUTION]-=2) <3)
				c[CONSTITUTION]=3;
			if ((c[DEXTERITY]-=2) <3)
				c[DEXTERITY]=3;
			if ((c[STRENGTH]-=2) <3)
				c[STRENGTH]=3;
			forget();
			bottomline();
		} 
		else if (i=='t') {
			lprcat("take.");
			if (take(OSPEED,0)==0) forget();
		} 
		else 
		    lprcat("ignore.");
		break;

	case OSHROOMS:	
		lprcat("\nYou find some magic mushrooms.");
		lprcat("\nDo you (e) eat them, (t) take them, or (i) ignore them? ");
		i=0; 
		while ((i!='e') && (i!='i') && (i!='t') && (i!=ESC)) 
			i=getcharacter();
		if (i=='e') {
			lprcat("eat!");
			lprcat("\nThings start to get real spacey...");
			c[HASTEMONST] += rnd(75) + 25;
			c[CONFUSE] += 30+rnd(10);
			c[WISDOM]+=2;
			c[CHARISMA]+=2;
			forget();
			bottomline();
		} 
		else if (i=='t') {
			lprcat("take.");
			if (take(OSHROOMS,0)==0) forget();
		} 
		else
			lprcat("ignore.");
		break;

	case OACID:	
		lprcat("\nYou find some LSD.");
		lprcat("\nDo you (e) eat it, (t) take it, or (i) ignore it? ");
		i=0; 
		while ((i!='e') && (i!='i') && (i!='t') && (i!=ESC)) 
			i=getcharacter();
		if (i=='e') {
			lprcat("eat!");
			lprcat("\nYou are now frying your ass off!");
			c[CONFUSE]+=30+rnd(10);
			c[WISDOM]+=2;
			c[INTELLIGENCE]+=2;
			c[AWARENESS]+=1500;
			c[AGGRAVATE]+=1500;
			{ 	
				int j,k;	/* heal monsters */
				for(j=0;j<MAXY;j++)
					for(k=0;k<MAXX;k++)
						if (mitem[k][j].mon)
							hitp[k][j]=monster[mitem[k][j].mon].hitpoints;
			}
			forget();
			bottomline();
		}
		else if (i=='t') {
			lprcat("take.");
			if (take(OACID,0)==0) forget();
		}
		else lprcat("ignore.");
		break;

	case OHASH:	
		lprcat("\nYou find some hashish.");
		lprcat("\nDo you (s) smoke it, (t) take it, or (i) ignore it? ");
		i=0; 
		while ((i!='s') && (i!='i') && (i!='t') && (i!=ESC)) 
			i=getcharacter();
		if (i=='s') {
			lprcat("smoke!");
			lprcat("\nWOW! You feel stooooooned...");
			c[HASTEMONST]+=rnd(75)+25;
			c[INTELLIGENCE]+=2;
			c[WISDOM]+=2;
			if( (c[CONSTITUTION]-=2) < 3) 
				c[CONSTITUTION]=3;
			if( (c[DEXTERITY]-=2) < 3) 
				c[DEXTERITY]=3;
			c[HALFDAM]+=300+rnd(200);
			c[CLUMSINESS]+=rnd(1800)+200;
			forget();
			bottomline();
		}
		else if (i=='t') {
			lprcat("take.");
			if (take(OHASH,0)==0) forget();
		}
		else lprcat("ignore.");
		break;

	case OCOKE:	
		lprcat("\nYou find some cocaine.");
		lprcat("\nDo you want to (s) snort it, (t) take it, or (i) ignore it? ");
		i=0; 
		while ((i!='s') && (i!='i') && (i!='t') && (i!=ESC)) 
			i=getcharacter();
		if (i=='s') {
			lprcat("snort!");
			lprcat("\nYour nose begins to bleed!");
			if ((c[DEXTERITY]-=2) <3)
				c[DEXTERITY]=3;
			if ((c[CONSTITUTION]-=2) <3)
				c[CONSTITUTION]=3;
			c[CHARISMA]+=3;
			for(i=0;i<6;i++)
				c[i]+=33;
			c[COKED]+=10;
			forget();
			bottomline();
		}
		else if (i=='t') {
			lprcat("take.");
			if (take(OCOKE,0)==0) forget();
		}
		else lprcat("ignore.");
		break;	

	case OWALL:	
		break;

	case OANNIHILATION:
		for (i=0;i<IVENSIZE;i++)
			if (iven[i]==OSPHTALISMAN) {
				lprcat("\nThe Talisman of the Sphere protects you from "
					   "annihilation!");
				return;
			}
		/* annihilated by sphere of annihilation */	
		died(283);
		return;

	case OLRS:	
		if (nearbymonst()) return;
		lprcat("\n\nThere is an LRS office here.");
		lprcat("\nDo you (g) go inside, or (i) stay here? ");
		i=0; 
		while ((i!='g') && (i!='i') && (i!=ESC)) i=getcharacter();
		if (i == 'g')
			olrs();  /*  the larn revenue service */
		else  lprcat(" stay here.");
		break;
	default:	
		finditem(i); 
		break;
	};
}
示例#20
0
/*
	parse()

	get and execute a command
 */
static void
parse(void)
{
	int    i, j, k, flag;
	while (1) {
		k = yylex();
		switch (k) {	/* get the token from the input and switch on
				 * it	 */
		case 'h':
			moveplayer(4);
			return;	/* west		 */
		case 'H':
			run(4);
			return;	/* west		 */
		case 'l':
			moveplayer(2);
			return;	/* east		 */
		case 'L':
			run(2);
			return;	/* east		 */
		case 'j':
			moveplayer(1);
			return;	/* south		 */
		case 'J':
			run(1);
			return;	/* south		 */
		case 'k':
			moveplayer(3);
			return;	/* north		 */
		case 'K':
			run(3);
			return;	/* north		 */
		case 'u':
			moveplayer(5);
			return;	/* northeast	 */
		case 'U':
			run(5);
			return;	/* northeast	 */
		case 'y':
			moveplayer(6);
			return;	/* northwest	 */
		case 'Y':
			run(6);
			return;	/* northwest	 */
		case 'n':
			moveplayer(7);
			return;	/* southeast	 */
		case 'N':
			run(7);
			return;	/* southeast	 */
		case 'b':
			moveplayer(8);
			return;	/* southwest	 */
		case 'B':
			run(8);
			return;	/* southwest	 */

		case '.':
			if (yrepcount)
				viewflag = 1;
			return;	/* stay here		 */

		case 'w':
			yrepcount = 0;
			wield();
			return;	/* wield a weapon */

		case 'W':
			yrepcount = 0;
			wear();
			return;	/* wear armor	 */

		case 'r':
			yrepcount = 0;
			if (c[BLINDCOUNT]) {
				cursors();
				lprcat("\nYou can't read anything when you're blind!");
			} else if (c[TIMESTOP] == 0)
				readscr();
			return;	/* to read a scroll	 */

		case 'q':
			yrepcount = 0;
			if (c[TIMESTOP] == 0)
				quaff();
			return;	/* quaff a potion		 */

		case 'd':
			yrepcount = 0;
			if (c[TIMESTOP] == 0)
				dropobj();
			return;	/* to drop an object	 */

		case 'c':
			yrepcount = 0;
			cast();
			return;	/* cast a spell	 */

		case 'i':
			yrepcount = 0;
			nomove = 1;
			showstr();
			return;	/* status		 */

		case 'e':
			yrepcount = 0;
			if (c[TIMESTOP] == 0)
				eatcookie();
			return;	/* to eat a fortune cookie */

		case 'D':
			yrepcount = 0;
			seemagic(0);
			nomove = 1;
			return;	/* list spells and scrolls */

		case '?':
			yrepcount = 0;
			help();
			nomove = 1;
			return;	/* give the help screen */

		case 'S':
			clear();
			lprcat("Saving . . .");
			lflush();
			savegame(savefilename);
			wizard = 1;
			died(-257);	/* save the game - doesn't return	 */

		case 'Z':
			yrepcount = 0;
			if (c[LEVEL] > 9) {
				oteleport(1);
				return;
			}
			cursors();
			lprcat("\nAs yet, you don't have enough experience to use teleportation");
			return;	/* teleport yourself	 */

		case '^':	/* identify traps */
			flag = yrepcount = 0;
			cursors();
			lprc('\n');
			for (j = playery - 1; j < playery + 2; j++) {
				if (j < 0)
					j = 0;
				if (j >= MAXY)
					break;
				for (i = playerx - 1; i < playerx + 2; i++) {
					if (i < 0)
						i = 0;
					if (i >= MAXX)
						break;
					switch (item[i][j]) {
					case OTRAPDOOR:
					case ODARTRAP:
					case OTRAPARROW:
					case OTELEPORTER:
						lprcat("\nIt's ");
						lprcat(objectname[item[i][j]]);
						flag++;
					};
				}
			}
			if (flag == 0)
				lprcat("\nNo traps are visible");
			return;

#if WIZID
		case '_':	/* this is the fudge player password for
				 * wizard mode */
			yrepcount = 0;
			cursors();
			nomove = 1;
			if (userid != wisid) {
				lprcat("Sorry, you are not empowered to be a wizard.\n");
				scbr();	/* system("stty -echo cbreak"); */
				lflush();
				return;
			}
			if (getpassword() == 0) {
				scbr();	/* system("stty -echo cbreak"); */
				return;
			}
			wizard = 1;
			scbr();	/* system("stty -echo cbreak"); */
			for (i = 0; i < 6; i++)
				c[i] = 70;
			iven[0] = iven[1] = 0;
			take(OPROTRING, 50);
			take(OLANCE, 25);
			c[WIELD] = 1;
			c[LANCEDEATH] = 1;
			c[WEAR] = c[SHIELD] = -1;
			raiseexperience(6000000L);
			c[AWARENESS] += 25000;
			{
				int    i, j;
				for (i = 0; i < MAXY; i++)
					for (j = 0; j < MAXX; j++)
						know[j][i] = 1;
				for (i = 0; i < SPNUM; i++)
					spelknow[i] = 1;
				for (i = 0; i < MAXSCROLL; i++)
					scrollname[i] = scrollhide[i];
				for (i = 0; i < MAXPOTION; i++)
					potionname[i] = potionhide[i];
			}
			for (i = 0; i < MAXSCROLL; i++)
				if (strlen(scrollname[i]) > 2) {	/* no null items */
					item[i][0] = OSCROLL;
					iarg[i][0] = i;
				}
			for (i = MAXX - 1; i > MAXX - 1 - MAXPOTION; i--)
				if (strlen(potionname[i - MAXX + MAXPOTION]) > 2) {	/* no null items */
					item[i][0] = OPOTION;
					iarg[i][0] = i - MAXX + MAXPOTION;
				}
			for (i = 1; i < MAXY; i++) {
				item[0][i] = i;
				iarg[0][i] = 0;
			}
			for (i = MAXY; i < MAXY + MAXX; i++) {
				item[i - MAXY][MAXY - 1] = i;
				iarg[i - MAXY][MAXY - 1] = 0;
			}
			for (i = MAXX + MAXY; i < MAXX + MAXY + MAXY; i++) {
				item[MAXX - 1][i - MAXX - MAXY] = i;
				iarg[MAXX - 1][i - MAXX - MAXY] = 0;
			}
			c[GOLD] += 25000;
			drawscreen();
			return;
#endif

		case 'T':
			yrepcount = 0;
			cursors();
			if (c[SHIELD] != -1) {
				c[SHIELD] = -1;
				lprcat("\nYour shield is off");
				bottomline();
			} else if (c[WEAR] != -1) {
				c[WEAR] = -1;
				lprcat("\nYour armor is off");
				bottomline();
			} else
				lprcat("\nYou aren't wearing anything");
			return;

		case 'g':
			cursors();
			lprintf("\nThe stuff you are carrying presently weighs %ld pounds", (long) packweight());
		case ' ':
			yrepcount = 0;
			nomove = 1;
			return;

		case 'v':
			yrepcount = 0;
			cursors();
			lprintf("\nCaverns of Larn, Version %ld.%ld, Diff=%ld",
				(long) VERSION, (long) SUBVERSION,
				(long) c[HARDGAME]);
			if (wizard)
				lprcat(" Wizard");
			nomove = 1;
			if (cheat)
				lprcat(" Cheater");
			lprcat(copyright);
			return;

		case 'Q':
			yrepcount = 0;
			quit();
			nomove = 1;
			return;	/* quit		 */

		case 'L' - 64:
			yrepcount = 0;
			drawscreen();
			nomove = 1;
			return;	/* look		 */

#if WIZID
#ifdef EXTRA
		case 'A':
			yrepcount = 0;
			nomove = 1;
			if (wizard) {
				diag();
				return;
			}	/* create diagnostic file */
			return;
#endif
#endif
		case 'P':
			cursors();
			if (outstanding_taxes > 0)
				lprintf("\nYou presently owe %ld gp in taxes.",
					(long) outstanding_taxes);
			else
				lprcat("\nYou do not owe any taxes.");
			return;
		};
	}
}
示例#21
0
/** handleTimer() reacts to the signal sent off by the timer*/
void MainWindow::handleTimer()
{
  if(inGame && !gamePaused && playerAlive)
  {
/*TRUESHOT*/
	if(trueshotfiring)
	{
		leftclickholdcounter++;
		if(leftclickholdcounter%25==0){
			objects.push_back(new TrueShot(*trueshot,objects.first()->getX(),objects.first()->getY(),1000,0,view->getpoint().rx(),view->getpoint().ry()));
			objects.last()->setPos(objects.first()->getX(),objects.first()->getY());
			scene->addItem(objects.last());
			dispmana=numtostr(objects.first()->getMana());
			mana->setText(dispmana);
			trueshotfiring=false;
			leftclickholdcounter=0;
		}
	}
/* MOVING EZ*/
	if(up)
	{
		objects.first()->movetile(objects.first()->getX(),objects.first()->getY()-20);
	}
	else if(down)
	{
		objects.first()->movetile(objects.first()->getX(),objects.first()->getY()+20);
	}
	if(left)
	{
		objects.first()->movetile(objects.first()->getX()-20,objects.first()->getY());
	}
	else if(right)
	{
		objects.first()->movetile(objects.first()->getX()+20,objects.first()->getY());
	}
/* Spawn Icon*/
	iconspawn++;
	if(iconspawn%200==0)
	{
		int temp=rand()%3;
		if(temp==0)
		{
			int objectx,objecty;
			objectx=rand()%1175;objecty=rand()%575;
			objects.push_back(new Heal(*heal,objectx,objecty,1,0));
			objects.last()->setPos(objectx,objecty);
			scene->addItem(objects.last());
			iconspawn=0;
		}
		else if(temp==1)
		{
			int objectx,objecty;
			objectx=rand()%1175;objecty=rand()%575;
			objects.push_back(new Clarity(*clarity,objectx,objecty,1,0));
			objects.last()->setPos(objectx,objecty);
			scene->addItem(objects.last());
			iconspawn=0;
		}
		else if(temp==2)
		{
			int objectx,objecty;
			objectx=rand()%1175;objecty=rand()%575;
			objects.push_back(new Ignite(*ignite,objectx,objecty,1,0));
			objects.last()->setPos(objectx,objecty);
			scene->addItem(objects.last());
			iconspawn=0;
		}
	}
/* Spawning melee*/
	spawnmelee++;
	if(spawnmelee%50==0)
	{
		int objectx,objecty;
		objectx=rand()%1175;objecty=rand()%575;
		objects.push_back(new MeleeMinion(*melee,objectx,objecty,75,50));
		objects.last()->setPos(objectx,objecty);
		scene->addItem(objects.last());
		spawnmelee=0;
	}
	for( int i=0;i<objects.size();i++)
	{
		if(objects[i]->getType()==8)
			objects[i]->movetile();
	}
/* Spawning Siege*/
	spawnsiege++;
	if(spawnsiege%700==0)
	{
		int objectx,objecty;
		objectx=rand()%1175;objecty=rand()%575;
		objects.push_back(new SiegeMinion(*siege,objectx,objecty,150,0));
		objects.last()->setPos(objectx,objecty);
		scene->addItem(objects.last());
		spawnsiege=0;
	}
	for( int i=0;i<objects.size();i++)
	{
		if(objects[i]->getType()==10)
		{
			objects[i]->movetile(objects.first()->getX(),objects.first()->getY());
		/*Can he shoot*/
			int curplayx=sqrt(pow(objects.first()->getX()+75/2,2));
			int curplayy=sqrt(pow(objects.first()->getY()+75/2+25,2));
			int curx=sqrt(pow(objects[i]->getX()+65/2,2));
			int cury=sqrt(pow(objects[i]->getY()+65/2,2));
			if(120 >= sqrt(pow((curplayx-curx),2) + pow((curplayy-cury),2)))
			{
				countcannon++;
				if(countcannon%10==0)
				{
				objects.push_back(new CannonShot(*cannon,objects[i]->getX(),objects[i]->getY(),1,0,objects.first()->getX(),objects.first()->getY()));
				objects.last()->setPos(objects.first()->getX(),objects.first()->getY());
				scene->addItem(objects.last());
				}
			}
		}
	}
/* Spawning caster*/
	spawncaster++;
	if(spawncaster%500==0)
	{
		int objectx,objecty;
		objectx=rand()%1175;objecty=rand()%575;
		objects.push_back(new CasterMinion(*caster,objectx,objecty,50,0));
		objects.last()->setPos(objectx,objecty);
		scene->addItem(objects.last());
		spawncaster=0;
	}
	for( int i=0;i<objects.size();i++)
	{
		if(objects[i]->getType()==2)
		{
			objects[i]->movetile(objects.first()->getX(),objects.first()->getY());
		/*Can he shoot*/
			int curplayx=sqrt(pow(objects.first()->getX()+75/2,2));
			int curplayy=sqrt(pow(objects.first()->getY()+75/2+25,2));
			int curx=sqrt(pow(objects[i]->getX()+65/2,2));
			int cury=sqrt(pow(objects[i]->getY()+65/2,2));
			if(120 >= sqrt(pow((curplayx-curx),2) + pow((curplayy-cury),2)))
			{
				countbolt++;
				if(countbolt%10==0)
				{
				objects.push_back(new EnergyBolt(*energy,objects[i]->getX(),objects[i]->getY(),1,0,objects.first()->getX(),objects.first()->getY()));
				objects.last()->setPos(objects.last()->getX(),objects.last()->getY());
				scene->addItem(objects.last());
				}
			}
		}
	}
/* Move all shots */
	for( int i=0;i<objects.size();i++)
	{
		if(objects[i]->getType()== 0 || objects[i]->getType()== 1 ||objects[i]->getType()== 4 ||objects[i]->getType()== 9 ||objects[i]->getType()== 11)
		{
				objects[i]->movetile();
		}
	}
/* Removes cases for the shots*/
	for( int i=0;i<objects.size();i++)
	{
		if(objects[i]->getType()== 0 || objects[i]->getType()== 1 ||objects[i]->getType()== 4 ||objects[i]->getType()== 9 ||objects[i]->getType()== 11)
		{
			if(objects[i]->getHealth()<=0 || objects[i]->isGone())
				died(objects[i]);
		}
	}
/* Check for collision and do damage*/
	for( int i=0;i<objects.size();i++)
	{
		SceneObject* itemA=objects[i];
		for(int j=0;j<objects.size();j++)
		{
			SceneObject* itemB=objects[j];
			if(i==j)
				continue;
			if(itemA->collidesWithItem(itemB))
			{
				// ezreal hits a monster or attack
				if(itemA->getType()==5 && (itemB->getType()== 1 || itemB->getType()== 2 || itemB->getType()==4 || itemB->getType()== 8 || itemB->getType()==10))
				{
					ezhurt++;
					if(ezhurt%4==0)
					{
						itemA->setHealth(itemA->getHealth()-itemB->getDamage());
						itemB->setHealth(itemB->getHealth()-itemA->getDamage());
						//cout << "Ez was hurt: " <<objects.first()->getHealth()<< endl;
						//cout << "Monster was hurt: " << itemB->getHealth() << endl;
						disphealth=numtostr(objects.first()->getHealth());
						health->setText(disphealth);
						cout << "HEALTH: " << objects.first()->getHealth() << "  MANA: " << objects.first()->getMana() << "  LEVEL: " << levelff << "  SCORE: " << points*50 << endl;
						ezhurt=0;
					}
				}
				// monsters are hit by an attack
				if((itemA->getType()==2 || itemA->getType()==8 || itemA->getType()==10) && (itemB->getType()== 0 || itemB->getType()== 9 || itemB->getType()== 11))
				{
					itemA->setHealth(itemA->getHealth()-itemB->getDamage());
				}
				// Ez's attack's hit a monster
				if((itemA->getType()==0 || itemA->getType()==9 || itemA->getType()==11) && (itemB->getType()== 2 || itemB->getType()== 8 || itemB->getType()== 10))
				{
					itemA->setHealth(itemA->getHealth()-itemB->getDamage());
				}
				// monster attack's hit ez
				if((itemA->getType()==1 || itemA->getType()==4) && (itemB->getType()== 5))
				{
					ezhurt++;
					if(ezhurt%10==0)
					{
						itemA->setHealth(itemA->getHealth()-itemB->getDamage());
						//cout << "Ez was hurt: " << objects.first()->getHealth() << endl;
						disphealth=numtostr(objects.first()->getHealth());
						health->setText(disphealth);
						cout << "HEALTH: " << objects.first()->getHealth() << "  MANA: " << objects.first()->getMana() << "  LEVEL: " << levelff << "  SCORE: " << points*50 << endl;
						ezhurt=0;
					}
				}
				// powerups touched by Ez
				if((itemA->getType()==3 || itemA->getType()==6 || itemA->getType()==7) && (itemB->getType()== 5))
				{
					itemA->setHealth(itemA->getHealth()-itemB->getDamage());
				}
				// Ez touched Heal
				if( itemA->getType()== 5 && itemB->getType()==6 )
				{
					itemA->setHealth(itemA->getHealth()+itemB->getDamage());
					itemB->setHealth(itemB->getHealth()-itemA->getDamage());
				}
				// Ez touched Clarity
				if( itemA->getType()== 5 && itemB->getType()==3 )
				{
					itemA->setMana(itemA->getMana()+itemB->getDamage());
					itemB->setHealth(itemB->getHealth()-itemA->getDamage());
				}
				// Ez touched Ignite
				if( itemA->getType()== 5 && itemB->getType()==7 )
				{
					grabbedignite=true;
				}
			}
		}
	}  
	// for loop checking if ignite was grabbed
	if(grabbedignite)
	{
		for(int i=1;i<objects.size()/4;i++)
		{
			died(objects[i]);
		}
		grabbedignite=false;
	}
	// for loop checking if anythings health is 0 or below
	for(int i=0;i<objects.size();i++)
	{
		if(objects[i]->getHealth()<=0)
		{
			if(objects[i]->getType()==5)
			{
				playerAlive=false;
				inGame=false;
				lostgame=true;
				// write out to file for score
				ofstream fout;
				fout.open("scores.txt");
				bool printscore=false;
				if(scorenames.empty())
				{
				    fout << (name->toPlainText()).toStdString() << "|" << points*50<< endl;
				}
				else
				{
					for(int i=0; i<scorenames.size();i++){
						if(scores[i]<points*50 && !printscore)
						{
							fout << (name->toPlainText()).toStdString() << "|" << points*50<< endl;
							cout << (name->toPlainText()).toStdString() << "|" << points*50<< endl;
							printscore=true;
						}
						fout << scorenames[i] << "|" << scores[i] << endl;
						cout << scorenames[i] << "|" << scores[i] << endl;
					}
				}
				fout.close();
			}
			//cout << "Someone DIED!" << endl;
			if((objects[i]->getType()==2 || objects[i]->getType()==8 || objects[i]->getType()==10) && objects[i]->getHealth()<=0)
				points++;
			if(points>20)
			{
				view->setBackgroundBrush(Qt::red);
				timer->stop();
				timer->start(20);
				levelff=4;
				level->setText("LEVEL: 0"+numtostr(levelff));
				cout << "HEALTH: " << objects.first()->getHealth() << "  MANA: " << objects.first()->getMana() << "  LEVEL: " << levelff << "  SCORE: " << points*50 << endl;
			}
			else if(points>15)
			{
				view->setBackgroundBrush(Qt::yellow);
				timer->stop();
				timer->start(30);
				levelff=3;
				level->setText("LEVEL: 0"+numtostr(levelff));
				cout << "HEALTH: " << objects.first()->getHealth() << "  MANA: " << objects.first()->getMana() << "  LEVEL: " << levelff << "  SCORE: " << points*50 << endl;
			}
			else if(points>10)
			{
				view->setBackgroundBrush(Qt::blue);
				timer->stop();
				timer->start(50);
				levelff=2;
				level->setText("LEVEL: 0"+numtostr(levelff));
				cout << "HEALTH: " << objects.first()->getHealth() << "  MANA: " << objects.first()->getMana() << "  LEVEL: " << levelff << "  SCORE: " << points*50 << endl;
			}
			QString temp("SCORE: "+numtostr(points*50));
			score->setText(temp);
			score->show();
			cout << "HEALTH: " << objects.first()->getHealth() << "  MANA: " << objects.first()->getMana() << "  LEVEL: " << levelff << "  SCORE: " << points*50 << endl;
			died(objects[i]);
		}
	}
	update();
  }
}
int main(int argc, char const *const *argv) {
    struct sockaddr_in si_me, si_other;

    int s, i, slen = sizeof(si_other) , recv_len;
    char buf[BUFLEN];

    if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
        died("socket");
    }

    memset((char *) &si_me, 0, sizeof(si_me));

    si_me.sin_family = AF_INET;
    si_me.sin_port = htons(PORT);
    si_me.sin_addr.s_addr = htonl(INADDR_ANY);

    //bind socket to port
    if( bind(s , (struct sockaddr*)&si_me, sizeof(si_me) ) == -1) {
        died("bind");
    }

    if (argc < 2) {
      fprintf(stderr, "Usage: udp_producer host port\n");
      return 1;
    }
    char const *hostname;
    int port;

    hostname = argv[1];
    port = atoi(argv[2]);
    // amqp


    // char const *hostname = "localhost"; int port = 5674;
    int status;
    amqp_socket_t *socket = NULL;
    amqp_connection_state_t conn;
    conn = amqp_new_connection();
    socket = amqp_tcp_socket_new(conn);
    if (!socket) {
      died("creating TCP socket");
    }
    status = amqp_socket_open(socket, hostname, port);
    if (status) {
      died("opening TCP socket");
    }

    die_on_amqp_error(amqp_login(conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN, "guest", "guest"), "Logging in");
    amqp_channel_open(conn, 1);
    die_on_amqp_error(amqp_get_rpc_reply(conn), "Opening channel");

    while(1) {
        if ((recv_len = recvfrom(s, buf, BUFLEN, 0, (struct sockaddr *) &si_other, &slen)) == -1) {
            died("recvfrom()");
        }

        amqp_bytes_t message_bytes;
        message_bytes.len = sizeof(buf);
        message_bytes.bytes = buf;

        die_on_error(amqp_basic_publish(conn, 1,
          amqp_cstring_bytes("udp"),
          amqp_cstring_bytes("udp"),
          0, 0,NULL, message_bytes),"Publishing");
    }

    close(s);
    return 0;
}
示例#23
0
文件: main.c 项目: HunterZ/larn
/*
 * parse()
 *
 * get and execute a command
 */
static void parse(void)
{
	int i, j, k, flag;

    while   (1)
        {
        k = yylex();
        switch(k)   /*  get the token from the input and switch on it   */
            {
            case 'h':   moveplayer(4);  return;     /*  west        */
            case 'H':   run(4);         return;     /*  west        */
            case 'l':   moveplayer(2);  return;     /*  east        */
            case 'L':   run(2);         return;     /*  east        */
            case 'j':   moveplayer(1);  return;     /*  south       */
            case 'J':   run(1);         return;     /*  south       */
            case 'k':   moveplayer(3);  return;     /*  north       */
            case 'K':   run(3);         return;     /*  north       */
            case 'u':   moveplayer(5);  return;     /*  northeast   */
            case 'U':   run(5);         return;     /*  northeast   */
            case 'y':   moveplayer(6);  return;     /*  northwest   */
            case 'Y':   run(6);         return;     /*  northwest   */
            case 'n':   moveplayer(7);  return;     /*  southeast   */
            case 'N':   run(7);         return;     /*  southeast   */
            case 'b':   moveplayer(8);  return;     /*  southwest   */
            case 'B':   run(8);         return;     /*  southwest   */

            case '.':                               /*  stay here       */
                if (yrepcount) 
                    viewflag=1;
                return;

            case 'c':
                yrepcount=0;
                cast();
                return;     /*  cast a spell    */

            case 'd':
                yrepcount=0;
                if (c[TIMESTOP]==0)
                    dropobj();
                return; /*  to drop an object   */

            case 'e':
                yrepcount=0;
                if (c[TIMESTOP]==0)
                    if (!floor_consume( OCOOKIE, "eat" ))
                        consume( OCOOKIE, "eat", showeat );
                return; /*  to eat a fortune cookie */

            case 'g':   
                yrepcount = 0 ;
                cursors();
                lprintf("\nThe stuff you are carrying presently weighs %d pounds",(long)packweight());
                break ;

            case 'i':       /* inventory */
                yrepcount=0;
                nomove=1;
                showstr(FALSE);
                return;

            case 'p':           /* pray at an altar */
                yrepcount = 0;
                    pray_at_altar();
                return;

            case 'q':           /* quaff a potion */
                yrepcount=0;
                if (c[TIMESTOP]==0)
                    if (!floor_consume( OPOTION, "quaff"))
                        consume( OPOTION, "quaff", showquaff );
                return;

            case 'r':
                yrepcount=0;
                if (c[BLINDCOUNT])
                    {
                    cursors();
                    lprcat("\nYou can't read anything when you're blind!");
                    }
                else if (c[TIMESTOP]==0)
                    if (!floor_consume( OSCROLL, "read" ))
                        if (!floor_consume( OBOOK, "read" ))
                            consume( OSCROLL, "read", showread );
                return;     /*  to read a scroll    */

            case 's':
                yrepcount = 0 ;
                    sit_on_throne();
                return ;

            case 't':                       /* Tidy up at fountain */
                yrepcount = 0 ;
                    wash_fountain() ;
                return ;

            case 'v':
                yrepcount=0;
                nomove = 1;
                cursors();
                lprintf("\nLarn, Version %d.%d.%d, Diff=%d",(long)VERSION,(long)SUBVERSION,(long)PATCHLEVEL,(long)c[HARDGAME]);
                if (wizard)
                    lprcat(" Wizard");
                if (cheat) 
                    lprcat(" Cheater");
                return;

            case 'w':                       /*  wield a weapon */
                yrepcount=0;
                wield();
                return;

            case 'A':
                yrepcount = 0;
                    desecrate_altar();
                return;

            case 'C':                       /* Close something */
                yrepcount = 0 ;
                    close_something();
                return;

            case 'D':                       /* Drink at fountain */
                yrepcount = 0 ;
                    drink_fountain() ;
                return ;

            case 'E':               /* Enter a building */
                yrepcount = 0 ;
                    enter() ;
                break ;

            case 'I':              /*  list spells and scrolls */
                yrepcount=0;
                seemagic(0);
                nomove=1;
                return;

            case 'O':               /* Open something */
                yrepcount = 0 ;
                    open_something();
                return;

            case 'P':
                cursors();
                yrepcount = 0;
                nomove = 1;
                if (outstanding_taxes>0)
                    lprintf("\nYou presently owe %d gp in taxes.",(long)outstanding_taxes);
                else
                    lprcat("\nYou do not owe any taxes.");
                return;

            case 'Q':    /*  quit        */
                yrepcount=0;
                quit();
                nomove=1;
                return;

            case 'R' :          /* remove gems from a throne */
                yrepcount = 0 ;
                    remove_gems( );
                return ;

            case 'S':
                /* And do the save.
                 */
                cursors();
                lprintf("\nSaving to `%s' . . . ", savefilename);
                lflush();
                save_mode = 1;
                savegame(savefilename);
                clear();
                lflush();
                wizard=1;
                died(-257); /* doesn't return */
                break;


            case 'T':   yrepcount=0;    cursors();  if (c[SHIELD] != -1) { c[SHIELD] = -1; lprcat("\nYour shield is off"); bottomline(); } else
                                        if (c[WEAR] != -1) { c[WEAR] = -1; lprcat("\nYour armor is off"); bottomline(); }
                        else lprcat("\nYou aren't wearing anything");
                        return;

            case 'W':
                yrepcount=0;
                wear();
                return; /*  wear armor  */

            case 'Z':
                yrepcount=0;
                if (c[LEVEL]>9) 
                    { 
                    oteleport(1);
                    return; 
                    }
                cursors(); 
                lprcat("\nAs yet, you don't have enough experience to use teleportation");
                return; /*  teleport yourself   */

            case ' ':   yrepcount=0;    nomove=1;  return;

            case 'L'-64:  yrepcount=0;  drawscreen();  nomove=1; return;    /*  look        */

#if WIZID
#ifdef EXTRA
            case 'A'-64:    yrepcount=0;    nomove=1; if (wizard) { diag(); return; }  /*   create diagnostic file */
                        return;
#endif
#endif
	    
	    case '<':                       /* Go up stairs or vol shaft */
                yrepcount = 0;
                    up_stairs();
                return ;

            case '>':                       /* Go down stairs or vol shaft*/
                yrepcount = 0 ;
                    down_stairs();
                return ;

            case '?':                       /* give the help screen */
                yrepcount=0;
                help();
                nomove=1;
                return; 

        case ',':                       /* pick up an item */
            yrepcount = 0 ;
            /* pickup, don't identify or prompt for action */
            lookforobject( FALSE, TRUE, FALSE );
        return;

            case ':':                       /* look at object */
                yrepcount = 0 ;
            /* identify, don't pick up or prompt for action */
                    lookforobject( TRUE, FALSE, FALSE );
                nomove = 1;  /* assumes look takes no time */
                return;

        case '/':        /* identify object/monster */
            specify_object();
            nomove = 1 ;
            yrepcount = 0 ;
            return;

        case '^':                       /* identify traps */
                flag = yrepcount = 0;
                cursors();
                lprc('\n');
                for (j=playery-1; j<playery+2; j++)
                    {
                    if (j < 0)
                        j=0;
                    if (j >= MAXY)
                        break;
                    for (i=playerx-1; i<playerx+2; i++)
                        {
                        if (i < 0) 
                            i=0;
                        if (i >= MAXX) 
                            break;
                        switch(item[i][j])
                            {
                            case OTRAPDOOR:     case ODARTRAP:
                            case OTRAPARROW:    case OTELEPORTER:
                            case OPIT:
                                lprcat("\nIts ");
                                lprcat(objectname[item[i][j]]);
                                flag++;
                            };
                        }
                    }
                if (flag==0) 
                    lprcat("\nNo traps are visible");
                return;

#if WIZID
            case '_':   /*  this is the fudge player password for wizard mode*/
                        yrepcount=0;    cursors(); nomove=1;

                        if (getpassword()==0)
                            {
                            scbr(); /* system("stty -echo cbreak"); */ return;
                            }
                        wizard=1;  scbr(); /* system("stty -echo cbreak"); */
                        for (i=0; i<6; i++)  c[i]=70;  iven[0]=iven[1]=0;
                        take(OPROTRING,50);   take(OLANCE,25);  c[WIELD]=1;
                        c[LANCEDEATH]=1;   c[WEAR] = c[SHIELD] = -1;
                        raiseexperience(6000000L);  c[AWARENESS] += 25000;
                        {
                        int i,j;
                        for (i=0; i<MAXY; i++)
                            for (j=0; j<MAXX; j++)  know[j][i]=KNOWALL;
                        for (i=0; i<SPNUM; i++) spelknow[i]=1;
                        for (i=0; i<MAXSCROLL; i++)  scrollname[i][0]=' ';
                        for (i=0; i<MAXPOTION; i++)  potionname[i][0]=' ';
                        }
                        for (i=0; i<MAXSCROLL; i++)
                          if (strlen(scrollname[i])>2) /* no null items */
                            { item[i][0]=OSCROLL; iarg[i][0]=i; }
                        for (i=MAXX-1; i>MAXX-1-MAXPOTION; i--)
                          if (strlen(potionname[i-MAXX+MAXPOTION])>2) /* no null items */
                            { item[i][0]=OPOTION; iarg[i][0]=i-MAXX+MAXPOTION; }
                        for (i=1; i<MAXY; i++)
                            { item[0][i]=i; iarg[0][i]=0; }
                        for (i=MAXY; i<MAXY+MAXX; i++)
                            { item[i-MAXY][MAXY-1]=i; iarg[i-MAXY][MAXY-1]=0; }
            for (i=MAXX+MAXY; i<MAXOBJECT; i++)
                {
                item[MAXX-1][i-MAXX-MAXY]=i;
                iarg[MAXX-1][i-MAXX-MAXY]=0;
                }
                        c[GOLD]+=250000;    drawscreen();   return;
#endif

            };
        }
}