C++【生存游戏】开发:荒岛往事 第二期

前言(我还活着呢!)

第一期戳这里

距离第一期已经有......1年多了?!

对不起啊,最近忙于学习(并非)

这一系列的游戏win10~win7都可以用!!

最近一段时间,我一直在继续研究荒岛往事游戏项目,十分的努力,一点都没有些,甚至卷到凌晨0点32分。

Doge:不是的不是的,作者天天偷懒,放学回家后就玩Smilemo**

本期预览:

对了,根据评论区要求,我现在可以根据评论要求写文章 。所以大家要多发评论呀!

正文

大致改动

这一次更新主要是增加了主界面去野外的界面,很Low,所以先凑活着用吧!

1、定义结构体

首先,我们先编写一些用来表示敌人地区结构体

cpp 复制代码
struct Enemy {
	string name;
	string attack[10];
	int hurt[10];
	int Area;
    int DangerIndex;
};

struct Area {
	string Name;
	int areaID;
	int things[1000];
};

Enemy中,name贵物名称attack 是攻击的招式hurt 是每一个攻击招式对应的伤害值Area 指在哪个地区能够出现这种贵物DangerIndex危险指数

我这里设计了7种贵物 ,暂时想不到更多了。如果有对这个项目感兴趣的粉丝,可以在评论区投稿!感谢!🙏🙏🙏

cpp 复制代码
// 平原 丘陵 山 森林 沉船
Enemy enemy[20] = {
	"小野猪", {"使用 獠牙 攻击", " 撕咬 "}, {5, 8}, 1, 1,
	"疯牛", {"使用 牛角 撞击", " 冲撞 "}, {10, 12}, 1, 2,
	"狮子", {"使用 利齿 撕咬", "使用 利爪 攻击"}, {15, 12}, 2, 2,
	"鹰", {"使用 利爪 攻击", "使用 石头 砸中"}, {8, 18}, 2, 2,
	"愤怒的山羊", {"使用 羊角 撞击", "撞击"}, {12, 8}, 3, 2,
	"狼", {"使用 利齿 撕咬"}, {15}, 3, 2,
	"老虎", {"使用 利齿 撕咬", "使用 利爪 攻击"}, {20, 18}, 3, 3,
};

Area中,Name仍是地区的名字areaID是每一个地区对应的值things是指在此地区能获得的东西

时间问题,我只设计了一个,可以投稿!~~

cpp 复制代码
Area area[10] = {
	{"", N, {N, N, N}},
	{"绿色草原", 1, {0, 1, 2}},
};

然后就是物品,仍然欢迎投稿

cpp 复制代码
struct Things {
	string Name;
	int Sum;
	int Type;
	int ID;
};

Name就不多说了,Sum是玩家一开始有多少这个物品 ,因为玩家一开始啥也没有,所以都为0,之后我们会写存档系统 ,到时候再改。Type物品的类型ID就是物品ID

Doge:下期预告:存档 + 打怪

物品我设计了很多:

cpp 复制代码
Things thingsName[1000] = {
	"树枝", 0, 1, 0,
	"木头", 0, 1, 1,
	"石片", 0, 1, 2,
	"石块", 0, 1, 3,
	"藤条", 0, 1, 4,
	"铁矿", 0, 1, 5,
	"煤炭", 0, 1, 6,
	"铁片", 0, 1, 7,
	"棕榈叶", 0, 1, 8,
	"钢铁", 0, 1, 9,
	"生肉", 0, 2, 10,
	"熟肉", 0, 2, 11,
	"肉汤", 0, 2, 12,
	"露水", 0, 2, 13,
	"雨水", 0, 2, 14,
	"雪水", 0, 2, 15,
	"面粉", 0, 2, 16,
	"小麦", 0, 2, 17,
	"面包", 0, 2, 18,
	"饼干", 0, 2, 19,
	"土豆", 0, 2, 20,
	"蜂蜜", 0, 2, 21,
	"小锉刀", 0, 3, 22,
	"长刀", 0, 3, 23,
	"利剑", 0, 3, 24
};

2、绘制地图

我们接着在上一期的GAME结构体里面编写函数。可能有人就问了,为什么要用结构体?直接写函数不是更简单吗?而我的回答是:

