Example #1
0
void player_hurt(unsigned int damage)
{
	damage = stats_hurt(&player.stats, damage);

	if(player.stats.hp == 0) {
		/* Player is dead, do something about it */
	}

	player_status();
	msg_printf("[%u pts.]", damage);
}
Example #2
0
File: main.c Project: davel/lartem
int main(int argc, char *argv[])
{
	int k;
	struct coord c;
	unsigned int i;
	unsigned char turn_taken = 1, running = 0;

	seed_rng();

	display_init();

	if(player_init() == -1) return 0;

	level_init(&levels[0], 8);
	player_set_level(&levels[0]);

	while(1) {
		main_clear();
		player_see();
		player_status();

		turn_taken = 0;

		if(!running) k = display_getch();

		msg_clear();

		switch(k) {
		case '8':
		case '9':
		case '6':
		case '3':
		case '2':
		case '1':
		case '4':
		case '7':
		case KEY_UP:
		case KEY_DOWN:
		case KEY_LEFT:
		case KEY_RIGHT:
			c = key_to_direction(k);
			if(!player_move(c.x, c.y)) running = 0;
			turn_taken = 1;
			break;
		case 'c':
			c = key_to_direction(ask_key("In which direction?"));
			msg_clear();
			player_close(c.x, c.y);
			turn_taken = 1;
			break;
		case 'o':
			c = key_to_direction(ask_key("In which direction?"));
			msg_clear();
			player_open(c.x, c.y);
			turn_taken = 1;
			break;
		case 'k':
			c = key_to_direction(ask_key("In which direction?"));
			msg_clear();
			player_kick(c.x, c.y);
			turn_taken = 1;
			break;
		case 'g':
		case 'G':
			k = ask_key("In which direction?");
			c = key_to_direction(k);
			if((c.x || c.y) && player_move(c.x, c.y)) running = 1;
			turn_taken = 1;
			break;
		case ':':
			player_look();
			break;
		case ';':
			msg_printf("Pick an object...");
			c = player_select_square();
			msg_clear();
			player_remote_look(c.x, c.y);
			break;
		case '.':
			turn_taken = 1;
			break;
		}


		if(turn_taken) {
			if(player_poll()) running = 0;

			for(i = 0; i < levels[0].nmonst; i++)
				if(monster_poll(levels[0].monsters[i]))
					running = 0;
		}
	}

	return 0;
}
Example #3
0
int main(int argc, char* argv[])
{
	struct deck thisDeck;
	struct player thisPlayer;
	struct game thisGame;
	int inputValidity;
	int menu;
	int game;
	int load = 0;
	
	//Not Working!!! card_init_deck(&thisDeck);
	
	//This is the exact same algorithm used in card.c and it works great here!!! Why!!!
	for (int k = 0; k < 4; k++)
	{
		for (int i = 0; i < 13; i++)
		{
			for (int j = 0; j < 4; j++)
			{
				strcpy(thisDeck.oneCard[k*52+i*4+j].rank, ranks[i]);
				strcpy(thisDeck.oneCard[k*52+i*4+j].suit, suits[j]);
				thisDeck.oneCard[k*52+i*4+j].value = value[i];
			}
		}
	}
	
	card_shuffle(&thisDeck);
	thisPlayer.chip = 0;
	
	system("clear");
		
	while (1)
	{
		printf("\n\n**********BlackJack**********\n\n");
		printf(" 1. Play\n");
		printf(" 2. Load\n");
		printf(" 3. Player status\n");
		printf(" 4. Exit\n\n");
		printf("*****************************\n\n");
		while(1)
		{
			printf("Please enter menu number: ");
			inputValidity = scanf("%d", &menu);
			while(getchar()!='\n'){}
			if (inputValidity)
			{
				if (menu < 1 || menu > 4)
				{
					printf("Please select from menu!\n");
				}
				else
				{
					break;
				}
			}
			else
			{
				printf("Please enter a NUMBER!\n");
			}
		}
		
		if (menu == 4)
		{
			player_save(&thisPlayer);
			printf("Thanks for playing! Bye!\n");
			break;
		}
		else if (menu == 3)
		{
			if (thisPlayer.name == NULL)
			{
				printf("No player record.\n");
				continue;
			}
			player_status(&thisPlayer);
			continue;
		}
		else if (menu == 2)
		{
			player_load(&thisPlayer);
			continue;
		}
		else
		{
			if (thisPlayer.chip == 0)
			{
				player_name(&thisPlayer);
				player_chip(&thisPlayer);
			}
			printf("Welcome %s!\nHave fun!\n\n", thisPlayer.name);
			
			while(1)
			{
				//Deal initial cards
				game_init(&thisGame);
				if (thisDeck.cardNow > 180)
				{
					printf("\n\nShuffling...\n\n");
					card_shuffle(&thisDeck);
				}
				if (thisPlayer.chip <= 0)
				{
					printf("You are penniless!\n");
					thisPlayer.win = 0;
					thisPlayer.lose = 0;
					thisPlayer.push = 0;
					break;
				}
				game_bet(1, &thisPlayer, &thisGame);
				printf("\nDealer is dealing the cards...\n\n");
				game_deal_card(2, &thisGame, &thisDeck);
				game_deal_card(1, &thisGame, &thisDeck);
				game_deal_card(2, &thisGame, &thisDeck);
				game_deal_card(1, &thisGame, &thisDeck);
				printf("Dealer shows %s of %s\n", thisDeck.oneCard[thisGame.dealer_inhand[0]].rank, thisDeck.oneCard[thisGame.dealer_inhand[0]].suit);
				printf("Dealer\'s point is %d\n", thisDeck.oneCard[thisGame.dealer_inhand[0]].value);
				printf("Your cards: ");
				game_print_card(2, &thisGame, &thisDeck);
				printf("\n");
				printf("Your point is %d\n", game_totalvalue(2, &thisGame, &thisDeck));
				
				//Check if dealer shows an Ace
				if (thisDeck.oneCard[thisGame.dealer_inhand[0]].value == 11)
				{
					game_bet(2, &thisPlayer, &thisGame);
					if (game_totalvalue(1, &thisGame, &thisDeck) == 21 && game_judge(&thisGame, &thisDeck) != 4)
					{
						if (thisGame.is_insured)
						{
							thisPlayer.chip += thisGame.bet;
						}
						thisPlayer.lose++;
						printf("Dealer\'s cards: ");
						game_print_card(1, &thisGame, &thisDeck);
						printf("\n");
						printf("Dealer\'s point is %d\n", game_totalvalue(1, &thisGame, &thisDeck));
						printf("Dealer is BlackJack!\n");
						if (game_end())
						{
							break;
						}
						else
						{
							continue;
						}
					}
					else if (game_totalvalue(2, &thisGame, &thisDeck) == 21 && game_judge(&thisGame, &thisDeck) == 4)
					{
						thisPlayer.chip += thisGame.bet;
						thisPlayer.push++;
						printf("Push!\n");
					}
				}
				
				game_play(&thisPlayer, &thisDeck, &thisGame);
				if (game_end())
				{
					break;
				}
				continue;
			}
			continue;
		}
	}
	
	return 0;
}