C++【生存游戏】开发:荒岛往事 第一期
字幕君已上线......
副字幕君已上线......
计数君已上线......
彩色字幕君 ( 花了重金请来的 ) 已上线......
Doge智能系统已上线......
Doge:嗨嗨我又来了!
观众们......已上线!!!!!
OK LET`S GO!
前言(闲扯两分半)
最近迷上了生存游戏"坤坤岛"想要手搓一个,(注意:手搓这个词很重要)
所以我在Scratch上试了一个,结果发现:代码越来越多,BUG越来越多!
好吧......我又把目光放到了C嘎嘎上
::)
准备工作
1、Red Panda Dev C++ Maker【3.0自创黑客版】 这是下载链接
2、音乐:Liudiam.mp3、Click.wav 这个需要自己准备
Doge:Liudiam.mp3是比较长的轻音乐,可循环播放,是用于主菜单的,Click是选择音效,很短
3、一张SetConsoleTextAttribute色表:
不熟悉Maker_Game/Console.h头文件的,可以查看这篇文章:文章传送门
本期目标:制作出主界面和大概的剧情
以及托盘图标
首先,一个标标准准的荒岛生存游戏需要有什么?无非就是主界面,各种地形,打怪,各种武器工具,各种剧情等等。所以,我们先从主界面开始制作。
开始制作
1、包含头文件
首先,这是一个控制台程序,所以直接使用我的万能游戏头文件Maker_Game的Console.h:
#include <Maker_Game/Console.h>
using namespace console_game;
2、编写函数
然后,我们可以定义一个结构体GAME,用来存放游戏函数。
主菜单函数
我们命名这个函数名字叫做MainMeum
首先,稍微设置一下标题和窗口的样子:
HideCursor();
ModeWindow(120, 30);
Art_Title("荒岛往事 Alpha V1.0.3");
Art_Windows(1);
然后,我们需要绘制背景,有沙滩,有椰子树,有蓝天。
//绘制天空
color(63);
PrintSpace(30, 119);// 绘制沙滩
color(238);
gotoxy(27, 0);
PrintSpace(3, 119);
//黄238 白255//绘制太阳
color(255);
gotoxy(3, 100);
cout << " ";
gotoxy(4, 100);
cout << " ";
gotoxy(5, 100);
cout << " ";
gotoxy(6, 100);
cout << " ";// 绘制棕榈树
gotoxy(19, 8);
color(34);
printf(" ");
gotoxy(19, 16);
color(34);
printf(" ");
gotoxy(20, 10);
color(34);
printf(" ");
gotoxy(20, 14);
color(34);
printf(" ");
gotoxy(21, 12);
color(34);
printf(" ");
gotoxy(22, 12);
color(102);
printf(" ");
gotoxy(23, 12);
color(102);
printf(" ");
gotoxy(24, 12);
color(102);
printf(" ");
gotoxy(25, 12);
color(102);
printf(" ");
gotoxy(26, 12);
color(102);
printf(" ");
gotoxy(22, 10);
color(34);
printf(" ");
gotoxy(23, 8);
color(34);
printf(" ");
gotoxy(23, 16);
color(34);
printf(" ");
然后需要打印出来标题和选项。在这里,我想使用上下键选择,空格键确定:
color(63);
gotoxy(13, 56);
printf("荒岛往事");
while (press != ' ') {if (startchange == 1) {gotoxy(15, 55);printf("[开始游戏]");gotoxy(17, 55);printf(" 设置游戏 ");gotoxy(19, 55);printf(" 退出游戏 ");}if (startchange == 2) {gotoxy(15, 55);printf(" 开始游戏 ");gotoxy(17, 55);printf("[设置游戏]");gotoxy(19, 55);printf(" 退出游戏 ");}if (startchange == 3) {gotoxy(15, 55);printf(" 开始游戏 ");gotoxy(17, 55);printf(" 设置游戏 ");gotoxy(19, 55);printf("[退出游戏]");}press = getch();if (press == Down)if (startchange != 3)startchange++;elsestartchange = 1;if (press == Up)if (startchange != 1)startchange--;elsestartchange = 3;music.SendMusic("Click.mp3");Sleep(100);
}
if (startchange == 1) {Start();Sleep(10000);
} else if (startchange == 3)exit(0);
音乐函数
游戏可以添加一些音乐,但是直接调用music.h函数,会发现报错了:getch重了,所以还是自己再写一遍叭:(渐渐发现Maker_Game也不是很万能)
struct MciMusic {void SendMusic(LPCSTR musicname) {char Code[10] = "play ";strcat(Code, musicname);mciSendString(Code, N, 0, N);}void PauseMusic(LPCSTR musicname) {char Code[10] = "pause ";strcat(Code, musicname);mciSendString(Code, N, 0, N);}void ResumeMusic(LPCSTR musicname) {char Code[10] = "resume ";strcat(Code, musicname);mciSendString(Code, N, 0, N);}void CloseMusic(LPCSTR musicname) {char Code[10] = "close ";strcat(Code, musicname);mciSendString(Code, N, 0, N);}
};MciMusic music;
剧情函数
我一共写了两个剧情,所以分两个函数。还有一个是把他们结合在一起的。
但是,我需要定义一个剧情结构体、一个Isay(玩家说话)函数和一个SlowSay函数
网友:不是Maker_Game里面自带SlowSay吗,为什么还要自己写QAQ
啊,最近我发现这个SlowSay用不了!(渐渐发现Maker_Game也不是很万能*2)所以还是自己写一个叭:
剧情结构体:
struct outtext{char text[100000];int t;
};//内容想怎么写怎么写outtext text[20] = {" ", 0,"在一片浩瀚无垠的蔚蓝大海上,阳光如同碎金般洒落在波光粼粼的水面上。你正惬意地乘坐着豪华游轮,享受着这美好的海上旅程。\n", 25,"然而,突如其来的风暴打破了这份宁静,巨大的海浪如同巨兽般吞噬着一切。游轮在狂风巨浪中剧烈摇晃,发出令人胆寒的嘎吱声。\n\n船身被海浪一次次冲击,最终不堪重负,开始解体。你在混乱中被卷入了汹涌的大海,冰冷的海水瞬间将你包围......\n", 20,"在奋力挣扎了不知多久后,你幸运又不幸地成为了这场灾难中唯一的幸存者,漂流到了一座荒无人烟的岛屿上。当你拖着疲惫不堪的身体爬上沙滩,看着眼前陌生而又荒芜的景象,心中充满了恐惧与无助,但求生的本能却在此时开始悄然觉醒......\n", 30,"请键入你的用户名: ", 20,"醒醒......\n", 50,"我在哪里?......\n", 30,"Prew......我居然活下来了!\n", 30,"呼......\n", 30,"真累哈......\n", 40,"好了,是时候考虑活下去的问题了......\n", 40
};
Isay函数:
void Isay()
{cout << PlayerName << ": ";
}
SlowPrint函数(为了不和SlowSay函数重复而报错,所以我换了一个名字):
void slowprint(outtext tet)
{for(int i = 0; i <= strlen(tet.text) - 1; i++){Beep(3000, 20);printf("%c",tet.text[i]);_sleep(tet.t);}
}
剧情一函数:
void Story1() {color(15);gotoxy(0, 0);slowprint(text[1]);Sleep(1000);color(10);Pause();Cls();color(15);slowprint(text[2]);Sleep(1000);color(10);Pause();Cls();color(15);slowprint(text[3]);Sleep(1000);color(10);Pause();Cls();Sleep(3000);
}
剧情二函数:
void Story2() {Sleep(5000);slowprint(text[5]);Sleep(2000);slowprint(text[5]);Sleep(2000);Cls();syscolor("8f");Sleep(1000);syscolor("7f");Sleep(1000);syscolor("f0");Sleep(3000);Isay();slowprint(text[6]);Sleep(3000);Isay();slowprint(text[7]);Sleep(3000);Isay();slowprint(text[8]);Sleep(3000);Isay();slowprint(text[9]);Sleep(3000);Isay();slowprint(text[10]);Sleep(6000);
}
3、托盘图标
这个简单,但需要使用另一个文件:
#include <windows.h>
#include <shellapi.h>
#include <string>
#include <cstring>
#include <windows.h>
#include <tlhelp32.h>
#include <iostream>
#include <string>// 禁用安全函数警告(若编译器支持)
#define _CRT_SECURE_NO_WARNINGS// 定义托盘图标消息
#define WM_TRAYICON (WM_USER + 1)bool IsProcessRunning(const std::string& processName) {// 创建系统进程快照HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);if (hSnapshot == INVALID_HANDLE_VALUE) {return false;}// 用于存储进程信息的结构体PROCESSENTRY32 pe32;pe32.dwSize = sizeof(PROCESSENTRY32);// 获取第一个进程信息if (!Process32First(hSnapshot, &pe32)) {CloseHandle(hSnapshot);return false;}// 遍历所有进程bool found = false;do {// 将进程名称转换为小写进行比较(不区分大小写)std::string currentProcess = pe32.szExeFile;for (char& c : currentProcess) {c = std::tolower(c);}std::string targetProcess = processName;for (char& c : targetProcess) {c = std::tolower(c);}if (currentProcess.find(targetProcess) != std::string::npos) {found = true;break;}} while (Process32Next(hSnapshot, &pe32));// 关闭快照句柄CloseHandle(hSnapshot);return found;
}// 打开浏览器访问微信支付页面
void open_payment_page(const std::string& pay_url) {std::string command = "start " + pay_url; // Windows系统// 对于Linux系统:system(("xdg-open " + pay_url).c_str());// 对于macOS系统:system(("open " + pay_url).c_str());system(command.c_str());
}// 窗口过程函数,处理托盘消息
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {switch (uMsg) {case WM_TRAYICON:// 处理托盘图标事件switch (LOWORD(lParam)) {case WM_RBUTTONUP: {// 创建右键菜单HMENU hMenu = CreatePopupMenu();AppendMenu(hMenu, MF_STRING, 1, "打开");AppendMenu(hMenu, MF_STRING, 2, "退出");// 获取鼠标位置POINT pt;GetCursorPos(&pt);// 显示菜单SetForegroundWindow(hwnd);TrackPopupMenu(hMenu, TPM_RIGHTBUTTON, pt.x, pt.y, 0, hwnd, NULL);DestroyMenu(hMenu);break;}case WM_LBUTTONDBLCLK:// 双击处理//MessageBox(hwnd, "托盘图标被双击!", "提示", MB_OK);if(IsProcessRunning("main.exe") == 0)system("start main.exe");break;}return 0;case WM_COMMAND:// 处理菜单项点击switch (LOWORD(wParam)) {case 1:if(IsProcessRunning("main.exe") == 0)system("start main.exe");//MessageBox(hwnd, "打开功能已触发!", "提示", MB_OK);break;case 2:// 退出程序前移除托盘图标NOTIFYICONDATA nid = {.cbSize = sizeof(NOTIFYICONDATA),.hWnd = hwnd,.uID = 1,.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP,.uCallbackMessage = WM_TRAYICON,.hIcon = NULL,.szTip = {0},.dwState = 0,.dwStateMask = 0,.szInfo = {0},.uTimeout = 0,.szInfoTitle = {0},.dwInfoFlags = 0};Shell_NotifyIcon(NIM_DELETE, &nid);PostQuitMessage(0);break;}return 0;case WM_DESTROY:// 窗口销毁时移除托盘图标NOTIFYICONDATA nid = {.cbSize = sizeof(NOTIFYICONDATA),.hWnd = hwnd,.uID = 1,.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP,.uCallbackMessage = WM_TRAYICON,.hIcon = NULL,.szTip = {0},.dwState = 0,.dwStateMask = 0,.szInfo = {0},.uTimeout = 0,.szInfoTitle = {0},.dwInfoFlags = 0};Shell_NotifyIcon(NIM_DELETE, &nid);PostQuitMessage(0);return 0;}return DefWindowProc(hwnd, uMsg, wParam, lParam);
}// 在托盘创建图标的函数
bool CreateSystemTrayIcon(HWND hwnd, const std::string& tooltip) {NOTIFYICONDATA nid = {.cbSize = sizeof(NOTIFYICONDATA),.hWnd = hwnd,.uID = 1,.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP,.uCallbackMessage = WM_TRAYICON,.szTip = {0}};// 加载图标HICON hIcon = (HICON)LoadImage(NULL, "Opener.ico", IMAGE_ICON, 16, 16, LR_LOADFROMFILE);if (!hIcon) {DWORD error = GetLastError();char buffer[256];sprintf(buffer, "图标加载失败!错误代码: %lu", error);MessageBox(hwnd, buffer, "错误", MB_ICONERROR);hIcon = (HICON)LoadImage(NULL, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_SHARED);}nid.hIcon = hIcon;strncpy(nid.szTip, tooltip.c_str(), sizeof(nid.szTip) - 1);// 添加托盘图标并返回结果return Shell_NotifyIcon(NIM_ADD, &nid) != FALSE;
}int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*nCmdShow*/) {system("start main.exe");// 注册窗口类(按正确顺序初始化)WNDCLASS wc = {.style = 0,.lpfnWndProc = WindowProc,.cbClsExtra = 0,.cbWndExtra = 0,.hInstance = hInstance,.hIcon = NULL,.hCursor = LoadCursor(NULL, IDC_ARROW),.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1),.lpszMenuName = NULL,.lpszClassName = "TrayAppClass"};RegisterClass(&wc);// 创建隐藏窗口HWND hwnd = CreateWindow(wc.lpszClassName, "Tray Application", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL, hInstance, NULL);if (!hwnd) return 1;// 创建托盘图标if (!CreateSystemTrayIcon(hwnd, "荒岛往事")) {MessageBox(hwnd, "创建托盘图标失败!", "错误", MB_ICONERROR);return 1;}// 隐藏窗口ShowWindow(hwnd, SW_HIDE);// 消息循环MSG msg = {0};while (GetMessage(&msg, NULL, 0, 0)) {TranslateMessage(&msg);DispatchMessage(&msg);}return (int)msg.wParam;
}
完整代码
game.cpp
#include <windows.h>
#include <shellapi.h>
#include <string>
#include <cstring>
#include <windows.h>
#include <tlhelp32.h>
#include <iostream>
#include <string>// 禁用安全函数警告(若编译器支持)
#define _CRT_SECURE_NO_WARNINGS// 定义托盘图标消息
#define WM_TRAYICON (WM_USER + 1)bool IsProcessRunning(const std::string& processName) {// 创建系统进程快照HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);if (hSnapshot == INVALID_HANDLE_VALUE) {return false;}// 用于存储进程信息的结构体PROCESSENTRY32 pe32;pe32.dwSize = sizeof(PROCESSENTRY32);// 获取第一个进程信息if (!Process32First(hSnapshot, &pe32)) {CloseHandle(hSnapshot);return false;}// 遍历所有进程bool found = false;do {// 将进程名称转换为小写进行比较(不区分大小写)std::string currentProcess = pe32.szExeFile;for (char& c : currentProcess) {c = std::tolower(c);}std::string targetProcess = processName;for (char& c : targetProcess) {c = std::tolower(c);}if (currentProcess.find(targetProcess) != std::string::npos) {found = true;break;}} while (Process32Next(hSnapshot, &pe32));// 关闭快照句柄CloseHandle(hSnapshot);return found;
}// 打开浏览器访问微信支付页面
void open_payment_page(const std::string& pay_url) {std::string command = "start " + pay_url; // Windows系统// 对于Linux系统:system(("xdg-open " + pay_url).c_str());// 对于macOS系统:system(("open " + pay_url).c_str());system(command.c_str());
}// 窗口过程函数,处理托盘消息
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {switch (uMsg) {case WM_TRAYICON:// 处理托盘图标事件switch (LOWORD(lParam)) {case WM_RBUTTONUP: {// 创建右键菜单HMENU hMenu = CreatePopupMenu();AppendMenu(hMenu, MF_STRING, 1, "打开");AppendMenu(hMenu, MF_STRING, 2, "退出");// 获取鼠标位置POINT pt;GetCursorPos(&pt);// 显示菜单SetForegroundWindow(hwnd);TrackPopupMenu(hMenu, TPM_RIGHTBUTTON, pt.x, pt.y, 0, hwnd, NULL);DestroyMenu(hMenu);break;}case WM_LBUTTONDBLCLK:// 双击处理//MessageBox(hwnd, "托盘图标被双击!", "提示", MB_OK);if(IsProcessRunning("main.exe") == 0)system("start main.exe");break;}return 0;case WM_COMMAND:// 处理菜单项点击switch (LOWORD(wParam)) {case 1:if(IsProcessRunning("main.exe") == 0)system("start main.exe");//MessageBox(hwnd, "打开功能已触发!", "提示", MB_OK);break;case 2:// 退出程序前移除托盘图标NOTIFYICONDATA nid = {.cbSize = sizeof(NOTIFYICONDATA),.hWnd = hwnd,.uID = 1,.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP,.uCallbackMessage = WM_TRAYICON,.hIcon = NULL,.szTip = {0},.dwState = 0,.dwStateMask = 0,.szInfo = {0},.uTimeout = 0,.szInfoTitle = {0},.dwInfoFlags = 0};Shell_NotifyIcon(NIM_DELETE, &nid);PostQuitMessage(0);break;}return 0;case WM_DESTROY:// 窗口销毁时移除托盘图标NOTIFYICONDATA nid = {.cbSize = sizeof(NOTIFYICONDATA),.hWnd = hwnd,.uID = 1,.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP,.uCallbackMessage = WM_TRAYICON,.hIcon = NULL,.szTip = {0},.dwState = 0,.dwStateMask = 0,.szInfo = {0},.uTimeout = 0,.szInfoTitle = {0},.dwInfoFlags = 0};Shell_NotifyIcon(NIM_DELETE, &nid);PostQuitMessage(0);return 0;}return DefWindowProc(hwnd, uMsg, wParam, lParam);
}// 在托盘创建图标的函数
bool CreateSystemTrayIcon(HWND hwnd, const std::string& tooltip) {NOTIFYICONDATA nid = {.cbSize = sizeof(NOTIFYICONDATA),.hWnd = hwnd,.uID = 1,.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP,.uCallbackMessage = WM_TRAYICON,.szTip = {0}};// 加载图标HICON hIcon = (HICON)LoadImage(NULL, "Opener.ico", IMAGE_ICON, 16, 16, LR_LOADFROMFILE);if (!hIcon) {DWORD error = GetLastError();char buffer[256];sprintf(buffer, "图标加载失败!错误代码: %lu", error);MessageBox(hwnd, buffer, "错误", MB_ICONERROR);hIcon = (HICON)LoadImage(NULL, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_SHARED);}nid.hIcon = hIcon;strncpy(nid.szTip, tooltip.c_str(), sizeof(nid.szTip) - 1);// 添加托盘图标并返回结果return Shell_NotifyIcon(NIM_ADD, &nid) != FALSE;
}int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int /*nCmdShow*/) {system("start main.exe");// 注册窗口类(按正确顺序初始化)WNDCLASS wc = {.style = 0,.lpfnWndProc = WindowProc,.cbClsExtra = 0,.cbWndExtra = 0,.hInstance = hInstance,.hIcon = NULL,.hCursor = LoadCursor(NULL, IDC_ARROW),.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1),.lpszMenuName = NULL,.lpszClassName = "TrayAppClass"};RegisterClass(&wc);// 创建隐藏窗口HWND hwnd = CreateWindow(wc.lpszClassName, "Tray Application", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL, hInstance, NULL);if (!hwnd) return 1;// 创建托盘图标if (!CreateSystemTrayIcon(hwnd, "荒岛往事")) {MessageBox(hwnd, "创建托盘图标失败!", "错误", MB_ICONERROR);return 1;}// 隐藏窗口ShowWindow(hwnd, SW_HIDE);// 消息循环MSG msg = {0};while (GetMessage(&msg, NULL, 0, 0)) {TranslateMessage(&msg);DispatchMessage(&msg);}return (int)msg.wParam;
}
main.cpp
#include <Maker_Game/Console.h>
#define N NULL
using namespace console_game;//x:行, y:列
char press = '1';
int startchange = 1;
int things[1000];struct outtext{char text[100000];int t;
};outtext text[20] = {" ", 0,"在一片浩瀚无垠的蔚蓝大海上,阳光如同碎金般洒落在波光粼粼的水面上。你正惬意地乘坐着豪华游轮,享受着这美好的海上旅程。\n", 25,"然而,突如其来的风暴打破了这份宁静,巨大的海浪如同巨兽般吞噬着一切。游轮在狂风巨浪中剧烈摇晃,发出令人胆寒的嘎吱声。\n\n船身被海浪一次次冲击,最终不堪重负,开始解体。你在混乱中被卷入了汹涌的大海,冰冷的海水瞬间将你包围......\n", 20,"在奋力挣扎了不知多久后,你幸运又不幸地成为了这场灾难中唯一的幸存者,漂流到了一座荒无人烟的岛屿上。当你拖着疲惫不堪的身体爬上沙滩,看着眼前陌生而又荒芜的景象,心中充满了恐惧与无助,但求生的本能却在此时开始悄然觉醒......\n", 30,"请键入你的用户名: ", 20,"醒醒......\n", 50,"我在哪里?......\n", 30,"Prew......我居然活下来了!\n", 30,"呼......\n", 30,"真累哈......\n", 40,"好了,是时候考虑活下去的问题了......\n", 40
};struct MciMusic {void SendMusic(LPCSTR musicname) {char Code[10] = "play ";strcat(Code, musicname);mciSendString(Code, N, 0, N);}void PauseMusic(LPCSTR musicname) {char Code[10] = "pause ";strcat(Code, musicname);mciSendString(Code, N, 0, N);}void ResumeMusic(LPCSTR musicname) {char Code[10] = "resume ";strcat(Code, musicname);mciSendString(Code, N, 0, N);}void CloseMusic(LPCSTR musicname) {char Code[10] = "close ";strcat(Code, musicname);mciSendString(Code, N, 0, N);}
};MciMusic music;string PlayerName;struct GAME {void Story1(){color(15);gotoxy(0, 0);slowprint(text[1]);Sleep(1000);color(10);Pause();Cls();color(15);slowprint(text[2]);Sleep(1000);color(10);Pause();Cls();color(15);slowprint(text[3]);Sleep(1000);color(10);Pause();Cls();Sleep(3000); }void Story2(){Sleep(5000);slowprint(text[5]);Sleep(2000);slowprint(text[5]);Sleep(2000);Cls();syscolor("8f");Sleep(1000);syscolor("7f");Sleep(1000);syscolor("f0");Sleep(3000);Isay();slowprint(text[6]);Sleep(3000);Isay();slowprint(text[7]);Sleep(3000);Isay();slowprint(text[8]);Sleep(3000);Isay();slowprint(text[9]);Sleep(3000);Isay();slowprint(text[10]);Sleep(6000);}void slowprint(outtext tet){for(int i = 0; i <= strlen(tet.text) - 1; i++){Beep(3000, 20);printf("%c",tet.text[i]);_sleep(tet.t);} }void Isay(){cout << PlayerName << ": ";}void Start() {syscolor("7f");Sleep(100);syscolor("87");Sleep(100);syscolor("08");Sleep(100);Cls();color(15);Sleep(1000);music.CloseMusic("Liudiam.mp3");Story1();color(15);slowprint(text[4]);cin >> PlayerName;Cls();Story2();Cls();}void MainMeum() {Run();HideCursor();ModeWindow(120, 30);Art_Title("荒岛往事 Alpha V1.0.3");Art_Windows(1);color(63);PrintSpace(30, 119);music.SendMusic("Liudiam.mp3");// 绘制沙滩color(238);gotoxy(27, 0);PrintSpace(3, 119);//黄238 白255//绘制太阳color(255);gotoxy(3, 100);cout << " "; gotoxy(4, 100);cout << " "; gotoxy(5, 100);cout << " "; gotoxy(6, 100);cout << " "; // 绘制棕榈树gotoxy(19, 8);color(34);printf(" ");gotoxy(19, 16);color(34);printf(" ");gotoxy(20, 10);color(34);printf(" ");gotoxy(20, 14);color(34);printf(" ");gotoxy(21, 12);color(34);printf(" ");gotoxy(22, 12);color(102);printf(" ");gotoxy(23, 12);color(102);printf(" ");gotoxy(24, 12);color(102);printf(" ");gotoxy(25, 12);color(102);printf(" ");gotoxy(26, 12);color(102);printf(" ");gotoxy(22, 10);color(34);printf(" ");gotoxy(23, 8);color(34);printf(" ");gotoxy(23, 16);color(34);printf(" ");color(63);gotoxy(13, 56);printf("荒岛往事");while (press != ' ') {if (startchange == 1) {gotoxy(15, 55);printf("[开始游戏]");gotoxy(17, 55);printf(" 设置游戏 ");gotoxy(19, 55);printf(" 退出游戏 ");}if (startchange == 2) {gotoxy(15, 55);printf(" 开始游戏 ");gotoxy(17, 55);printf("[设置游戏]");gotoxy(19, 55);printf(" 退出游戏 ");}if (startchange == 3) {gotoxy(15, 55);printf(" 开始游戏 ");gotoxy(17, 55);printf(" 设置游戏 ");gotoxy(19, 55);printf("[退出游戏]");}press = getch();if (press == Down)if (startchange != 3)startchange++;elsestartchange = 1;if (press == Up)if (startchange != 1)startchange--;elsestartchange = 3;music.SendMusic("Click.mp3");Sleep(100);}if (startchange == 1) {Start();Sleep(10000);} else if (startchange == 3)exit(0);return;}void Make_Text(string same, string name) {ofstream outfile(same, ios::out);if (!outfile) {cerr << "open error" << endl;}outfile << name;outfile.close();}void Hide() {HWND s;s = FindWindow("ConsoleWindowClass", NULL);//找到当前窗口句柄if (s) {ShowOwnedPopups(s, SW_HIDE);//显示或隐藏由指定窗口所有的全部弹出式窗口ShowWindow(s, SW_HIDE);//隐藏窗口}}BOOL IsOsWin7OrAbove() {OSVERSIONINFOEX osInfo = {0};osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);osInfo.dwMajorVersion = 6;osInfo.dwMinorVersion = 1;DWORDLONG conditionMask = 0;VER_SET_CONDITION(conditionMask, VER_MAJORVERSION, VER_EQUAL);VER_SET_CONDITION(conditionMask, VER_MINORVERSION, VER_EQUAL);return VerifyVersionInfo(&osInfo,VER_MAJORVERSION | VER_MINORVERSION,conditionMask) != 0;}void PrintSpace(int H, int L) {for (int i = 1; i <= H; i++) {for (int j = 1; j <= L; j++)cout << " ";cout << endl;}}void Run() {BOOL CanRun = IsOsWin7OrAbove();if (CanRun == FALSE) {Hide();MessageBox(NULL, "很遗憾!\n此产品不支持当前系统版本!\n(仅支持 Windows 7)\n", "荒岛往事.exe 运行错误!", MB_ICONERROR | MB_OK);exit(0);}}void GameRun() {MainMeum();return;}
};GAME game;int main(void) {srand((unsigned)time(NULL));game.GameRun();return 0;
}
Doge:别急着走啊,按下Ctrl + D有惊喜呀~
Doge:点个赞吧这个方块里面有四个字,你可以看出是什么吗?