字幕君已上線......
副字幕君已上線......
計數君已上線......
彩色字幕君?( 花了重金請來的 )?已上線......
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:點個贊吧這個方塊里面有四個字,你可以看出是什么嗎?