cpp 复制代码
	void KillEnemy(int a) {
		Cls();
		int safe = rand() % 3;
		int collect = rand() % 3;
		int howm = rand() % 10 + 1;
		if (safe == 1) {
			cout << "这里安全,可以收集 " << thingsName[area[a].things[collect]].Name << endl << endl;
			Sleep(600);
			cout << "你收集了 " << howm << " 个 " << thingsName[area[a].things[collect]].Name;
			Sleep(1000);
		}
	}

	void PrintTree(int x, int y) {
		gotoxy(x, y + 4);
		color(162);
		cout << "  ";
		gotoxy(x + 1, y + 2);
		cout << "  ~  ~";
		gotoxy(x + 2, y);
		color(42);
		cout << " ~    ~~  ";
		gotoxy(x + 3, y + 4);
		color(102);
		cout << "  ";
	}

	void Move() {
		Cls();
		syscolor("ef");
		gotoxy(0, 0);
		color(51);
		cout << "                     " << endl;
		cout << "            " << endl;
		cout << "      " << endl;
		cout << "       " << endl;
		cout << "  " << endl;
		cout << "        " << endl;
		cout << "              " << endl;
		cout << "              " << endl;
		cout << "              " << endl;
		cout << "           " << endl;
		cout << "              " << endl;
		cout << "                  " << endl;
		cout << "          " << endl;
		cout << "      " << endl;
		cout << "    " << endl;
		cout << "      " << endl;
		cout << "  " << endl;
		cout << "        " << endl;
		cout << "           " << endl;
		cout << "              " << endl;
		cout << "            " << endl;
		cout << "                " << endl;
		cout << "              " << endl;
		cout << "         " << endl;
		cout << "              " << endl;
		cout << "               " << endl;
		cout << "                      " << endl;
		cout << "                           " << endl;
		for (int i = 0; i <= 29; i++) {
			color(120);
			gotoxy(i, 85 - i);
			for (int j = 0; j <= 20; j++)
				cout << " ";
			color(135);
			for (int j = 0; j <= 13 + i; j++) {
				cout << " ";
			}
		}

		color(234);
		gotoxy(6, 25);
		printf("γ                   ψ");
		gotoxy(7, 25);
		printf("           γ");
		gotoxy(8, 25);
		printf("   γ  ψ");
		gotoxy(9, 25);
		printf("       γ                     ψ");

		PrintTree(11, 27);
		PrintTree(10, 31);
		PrintTree(11, 35);

		PrintTree(13, 32);
		PrintTree(12, 36);
		PrintTree(13, 40);

		PrintTree(11, 37);
		PrintTree(10, 41);
		PrintTree(11, 45);

		PrintTree(12, 42);
		PrintTree(11, 46);
		PrintTree(12, 50);

		color(49);
		gotoxy(0, 105);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(1, 105);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(2, 104);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(3, 104);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(4, 103);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(5, 103);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(6, 102);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(7, 102);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(8, 101);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(9, 101);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(10, 100);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(11, 100);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(12, 99);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(13, 99);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(14, 98);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(15, 98);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(16, 97);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(17, 97);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(18, 96);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(19, 96);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(20, 95);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(21, 95);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(22, 94);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(23, 94);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(24, 93);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(25, 93);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(23, 0);
		cout << "                                                                                                           ";
		gotoxy(24, 0);
		cout << "                                                                                                           ";
		gotoxy(25, 0);
		cout << "                                                                                                           ";
		gotoxy(26, 0);
		cout << "                                                                                                           ";
		gotoxy(27, 0);
		color(17);
		cout << "                                                                                                           ";
		color(120);
		gotoxy(28, 0);
		cout << "                                                             ";
		gotoxy(29, 0);
		cout << "                                                             ";
		color(135);
		gotoxy(3, 86);
		cout << "┌─┐";
		gotoxy(4, 84);
		cout << "┌     ┐";
		gotoxy(5, 84);
		cout << "└   ▲┘";
		gotoxy(6, 86);
		cout << "└─┘";
		color(15);
		gotoxy(0, 0);
		cout << "你要去哪里?";
		while (1) {
			if (outbutton(outdo, 1, 0) == "1、草原") {
				KillEnemy(1);
			}
		}

		Sleep(10000);
		return;
	}

这几个绘制函数超难写qwq!!!

3、游戏主函数

