示例#1
0
void BlackJack::menu()
{
    cout << "           ********************************\n"
         << "           *  h key = hit | s key = stay  *\n"
         << "           ********************************\n"
         << "           Enter: ";

    char choice;
    cin >> choice;

    switch (tolower(choice)) {
    case 'h':

        playerHit();
        showCards();
        control = true; // Run menu() again.
        break;

    case 's':

        dealerHit();
        hideCard = false; // Player's turn is complete. Show dealer's hand.
        control = false; // menu() terminates.
        break;

    default:

        cout << "\n  Enter a valid option.";
        control = true; // Run menu() again.
        break;
    }

    cout << "\n";
}
示例#2
0
static void simulate(void)
{
   int sh, i, j, pl, pl2, actp;
   double l;
   Vec2d v;
   
   for(i = 0; i < conf.segmentSteps; ++i)
   {
      for(pl = 0; pl < conf.maxPlayers; ++pl)
      {
         SimPlayer* p = &(player[pl]);
         if(p->watch) continue;
         if(!p->active) continue;
         for(sh = 0; sh < conf.numShots; ++sh)
         {
            SimShot* s = &(p->shot[sh]);
            SimMissile* m = &(s->missile);
            if(!m->live) continue;
            for(j = 0; j < conf.numPlanets; ++j)
            {
               v = vsub(planet[j].position, m->position);
               l = length(v);

               if (l <= planet[j].radius)
               {
                  planetHit(s);
               }

               v = vdiv(v, l);
               v = vmul(v, planet[j].mass / (l * l));
               v = vdiv(v, conf.segmentSteps);

               m->speed = vadd(m->speed, v);
            }
            v = vdiv(m->speed, conf.segmentSteps);
            m->position = vadd(m->position, v);

            for(pl2 = 0; pl2 < conf.maxPlayers; ++pl2)
            {
               if(!player[pl2].active) continue;
               l = distance(player[pl2].position, m->position);

               if (  (l <= conf.playerDiameter)
                  && (m->leftSource == 1)
                  )
               {
		  if(conf.debug & 1) printf("l = %.5f playerDiameter = %.5f missile.x = %.5f missile.y = %.5f player.x = %5f player.y = %5f\n",l,conf.playerDiameter,m->position.x,m->position.y,player[pl2].position.x,player[pl2].position.y);
                  playerHit(s, pl, pl2);
               }

               if (  (l > (conf.playerDiameter + 1))
                  && (pl2 == pl)
                  )
               {
                  m->leftSource = 1;
               }
            }

            if (  (m->position.x < -conf.marginleft)
               || (m->position.x > conf.battlefieldW + conf.marginright)
               || (m->position.y < -conf.margintop)
               || (m->position.y > conf.battlefieldH + conf.marginbottom)
               )
            {
               wallHit(s);
            }
         }
      }
   }
   for(pl = 0, actp = 0; pl < conf.maxPlayers; ++pl) actp += player[pl].active;  
   for(pl = 0; pl < conf.maxPlayers; ++pl)
   {
      SimPlayer* p = &(player[pl]);
      if(!p->active) continue;
      if(p->watch) continue;
      if(p->timeout) p->timeout--;
      if(p->valid || actp == 1) p->timeout = conf.timeout;
      for(sh = 0; sh < conf.numShots; ++sh)
      {
         SimShot* s = &(p->shot[sh]);
         if(!s->missile.live) continue;
         p->timeout = conf.timeout;
         player[currentPlayer].timeoutcnt = 0;
         s->dot[s->length++] = d2f(s->missile.position);
         if(s->length == conf.maxSegments)
         {
            s->missile.live = 0;
            allSendShotFinished(s);
         }
      }
   }
}