#pragma once
#define _CRT_SECURE_NO_WARNINGS 1
#include
#include
#include
#include
#include
#include
#pragma comment(lib,"Winmm.lib")
#define NUM_PEO 6
#define ROW 20
#define COL 100
typedef struct character
{
char name[20];
int attack;
int defense;
int life;
}chara;
void game();
void map1();
void move(int x, int y, char m[ROW][COL]);
void story();
void buy(chara peo[],int choice, int shop_gold[20][4]);
void Init_shop(int shop_gold[20][4]);
void rule();
void tmenu();
void menu();
void line();
void menu1();
void menu2();
void menu3();
int battle(int num);
void shop();
void peoatt(chara peo[], int choice);
void Init(chara peo[]);
int judge(char m[ROW][COL], int now_x, int ori_x, int now_y,
int ori_y);
void judge_(char m[ROW][COL], int now_x, int ori_x, int now_y,
int ori_y);
void Display(char m[ROW][COL]);
void judge_K(char m[ROW][COL], int now_x, int ori_x, int now_y,
int ori_y);
void exchange(char m[ROW][COL], int now_x, int ori_x, int now_y,
int ori_y);
void judge_$(char m[ROW][COL], int now_x, int ori_x, int now_y,
int ori_y);
void judge_apple(char m[ROW][COL], int now_x, int ori_x, int now_y,
int ori_y);
int judge_door(char m[ROW][COL], int now_x, int ori_x, int now_y,
int ori_y);
int judge_monster(char m[ROW][COL], int now_x, int ori_x, int now_y,
int ori_y);
int judge_jin(char m[ROW][COL], int now_x, int ori_x, int now_y,
int ori_y);
void judge_shop(char m[ROW][COL], int now_x, int ori_x, int now_y,
int ori_y);
#include "game.h"
int x = 1;
int y = 1;
int K = 0;
int gold = 5;
chara peo[NUM_PEO];
int choice = 0;
//商店物品的价格,攻击,生命,防御
int shop_gold[20][4] = { 0 };
int monster[5][4] = { {1,1,0,1},
{5, 3,1, 5},
{15,7,3,14},
{31,15,7,29},
{0,31,15,60} };
int main()
{
story();
//PlaySound(TEXT("D:\\Desktop\\110期\\test\\Test_6_12\\Test_6_12\\苏星婕 - 听悲伤的情歌.wav"), NULL, SND_FILENAME | SND_ASYNC); // 这里是你文件的路径
PlaySound(TEXT("D:\\Desktop\\110期\\test\\Test_6_12\\Test_6_12\\
庄东茹 - 时间更改.wav"), NULL, SND_FILENAME | SND_ASYNC);
// 这里是你文件的路径
//PlaySound(TEXT("D:\\Desktop\\110期\\test\\Test_6_12\\Test_6_12\\苏星婕 - 听悲伤的情歌.wav"), NULL, SND_FILENAME | SND_ASYNC); // 这里是你文件的路径
system("pause");
srand((unsigned int)time(NULL));
int N = 0;
rule();
tmenu();
menu();
Init(peo);
printf("请选择初始人物: (1 2 3)\n");
scanf("%d", &choice);
choice -= 1;
system("cls");
Init_shop(shop_gold);
while (1)
{
Sleep(1000);
rule();
tmenu();
printf("#你要做什么?\n");
scanf("%d", &N);
switch (N)
{
case 1:
shop();
buy(peo, choice, shop_gold);
break;
case 2:
peoatt(peo,choice);
break;
case 3:
game();
case 0:
exit(-1);
break;
default:
printf("骚年,按错喽,公主不是这么救的\n");
}
}
menu();
return 0;
}
#include "game.h"
void story()
{
char story[] = "三百年前,有一位漂亮可爱的公主在中北大陆生活着,
可是突然有一天,一头猥琐的魔龙XXX来到这片大陆
掳走了公主,而你正是这位公主的倾慕者,你决心要打
败魔龙,救回公主..................";
int len = strlen(story);
for (int i = 0; i < len; i++)
{
printf("%c", story[i]);
if ((i + 1) % 30 == 0)
{
printf("\n");
}
Sleep(90);
}
printf("\n");
Sleep(1000);
}
void rule()
{
printf(" szl制作\n");
line();
printf("你需要通过 w a s d 四个键来控制人物O的走动\n");
printf("K:钥匙 *:属性果实 >: 通往下层的楼梯 —: 锁着的门\n");
printf("$:金币 <:回到上层 &:商人\n");
printf("A: 小怪兽 (攻: 1 防: 0 命: 1)
B: 中怪兽(攻: 3 防: 1 命: 5)\n");
printf("C: 大怪兽 (攻: 7 防: 3 命: 14)
D: 巨兽 (攻: 15 防: 7 命: 29)\n");
printf("X: BOSS魔龙(攻: 31 防: 15 命: 60)\n");
printf("击杀可得金币: 1 5 15 31\n");
line();
printf("\n");
}
void tmenu()
{
printf("************************************************\n");
printf("****** 1. 进入商店 2.查看人物 ******\n");
printf("****** 3. 进入魔窟 0.退出游戏 ******\n");
printf("************************************************\n");
}
void menu()
{
printf("请选择初始人物:\n");
menu1();
menu2();
menu3();
}
void menu1()
{
line();
printf("马保国\n");
printf("攻: 1 防: 1 命: 6\n");
line();
}
void menu2()
{
line();
printf("蔡徐坤\n");
printf("攻: 2 防: 2 命: 3\n");
line();
}
void menu3()
{
line();
printf("YOU\n");
printf("攻: 1 防: 3 命: 3\n");
line();
}
void line()
{
printf("------------------------------------------------
---------------------\n");
}
void shop()
{
line();
printf("地精@@: 你想要点什么?\n");
printf("********************************************************
**********************************\n");
printf("\n");
printf("加攻击\n");
printf("1. 铁拳套 +1 价格:1金币
2. 银拳套 +3 价格:4金币\n");
printf("3. 金拳套 +7 价格:10金币
4. 究极拳 +20 价格:30金币\n");
printf("\n");
printf("加生命和防御\n");
printf("5. 麻衣 +1 +0 价格:1金币
6. 布衣 +3 +1 价格:4金币\n");
printf("7. 精致的羽绒服 +6 +2 价格:10金币
8. 武道服 +14 +4 价格:30金币\n");
printf("9. 圣衣 +30 +10 价格:50金币\n");
printf("\n");
printf("*****************************************************
**************************************\n");
line();
printf("\n");
}
void Init_shop(int shop_gold[20][4])
{
for (int i = 0; i < 8; i+=4)
{
shop_gold[i][0] = 1;
shop_gold[i + 1][0] = 4;
shop_gold[i + 2][0] = 10;
shop_gold[i + 3][0] = 30;
}
shop_gold[8][0] = 50;
//攻击
shop_gold[0][1] = 1;
shop_gold[1][1] = 3;
shop_gold[2][1] = 7;
shop_gold[3][1] = 20;
//生命
shop_gold[4][2] = 1;
shop_gold[5][2] = 3;
shop_gold[6][2] = 6;
shop_gold[7][2] = 14;
shop_gold[8][2] = 30;
//防御
shop_gold[5][3] = 1;
shop_gold[6][3] = 2;
shop_gold[7][3] = 4;
shop_gold[8][3] = 10;
}
void buy(chara peo[], int choice, int shop_gold[20][4])
{
extern int gold;
printf("当前金币数量: %d\n", gold);
printf("你需要点什么?(输入对应数字)\n");
int name = 0;
scanf("%d", &name);
if (gold >= shop_gold[name - 1][0])
{
gold -= shop_gold[name - 1][0];
peo[choice].attack += shop_gold[name - 1][1];
peo[choice].defense += shop_gold[name - 1][3];
peo[choice].life += shop_gold[name - 1][2];
shop_gold[name - 1][1] = 0;
shop_gold[name - 1][2] = 0;
shop_gold[name - 1][3] = 0;
}
else
{
printf("金币不足还想买,想屁吃?\n");
}
printf("当前金币数量: %d\n", gold);
}
void peoatt(chara peo[], int choice)//人物属性
{
printf("%s\n", peo[choice].name);
printf("攻击: %d\n", peo[choice].attack);
printf("防御: %d\n", peo[choice].defense);
printf("生命: %d\n", peo[choice].life);
}
void Init(chara peo[])//初始化
{
strcpy(peo[0].name, "马保国");
peo[0].attack = 1;
peo[0].defense = 1;
peo[0].life = 6;
strcpy(peo[1].name, "蔡徐坤");
peo[1].attack = 2;
peo[1].defense = 2;
peo[1].life = 3;
strcpy(peo[2].name, "YOU");
peo[2].attack = 1;
peo[2].defense = 3;
peo[2].life = 3;
}
void game()
{
PlaySound(TEXT("D:\\Desktop\\110期\\test\\Test_6_12
\\Test_6_12\\苏星婕 - 听悲伤的情歌.wav"), NULL, SND_FILENAME | SND_ASYNC);
//PlaySound(TEXT("D:\\Desktop\\110期\\test\\Test_6_12\\Test_6_12\\庄东茹 - 时间更改.wav"), NULL, SND_FILENAME | SND_ASYNC); // 这里是你文件的路径
map1();
}
void map1()
{
char m[ROW][COL] =
{
"#########################################################",
"#OA# * B #",
"# K######## #",
"# # #",
"#AA#A######A #",
"# $#-#K #",
"# # * #",
"# B#-# ################################################",
"#CK#$#---#################################################",
"#### # BBB###############################################",
"#& # # BKB###############################################",
"# # # BBB###A #########################################",
"# C# #-###### ######################################",
"# # ## B ############################################",
"###### ## ############################################",
"#*C $# ##################################################",
"#### ##################################################",
"#########################################################"
};
extern int x;
extern int y;
move(x, y, m);
}
void move(int x, int y, char m[ROW][COL])
{
while (1)
{
system("cls");
printf("\n");
printf("\n");
printf("\n");
Display(m);
char ch = _getch();
if (ch == 'w' && ch != '#')
{
int a = judge(m, x - 1, x, y, y);
if (a == 1)
{
x--;
}
}
else if(ch == 's' && ch!= '#')
{
int a = judge(m, x + 1, x, y, y);
if (a == 1)
{
x++;
}
}
else if(ch == 'a' && ch != '#')
{
int a = judge(m, x, x, y - 1, y);
if (a == 1)
{
y--;
}
}
else if (ch == 'd' && ch != '#')
{
int a = judge(m, x, x, y + 1, y);
if (a == 1)
{
y++;
}
}
else
{
printf("看清路再走!\n");
Sleep(1500);
}
}
}
void Display(char m[ROW][COL])
{
for (int i = 0; i < ROW; i++)
{
printf("%s\n", m[i]);
}
}
int judge(char m[ROW][COL], int now_x, int ori_x, int now_y, int ori_y)
{
int a = judge_jin(m, now_x, ori_x, now_y, ori_y);
judge_(m, now_x, ori_x, now_y, ori_y);
judge_K(m, now_x, ori_x, now_y, ori_y);
judge_$(m, now_x, ori_x, now_y, ori_y);
judge_apple(m, now_x, ori_x, now_y, ori_y);
int g = judge_door(m, now_x, ori_x, now_y, ori_y);
int h = judge_monster(m, now_x, ori_x, now_y, ori_y);
judge_shop(m, now_x, ori_x, now_y, ori_y);
return (a && g && h);
}
void judge_shop(char m[ROW][COL], int now_x, int ori_x, int now_y, int ori_y)
{
extern chara peo[NUM_PEO];
extern int choice;
extern int shop_gold[20][4];
if (m[now_x][now_y] == '&')
{
shop();
buy(peo, choice, shop_gold);
peoatt(peo, choice);
Sleep(2000);
}
}
int judge_jin(char m[ROW][COL], int now_x, int ori_x, int now_y, int ori_y)
{
if (m[now_x][now_y] == '#')
{
printf("撞墙了!(#`O′)\n");
Sleep(1500);
return 0;
}
}
int judge_monster(char m[ROW][COL], int now_x, int ori_x, int now_y, int ori_y)
{
extern int monster[5][4];
extern int gold;
if (m[now_x][now_y] >= 'A' && m[now_x][now_y] <= 'D')
{
int num = 0;
num = m[now_x][now_y] - 'A';
int ret = battle(num);
if (ret == 1)
{
printf("%c死了...\n", 'A' + num);
printf("战斗胜利!\n");
printf("获得金币:%d\n", monster[num][0]);
Sleep(500);
gold += monster[num][0];
printf("当前金币:%d\n",gold);
Sleep(2000);
m[now_x][now_y] = ' ';
exchange(m, now_x, ori_x, now_y, ori_y);
return 1;
}
else
{
printf("战斗失败!\n");
Sleep(1500);
return 0;
}
}
return 1;
}
int battle(int num)
{
extern int choice;
extern int monster[5][4];
extern chara peo[NUM_PEO];
int ori_PH = peo[choice].life;
int mon_PH = monster[num][3];
int flag = 0;
printf("战斗开始!\n");
printf("进行综合素质比对ing......\n");
if ((peo[choice].attack + peo[choice].defense + ori_PH) > (monster[num][1] + monster[num][2] + mon_PH))
{
flag = 1;
printf("--->\n");
printf("你的三值素质更高,你先出手!\n");
}
else
{
flag = 0;
printf("--->\n");
printf("怪物的的三值素质更高,它先出手!\n");
}
int count = 0;
while (ori_PH > 0 && mon_PH > 0 && count <= 20)
{
count++;
if (flag == 1)
{
if (peo[choice].attack - monster[num][2] < 0)
{
printf("%s对%c造成%d伤害!\n", peo[choice].name,
num + 'A', 0);
}
else
{
printf("%s对%c造成%d伤害!\n", peo[choice].name, num + 'A', peo[choice].attack - monster[num][2]);
mon_PH -= peo[choice].attack - monster[num][2];
}
if (mon_PH > 0)
{
if (monster[num][1] - peo[choice].defense < 0)
{
printf("%c对%s造成%d伤害!\n", num + 'A',
peo[choice].name, 0);
}
else
{
printf("%c对%s造成%d伤害!\n", num + 'A', peo[choice].name, monster[num][1] - peo[choice].defense);
ori_PH -= monster[num][1] - peo[choice].defense;
}
}
}
else
{
if (monster[num][1] - peo[choice].defense < 0)
{
printf("%c对%s造成%d伤害!\n", num + 'A', peo[choice].name, 0);
}
else
{
printf("%c对%s造成%d伤害!\n", num + 'A', peo[choice].name,
monster[num][1] - peo[choice].defense);
ori_PH -= monster[num][1] - peo[choice].defense;
}
if (peo[choice].life > 0)
{
if (peo[choice].attack - monster[num][2] < 0)
{
printf("%s对%c造成%d伤害!\n", peo[choice].name,
num + 'A', 0);
}
else
{
printf("%s对%c造成%d伤害!\n", peo[choice].name, num + 'A', peo[choice].attack - monster[num][2]);
mon_PH -= peo[choice].attack - monster[num][2];
}
}
}
}
if (count >= 20)
{
printf("你无法打败怪兽!\n");
return 0;
}
if (ori_PH < 0)
{
return 0;
}
else
{
return 1;
}
}
//char m[8][15], int x, int now_y, int ori_y
void judge_(char m[ROW][COL], int now_x, int ori_x, int now_y, int ori_y)
{
if (m[now_x][now_y] == ' ')
{
exchange(m, now_x, ori_x, now_y, ori_y);
}
}
int judge_door(char m[ROW][COL], int now_x, int ori_x, int now_y, int ori_y)
{
extern int K;
if (m[now_x][now_y] == '-' && K > 0)
{
m[now_x][now_y] = ' ';
exchange(m, now_x, ori_x, now_y, ori_y);
K--;
return 1;
}
else if(m[now_x][now_y] == '-' && K == 0)
{
printf("莫得钥匙,找找钥匙再开门吧!\n");
Sleep(1500);
return 0;
}
else
{
return 1;
}
}
void judge_K(char m[ROW][COL], int now_x, int ori_x, int now_y, int ori_y)
{
extern int K;
if (m[now_x][now_y] == 'K')
{
m[now_x][now_y] = ' ';
exchange(m, now_x, ori_x, now_y, ori_y);
K++;
}
}
void judge_$(char m[ROW][COL], int now_x, int ori_x, int now_y, int ori_y)
{
extern int gold;
if (m[now_x][now_y] == '$')
{
m[now_x][now_y] = ' ';
exchange(m, now_x, ori_x, now_y, ori_y);
gold += rand() % 6 + 1;
printf("当前金币:%d\n", gold);
Sleep(500);
}
}
void judge_apple(char m[ROW][COL], int now_x, int ori_x, int now_y, int ori_y)
{
extern int choice;
extern chara peo[NUM_PEO];
if (m[now_x][now_y] == '*')
{
m[now_x][now_y] = ' ';
exchange(m, now_x, ori_x, now_y, ori_y);
peo[choice].attack += rand() % 3 + 1;
peo[choice].defense += rand() % 3 + 1;
peo[choice].life += rand() % 3 + 1;
printf("当前攻击:%d\n", peo[choice].attack);
printf("当前防御:%d\n", peo[choice].defense);
printf("当前生命:%d\n", peo[choice].life);
Sleep(2500);
}
}
void exchange(char m[ROW][COL], int now_x, int ori_x, int now_y, int ori_y)
{
if (now_x == ori_x)
{
char temp = m[now_x][ori_y];
m[now_x][ori_y] = m[now_x][now_y];
m[now_x][now_y] = temp;
}
if (now_y == ori_y)
{
char temp = m[ori_x][now_y];
m[ori_x][now_y] = m[now_x][now_y];
m[now_x][now_y] = temp;
}
}
地图大家可以自己根据自己的想法进行改变,或者说商店和属性不满意都可以改哦~