cpp 复制代码
	void GameMain() {
		Cls();
		syscolor("f0");
		printf("──────────时间:");
		Random = rand() % 6;
		if (Random == 0) {
			Time = "早晨";
			printf("早晨");
		} else if (Random == 1) {
			Time = "上午";
			printf("上午");
		} else if (Random == 2) {
			Time = "中午";
			printf("中午");
		} else if (Random == 3) {
			Time = "下午";
			printf("下午");
		} else if (Random == 4) {
			Time = "晚上";
			printf("晚上");
		} else if (Random == 5) {
			Time = "凌晨";
			printf("凌晨");
		}
		printf("────季节:");
		Random = rand() % 4;
		if (Random == 0) {
			Season = "春";
			printf("春");
		}
		if (Random == 1) {
			Season = "夏";
			printf("夏");
		}
		if (Random == 2) {
			Season = "秋";
			printf("秋");
		}
		if (Random == 3) {
			Season = "冬";
			printf("冬");
		}
		Random = rand() % 7;
		printf("────天气:");
		if (Random == 0) {
			Weather = "晴朗无云";
			printf("晴朗无云");
		}
		if (Random == 1) {
			Weather = "多云";
			printf("多云──");
		}
		if (Random == 2) {
			Weather = "阴";
			printf("阴───");
		}
		if (Random == 3) {
			Weather = "雨";
			printf("雨───");
		}
		if (Random == 4) {
			Weather = "大风";
			printf("大风──");
		}
		if (Random == 5) {
			Weather = "暴风雨";
			printf("暴风雨─");
		}
		if (Random == 6 && Season == "冬") {
			Weather = "雪";
			printf("雪───");
		}
		printf("────生存天数:%d", LiveDay);
		printf("───────────────────────────────────────────────────────\n");
		cout << PlayerName << " 想要做什么?";
		while (1) {
			if (outbutton(homedo, 4, 0) == "1、移动") {
				Move();
			}
		}
	}

目前有天气❄️、时间⌚️、移动(互动)🏃‍♀️三个功能。

完整代码

运行game.cpp这个程序,这个程序有托盘

把这两个文件放在同一个文件夹内哦

game.cpp

game.cpp()和上期一样没变:

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

cpp 复制代码
#include "Files/Console.in"
#include <iostream>
#include <string>
#include <fstream>
#include <windows.h>  // 包含 Windows API 函数声明
#include <conio.h>    // 包含 _getch()、gotoxy 等控制台函数
#include <cstdlib>    // 包含 rand()、exit() 等
#include <ctime>      // 包含 time() 函数
using namespace std;
#define N NULL
using namespace console_game;

//x:行, y:列
char press = '1';
int startchange = 1;

struct Enemy {
	string name;
	string attack[10];
	int hurt[10];
	int Area;
	int DangerIndex;
};

struct Area {
	string Name;
	int areaID;
	int things[1000];
};

Area area[10] = {
	{"", N, {N, N, N}},
	{"绿色草原", 1, {0, 1, 2}},
};

struct outtext {
	char text[100000];
	int t;
};
// 平原 丘陵 山 森林 沉船
Enemy enemy[20] = {
	"小野猪", {"使用 獠牙 攻击", " 撕咬 "}, {5, 8}, 1, 1,
	"疯牛", {"使用 牛角 撞击", " 冲撞 "}, {10, 12}, 1, 2,
	"狮子", {"使用 利齿 撕咬", "使用 利爪 攻击"}, {15, 12}, 2, 2,
	"鹰", {"使用 利爪 攻击", "使用 石头 砸中"}, {8, 18}, 2, 2,
	"愤怒的山羊", {"使用 羊角 撞击", "撞击"}, {12, 8}, 3, 2,
	"狼", {"使用 利齿 撕咬"}, {15}, 3, 2,
	"老虎", {"使用 利齿 撕咬", "使用 利爪 攻击"}, {20, 18}, 3, 3,
};


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 Time;
string Weather;
string Season;
int ismap;
int isrun;
int ispapp;
button homedo[] = {"", {"1、移动", "2、吃饭", "3、医疗", "4、睡觉", "5、建造"}, 5};
button outdo[] = {"", {"1、草原", "2、沙滩", "3、瀑布", "4、河流", "5、海边", "6、远山", "7、山顶洞穴"}, 7};
int LiveDay;

int Random;

