Beispiel #1
0
/* function main begins program execution */
int main( void )
{ 
   int sum; /* sum of rolled dice */
   int myPoint; /* point earned */

   enum Status gameStatus; /* can contain CONTINUE, WON, or LOST */

   /* randomize random number generator using current time */
   srand( time( NULL ) );

   sum = rollDice(); /* first roll of the dice */

   /* determine game status based on sum of dice */
   switch( sum ) {
      /* win on first roll */
      case 7: 
      case 11:          
         gameStatus = WON;
         break;

      /* lose on first roll */
      case 2: 
      case 3: 
      case 12:  
         gameStatus = LOST;
         break;

      /* remember point */
      default:                  
         gameStatus = CONTINUE;
         myPoint = sum;
         printf( "Point is %d\n", myPoint );
         break; /* optional */
   } /* end switch */

   /* while game not complete */
   while ( gameStatus == CONTINUE ) {    
      sum = rollDice(); /* roll dice again */

      /* determine game status */
      if ( sum == myPoint ) { /* win by making point */
         gameStatus = WON; /* game over, player won */
      } /* end if */
      else {
         if ( sum == 7 ) { /* lose by rolling 7 */
            gameStatus = LOST; /* game over, player lost */
         } /* end if */
      } /* end else */
   } /* end while */

   /* display won or lost message */
   if ( gameStatus == WON ) { /* did player win? */
      printf( "Player wins\n" );
   } /* end if */
   else { /* player lost */ 
      printf( "Player loses\n" );
   } /* end else */

   return 0; /* indicates successful termination */
} /* end main */
Beispiel #2
0
/**
  * Overrides parent's mouseReleaseEvent
  * Requests a server dice roll if dropped in gameView or chatView,
  * or does a local, private dice roll if dropped in statusView
  */
