Exemplo n.º 1
0
int chat_roll_dice( int unum, char *msg )
{
  static int seeded;
  int ndice = 2;
  int die = 6;
  int total = 0;
  int i, roll;
  char diebuf[8];
  char *rollspec = nextword(&msg);
  char *d;
  if (!seeded) {
    srand((int)time(NULL));
    seeded++;
  }
  if ((d = strchr(rollspec, 'd')) != NULL) {
    *d = '\0';
    die = atoi(d+1);
  }
  if (*rollspec != '\0') {
    ndice = atoi(rollspec);
  }
  if (ndice < 0 || ndice > 10) {
    send_to_unum(unum, "*** May only roll from 1 to 10 dice\n", -1);
    return 0;
  }
  if (die < 2 || die > 100) {
    send_to_unum(unum, "*** Die must have from 2 to 100 sides\n", -1);
    return 0;
  }
  strcpy(genbuf, "*** ");
  strcat(genbuf, users[unum].chatid);
  strcat(genbuf, " rolled (");
  for (i=0; i<ndice; i++) {
    roll = diceroll(die);
    if (i > 0) strcat(genbuf, ", ");
    sprintf(diebuf, "%d", roll);
    strcat(genbuf, diebuf);
    total += roll;        
  }
  strcat(genbuf, ") = ");
  sprintf(diebuf, "%d", total);
  strcat(genbuf, diebuf);
  strcat(genbuf, " on ");
  sprintf(diebuf, "%dd%d", ndice, die);
  strcat(genbuf, diebuf);
  strcat(genbuf, "\n");
  send_to_room(users[unum].room, genbuf, unum);
  return 0;  
}  
Exemplo n.º 2
0
main(){
int bet, p, ep, t, your, enemy, bat=0; 		// These are the declarations used in to indicate the players, money as well as the bet.
int d1, d2, d3, end=0, choice; 			//These are for the dices and the choice declarations.
char turn[10]; 					//This one is for the turn of each player. 

header();		//This is the start of the game proper.

strcpy(turn, "Player 1");
t = 0;

p = 1000;		//The initial money of both players is 1000 each.
ep = 1000;

while(end!=1){		//This is the loop used to regulate the turns of each player.
	if(p<=0){
		printf("Player 1 has lost all your money! GAMEOVER!\n\n"); //This will indicate which of the player has lost all his/her money.
		end=1;
		}
	else if(ep<=0){
		printf("Player 2 has lost all money! GAMEOVER!\n\n");
		end=1;
		}
		
	if(end==0){				//This will facilitate the flow of turns of each player.
		printf("\n\nTurn: %s", turn);
		printf("\n\n# S E L E C T #\n\n[1] To PLAY!\n[2] TO EXIT\n[3] FOR INSTRUCTIONS\n\nM1: %d\tM2: %d\n\nMode: ", p, ep);
		scanf("%d", &choice);		//This will let the players to choose whether to play/continue, to stop/close or to read the instruction.
		
		if(t==0)			//This will regulate the turn to bet of each player.
			bet = p + 1;
		else if(t==1)
			bet = ep + 1;
		}
	
	if(end==0)
	switch(choice){				//This will facilitate the game proper which includes the bet, the rolling of dice and the cases indicated in the combo menu.
		case 1:
			
			if(t==0){		//This will check if the bet entered by the Player1 is exceeding the original amount of his/her money.
				while(bet>p){
					printf("\n# P L A C E   Y O U R   B E T #\n\nBet: ");
					scanf("%d", &bet);
					if(bet>p)
						printf("\n\nYour bet is higher than your current money!\n\nBet again!\n\n");
					}
				p = p - bet;	//This will deduct the bet from the money of the loser (player1).
				}
								
			else if(t==1){		//This will check if the bet entered by the Player2 is exceeding the original amount of his/her money.
				while(bet>ep){
					printf("\n# P L A C E   Y O U R   B E T #\n\nBet: ");
					scanf("%d", &bet);
					if(bet>ep)
						printf("\n\nYour bet is higher than your current money!\n\nBet again!\n\n");
					}
				ep = ep - bet; //This will deduct the bet from the money of the loser(player2).
				}
							
			printf("\n\n");		//This is where the rolling of dice takes place. 
			
			d1 = diceroll();
			wait();
			d2 = diceroll();
			wait();
			d3 = diceroll();
			wait();
					//This is where the evaluation of the results occurs. 
			if(d1==d2&&d2==d3&&d1==d3){
				printf("\n\n N - N - N COMBO!!\n\n You WIN 3x of bet!\n\n");	//The N-N-N combo was displayed.
				if(t==0)
					p = p + bet*3;			//The bet is multiplied thrice and added to the money of the player(winner).
				else if(t==1)
					ep = ep + bet*3;
				}

			else if(d1+d2+d3==15&&(d1!=d2&&d2!=d3&&d1!=d3)){
				printf("\n\n4 - 5 - 6 COMBO!!\n\nYou WIN 2x of bet!\n\n"); //The 4-5-6 combo appeared.
				if(t==0)
					p = p + bet*2;			//The bet is multiplied twice and added to the money of the player(winner).
				else if(t==1)
					ep = ep + bet*2;
				}
				
			else if(d1+d2+d3==6&&(d1!=d2&&d2!=d3&&d1!=d3)){
				printf("\n\n1 - 2 - 3 COMBO..\n\nYou LOSE 2x of bet!\n\n"); //The 1-2-3 combo also appeared.
				if(t==0)
					p = p - bet*2;			//The bet is multiplied twice but deducted from the money of the player(loser).
				else if(t==1)
					ep = ep - bet*2;
				}

			else if(d1==d2&&(d1!=d3&&d2!=d3)){
				printf("\n\nX - X - N COMBO!!\n\nYour value %d is stored for DICE BATTLE!\n\n", d3); //The X-X-N combo was displayed.
				wait();
				if(t==0){
					your = d3;
					bat = 1;
					}
				else if(t==1){
					enemy = d3;
					bat = 1;
					}
				}

			else if(d2==d3&&(d2!=d1&&d3!=d1)){
   				printf("\n\n N - X - X COMBO!!\n\nYour value %d is stored for DICE BATTLE!\n\n", d1); //The N-X-X combo was displayed.
   				wait();
   				if(t==0){
   				your = d1;
				bat = 1;
				}
			else if(t==1){
				enemy = d1;
				bat = 1;
				}
      			     }


   			else if(d1==d3&&(d1!=d2&&d3!=d2)){
  				printf("\n\n X - N - X COMBO!!\n\nYour value %d is stored for DICE BATTLE!\n\n", d2); //The X-N-X combo was displayed.
   				wait();
   				if(t==0){
   				your = d2;
				bat = 1;
					}
			else if(t==1){
				enemy = d2;
				bat = 1;
				}
    			     }

			else{
				printf("\n\n NO COMBOS! NexT Player, Please!!!\n\n"); //This will let the player roll again until there is a specific combo.
				if(t==0)
					p = p + bet;
				else if(t==1)
					ep = ep + bet;
				}
				
			break;
			
		case 2:
			end = 1;
			break;
			
		case 3:
			printf("\n\n\tInstructions:\n\n");
			printf("\tPlace your bet and roll the dice!\n\n");
			printf("\tCOMBOS:\n\n\n");
			printf("\t1 - 2 - 3 COMBO\n");
			printf("\t    RESULT:   LOSE 2x of your bet\n\n");
			printf("\t4 - 5 - 6 COMBO\n");
			printf("\t    RESULT:   WIN 2x of your bet\n\n");
			printf("\tN - N - N COMBO\n");
			printf("\t    RESULT:   WIN 3x of your bet\n\n");
			printf("\tX - X - N COMBO\n");
			printf("\t    RESULT:   DICE BATTLE! WINNER TAKES THE BET!\n\n");
			if(strcmp(turn, "Player 1")==0){
				strcpy(turn, "Player 2");
				t = 1;
				}
		
			else{
				strcpy(turn, "Player 1");
				t = 0;
				}
				
			break;
			
		default:
			printf("\n\nERROR!\n\nLose one turn!\n\n");
		}
		
	if(strcmp(turn, "Player 1")==0){
		strcpy(turn, "Player 2");
		t = 1;
		}
		
	else{
		strcpy(turn, "Player 1");	//This is an extension of the last combo,X-X-N Combination. 
		t = 0;
		}
		
	while(bat == 1){
		printf("\n%s rolls to battle the value of ", turn); //The unique number is being saved to be compared to the next unique number.
		wait();
		if(t==1){
			printf("%d!\n\n", your);
			wait();
			d1 = diceroll();
			wait();
			printf("\n\nThe value of %d will be used!\n\n", d1);
			enemy = d1;
			}
		else if(t==0){
			printf("%d!\n\n", enemy);
			wait();
			d1 = diceroll();
			wait();
			printf("\n\nThe value of %d will be used!\n\n", d1);
			your = d1;
			}
			
		wait();
			
		if(your>enemy){			//This will compare which of the unique numbers is higher. Furthermore, to know who will get the bet.
			printf("Player 1 wins the battle!\n\n");
			wait();
			printf("Bet subtracted to Player 2!\n\n");	//Player 1's unique number is higher than Player2.
			p = p + bet;
			bat = 0;
			}
			
		else if(enemy>your){
			printf("Player 2 wins the battle!\n\n");	//Player 2's unique number is higher than Player1.
			printf("Bet subtracted to Player 1!\n\n");
			p = p + bet;
			bat = 0;
			}
		
		else if(enemy==your){		//This indicate if the unique numbers of both players are the same. DRAW!!!
			bat = 0;
			if(t==0)
				p = p + bet;
			else if(t==1)
				ep = ep + bet;
			printf("\n\nDRAAWWW!!!(^.^)v \n\n");
			}
		}
	}
}