Example #1
0
//READ THE COMMENT BELOW
//DO NOT REMOVE THIS FUNCTION
//READ THE COMMENT ABOVE
void Player::takeTurn(Board &game){
  int d1, d2;
  Die dice;
  dice.roll();
  cout<<"\nPlayer "<<turnControl<<endl;
  cout<<"Player Balance: "<<balance<<endl;
  diceTotal = dice.getTotal();
  update(game,diceTotal);
  displayDice(dice.d1, dice.d2);
  game.spaceManager(this);
  }
Example #2
0
/*********************************************************************
** Function:         defense_roll()
** Description:      Makes the appropriate type of die and rolls it
**                   the appropriate number of times
** Parameters:       None
** Pre-Conditions:   Creature must have data members set
** Post-Conditions:  Prints result of each roll and returns the total
**                   of all rolls (if multiple)
********************************************************************/
int Creature::defense_roll()
{
	int total_roll = 0, roll = 0;
	Die* die = new Die(this->defense_dice_sides);

	for (int i = 0; i < this->defense_dice_count; i++)
	{
		roll = die->roll();
		total_roll += roll;
		std::cout << this->type_name << " rolls defense die: d" << defense_dice_sides << " for " << roll << "\n";
	}
	std::cout << "Total defense roll: " << total_roll << "\n";
	delete die;
	return total_roll;
}
Example #3
0
int main()
{
	//frame setup
	system("title Dice Game");
	system("mode con: cols=63 lines=20");
	system("color 27");
	
	
	//animation array, this was shorteded to var "a" for easy use
	int a[20][2] = {{5,9},{7,7},{9,4},{11,2},{13,2},
					{15,4},{17,6},{19,9},{21,8},{23,7},
					{25,6},{27,5},{29,4},{31,5},{33,6},
					{35,7},{37,8},{39,9},{41,9},{42,9}};
	
	
	//var setup
	Renderer renderer;
	Die die;
	int dice1;
	int dice2;
	int yourScore = 0;
	int dealerScore = 0;
	int input;
	bool even;
	srand(5);
	
	
	//Start Game Here
	cout<< "Note:\n -Number displays work best if you pick less than 10 iterations\n -For best effect dont resize window\n-------------------------------------------------------------";
	cout<< "\nHow Many times do you want to play? ";
	cin >> input;
	cout << "\nEven or odd (0 or 1)? ";
	cin >> even;
	for(int j = 0; j < input; j ++){
		for(int i = 0; i < 20; i ++){
			//clear renderer
			renderer.clear();
			//display roll number
			char rollnum[8] = {'R','o','l','l',' ',(char)(j + 49),':','\0'};
			renderer.write(5,1,rollnum,7);
			//die #1 display
			die.roll();
			switch(dice1 = die.getValue()){
				case 1:
					renderer.draw(a[i][0],a[i][1]," ----- |     ||  O  ||     | ----- ",7,7*5);
					break;
				case 2:
					renderer.draw(a[i][0],a[i][1]," ----- |O    ||     ||    O| ----- ",7,7*5);
					break;
				case 3:
					renderer.draw(a[i][0],a[i][1]," ----- |O    ||  O  ||    O| ----- ",7,7*5);
					break;
				case 4:
					renderer.draw(a[i][0],a[i][1]," ----- |O   O||     ||O   O| ----- ",7,7*5);
					break;
				case 5:
					renderer.draw(a[i][0],a[i][1]," ----- |O   O||  O  ||O   O| ----- ",7,7*5);
					break;
				case 6:
					renderer.draw(a[i][0],a[i][1]," ----- |O   O||O   O||O   O| ----- ",7,7*5);
					break;
			};
			//die #2 display
			die.roll();
			switch(dice2 = die.getValue()){
				case 1:
					renderer.draw(a[i][0]+8,a[i][1]," ----- |     ||  O  ||     | ----- ",7,7*5);
					break;
				case 2:
					renderer.draw(a[i][0]+8,a[i][1]," ----- |O    ||     ||    O| ----- ",7,7*5);
					break;
				case 3:
					renderer.draw(a[i][0]+8,a[i][1]," ----- |O    ||  O  ||    O| ----- ",7,7*5);
					break;
				case 4:
					renderer.draw(a[i][0]+8,a[i][1]," ----- |O   O||     ||O   O| ----- ",7,7*5);
					break;
				case 5:
					renderer.draw(a[i][0]+8,a[i][1]," ----- |O   O||  O  ||O   O| ----- ",7,7*5);
					break;
				case 6:
					renderer.draw(a[i][0]+8,a[i][1]," ----- |O   O||O   O||O   O| ----- ",7,7*5);
					break;
			};
			//render frame
			renderer.render();
			//sleep for a sec then move on to the next frame
			usleep(100000);
		}
		//this if desides who wins the roll
	 	if(even ? (dice1+dice2)%2 == 1 : (dice1+dice2)%2 == 0){
	 		cout<<"\nYou Win!\n";
	 		yourScore ++;
		}else{
			cout << "\nDealer Wins!\n";
			dealerScore ++;
		}
		system("pause");
	}
	//clear renderer
	renderer.clear();
	//end game cstring setup
	char you[30] = {'Y','o','u','r',' ','f','i','n','a','l',' ','s','c','o','r','e',' ','i','s',' ',(char)(yourScore + 48),' ','p','o','i','n','t','s','.','\0'};
	char deal[34] = {'D','e','a','l','e','r',(char)96,'s',' ','f','i','n','a','l',' ','s','c','o','r','e',' ','i','s',' ',(char)(dealerScore + 48),' ','p','o','i','n','t','s','.','\0'};
	char win[9] =  {'Y','o','u',' ','W','i','n','!','\0'};
	char loss[9] =  {'Y','o','u',' ','L','o','s','t','\0'}; 
	//setup and display end game message
	if(yourScore <= dealerScore)
			renderer.write(28,9,loss,8);
	else 
			renderer.write(28,9,win,8);
	renderer.write(16,4,you,29);
	renderer.write(14,6,deal,33);
	renderer.render();
return 0;
}
		void roll()
		{
			dieOne.roll();
			dieTwo.roll();
		}