struct Things {
	string Name;
	int Sum;
	int Type;
	int ID;
};
// 1:锻造类
// 2:食物类
// 3:武器类
Things thingsName[1000] = {
	"树枝", 0, 1, 0,
	"木头", 0, 1, 1,
	"石片", 0, 1, 2,
	"石块", 0, 1, 3,
	"藤条", 0, 1, 4,
	"铁矿", 0, 1, 5,
	"煤炭", 0, 1, 6,
	"铁片", 0, 1, 7,
	"棕榈叶", 0, 1, 8,
	"钢铁", 0, 1, 9,
	"生肉", 0, 2, 10,
	"熟肉", 0, 2, 11,
	"肉汤", 0, 2, 12,
	"露水", 0, 2, 13,
	"雨水", 0, 2, 14,
	"雪水", 0, 2, 15,
	"面粉", 0, 2, 16,
	"小麦", 0, 2, 17,
	"面包", 0, 2, 18,
	"饼干", 0, 2, 19,
	"土豆", 0, 2, 20,
	"蜂蜜", 0, 2, 21,
	"小锉刀", 0, 3, 22,
	"长刀", 0, 3, 23,
	"利剑", 0, 3, 24
};

string PlayerName;

struct GAME {

	void KillEnemy(int a) {
		Cls();
		int safe = rand() % 3;
		int collect = rand() % 3;
		int howm = rand() % 10 + 1;
		if (safe == 1) {
			cout << "这里安全,可以收集 " << thingsName[area[a].things[collect]].Name << endl << endl;
			Sleep(600);
			cout << "你收集了 " << howm << " 个 " << thingsName[area[a].things[collect]].Name;
			Sleep(1000);
		}
	}

	void PrintTree(int x, int y) {
		gotoxy(x, y + 4);
		color(162);
		cout << "  ";
		gotoxy(x + 1, y + 2);
		cout << "  ~  ~";
		gotoxy(x + 2, y);
		color(42);
		cout << " ~    ~~  ";
		gotoxy(x + 3, y + 4);
		color(102);
		cout << "  ";
	}

