此代码仅包含4种卡牌(可增加其它id的卡牌效果函数)
此项目仅有一个固定攻击模式的boss。
以下是实现代码,
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int deck[10] = { 1, 1, 1, 1, 2, 2, 2, 2, 3, 4 };
int hand[5] = { 0 };
int draw_pile[10] = { 0 };
int discard_pile[10] = { 0 };
struct Character {
int HP;
int block;
int weakness;
int vulnerability;
} player, enemy;
int play_attack = 6;
int enemy_attack[10] = { 6,12,0,16,0,6,12,24,48,114514 };
void initialize_draw_pile() {
for (int i = 0; i < 10; i++) {
draw_pile[i] = deck[i];
}
}
void draw_card(int num_cards) {
for (int i = 0; i < num_cards; i++) {
int index = rand() % 10;
while (draw_pile[index] == 0) {
index = rand() % 10;
}
hand[i] = draw_pile[index];
draw_pile[index] = 0;
}
}
void Attack_module() {
if (player.weakness > 0) play_attack *= 0.75;
if (enemy.vulnerability > 0) play_attack *= 1.5;
if (play_attack > enemy.block)
enemy.HP -= (play_attack - enemy.block);
else
enemy.block -= play_attack;
}
void play_card(int cardIndex) {
if (hand[cardIndex] == 1) {
Attack_module();
}
else if (hand[cardIndex] == 2) {
player.block += 5;
}
else if (hand[cardIndex] == 3) {
enemy.weakness += 2;
}
else if (hand[cardIndex] == 4) {
enemy.vulnerability += 2;
}
for (int j = 0; j < 10; j++) {
if (discard_pile[j] == 0) {
discard_pile[j] = hand[cardIndex];
break;
}
}
hand[cardIndex] = 0;
// 判断boss的血量是否小于等于0
if (enemy.HP <= 0) {
printf("you win\n");
exit(0);// 终止程序
}
// 重新打印玩家手牌和状态
printf("玩家状态:HP=%d, block=%d, weakness=%d, vulnerability=%d\n", player.HP, player.block, player.weakness, player.vulnerability);
printf("Boss状态:HP=%d, block=%d, weakness=%d, vulnerability=%d\n", enemy.HP, enemy.block, enemy.weakness, enemy.vulnerability);
printf("玩家手牌:");
for (int i = 0; i < 5; i++) {
printf("%d ", hand[i]);
}
printf("\n");
}
void Injury_module(int num_round) {
if (enemy.weakness > 0) enemy_attack[num_round] *= 0.75;
if (player.vulnerability > 0) enemy_attack[num_round] *= 1.5;
if (enemy_attack[num_round] > player.block)
player.HP -= (enemy_attack[num_round] - player.block);
else
player.block -= enemy_attack[num_round];
}
void player_end_turn() {
for (int i = 0; i < 5; i++) {
if (hand[i] != 0) {
for (int j = 0; j < 10; j++) {
if (discard_pile[j] == 0) {
discard_pile[j] = hand[i];
break;
}
}
}
}
for (int i = 0; i < 5; i++) {
hand[i] = 0;
}
}
void enemy_end_turn() {
player.block = 0;
if (player.weakness > 0) {
player.weakness--;
}
if (player.vulnerability > 0) {
player.vulnerability--;
}
if (player.weakness < 0) {
player.weakness = 0;
}
if (player.vulnerability < 0) {
player.vulnerability = 0;
}
enemy.block = 0;
if (enemy.weakness > 0) {
enemy.weakness--;
}
if (enemy.vulnerability > 0) {
enemy.vulnerability--;
}
if (enemy.weakness < 0) {
enemy.weakness = 0;
}
if (enemy.vulnerability < 0) {
enemy.vulnerability = 0;
}
play_attack = 6;
}
void shuffle(int round) {
if (round % 2 == 0) {
for (int i = 0; i < 10; i++) {
draw_pile[i] = discard_pile[i];
discard_pile[i] = 0;
}
}
}
void Output_the_player_hand() {
printf("玩家手牌:");
for (int i = 0; i < 5; i++) {
printf("%d ", hand[i]);
}
printf("\n");
}
void player_turn() {
draw_card(5);
Output_the_player_hand();
for (int i = 0; i < 3; i++) {
int x;
scanf("%d", &x);
x = x - 1;
play_card(x);
}
player_end_turn();
}
void boss_turn(int round) {
int num_round = round - 1;
int attack_damage = enemy_attack[num_round];
Injury_module(num_round);
if (round == 3) player.weakness += 2;
if (round == 5) player.vulnerability += 2;
}
void Show_boss_action(int round)
{
if (round == 1)
printf("boss将在您的回合结束后对您造成6点伤害\n");
if (round == 2)
printf("boss将在您的回合结束后对您造成12点伤害\n");
if (round == 3)
printf("boss将在您的回合结束后对您造成0点伤害并施加两层虚弱\n");
if (round == 4)
printf("boss将在您的回合结束后对您造成16点伤害\n");
if (round == 5)
printf("boss将在您的回合结束后对您造成0点伤害并施加两层易伤\n");
if (round == 6)
printf("boss将在您的回合结束后对您造成6点伤害\n");
if (round == 7)
printf("boss将在您的回合结束后对您造成12点伤害\n");
if (round == 8)
printf("boss将在您的回合结束后对您造成24点伤害\n");
if (round == 9)
printf("boss将在您的回合结束后对您造成48点伤害\n");
if (round == 10)
printf("boss将在您的回合结束后对您造成114514点伤害\n");
}
int main() {
srand(time(0));
player.HP = 60;
player.block = 0;
player.weakness = 0;
player.vulnerability = 0;
enemy.HP = 100;
enemy.block = 0;
enemy.weakness = 0;
enemy.vulnerability = 0;
printf("0表示此编号的手牌为空 \n");
printf("1表示此编号的手牌为面板为6的攻击牌\n");
printf("2表示此编号的手牌为面板为5点格挡牌\n");
printf("3表示此编号的手牌为状态牌,对敌人施加2层虚弱(虚弱状态下敌人的攻击为原来的3 / 4)\n");
printf("4表示此编号的手牌为状态牌,对敌人施加2层易伤(易伤状态下敌人受到的攻击为原来的1.5倍)\n");
printf("玩家状态:HP=%d, block=%d, weakness=%d, vulnerability=%d\n", player.HP, player.block, player.weakness, player.vulnerability);
printf("Boss状态:HP=%d, block=%d, weakness=%d, vulnerability=%d\n", enemy.HP, enemy.block, enemy.weakness, enemy.vulnerability);
int round = 1;
initialize_draw_pile();
for (round; round < 11; round++) {
Show_boss_action(round);
player_turn();
shuffle(round);
boss_turn(round);
if (player.HP <= 0) {
printf("you lose\n");
exit(0); // 终止程序
}
enemy_end_turn();
printf("玩家状态:HP=%d, block=%d, weakness=%d, vulnerability=%d\n", player.HP, player.block, player.weakness, player.vulnerability);
printf("Boss状态:HP=%d, block=%d, weakness=%d, vulnerability=%d\n", enemy.HP, enemy.block, enemy.weakness, enemy.vulnerability);
}
return 0;
}
标签:enemy,int,vulnerability,C语言,player,简易版,尖塔,printf,round
From: https://blog.csdn.net/2401_82830057/article/details/137418426