- 现在只打了设置这些个东西,游戏主体还没打,那才是难点
已实现功能
游戏
设置
存档
注意事项!!!
- 没错,如你所见,这个游戏我是使用了MCI来播放声音的!
- 因此,你的DEV-C++需要链接到一个库
- 打开 工具->编译选项->编译器->编译时加入以下命令->勾选
- 然后在框里添上下面这个代码
-lwinmm
- 这样就能成功运行了!
- 音频文件来这里领 --> 百度网盘,提取码:abcc,放在和.cpp文件同一个文件夹里就行,网盘文件自带源代码。
- game.h 文件在我之前的一个文章里。(百度网盘也有)传送门 --> <教程> 我的游戏专用头文件 —— game.h
- body.h文件等会会贴上,百度网盘也有(没办法,就这么一个空壳都640行了,所以就分成几个文件来写)
body.h文件(没错,就这一点,等我打完了再放上来吧)
#ifndef thegamebody
#define thegamebody 1
#include "game.h" //这里可以体现出避免重复引用的重要性
#define GO keymode[1]
#define BACK keymode[2]
#define LEFT keymode[3]
#define RIGHT keymode[4]
#define RUN keymode[5]
#define INTURN keymode[6]
#define STOP keymode[7]
#define MAPMODE keymode[8]
#define SKILL_1 keymode[9]
#define SKILL_2 keymode[10]
#define ENTER keymode[11]
#define MAIN_V vol[1]
#define MUSIC_V vol[2]
#define BUTTON_V vol[3]
#define ENEMY_V vol[4]
#define ENVIR_V vol[5]
#define STEP_V vol[6]
void game() {
system("mode con cols=80 lines=35");
return ;
}
#endif
最后的最后,贴上现在的(空壳)代码(2023/2/1)
#include "game.h"
#include "body.h"
int isplayed;
int vol[7] = {0, 1000, 1000, 1000, 1000, 1000, 1000};
int keymode[12] = {0, 87, 83, 65, 68, 160, 69, 27, 76, 90, 67, 13};
char volname[7][100] = {"", "", "backmus", "button", "", "", "step"};
void read() {
FILE *fp = fopen("save", "r");
for (int i = 1; i < 7; i++) {
fscanf(fp, "%d", vol + i);
}
for (int i = 1; i < 12; i++) {
fscanf(fp, "%d", keymode + i);
}
fclose(fp);
return ;
}
void save() {
FILE *fp = fopen("save", "w");
for (int i = 1; i < 7; i++) {
fprintf(fp, "%d ", vol[i]);
}
for (int i = 1; i < 12; i++) {
fprintf(fp, "%d ", keymode[i]);
}
fclose(fp);
return ;
}
void resett() {
save();
return ;
}
void init() {
thread test(KD_check);
test.detach();
CONSOLE_CURSOR_INFO cursor_info = {1, 0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
srand((unsigned)time(NULL));
isplayed = Is_File_Exist("save");
cancelclose();
mciSendString("open BackMusic.mp3 alias backmus", NULL, 0, NULL);
mciSendString("open StepSound.mp3 alias step", NULL, 0, NULL);
mciSendString("open click.mp3 alias button", NULL, 0, NULL);
if (isplayed == 0) {
resett();
} else {
read();
}
set_volume(volname[2], MAIN_V * MUSIC_V / 1000);
set_volume(volname[6], MAIN_V * STEP_V / 1000);
set_volume(volname[3], MAIN_V * BUTTON_V / 1000);
mciSendString("play backmus repeat", NULL, 0, NULL);
return ;
}
void ss_cover() {
color(4), system("cls");
color(4);
gto(2, 21), printf("--------------------");
gto(5, 9), printf("音乐音量"), gto(5, 21), printf("--------------------");
gto(8, 9), printf("按键音量"), gto(8, 21), printf("--------------------");
gto(11, 9), printf("敌人音量"), gto(11, 21), printf("--------------------");
gto(14, 9), printf("环境音量"), gto(14, 21), printf("--------------------");
gto(17, 9), printf("脚步音量"), gto(17, 21), printf("--------------------");
color(228);
gto(2, 7), printf("[ 主音量 ]"), gto(2, (MAIN_V / 50) + 20), printf(" ");
gto(5, (MUSIC_V / 50) + 20), printf(" ");
gto(8, (BUTTON_V / 50) + 20), printf(" ");
gto(11, (ENEMY_V / 50) + 20), printf(" ");
gto(14, (ENVIR_V / 50) + 20), printf(" ");
gto(17, (STEP_V / 50) + 20), printf(" ");
color(4);
gto(19, 2);
printf("按[Esc]退出;按右箭头进入更改;");
gto(20, 15);
printf("按%s完成设置", KEY_NAME(ENTER));
return ;
}
void ssetin(int x) {
gto(x * 3 - 1, (vol[x] / 50) + 20);
color(204);
printf(" ");
int lst = vol[x], lkt3 = 0, lkt4 = 0;
bool flag = 0;
while (1) {
if (lkt3 != KEY_TIME(37) && KEY_DOWN(37)) {
lkt3 = KEY_TIME(37);
if (vol[x] != 0) {
vol[x] -= 50;
}
} else if (lkt4 != KEY_TIME(39) && KEY_DOWN(39)) {
lkt4 = KEY_TIME(39);
if (vol[x] != 1000) {
vol[x] += 50;
}
}
if (vol[x] != lst) {
if (x == 1) {
set_volume(volname[2], MAIN_V * MUSIC_V / 1000);
set_volume(volname[6], MAIN_V * STEP_V / 1000);
set_volume(volname[3], MAIN_V * BUTTON_V / 1000);
} else if (x == 2) {
set_volume(volname[2], MAIN_V * MUSIC_V / 1000);
} else if (x == 3) {
set_volume(volname[3], MAIN_V * BUTTON_V / 1000);
} else if (x == 6) {
set_volume(volname[6], MAIN_V * STEP_V / 1000);
}
play_once(volname[3]);
gto(x * 3 - 1, (lst / 50) + 20);
color(4);
if (lst == 1000) {
printf("-- ");
} else if (lst == 0) {
printf(" --");
} else {
printf("---");
}
gto(x * 3 - 1, (vol[x] / 50) + 20);
color(204);
printf(" ");
lst = vol[x];
}
if (KEY_DOWN(ENTER)) {
flag = 1;
} else if (flag) {
flag = 0;
play_once(volname[3]);
break;
}
Sleep(50);
}
gto(x * 3 - 1, (vol[x] / 50) + 20);
color(228);
printf(" ");
return ;
}
void soundset() {
ss_cover();
int now = 1, lst = 1, lkt3 = 0, lkt4 = 0;
bool flag = 0, ff = 0;
while (1) {
if (lkt3 != KEY_TIME(38) && KEY_DOWN(38)) {
lkt3 = KEY_TIME(38);
if (now != 1) {
now--;
}
play_once(volname[3]);
} else if (lkt4 != KEY_TIME(40) && KEY_DOWN(40)) {
lkt4 = KEY_TIME(40);
if (now != 6) {
now++;
}
play_once(volname[3]);
}
if (now != lst) {
gto(lst * 3 - 1, 7);
color(4);
if (lst == 1) {
printf(" 主音量 ");
} else if (lst == 2) {
printf(" 音乐音量 ");
} else if (lst == 3) {
printf(" 按键音量 ");
} else if (lst == 4) {
printf(" 敌人音量 ");
} else if (lst == 5) {
printf(" 环境音量 ");
} else {
printf(" 脚步音量 ");
}
gto(now * 3 - 1, 7);
color(228);
if (now == 1) {
printf("[ 主音量 ]");
} else if (now == 2) {
printf("[ 音乐音量 ]");
} else if (now == 3) {
printf("[ 按键音量 ]");
} else if (now == 4) {
printf("[ 敌人音量 ]");
} else if (now == 5) {
printf("[ 环境音量 ]");
} else {
printf("[ 脚步音量 ]");
}
color(7);
lst = now;
}
if (KEY_DOWN(39)) {
ff = 1;
} else if (ff) {
play_once(volname[3]);
ff = 0;
ssetin(now);
}
if (KEY_DOWN(VK_ESCAPE)) {
flag = 1;
} else if (flag) {
play_once(volname[3]);
flag = 0;
return ;
}
Sleep(50);
}
return ;
}
void cs_cover() {
system("mode con cols=50 lines=24");
color(4), system("cls");
color(228), gto(1, 2), printf("[ 前进 ]");
color(4);
gto(1, 22), printf("%s", KEY_NAME(GO));
gto(3, 6), printf("后退"), gto(3, 22), printf("%s", KEY_NAME(BACK));
gto(5, 6), printf("向左"), gto(5, 22), printf("%s", KEY_NAME(LEFT));
gto(7, 6), printf("向右"), gto(7, 22), printf("%s", KEY_NAME(RIGHT));
gto(9, 6), printf("疾跑"), gto(9, 22), printf("%s", KEY_NAME(RUN));
gto(11, 6), printf("交互"), gto(11, 22), printf("%s", KEY_NAME(INTURN));
gto(13, 6), printf("暂停"), gto(13, 22), printf("%s", KEY_NAME(STOP));
gto(15, 4), printf("地图大小"), gto(15, 22), printf("%s", KEY_NAME(MAPMODE));
gto(17, 5), printf("技能一"), gto(17, 22), printf("%s", KEY_NAME(SKILL_1));
gto(19, 5), printf("技能二"), gto(19, 22), printf("%s", KEY_NAME(SKILL_2));
gto(21, 5), printf("确认键"), gto(21, 22), printf("%s", KEY_NAME(ENTER));
color(228);
gto(8, 32), printf("按[Esc]退出"), gto(10, 32), printf("按右箭头进入更改");
gto(12, 32), printf("按下对应键以更改");
color(4);
return ;
}
void csetin(int x) {
color(228);
gto((x << 1) - 1, 17);
printf(" [ %s ] ", KEY_NAME(keymode[x]));
bool vis[260], flag = 0;
memset(vis, 0, sizeof(vis));
while (1) {
for (int i = 1; i <= 256; i++) {
if (i == 16) {
i = 18;
continue;
}
if (KEY_DOWN(i)) {
vis[i] = 1;
} else if (vis[i]) {
keymode[x] = i;
flag = 1;
break;
}
}
if (flag) {
break;
}
Sleep(50);
}
color(4);
gto((x << 1) - 1, 17);
printf(" %s ", KEY_NAME(keymode[x]));
return ;
}
void ctrlset() {
cs_cover();
int now = 1, lst = 1, lkt3 = 0, lkt4 = 0;
bool flag = 0, ff = 0;
while (1) {
if (lkt3 != KEY_TIME(38) && KEY_DOWN(38)) {
lkt3 = KEY_TIME(38);
if (now != 1) {
now--;
}
play_once(volname[3]);
} else if (lkt4 != KEY_TIME(40) && KEY_DOWN(40)) {
lkt4 = KEY_TIME(40);
if (now != 11) {
now++;
}
play_once(volname[3]);
}
if (now != lst) {
color(4);
gto((lst << 1) - 1, 2);
if (lst == 1) {
printf(" 向前 ");
} else if (lst == 2) {
printf(" 后退 ");
} else if (lst == 3) {
printf(" 向左 ");
} else if (lst == 4) {
printf(" 向右 ");
} else if (lst == 5) {
printf(" 疾跑 ");
} else if (lst == 6) {
printf(" 交互 ");
} else if (lst == 7) {
printf(" 暂停 ");
} else if (lst == 8) {
printf(" 地图大小 ");
} else if (lst == 9) {
printf(" 技能一 ");
} else if (lst == 10) {
printf(" 技能二 ");
} else {
printf(" 确认键 ");
}
color(228);
gto((now << 1) - 1, 2);
if (now == 1) {
printf("[ 向前 ]");
} else if (now == 2) {
printf("[ 向后 ]");
} else if (now == 3) {
printf("[ 向左 ]");
} else if (now == 4) {
printf("[ 向右 ]");
} else if (now == 5) {
printf("[ 疾跑 ]");
} else if (now == 6) {
printf("[ 交互 ]");
} else if (now == 7) {
printf("[ 暂停 ]");
} else if (now == 8) {
printf("[ 地图大小 ]");
} else if (now == 9) {
printf("[ 技能一 ]");
} else if (now == 10) {
printf("[ 技能二 ]");
} else {
printf("[ 确认键 ]");
}
color(4);
lst = now;
}
if (KEY_DOWN(39)) {
ff = 1;
} else if (ff) {
play_once(volname[3]);
color(4);
gto((now << 1) - 1, 2);
if (now == 1) {
printf(" 向前 ");
} else if (now == 2) {
printf(" 后退 ");
} else if (now == 3) {
printf(" 向左 ");
} else if (now == 4) {
printf(" 向右 ");
} else if (now == 5) {
printf(" 疾跑 ");
} else if (now == 6) {
printf(" 交互 ");
} else if (now == 7) {
printf(" 暂停 ");
} else if (now == 8) {
printf(" 地图大小 ");
} else if (now == 9) {
printf(" 技能一 ");
} else if (now == 10) {
printf(" 技能二 ");
} else {
printf(" 确认键 ");
}
csetin(now);
ff = 0;
color(228);
gto((now << 1) - 1, 2);
if (now == 1) {
printf("[ 向前 ]");
} else if (now == 2) {
printf("[ 向后 ]");
} else if (now == 3) {
printf("[ 向左 ]");
} else if (now == 4) {
printf("[ 向右 ]");
} else if (now == 5) {
printf("[ 疾跑 ]");
} else if (now == 6) {
printf("[ 交互 ]");
} else if (now == 7) {
printf("[ 暂停 ]");
} else if (now == 8) {
printf("[ 地图大小 ]");
} else if (now == 9) {
printf("[ 技能一 ]");
} else if (now == 10) {
printf("[ 技能二 ]");
} else {
printf("[ 确认键 ]");
}
color(4);
}
if (KEY_DOWN(VK_ESCAPE)) {
flag = 1;
} else if (flag) {
play_once(volname[3]);
flag = 0;
return ;
}
Sleep(50);
}
return ;
}
void set_cover() {
system("mode con cols=50 lines=22");
color(4), system("cls");
color(228), gto(5, 10), printf("[ 音量设置 ]");
color(4), gto(10, 12), printf("控制设置"), gto(13, 14), printf("退出");
color(14), gto(8, 22), printf("按%s以选择", keyname[ENTER]);
return ;
}
void sett() {
A:
set_cover();
int now = 1, lst = 1, lkt3 = 0, lkt4 = 0;
bool flag = 0;
while (1) {
if (lkt3 != KEY_TIME(38) && KEY_DOWN(38)) {
lkt3 = KEY_TIME(38);
if (now != 1) {
now--;
}
play_once(volname[3]);
} else if (lkt4 != KEY_TIME(40) && KEY_DOWN(40)) {
lkt4 = KEY_TIME(40);
if (now != 3) {
now++;
}
play_once(volname[3]);
}
if (now != lst) {
color(4);
if (lst == 1) {
gto(5, 10);
printf(" 音量设置 ");
} else if (lst == 2) {
gto(10, 10);
printf(" 控制设置 ");
} else {
gto(13, 10);
printf(" 退出 ");
}
color(228);
if (now == 1) {
gto(5, 10);
printf("[ 音量设置 ]");
} else if (now == 2) {
gto(10, 10);
printf("[ 控制设置 ]");
} else {
gto(13, 10);
printf("[ 退出 ]");
}
color(7);
lst = now;
}
if (KEY_DOWN(ENTER)) {
flag = 1;
} else if (flag) {
play_once(volname[3]);
flag = 0;
if (now == 3) {
return ;
} else if (now == 1) {
soundset();
goto A;
} else {
ctrlset();
goto A;
}
}
Sleep(50);
}
return ;
}
void st_cover() {
color(4);
system("cls");
system("mode con cols=50 lines=22");
color(68);
//D
gto(4, 3), printf(" ");
gto(5, 4), printf(" "), gto(5, 9), printf(" ");
gto(6, 4), printf(" "), gto(6, 11), printf(" ");
color(4);
gto(7, 7), printf("De");
color(68);
gto(7, 4), printf(" "), gto(7, 11), printf(" ");
gto(8, 4), printf(" "), gto(8, 10), printf(" ");
gto(9, 3), printf(" ");
//a
gto(6, 16), printf(" ");
gto(7, 15), printf(" "), gto(7, 20), printf(" ");
color(4);
gto(7, 17);
printf("cep");
color(68);
gto(8, 15), printf(" "), gto(8, 20), printf(" ");
gto(9, 16), printf(" "), gto(9, 21), printf(" ");
//r
gto(6, 24), printf(" "), gto(6, 27), printf(" ");
gto(7, 24), printf(" "), gto(7, 29), printf(" ");
gto(8, 24), printf(" ");
color(4);
gto(7, 27);
printf("ti");
color(68);
gto(9, 24), printf(" ");
//k
gto(4, 33), printf(" ");
gto(5, 33), printf(" ");
gto(6, 33), printf(" "), gto(6, 37), printf(" ");
gto(7, 33), printf(" ");
color(4);
gto(7, 38);
printf("on");
color(68);
gto(8, 33), printf(" "), gto(8, 36), printf(" ");
gto(9, 33), printf(" "), gto(9, 38), printf(" ");
color(14);
gto(14, 4);
printf("按%s以选择", keyname[ENTER]);
color(228);
gto(11, 23);
if (isplayed) {
printf("[ 继续游戏 ]");
} else {
printf("[ 开始游戏 ]");
}
color(4);
if (isplayed) {
gto(13, 26);
printf("新游戏");
}
gto(15, 27);
printf("选项");
gto(17, 27);
printf("退出");
color(7);
return ;
}
bool start() {
A:
st_cover();
int now = 1, lst = 1, lkt3 = 0, lkt4 = 0;
bool flag = 0;
while (1) {
if (lkt3 != KEY_TIME(38) && KEY_DOWN(38)) {
lkt3 = KEY_TIME(38);
if (now == 3 && isplayed == 0) {
now = 1;
} else if (now > 1) {
now--;
}
play_once(volname[3]);
} else if (lkt4 != KEY_TIME(40) && KEY_DOWN(40)) {
lkt4 = KEY_TIME(40);
if (now == 1 && isplayed == 0) {
now = 3;
} else if (now < 4) {
now++;
}
play_once(volname[3]);
}
if (now != lst) {
color(4);
gto((lst << 1) + 9, 23);
if (lst == 1) {
if (isplayed) {
printf(" 继续游戏 ");
} else {
printf(" 开始游戏 ");
}
} else if (lst == 2) {
printf(" 新游戏 ");
} else if (lst == 3) {
printf(" 选项 ");
} else if (lst == 4) {
printf(" 退出 ");
}
color(228);
gto((now << 1) + 9, 23);
if (now == 1) {
if (isplayed) {
printf("[ 继续游戏 ]");
} else {
printf("[ 开始游戏 ]");
}
} else if (now == 2) {
printf("[ 新游戏 ]");
} else if (now == 3) {
printf("[ 选项 ]");
} else if (now == 4) {
printf("[ 退出 ]");
}
color(7);
lst = now;
}
if (KEY_DOWN(ENTER)) {
flag = 1;
} else if (flag) {
play_once(volname[3]);
flag = 0;
if (now == 4) {
return 0;
} else if (now == 1) {
game();
goto A;
} else if (now == 2) {
resett();
game();
goto A;
} else if (now == 3) {
sett();
goto A;
}
}
Sleep(50);
}
return 0;
}
int main() {
init();
if (start()) {
return 0;
}
save();
return 0;
}