void BarDice::mouseReleaseEvent(QMouseEvent *ev)
{
    movingLabel->hide();
    //int y = ev->globalPos().y();
    //int gametop = gameView->mapToGlobal(QPoint(0,0)).y();
    //int gamebottom = gameView->mapToGlobal(QPoint(0,gameView->height())).y();
    if (ev->globalPos().y() < (statusView->mapToGlobal(QPoint(0,0))).y()) {
        emit rollDice(2,6,true);
    }
    else emit rollDice(2,6,false);
}
Beispiel #3
0
//Calls all other functions in the order that creates a coherent game
void playGame(){
	char playerMove;
	int dice1;
	int dice2;
	int sum;
	int playerCount;
	int choice;
	while(1)
	{
		printf("Welcome to Dice Blackjack!\n");
		printf("I am now rolling two dice\n");
		dice1 = rollDice();
		dice2 = rollDice();
		printf("You got a %d and a %d\n",dice1,dice2);
		sum = dice1 + dice2;
		printf("Total sum is %d\n",sum);
		playerCount = (sum + sum);
		printf("Your total player count is %d\n",playerCount);

		while(playerMove != 'S'){

			playerMove = getPlayerMove();

			if(playerMove == 'H')
			{
				printf("Rolling two more dice\n");
				dice1 = rollDice();
				dice2 = rollDice();
				printf("You have rolled a %d from the first dice and a %d on the second dice\n",dice1,dice2);
				choice = getPlayerChoice();

				if(playerCount > 21)
				{
				printf("You have busted!\n");
				break;
				}	

				else
				printf("You have a %d player count\n", playerCount);
				}
			}
		

			//Call the rest of the functions to get the game working
			//Game logic
			//Declare the winner of this round
			printf("Would you like to play again? Y/N:\n");	//If the player enters  			
			if(playerMove == 'N')// N, the game ends.
				exit(0);
		
	}
}
Beispiel #4
0
int main( void )
{
   int sum;
   int myPoint;
   
   enum Status gameStatus;

   srand( time(NULL) );
   sum = rollDice();

   switch( sum ) {
      case 7:
      case 11:
         gameStatus = WON;
         break;

      case 2:
      case 3:
      case 12:
         gameStatus = LOST;
         break;
      default:
         gameStatus = CONTINUE;
         myPoint = sum;
         printf( "Point is %d\n", my Point );
         break;
   }

   while( gameStatus == CONTINUE ) {
      sum = rollDice();

      if ( sum == myPoint ) {
         gameStatus = WON;
      }

      else{
         if ( sum == 7 ) {
            gameStatus = LOST;
         }
      }
   }
  
   if ( gameStatus == WON ) {
      printf( "Player wins\n" );
   }
   else{
      printf( "Player loses\n" );
   }

   return 0;
}
Beispiel #5
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QQmlApplicationEngine engine;

    engine.rootContext()->setContextProperty("ScreenW",1920);//1920x1080
    engine.rootContext()->setContextProperty("ScreenH",1080);
    DiceResultModel* model = new DiceResultModel();

    engine.rootContext()->setContextProperty("_diceModel",model);

   /* QTextDocument text(NULL);
    CppHighLighter cppHighLighter(&text);
    engine.rootContext()->setContextProperty("_hightedDoc",&text);*/
    //engine.rootContext()->setContextProperty("CppHighLightedDocument",720);

    QmlControler ctr;
    ctr.setResultModel(model);

    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    QList<QObject*> roots = engine.rootObjects();
    QObject* root = roots.at(0);
    QObject::connect(root,SIGNAL(rollDiceCmd(QString)),&ctr,SLOT(rollDice(QString)));

    ctr.setEngine(&engine);

    ctr.setVisible(true);


    return app.exec();
}
int TheShadow::characterDefense(int _characterAttack)
{
	
	defense = rollDice(1, 6);

	/* Debugging Purposes / Checking Algorithm */
	// std::cout << "Defense Roll: " << defense << std::endl;

	if(achHeel == true)
	{
		defense /= 2;		// If the achilles tendon is cut, divide defense by 2.
	}

	int result = (_characterAttack - defense) - armor;

	shadowMove = shadowMovement();

	if(shadowMove == true)	// moved shadowMove into it's own function
	{
		return 0;
	}

	else if(result <= 0)
	{
		return 0;
	}

	return result;


}
Beispiel #7
0
void Battle::turn(Player* attacker, Player* defender)
{
	bool critical = false;
	
	if(getAttackRole(attacker) >= getArmorCheck(defender))
	{			
		int row = 0;
		for(int i = 1; i <= attacker->getWeaponDamageMin(); i++)
		{
			row += rollDice(1, attacker->getWeaponDamageMax(), 1);
			if (row >= attacker->getWeaponCriticalMin() && row <= attacker->getWeaponCriticalMax())
			{
				row *= attacker->getWeaponMultiplier();
				critical = true;
			}
		}
		
		int damage = row + attacker->getStrModifier();
		if(critical)
			cout << attacker->getName() << " swings his " << attacker->getWeaponName()  << " at his opponent %s and critically hits him for " << damage << " damage!" << endl;
		else {
			cout << attacker->getName() << " swings his " << attacker->getWeaponName() << " at " << defender->getName() << " and hits him for " << damage << " damage!" << endl;
		}
		
		defender->TakeDamage(damage);
	} 
	else {
		cout << attacker->getName() << " swings his " << attacker->getWeaponName() << " at his opponent and misses." << endl;
	}
}
Beispiel #8
0
//Select which dices to reroll
int selectReroll(int dices[]){
  char row[81], temp[2];
  int i, enteredInt;

  temp[1] = '\0';

  setColor(GREEN, BLACK);
  printf("Enter dices to re roll (example: 1 3 5)\nTo do no re rolls at all enter 0\nInput: ");

  //Read the users input as a character string
  fgets(row, 80, stdin);

  //loop through each character
  for(i = 0;row[i] != '\0';i++){
    //check that the input is valid
    if(row[i] >= '1' && row[i] <= '6'){
      //Convert the inputed character to a integer
      temp[0] = row[i];
      enteredInt = atoi(temp);

      //roll the speciefied dice
      dices[enteredInt-1] = rollDice();
    }else if(row[i] == '0' && i == 0){
      //User entered 0, ie doesn't want any more rerolls
      return 0;
    }
  }

  //Continue with rerolls
  return 1;
}
Beispiel #9
0
void rollAllDices(int dices[]){
  int i;

  //loop through all 5 dices and rolling them
  for(i=0;i<5;i++){
    dices[i] = rollDice();
  }
}
Beispiel #10
0
void MainWindow::newGame()
{
    gameRunning = false;
    disconnect(&possibleWords[0],SIGNAL(finished()),this,SLOT(dice0Complete()));
    disconnect(&possibleWords[1],SIGNAL(finished()),this,SLOT(dice1Complete()));
    for(int i=0;i<2;i++) {
        if(possibleWords[i].isRunning()) {
            possibleWords[i].terminate();
            while(possibleWords[i].isRunning()) {
                usleep(1000);
            }
        }
    }
    ui->wordTree->clear();
    for(int i=3;i<18;i++) {
        letterItems[i] = new QTreeWidgetItem(ui->wordTree);
        letterItems[i]->setText(0,QString().setNum(i).append(" Letter Words"));
    }
    letterItems[0] = new QTreeWidgetItem(ui->wordTree);
    letterItems[0]->setText(0,QString("Misspelled Words"));
    letterItems[1] = new QTreeWidgetItem(ui->wordTree);
    letterItems[1]->setText(0,QString("Invalid Words"));
    letterItems[2] = new QTreeWidgetItem(ui->wordTree);
    letterItems[2]->setText(0,QString("Missed Words"));

    rollDice();
    ui->numWords->display(0);
    ui->score->display(0);
    timeRemaining = TOTAL_TIME; //in seconds;
    QPalette timePalette = ui->timeRemaining->palette();
    timePalette.setColor(QPalette::Foreground, QColor("green"));
    ui->timeRemaining->setPalette(timePalette);
    timePalette = ui->timeBar->palette();
    timePalette.setColor(QPalette::Highlight, QColor("green"));
    ui->timeBar->setPalette(timePalette);
    ui->timeBar->setMaximum(TOTAL_TIME);
    ui->timeBar->setValue(TOTAL_TIME - timeRemaining);
    ui->timeRemaining->display(timeRemaining);
    timer->start(1000);
    allWords.clear();
    if(ui->calculateWords->isChecked()) {
        for(int i=0;i<2;i++) {
            possibleWords[i].setup(i);
            possibleWords[i].start();
        }
        ui->calculateBar->setEnabled(true);
        ui->calculateBar->setValue(0);
        ui->calculateBar->setMaximum(16);
    }
    else {
        ui->calculateBar->setEnabled(false);
        ui->calculateBar->setValue(0);
        ui->calculateBar->setMaximum(16);
    }
    connect(&possibleWords[0],SIGNAL(finished()),this,SLOT(dice0Complete()));
    connect(&possibleWords[1],SIGNAL(finished()),this,SLOT(dice1Complete()));
    gameRunning = true;
}
Beispiel #11
0
void DarkMoonEngine::drawLightningColumn() {
	int f = rollDice(1, 2, -1);
	int y = 0;

	for (int i = 0; i < 6; i++) {
		f ^= 1;
		drawBlockObject(f, 2, _lightningColumnShape, 72, y, 5);
		y += 64;
	}
}
Beispiel #12
0
int main() {

	int gameStatus, sum, myPoint;
	srand(time(NULL));
	sum = rollDice();

	/* primeira jogada dos dados */
	switch(sum) {
		case 7:
		case 11:
		/* vence na primeira jogada */
			gameStatus = 1;
		break;
		case 2:
		case 3:
		case 12:
		/* perde na primeira jogada */
			gameStatus = 2;
		break;
		default:
		/* armazena o ponto */
			gameStatus = 0;
			myPoint = sum;
			printf("O ponto e %d\n", myPoint);
		break;
	}

	while (gameStatus == 0) { 
	/* continua jogando */
		sum = rollDice();
		if(sum == myPoint) /* vence fazendo o ponto */
			gameStatus = 1;
			else
		if(sum == 7) /* perde obtendo o valor 7 */
			gameStatus = 2;
		}
		if(gameStatus == 1)
			printf("Jogador vence\n") ;
		else
			printf("Jogador perde\n");
return 0;

}
QString cElement::value() const
{
    QString Value = text_;

    for ( unsigned int i = 0; i < childCount(); ++i )
    {
        const cElement* childTag = getChild( i );

        if ( childTag->name() == "random" )
        {
            if ( childTag->hasAttribute( "min" ) && childTag->hasAttribute( "max" ) )
            {
                QString min = childTag->getAttribute( "min" );
                QString max = childTag->getAttribute( "max" );

                if ( min.contains( "." ) || max.contains( "." ) )
                    Value += QString::number( RandomNum( ( int ) min.toFloat(), ( int ) max.toFloat() ) );
                else
                    Value += QString::number( RandomNum( min.toInt(), max.toInt() ) );
            }
            else if ( childTag->hasAttribute( "valuelist" ) )
            {
                QStringList RandValues = QStringList::split( ",", childTag->getAttribute( "valuelist" ) );
                Value += RandValues[RandomNum( 0, RandValues.size() - 1 )];
            }
            else if ( childTag->hasAttribute( "list" ) )
            {
                Value += Definitions::instance()->getRandomListEntry( childTag->getAttribute( "list" ) );
            }
            else if ( childTag->hasAttribute( "dice" ) )
            {
                Value += QString::number( rollDice( childTag->getAttribute( "dice" ) ) );
            }
            else if ( childTag->hasAttribute( "value" ) )
            {
                QStringList parts = QStringList::split( "-", childTag->getAttribute( "value", "0-0" ) );

                if ( parts.count() >= 2 )
                {
                    QString min = parts[0];
                    QString max = parts[1];

                    if ( max.contains( "." ) || min.contains( "." ) )
                        Value += QString::number( RandomNum( ( int ) min.toFloat(), ( int ) max.toFloat() ) );
                    else
                        Value += QString::number( RandomNum( min.toInt(), max.toInt() ) );
                }
            }
            else
                Value += QString( "0" );
        }
    }

    return hex2dec( Value );
}
Beispiel #14
0
void simulateCraps(int games)
{
	int count = 0;
	
	while (count < games)
	{
		int result = rollDice();
		
		
		if (result == 7 || result == 11)
		{
			wincount = wincount + 1;
			count = count + 1;
		}
		else if (result == 2 || result == 3 || result == 12)
		{
			count = count + 1;
		
		}
		else
		{
			count = count + 1;
			int lastResult = result;
			int cont = 1;
			while (cont == 1)
			{
				result = rollDice();
				if (result == 7)
				{
					cont = 0;
					
				}
				else if (result == lastResult)
				{
					wincount = wincount + 1;
					cont = 0;
				}
			
			}
		}
	}
}
QString cDefinable::getNodeValue( const QDomElement &Tag )
{
	QString Value = QString();
	
	if( !Tag.hasChildNodes() )
		return "";
	else
	{
		QDomNode childNode = Tag.firstChild();
		while( !childNode.isNull() )
		{
			if( !childNode.isElement() )
			{
				if( childNode.isText() )
					Value += childNode.toText().data();
				childNode = childNode.nextSibling();
				continue;
			}
			QDomElement childTag = childNode.toElement();
			if( childTag.nodeName() == "random" )
			{
				if( childTag.attributes().contains("min") && childTag.attributes().contains("max") )
					Value += QString("%1").arg( RandomNum( childTag.attributeNode("min").nodeValue().toInt(), childTag.attributeNode("max").nodeValue().toInt() ) );
				else if( childTag.attributes().contains("valuelist") )
				{
					QStringList RandValues = QStringList::split(",", childTag.attributeNode("list").nodeValue());
					Value += RandValues[ RandomNum(0,RandValues.size()-1) ];
				}
				else if( childTag.attributes().contains( "list" ) )
				{
					Value += DefManager->getRandomListEntry( childTag.attribute( "list" ) );
				}
				else if( childTag.attributes().contains("dice") )
					Value += QString("%1").arg(rollDice(childTag.attributeNode("dice").nodeValue()));
				else
					Value += QString("0");
			}

			// Process the childnodes
			QDomNodeList childNodes = childTag.childNodes();

			for( int i = 0; i < childNodes.count(); i++ )
			{
				if( !childNodes.item( i ).isElement() )
					continue;

				Value += this->getNodeValue( childNodes.item( i ).toElement() );
			}
			childNode = childNode.nextSibling();
		}
	}
	return hex2dec( Value );
}
int TheShadow::characterAttack() 
{
	damage = rollDice(3, 8);

	if(damage >= 18)
	{
		std::cout << this->creatureName << " lands a stunning blow! The crowd goes wild!" << std::endl;
		this->vPoints++;
	}

	return damage;
}
Beispiel #17
0
/*
repeatedly roll until rolls point (win) or 7(lose)
Parameter: point
Return: True if rolled point number, false if rolled 7
*/
int rollForPoint(int point)
{
	int gotPoint = FALSE;
	int roll;

	roll = rollDice();
	Sleep(1500);
	printf("\nYou rolled a %d...\n", roll);

	while (roll != point&&roll != 7)
	{
		Sleep(1500);
		roll = rollDice();
		printf("You rolled a %d...\n", roll);
	}

	if (roll == point)
		gotPoint = TRUE;

	return gotPoint;
}
Beispiel #18
0
// This should be called everytime the game is reset.
void MonopolyGame::reset() {

    // Seed the random number generator.
    srand( (unsigned)time( 0 ) );

	// Reset the camera position.
	m_alCamera.cameraPosition[Positions::X_POS] = 0;
	m_alCamera.cameraPosition[Positions::Y_POS] = 0;

	m_isActive = false;

	m_playersTurn = 0;
	m_numPlayers = NUM_PLAYERS;
	m_firstTurn = true;
	m_turnDone = false;
	m_firstMovePass = true;

	m_currentReaction = ReactionType::NULL_REACTION;
	m_turnState = TurnState::NULL_STATE;

	m_diceRoll = rollDice( NUM_DICE, 0 );

	m_doublesRollCounter = 0;

	m_moveDestination = 0;

	m_exitGame = false;
	m_redrawScreen = true;

    // Reset each player attribute.
    for( int pCount = 0; pCount < NUM_PLAYERS; pCount++ ) {
    	m_playerList[pCount].set_location(0);
    	m_playerList[pCount].set_score(0);

        if( m_activeGameMode == GameMode::EASY ) {
        	m_playerList[pCount].set_money( 3500 );
        }
        else if( m_activeGameMode == GameMode::NORMAL ) {
        	m_playerList[pCount].set_money( 2500 );
        }
        else if( m_activeGameMode == GameMode::DIFFICULT ) {
        	m_playerList[pCount].set_money( 1500 );
        }
    }

    // Reset each property attribute.
    for( int pCount = 0; pCount < MAX_PROPERTIES; pCount++ ) {
    	m_propertyList[pCount].set_isMortgaged( false );
    	m_propertyList[pCount].set_isOwned( false );
    	m_propertyList[pCount].set_ownedBy( 0 );
    }
}
Beispiel #19
0
void runGame (void) {
    // create a dummy game
    int disciplines[] = DEFAULT_DISCIPLINES;
    int dice[] = DEFAULT_DICE;
    Game g = newGame (disciplines, dice);
    
    printf ("Running a test game...\n");
    // roll the dice
    int diceScore;
    diceScore = rollDice ();
    // progress the game
    throwDice (g, diceScore);
    
    printf ("Deciding on the action...\n");
    action newAction;
    newAction = decideAction (g);
    while (!getWinner (g)) {
        // if the player PASSES
        if (newAction.actionCode == PASS) {
            diceScore = rollDice ();
            // progress the game
            throwDice (g, diceScore);
        }
        else
        {
            if (isLegalAction (g, newAction)) {
                makeAction (g, newAction);
            } else {
                printf (">>> I'm sorry but you can't do that!\n");
            }
        }
        // get the next turn
        newAction = decideAction (g);
        
    }
    // the game is over
    printf ("\nGame over. Player %d wins\n", getWinner (g));
    disposeGame (g);
}
int Shadow::attack()
{
	int numDiceFace = 10;
	int numDice = 2;

	int attackTotal = 0; 
			
	for(int x = 0; x < numDice; x++)
	{
		attackTotal += rollDice(numDiceFace);
	}
	return attackTotal;
};
// function main begins program execution
int main( void )
{
   int sum; // sum of rolled dice
   // enumeration constants represent game status
   enum Status { CONTINUE, WON, LOST };
   enum Status gameStatus; // can contain CONTINUE, WON, or LOST

   sum = rollDice(); // first roll of the dice
   
   int realStatus = compareDiceNumber(sum);
   getResult(realStatus);
   system("pause");
   return 0;
} // end main
Beispiel #22
0
/************************************************************
 ** Henchman::attack
 ** Description: Generates a dice roll from AttackDice and
 ** AttackSides values and returns an attack value.
 ** If a 12 is rolled, the achilles attack is successful
 ** Parameters: Character& defender
 ************************************************************/
