校友细
2025-12-07 21:11:31
发布于:浙江
/*
* 卡牌对决游戏 - 完整版
* 开发时间:2025年12月7日20:55
* 运行环境:Windows + MinGW/GCC
* 包含系统:角色系统/卡牌系统/战斗系统/存档系统
*/
#include<bits/stdc++.h>
#include<windows.h> // 用于Sleep函数和控制台操作
#include<conio.h> // 用于键盘输入检测
using namespace std;
// ================== 全局常量定义 ==================
const int MAX_CARDS = 1000; // 最大持牌量
const string RANK_NAMES[] = {"青铜", "白银", "黄金", "铂金", "钻石"};
// ================== 游戏状态变量 ==================
int sp[MAX_CARDS], ge = 0, zd = 0; // 卡牌数组及指针(sp:牌堆, ge:牌数, zd:当前选中牌)
int famax = 1, fa = 1; // 法力系统(famax:上限, fa:当前法力)
int shengmax = 30, sheng = 30; // 生命系统
int dishengmax = 5, disheng = 5; // 敌人属性
int feng = 0, rankLevel = 1, winStreak = 0; // 排位数据(积分/段位/连胜)
// ================== 角色系统 ==================
struct Role {
string name; // 角色名称
string skillDesc; // 技能描述
int baseHP; // 基础生命值
int baseMana; // 基础法力上限
int skillType; // 技能类型(1:被动 2:主动)
};
Role roles[] = {
{"战士", "【被动】敌方伤害-1", 35, 1, 1},
{"法师", "【被动】初始法力+1", 25, 2, 1},
{"游侠", "【主动】首攻伤害+1", 30, 1, 2}
};
int currentRole = 0; // 当前选择角色
bool firstAttack = true;// 游侠技能标记
// ================== 卡牌系统 ==================
string getCardDescription(int index) {
if (index < 0 || index >= ge) return "无卡牌";
switch (sp[index]) {
case 1:
return "『普攻』(耗1法伤1)";
case 2:
return "『重击』(耗1法伤2自伤1)";
case 3:
return "『治疗』(耗2法回1血)";
case 4:
return "『冥想』(耗0法得1法)";
case 5:
return "『狗狗我爱死你了』(耗5法抽3牌伤1)";
case 6:
return "『暗影步』(耗2法回收1牌)";
case 7:
return "『战术撤退』(耗1法弃2抽1)";
default:
return "未知卡牌";
}
}
void acquireCard(int randVal) {
if (randVal >= 0 && randVal < 40) sp[ge++] = 1; // 40% 普攻
else if (randVal >= 40 && randVal < 70) sp[ge++] = 2; // 30% 重击
else if (randVal >= 70 && randVal < 85) sp[ge++] = 3; // 15% 治疗
else if (randVal >= 85 && randVal < 95) sp[ge++] = 4; // 10% 冥想
else if (randVal >= 95 && randVal < 98) sp[ge++] = 5; // 3% 狗狗卡
else if (randVal >= 98) sp[ge++] = 6; // 2% 暗影步
cout << "获得:" << getCardDescription(ge - 1) << endl;
}
// ================== 战斗系统 ==================
void enemyAction() {
if (rand() % 100 < 30 + rankLevel * 5) { // 基础30% + 段位加成
int damage = 1 + (rankLevel - 1) / 2;
if (currentRole == 0) damage = max(0, damage - 1); // 战士减伤
sheng -= damage;
cout << "敌人造成" << damage << "点伤害!";
if (rand() % 100 < 15) { // 15%暴击率
sheng -= 1;
cout << "【暴击】额外-1HP!";
}
cout << endl;
Sleep(800);
}
}
// ================== 存档系统 ==================
void saveProgress() {
ofstream saveFile("game.sav", ios::binary);
if (saveFile) {
saveFile.write((char*)¤tRole, sizeof(currentRole));
saveFile.write((char*)&rankLevel, sizeof(rankLevel));
saveFile.write((char*)&feng, sizeof(feng));
saveFile.write((char*)&winStreak, sizeof(winStreak));
cout << "进度已保存!" << endl;
} else {
cout << "存档失败!" << endl;
}
Sleep(1000);
}
void loadProgress() {
ifstream loadFile("game.sav", ios::binary);
if (loadFile) {
loadFile.read((char*)¤tRole, sizeof(currentRole));
loadFile.read((char*)&rankLevel, sizeof(rankLevel));
loadFile.read((char*)&feng, sizeof(feng));
loadFile.read((char*)&winStreak, sizeof(winStreak));
cout << "存档加载成功!当前段位:" << RANK_NAMES[rankLevel - 1] << endl;
} else {
cout << "未找到存档文件!" << endl;
}
Sleep(1000);
}
// ================== 新手教程 ==================
void runTutorial() {
system("cls");
cout << "★ 新手教程 ★ 北京时间2025-12-07 20:55 ★\n";
cout << "══════════════════════════════════════\n";
cout << "当前角色:" << roles[currentRole].name << endl;
cout << "技能效果:" << roles[currentRole].skillDesc << "\n\n";
// 初始化卡牌
sp[ge++] = 1; // 普攻
sp[ge++] = 3; // 治疗
sp[ge++] = 5; // 狗狗卡
cout << "初始卡牌组:" << endl;
for (int i = 0; i < 3; i++) {
cout << " [" << i + 1 << "] " << getCardDescription(i) << endl;
}
cout << "\n提示:按A/D切换卡牌,Q使用,W结束回合" << endl;
Sleep(3000);
// 简化战斗
disheng = 3;
while (disheng > 0 && sheng > 0) {
system("cls");
cout << "════════════ 战斗状态 ════════════\n";
cout << " 生命值:" << sheng << "/" << shengmax << endl;
cout << " 法力值:" << fa << "/" << famax << endl;
cout << " 敌人HP:" << disheng << "/3\n";
cout << "══════════════════════════════════════\n";
cout << "当前选择:" << getCardDescription(zd) << "\n\n";
if (_kbhit()) {
char input = toupper(_getch());
switch (input) {
case 'A':
zd = (zd + 2) % 3;
break; // 三张牌循环
case 'D':
zd = (zd + 1) % 3;
break;
case 'Q': // 使用卡牌
if (sp[zd] == 5 && fa >= 5) { // 狗狗卡
fa -= 5;
disheng--;
cout << "?? 效果发动!抽3张牌\n";
for (int i = 0; i < 3; i++) acquireCard(rand() % 100);
} else if (sp[zd] == 1 && fa >= 1) { // 普攻
fa -= 1;
disheng--;
} else if (sp[zd] == 3 && fa >= 2) { // 治疗
fa -= 2;
sheng = min(sheng + 1, shengmax);
}
break;
case 'W': // 结束回合
enemyAction();
fa = min(famax, fa + 2); // 每回合回2法
break;
}
}
Sleep(200);
}
cout << (disheng <= 0 ? "★ 教学完成 ★" : "※ 教学失败 ※") << endl;
cout << "按任意键返回主菜单...";
_getch();
}
// ================== 排位赛模式 ==================
void startRankMatch() {
// 初始化角色属性
shengmax = roles[currentRole].baseHP;
famax = roles[currentRole].baseMana;
if (currentRole == 1) famax++; // 法师被动加成
while (true) {
system("cls");
// 初始化战斗参数
dishengmax = 5 + rankLevel * 3;
disheng = dishengmax;
sheng = shengmax;
fa = famax;
ge = zd = 0;
firstAttack = true;
// 初始抽牌
cout << "══════ " << RANK_NAMES[rankLevel - 1] << rankLevel << "段 ══════\n";
for (int i = 0; i < 3; i++) {
acquireCard(rand() % 100);
Sleep(500);
}
// 战斗循环
while (disheng > 0 && sheng > 0) {
system("cls");
cout << "════════════ 战斗状态 ════════════\n";
cout << " 角色:" << roles[currentRole].name << " 技能:" << roles[currentRole].skillDesc << endl;
cout << " 生命:" << sheng << "/" << shengmax << " 法力:" << fa << "/" << famax << endl;
cout << " 敌方:" << disheng << "/" << dishengmax << " 积分:" << feng << endl;
cout << "══════════════════════════════════════\n";
cout << " 当前卡牌 (" << zd + 1 << "/" << ge << "): " << getCardDescription(zd) << "\n\n";
cout << "操作指令:\n [A]左移 [D]右移 [Q]使用 [W]结束 [S]存档\n";
if (_kbhit()) {
char input = toupper(_getch());
switch (input) {
case 'A':
zd = max(0, zd - 1);
break;
case 'D':
zd = min(ge - 1, zd + 1);
break;
case 'Q': // 使用卡牌
if (zd >= 0 && zd < ge) {
int extraDmg = (currentRole == 2 && firstAttack && sp[zd] == 1) ? 1 : 0;
switch (sp[zd]) {
case 1: // 普攻
if (fa >= 1) {
fa -= 1;
disheng -= (1 + extraDmg);
if (extraDmg) cout << "游侠技能触发!\n";
}
break;
case 5: // 狗狗卡
if (fa >= 5) {
fa -= 5;
disheng -= 1;
cout << "?? 狗狗发动效果!\n";
for (int i = 0; i < 3; i++) acquireCard(rand() % 100);
}
break;
case 2:
if (fa >= 1) {
fa--;
disheng -= 2;
sheng -= 2;
}
break;
case 3:
if (fa >= 2) {
fa -= 2;
sheng = min(shengmax, sheng + 1);
cout << "你回复了1点血";
}break;
case 4:
fa++;
break;
case 6:
if (fa >= 2) {
fa -= 2;
acquireCard(rand() % 100);
}break;
}
// 移除已使用卡牌
for (int i = zd; i < ge - 1; i++) sp[i] = sp[i + 1];
ge--;
zd = max(0, zd - 1);
}
break;
case 'W': // 结束回合
for (int i = 0; i < max(1, famax / 2); i++) enemyAction();
if(famax<10){
famax++;
}
fa = famax; // 回满法力
for (int i = 0; i < 2; i++) acquireCard(rand() % 100); // 抽牌
break;
case 'S':
saveProgress();
break;
}
}
Sleep(200);
}
// 结算界面
system("cls");
if (disheng <= 0) { // 胜利
winStreak++;
feng += 10 + winStreak * 2;
if (feng >= rankLevel * 100 && rankLevel < 5) rankLevel++;
cout << "★ 胜利! ★\n积分+" << (10 + winStreak * 2) << endl;
} else { // 失败
winStreak = 0;
feng = max(0, feng - 5);
cout << "※ 失败! ※\n积分-5" << endl;
}
cout << "按[R]继续 [Q]返回\n";
while (!_kbhit() || toupper(_getch()) != 'R');
}
}
// ================== 主菜单 ==================
void showMainMenu() {
system("cls");
cout << "════════ 卡牌对决 ════════\n";
cout << " 2025年12月7日 20:55\n";
cout << "══════════════════════════\n";
cout << " 1. 新手教程\n";
cout << " 2. 排位赛\n";
cout << " 3. 继续游戏\n";
cout << " 4. 退出游戏\n";
cout << "══════════════════════════\n";
cout << "当前版本:v2.1.1207\n";
}
// ================== 主函数 ==================
int main() {
srand(time(0)); // 初始化随机种子
while (true) {
showMainMenu();
char choice = _getch();
switch (choice) {
case '1': // 新手教程
runTutorial();
break;
case '2': // 排位赛
system("cls");
cout << "══════ 选择角色 ══════\n";
for (int i = 0; i < 3; i++) {
cout << " " << i + 1 << ". " << roles[i].name << " - "
<< roles[i].skillDesc << "\n";
}
currentRole = _getch() - '1';
currentRole = max(0, min(2, currentRole));
startRankMatch();
break;
case '3': // 继续游戏
loadProgress();
startRankMatch();
break;
case '4': // 退出
return 0;
default:
cout << "无效输入!";
Sleep(500);
}
}
}
这里空空如也












有帮助,赞一个