首页 > 其他分享 >C语言简易版杀戮尖塔

C语言简易版杀戮尖塔

时间:2024-04-06 09:00:10浏览次数:22  
标签:enemy int vulnerability C语言 player 简易版 尖塔 printf round

此代码仅包含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

相关文章

  • 【c语言】自定义类型:联合体(公用体)【详解】
    联合体联合体类型的声明像结构体⼀样,联合体也是由⼀个或者多个成员构成,这些成员可以不同的类型。但是编译器只为最⼤的成员分配⾜够的内存空间。联合体的特点是所有成员共⽤同⼀块内存空间。所以联合体也叫:共用体。给联合体其中⼀个成员赋值,其他成员的值也跟着变化。......
  • c语言之多重指针
    多重指针是定义了一个指针a后,又定义一个指针b引用指针a的地址,就叫多重指针多重指针定义的方法:类型名**指针名#include<stdio.h>intmain(){ inta; a=3; int*p=&a; int**y=&p; printf("%d\n",a); printf("%d\n",*p); printf("%d\n",**y); return0;}上面代码......
  • c语言之指针数组
    在c语言中,一个数组元素是由指针组成的,就叫指针数组。指针数组的定义方法类型名*数组名[数组长度]如果要处理多个字符串,用指针数组会方便多。举个例子,代码如下#include<stdio.h>intmain(){ inti; char*s[]={"cprogram","control","logic"}; for(i=0;i<3;i++) ......
  • 【C语言学习】之字符数组与字符串处理函数
    1.字符数组1.字符数组的初始化1.单字符形式chara[3]={'a','b','c'}                定义一个字符型一维数组,数组名a,三个下表变量a,b,ccharb[][3]={'a','b','c','d','e','f','g'}  ......
  • 【C语言学习】之一维数组
    1.相同类型的变量可以构成数组,数组一次可以定义多个相同类型的变量既然是变量,肯定有定义和引用:1.一维数组的定义1.定义格式:数据类型数组名[整型常量]例如:inta[4],                    //定义了一个数组a包含4个整形变量括号里......
  • 【C语言学习】之变量的作用域和作用类别
    1.局部变量(在函数内部(1.函数体开头定义的变量2.复合语句内定义的变量3.函数的形参)定义的变量,只能在函数内部使用。如果和全局变量同名则优先引用)2.全局变量(不在任何函数内部定义的变量都是全局变量,作用于定义它的地方开始到源文件的结束)全局变量的拓展:1.externc:可以把全局......
  • 【C语言系列】-- 数组结构
    数组结构前面介绍的数据类型都是基本数据类型,例如整型、字符型、浮点型等数据,这些都是简单的数据类型。对于有些数据,只有简单的数据类型是不够的,难以反映出数据的特点,也难以有效地进行处理。例如:假设需要接收并存储100个学员的成绩,此时无法使用for循环依次读取每个学员的成绩,因......
  • C语言——调试技巧
    1.Debug和Release的介绍Debug通常称为调试版本,它包含调试信息,并且不作任何优化,便于程序员调试程序。Release称为发布版本,它往往是进行了各种优化,使得程序在代码大小和运行速度上都是最优的,以便用户很好地使用。2.调试快捷键最常使用的几个快捷键:F5启动调试,经常用来直......
  • C语言常见概念(一)
    1.C语言发展史,学习C语言的必要性?2.编译和链接是什么?过程是什么?3.各个编译器我该使用什么?vs的优势?4.main函数究竟是啥?5.关键字有哪些?要背诵吗?6.字符?asc码?字符计算?7.C语言的字符串?字符和字符串有何区别?8.sizeof和strlen?竟然有坑?9.转义字符是什么?平时怎么......
  • 从无到有开始创建动态顺序表——C语言实现
    顺序表的概念    顺序表的底层结构是数组,对数组的封装,实现了常用的增删改查等接口。在物理结构和逻辑结构都是连续的,物理结构是指顺序表在计算机内存的存储方式,逻辑结构是我们思考的形式,顺序表和数组是类似的,都是使用了连续的空间进行数据的保存,由于是连续的空间,所......