	void Move() {
		Cls();
		syscolor("ef");
		gotoxy(0, 0);
		color(51);
		cout << "                     " << endl;
		cout << "            " << endl;
		cout << "      " << endl;
		cout << "       " << endl;
		cout << "  " << endl;
		cout << "        " << endl;
		cout << "              " << endl;
		cout << "              " << endl;
		cout << "              " << endl;
		cout << "           " << endl;
		cout << "              " << endl;
		cout << "                  " << endl;
		cout << "          " << endl;
		cout << "      " << endl;
		cout << "    " << endl;
		cout << "      " << endl;
		cout << "  " << endl;
		cout << "        " << endl;
		cout << "           " << endl;
		cout << "              " << endl;
		cout << "            " << endl;
		cout << "                " << endl;
		cout << "              " << endl;
		cout << "         " << endl;
		cout << "              " << endl;
		cout << "               " << endl;
		cout << "                      " << endl;
		cout << "                           " << endl;
		for (int i = 0; i <= 29; i++) {
			color(120);
			gotoxy(i, 85 - i);
			for (int j = 0; j <= 20; j++)
				cout << " ";
			color(135);
			for (int j = 0; j <= 13 + i; j++) {
				cout << " ";
			}
		}

		color(234);
		gotoxy(6, 25);
		printf("γ                   ψ");
		gotoxy(7, 25);
		printf("           γ");
		gotoxy(8, 25);
		printf("   γ  ψ");
		gotoxy(9, 25);
		printf("       γ                     ψ");

		PrintTree(11, 27);
		PrintTree(10, 31);
		PrintTree(11, 35);

		PrintTree(13, 32);
		PrintTree(12, 36);
		PrintTree(13, 40);

		PrintTree(11, 37);
		PrintTree(10, 41);
		PrintTree(11, 45);

		PrintTree(12, 42);
		PrintTree(11, 46);
		PrintTree(12, 50);

		color(49);
		gotoxy(0, 105);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(1, 105);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(2, 104);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(3, 104);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(4, 103);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(5, 103);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(6, 102);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(7, 102);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(8, 101);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(9, 101);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(10, 100);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(11, 100);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(12, 99);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(13, 99);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(14, 98);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(15, 98);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(16, 97);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(17, 97);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(18, 96);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(19, 96);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(20, 95);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(21, 95);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(22, 94);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(23, 94);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(24, 93);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(25, 93);
		cout << "              ";
		color(17);
		cout << " ";

		color(49);
		gotoxy(23, 0);
		cout << "                                                                                                           ";
		gotoxy(24, 0);
		cout << "                                                                                                           ";
		gotoxy(25, 0);
		cout << "                                                                                                           ";
		gotoxy(26, 0);
		cout << "                                                                                                           ";
		gotoxy(27, 0);
		color(17);
		cout << "                                                                                                           ";
		color(120);
		gotoxy(28, 0);
		cout << "                                                             ";
		gotoxy(29, 0);
		cout << "                                                             ";
		color(135);
		gotoxy(3, 86);
		cout << "┌─┐";
		gotoxy(4, 84);
		cout << "┌     ┐";
		gotoxy(5, 84);
		cout << "└   ▲┘";
		gotoxy(6, 86);
		cout << "└─┘";
		color(15);
		gotoxy(0, 0);
		cout << "你要去哪里?";
		while (1) {
			if (outbutton(outdo, 1, 0) == "1、草原") {
				KillEnemy(1);
			}
		}

		Sleep(10000);
		return;
	}

	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();
		//printf("───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────");
	}

	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++;
				else
					startchange = 1;
			if (press == Up)
				if (startchange != 1)
					startchange--;
				else
					startchange = 3;
			music.SendMusic("Click.mp3");
			Sleep(100);
		}
		if (startchange == 1) {
			Start();
			GameMain();
			Sleep(10000);
		} else if (startchange == 2) {
			gotoxy(0, 0);
			printf("上下键选择,空格键确定");
			_getch();
			startchange = 1;
			press = 'v';
			MainMeum();
		} 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;
	}

	void GameMain() {
		Cls();
		syscolor("f0");
		printf("──────────时间:");
		Random = rand() % 6;
		if (Random == 0) {
			Time = "早晨";
			printf("早晨");
		} else if (Random == 1) {
			Time = "上午";
			printf("上午");
		} else if (Random == 2) {
			Time = "中午";
			printf("中午");
		} else if (Random == 3) {
			Time = "下午";
			printf("下午");
		} else if (Random == 4) {
			Time = "晚上";
			printf("晚上");
		} else if (Random == 5) {
			Time = "凌晨";
			printf("凌晨");
		}
		printf("────季节:");
		Random = rand() % 4;
		if (Random == 0) {
			Season = "春";
			printf("春");
		}
		if (Random == 1) {
			Season = "夏";
			printf("夏");
		}
		if (Random == 2) {
			Season = "秋";
			printf("秋");
		}
		if (Random == 3) {
			Season = "冬";
			printf("冬");
		}
		Random = rand() % 7;
		printf("────天气:");
		if (Random == 0) {
			Weather = "晴朗无云";
			printf("晴朗无云");
		}
		if (Random == 1) {
			Weather = "多云";
			printf("多云──");
		}
		if (Random == 2) {
			Weather = "阴";
			printf("阴───");
		}
		if (Random == 3) {
			Weather = "雨";
			printf("雨───");
		}
		if (Random == 4) {
			Weather = "大风";
			printf("大风──");
		}
		if (Random == 5) {
			Weather = "暴风雨";
			printf("暴风雨─");
		}
		if (Random == 6 && Season == "冬") {
			Weather = "雪";
			printf("雪───");
		}
		printf("────生存天数:%d", LiveDay);
		printf("───────────────────────────────────────────────────────\n");
		cout << PlayerName << " 想要做什么?";
		while (1) {
			if (outbutton(homedo, 4, 0) == "1、移动") {
				Move();
			}
		}
	}
};

GAME game;

int main(void) {
	srand((unsigned)time(NULL));
	game.GameRun();
	return 0;
}

bye**~稿~~~****~**

相关推荐
LJHclasstore_luo3 小时前
【GoC游戏】等(wait)1.0.0版本
游戏·goc编程
码来的小朋友5 小时前
国风乡村 3D 地图生成器世界
游戏
河南花仙子科技13 小时前
小游戏开发中常见的BUG类型及成因
人工智能·科技·游戏·bug
爱自由的代码工13 小时前
游戏上线前需要准备什么:核心逻辑、执行步骤与关键指标
游戏·游戏发行·游戏运营·游戏分发
liulilittle15 小时前
麻将系统架构
服务器·网络·分布式·游戏·系统架构·通信
熬夜苦读学习1 天前
基于websocket的多用户五子棋网页游戏
linux·服务器·网络·websocket·网络协议·游戏·五子棋
yangmu32031 天前
【碧蓝幻想Relink】DPS伤害统计Mod安装教程 + XMOD物品面板功能推荐
游戏
lxysbly2 天前
Android PS3模拟器下载推荐2026|安卓PS3模拟器哪个好?手机玩PS3游戏指南
android·游戏·智能手机
笨鸟先飞的橘猫2 天前
游戏场景之大世界架构设计构想
游戏