int Henchman::attack(Character* defender)
{
   int attkTotal = 0;   // Reset accumulator

   for (int d = 0; d < getAttackDice(); d++)
   {
      attkTotal += rollDice(getAttackSides());
   }

   // Achilles attack successful if 12 is rolled and defender
   // is not another Henchman
   if (attkTotal == 12 && defender->getType() != HENCHMAN)
      setAchilles(true);

   return attkTotal;
}
Beispiel #23
0
void MonopolyGame::handleDiceRoll(MonopolyPlayer &plyr) {
	// Roll 2, six sided dice.
	m_diceRoll = rollDice( NUM_DICE, NUM_SIDES_PER_DIE );

	// If this is the player's first dice roll, reset the doubles counter.
	if( plyr.get_firstRoll() ) {
		m_doublesRollCounter = 0;
		plyr.set_firstRoll( false );
	}

	// If die 1 equals die 2, then increment the doubles counter.
	if( m_diceRoll[0] == m_diceRoll[1] ) {
		//  Need to ensure that when this player's turn ends, this counter is reset to 0.
		m_doublesRollCounter++;
	}
}
Beispiel #24
0
void Medusa::defense(int attack) {

	defenseVal = rollDice(numDiceDefense, numDiceDefenseSides);

	int damageTaken = (attack - armor) - defenseVal;

	if (damageTaken > 0) {
		strength -= damageTaken;
	}

	if (strength <= 0) {
		cout << " " << name << " " << identity << " has died." << endl;
		lifeValue = 0;
	}

}
Beispiel #25
0
/******************************************************************************************
** Function: Medusa Attack (special powerup)
** Description: This attack function uniquely allows Medusa to perform the Glare superpower
**		as a result of Glare, her enemy is immediately killed with an attack of 1000. 
** Parameters: N/A
** Pre-Conditions: N/A
** Post-Conditons: Glare occurs if the rollDice function returns a value of 12. 
******************************************************************************************/
int Medusa::attack() {
	attackVal = 0;
	int glare = 10000;

	attackVal = rollDice(numDiceAttack, numDiceAttackSides);

	if (attackVal == 12) {
		cout << " Oh no! The target has looked into ";
		cout << name << " " << identity << "'s eyes and is turned to stone." << endl;
		return glare;
	}

	else {
		return attackVal;
	}

}
Beispiel #26
0
// Allocates a set of random dice inside disciplines[]
void randomDice(int dice[]) {
   int diceIndex;
   int diceRolled;
   int totalRoll;
   
   diceIndex = 0;
   while (diceIndex < NUM_REGIONS) {
      totalRoll = 0;

      // roll a dice DICE_AMOUNT and add the total
      diceRolled = 0;
      while (diceRolled < DICE_AMOUNT) {
         totalRoll += rollDice();
         diceRolled++;
      }
      
      // allocate the totalRoll
      dice[diceIndex] = totalRoll;
      diceIndex++;
   }
}
Beispiel #27
0
void Battle::determineWinner(Player* player)
{
	if(player == player1)
		winner = player1;
	else
		winner = player2;

	winner->restoreLife();
	
	int expRequired = (winner->getExp() + winner->getLevel()) * winner->getExp();
	if (winner->getExp() == expRequired)
	{
		winner->increaseLevel();
		
		int hitPointsReceived = rollDice(1, 10, 0) + winner->getConModifier();
		
		winner->increaseHitPoints(hitPointsReceived);
	}
	
	cout << winner->getName() << " receives 10 gold" << endl;
}
int getStatis(int *SecondPoint, int gameStatus){
    int sum;
    int myPoint = *SecondPoint; 
    enum Status { CONTINUE, WON, LOST };

    while ( CONTINUE == gameStatus ) { // player should keep rolling
          sum = rollDice(); // roll dice again
    
          // determine game status
          if ( sum == myPoint ) { // win by making point
             gameStatus = WON; // game over, player won
             return gameStatus;
          } // end if
          else {
               if ( 7 == sum ) { // lose by rolling 7
                  gameStatus = LOST; // game over, player lost
                  return gameStatus;
               } // end if
          } // end else
   } // end while
}
Beispiel #29
0
void LoLEngine::timerUpdatePortraitAnimations(int skipUpdate) {
	if (skipUpdate != 1)
		skipUpdate = 0;

	for (int i = 0; i < 4; i++) {
		if (!(_characters[i].flags & 1) || (_characters[i].flags & 8) || (_characters[i].curFaceFrame > 1))
			continue;

		if (_characters[i].curFaceFrame != 1) {
			if (--_characters[i].nextAnimUpdateCountdown <= 0 && !skipUpdate) {
				_characters[i].curFaceFrame = 1;
				gui_drawCharPortraitWithStats(i);
				_timer->setCountdown(9, 10);
			}
		} else {
			_characters[i].curFaceFrame = 0;
			gui_drawCharPortraitWithStats(i);
			_characters[i].nextAnimUpdateCountdown = rollDice(1, 12) + 6;
		}
	}
}
Beispiel #30
0
   /***************************************************
    * Name:    playerAttack 
    * Entry:   Parameters for two Creatureobjects. 
    * Exit:    P2's strength is modified. 
    * Purpose: P1 attacks P2 and inflicts damage. 
    *************************************************/
   void Creature::playerAttack(Creature *opponent)
   {
      int roll_attack;
      int roll_defense;
      int damage;

      cout << std::string(30, '\n')
           << "** " << name << " ATTACKS **\n";
      
      //roll dice for attack
      cout << name << "'s turn -- ";
      roll_attack = rollDice('a');
      cout << name << " rolls an attack of " 
           << roll_attack << ".\n"; 
      cout << name << "'s base attack is " << base_attack << endl 
           << "Total combined attack: " 
           << base_attack + roll_attack << endl << endl;


      //roll dice for defense
      cout << opponent->getName() << "'s turn -- ";
      roll_defense = opponent->rollDice('d');
      cout << opponent->getName() <<  " rolls a defense of " 
           << roll_defense << ".\n";
      cout << opponent->getName() << "'s base defense is "
           << opponent->getDefense() << endl
           << "Total combined defense: " 
           << opponent->getDefense() + roll_defense << endl << endl;

      //display battle outcome
      damage = (roll_attack + base_attack) - (roll_defense + base_defense); 
      opponent->setStrength(damage);
      cout << "Total Attack Damage: " << damage << endl
           << opponent->getName() << " Armor Value: " 
           << opponent->getArmor() << endl
           << opponent->getName() << " Remaining Strength: " 
           << opponent->getStrength() << endl << endl;

      return;
   }