蓬莱做网站价格/网络营销师官网

蓬莱做网站价格,网络营销师官网,网站开发 成都,一般网站建设公司有多少客户啊【登陆系统--树结构】 1 首先我这里设计&#xff0c;由一个基类MainMenu构建树结构&#xff0c;并实现控制台上菜单之间的切换和返回操作 1 #ifndef _UI_BASE_H_2 #define _UI_BASE_H_3 4 #include <string>5 #include <vector>6 #include"..//Marco.h"7…

【登陆系统--树结构】

1 首先我这里设计,由一个基类MainMenu构建树结构,并实现控制台上菜单之间的切换和返回操作

 1 #ifndef _UI_BASE_H_
 2 #define _UI_BASE_H_
 3 
 4 #include <string>
 5 #include <vector>
 6 #include"..//Marco.h"
 7 using namespace std;
 8 
 9 //================  MainMenu 基类 ========================
10 class MainMenu
11 {
12 public:
13     MainMenu();
14     ~MainMenu();
15 
16 public:
17     // ==================== 外部接口 =======================
18     void PrintUI(char type, int X, int Y);    //打印UI点
19     virtual void LinkChild(MainMenu*);        //作为子目录链接
20     virtual void OutputFrame();                //打印框架
21     virtual void ChooseButton();            //按键选择
22     virtual void ChangingOver(){};            //切换界面
23 
24     //====================  内部函数  ======================
25     virtual void ButtonFunction(){};        //执行按钮功能
26     virtual void OutputButton();            //打印所有按键
27     virtual void RemoveButton();            //清除所有按键
28     virtual void RemoveButtonColor();        //移除按键底色
29     virtual void AppendButtonColor();        //添加按键底色
30 
31 private:
32     CC_PROPERTY(char**, m_frame, Frame);    //框架(界面)
33     CC_PROPERTY(int, m_row, Row);            //frame高度
34     CC_PROPERTY(int, m_colu, Colu);            //frame宽度
35     CC_PROPERTY(string*, m_button, Button); //自己的按键信息
36 
37     //打印 childButton 的坐标位置
38     CC_PROPERTY(size_t, m_index, Index);    //当前选中的按键序号(非角标)
39     CC_PROPERTY(int, m_buttonX, ButtonX);    
40     CC_PROPERTY(int, m_buttonY, ButtonY);
41 
42     //tree结构
43     CC_PROPERTY(MainMenu*, m_father, Father);            //上级目录
44     CC_PROPERTY(vector<MainMenu*>*, m_child, Child);    //下级目录
45 };
46 
47 #endif // _UI_BASE_H_
MainMenu.h
  1 #include<iostream>
  2 
  3 #include"..//Tip.h"
  4 #include "MainMenu.h"
  5 
  6 
  7 MainMenu::MainMenu()
  8 {
  9     //1 UI框架数据
 10     char frame[40][60] = {
 11         "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm",
 12         "m!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@m",
 13         "m*0000000000000000000000000000000000000000000000000000000*m",
 14         "m*0000000000000000000000000000000000000000000000000000000*m",
 15         "m*0000000000000000000000000000000000000000000000000000000*m",
 16         "m*0000000000000000000000000000000000000000000000000000000*m",
 17         "m*0000000000000000000000000000000000000000000000000000000*m",
 18         "m*0000000000000000000000000000000000000000000000000000000*m",
 19         "m*0000000000000000000000000000000000000000000000000000000*m",
 20         "m*0000000000000000000000000000000000000000000000000000000*m",
 21         "m*0000000000000000000000000000000000000000000000000000000*m",
 22         "m*0000000000000000000000000000000000000000000000000000000*m",
 23         "m*0000000000000000000000000000000000000000000000000000000*m",
 24         "m*0000000000000000000000000000000000000000000000000000000*m",
 25         "m*0000000000000000000000000000000000000000000000000000000*m",
 26         "m*0000000000000000000000000000000000000000000000000000000*m",
 27         "m*0000000000000000000000000000000000000000000000000000000*m",
 28         "m*0000000000000000000000000000000000000000000000000000000*m",
 29         "m*0000000000000000000000000000000000000000000000000000000*m",
 30         "m*0000000000000000000000000000000000000000000000000000000*m",
 31         "m*0000000000000000000000000000000000000000000000000000000*m",
 32         "m*0000000000000000000000000000000000000000000000000000000*m",
 33         "m*0000000000000000000000000000000000000000000000000000000*m",
 34         "m*0000000000000000000000000000000000000000000000000000000*m",
 35         "m*0000000000000000000000000000000000000000000000000000000*m",
 36         "m*0000000000000000000000000000000000000000000000000000000*m",
 37         "m*0000000000000000000000000000000000000000000000000000000*m",
 38         "m*0000000000000000000000000000000000000000000000000000000*m",
 39         "m*0000000000000000000000000000000000000000000000000000000*m",
 40         "m*0000000000000000000000000000000000000000000000000000000*m",
 41         "m*0000000000000000000000000000000000000000000000000000000*m",
 42         "m*0000000000000000000000000000000000000000000000000000000*m",
 43         "m*0000000000000000000000000000000000000000000000000000000*m",
 44         "m*0000000000000000000000000000000000000000000000000000000*m",
 45         "m*0000000000000000000000000000000000000000000000000000000*m",
 46         "m*0000000000000000000000000000000000000000000000000000000*m",
 47         "m*0000000000000000000000000000000000000000000000000000000*m",
 48         "m*0000000000000000000000000000000000000000000000000000000*m",
 49         "m#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%$m",
 50         "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm"
 51     };
 52     m_row = 40;
 53     m_colu = 60;
 54     m_frame = GetCharMemory(m_row, m_colu);
 55     for (int i = 0; i < m_row; i++)
 56         strcpy(m_frame[i], frame[i]);
 57 
 58     //Button数据
 59     m_button = new string[3];
 60 
 61     //目录按键的坐标起点
 62     m_index = 1;    //默认指向第一个按钮
 63     m_buttonX = 17; //第一个按钮的坐标x
 64     m_buttonY = 24; //第一个按钮的坐标y
 65 
 66     m_father = nullptr;
 67     m_child = nullptr;
 68 }
 69 
 70 MainMenu::~MainMenu()
 71 {
 72     if (m_frame != nullptr)
 73         DeleteCharMemory(m_frame,m_row);
 74 
 75     if (m_button != nullptr)
 76     {
 77         delete[] m_button;
 78         m_button = nullptr;
 79     }
 80 }
 81 
 82 // ===================== 外部接口 ===========================
 83 //打印框架
 84 void MainMenu::OutputFrame()
 85 {
 86     Color(CT_Grey, CT_Black);
 87     char** pFrame = GetFrame();
 88     //打印框架
 89     for (int i = 0; i < GetRow(); i++)
 90     {
 91         for (int j = 0; j < GetColu() - 1; j++)
 92         {
 93             PrintUI(pFrame[i][j], i, j);
 94         }
 95     }
 96 
 97     //游戏名字
 98     char gameName[5][52] = {
 99         "q000q00qq00qqqq0q0000qqq000q000q00qq00qqqq00qqqqqqq",
100         "q000q0q00q0q00q0q0000q00q00q000q0q00q0q00q000q0q0q0",
101         "q0q0q0q00q0qqqq0q0000q00q00q0q0q0qqqq0qqqq000q0q0q0",
102         "qq0qq0q00q0q0q00q0000q00q00qq0qq0q00q0q0q0000q0q0q0",
103         "q000q00qq00q00q0qqqq0qqq000q000q0q00q0q00q00qqqqqqq",
104     };
105 
106     Color(CT_Blue, CT_Blue);
107     ColorType color = CT_Blue;
108     for (int i = 0; i < 51; i++)
109     {
110         if (i == 44) color = CT_Red;
111         GotoXY(0 + 5, i + 4); 
112         gameName[0][i] == '0' ? Color(CT_Grey, CT_Blue) : Color(color, CT_Blue); cout << "  ";
113         GotoXY(1 + 5, i + 4); 
114         gameName[1][i] == '0' ? Color(CT_Grey, CT_Blue) : Color(color, CT_Blue); cout << "  ";
115         GotoXY(2 + 5, i + 4); 
116         gameName[2][i] == '0' ? Color(CT_Grey, CT_Blue) : Color(color, CT_Blue); cout << "  ";
117         GotoXY(3 + 5, i + 4); 
118         gameName[3][i] == '0' ? Color(CT_Grey, CT_Blue) : Color(color, CT_Blue); cout << "  ";
119         GotoXY(4 + 5, i + 4);
120         gameName[4][i] == '0' ? Color(CT_Grey, CT_Blue) : Color(color, CT_Blue); cout << "  ";
121         _sleep(20);
122     }
123 
124     Color(CT_Grey, CT_Blue);
125 }
126 
127 //按键选择
128 void  MainMenu::ChooseButton()
129 {
130     while (true)
131     {
132         fflush(stdin);
133         char choose = getch();                        //选择按键
134         PlaySound(TEXT(".\\Music\\选择.wav"), NULL, SND_ASYNC);
135         if (choose == -32)  choose = getch();        //屏蔽-32
136 
137         //当按了方向键,切换按钮
138         if (choose == 72 || choose == 80)
139         {
140             int dPos = 0;
141             switch (choose)
142             {
143             case 72: if ( m_index > 1 )                dPos = -1; break;
144             case 80: if ( m_index < m_child->size() )dPos = +1; break;
145             }
146             if (dPos != 0)                            //发生了变动
147             {
148                 this->RemoveButtonColor();            //清除底色打印
149                 m_index += dPos;
150                 this->AppendButtonColor();            //添加底色打印
151             }
152         }
153 
154         //按Enter确定按键进入子菜单
155         if (choose == 13)
156         {
157             //清除当前菜单按键、切换界面
158             this->RemoveButton();
159             this->ChangingOver();
160 
161             //如果是最低菜单,执行功能函数
162             if (m_child->at(m_index - 1)->m_child == nullptr)
163             {
164                 m_child->at(m_index - 1)->ButtonFunction();
165                 return;
166             }
167 
168             //否则打印子菜单按键
169             m_child->at(m_index - 1)->OutputButton();
170             m_child->at(m_index - 1)->ChooseButton();
171         }    
172     }
173 }
174 
175 //====================  内部函数  ======================
176 
177 //打印所有按键
178 void MainMenu::OutputButton()
179 {
180     if (m_child == nullptr)
181         return;
182 
183     Color(CT_Grey, CT_Black);
184     //遍历打印按钮
185     for (size_t i = 0; i < m_child->size(); i++)
186     {
187         //获取按键信息
188         string* button = m_child->at(i)->m_button;
189 
190         GotoXY(m_buttonX + 0 + 4 * i, m_buttonY);
191         cout << button[0];
192         GotoXY(m_buttonX + 1 + 4 * i, m_buttonY);
193         cout << button[1];
194         GotoXY(m_buttonX + 2 + 4 * i, m_buttonY);
195         cout << button[2];
196     }
197 
198     this->AppendButtonColor();
199 }
200 
201 //清除所有按键
202 void MainMenu::RemoveButton()
203 {
204     if (m_child == nullptr)
205         return;
206 
207     Color(CT_Grey, CT_Black);
208     //遍历打印在按钮位置打印空格,清除按键
209     for (size_t i = 0; i < m_child->size(); i++)
210     {
211         GotoXY(m_buttonX + 0 + 4 * i, m_buttonY);
212         cout << "                        ";
213         GotoXY(m_buttonX + 1 + 4 * i, m_buttonY);
214         cout << "                        ";
215         GotoXY(m_buttonX + 2 + 4 * i, m_buttonY);
216         cout << "                        ";
217     }
218 }
219 
220 //移除按键底色
221 void MainMenu::RemoveButtonColor()
222 {
223     Color(CT_Grey, CT_Black);
224     string* button = m_child->at(m_index - 1)->m_button;
225     GotoXY(m_buttonX + 0 + 4 * (m_index - 1), m_buttonY);
226     cout << button[0];
227     GotoXY(m_buttonX + 1 + 4 * (m_index - 1), m_buttonY);
228     cout << button[1];
229     GotoXY(m_buttonX + 2 + 4 * (m_index - 1), m_buttonY);
230     cout << button[2];
231 
232 }
233 
234 //添加按键底色
235 void MainMenu::AppendButtonColor()
236 {
237     Color(CT_SkyBlue, CT_Red);
238     string* button = m_child->at(m_index - 1)->m_button;
239     GotoXY(m_buttonX + 0 + 4 * (m_index - 1), m_buttonY);
240     cout << button[0];
241     GotoXY(m_buttonX + 1 + 4 * (m_index - 1), m_buttonY);
242     cout << button[1];
243     GotoXY(m_buttonX + 2 + 4 * (m_index - 1), m_buttonY);
244     cout << button[2];
245     Color(CT_Grey, CT_Black);
246 }
247 
248 
249 
250 //将pMainMenu作为子目录链接到本目录
251 void MainMenu::LinkChild(MainMenu* pMainMenu)
252 {
253     pMainMenu->m_father = this;
254 
255     if (this->m_child == nullptr)
256         m_child = new vector < MainMenu* > ;
257 
258     m_child->push_back(pMainMenu);
259 }
260 
261 
262 
263 
264 //打印UI点
265 void MainMenu::PrintUI(char type, int X, int Y)
266 {
267     GotoXY(X, Y);
268     switch (type)
269     {
270     case '0': Color(CT_Grey, CT_Blue);
271         cout << "  "; break;
272     case 'z':  Color(CT_White, CT_Black);
273         cout << ""; break;
274     case '3':  Color(CT_White, CT_Red);
275         cout << ""; break;
276     case '4':  Color(CT_White, CT_Black);
277         cout << ""; break;
278     case '5':   Color(CT_White, CT_Red);
279         cout << ""; break;
280     case '8':  Color(CT_White, CT_Black);
281         cout << ""; break;
282     case 'c':  Color(CT_White, CT_Black);
283         cout << ""; break;
284     case 'e':  Color(CT_Green, CT_White);
285         cout << ""; break;
286     case 't':   Color(CT_White, CT_Black);
287         cout << ""; break;
288     case 'r':   Color(CT_White, CT_Black);
289         cout << ""; break;
290     case 'v':   Color(CT_White, CT_Black);
291         cout << ""; break;
292     case 'b':   Color(CT_White, CT_Black);
293         cout << ""; break;
294     case 'y':  Color(CT_White, CT_Black);
295         cout << ""; break;
296     case 'u':  Color(CT_White, CT_Pink);
297         cout << ""; break;
298     case 'i':   Color(CT_White, CT_Black);
299         cout << ""; break;
300     case 'a':   Color(CT_White, CT_Black);
301         cout << ""; break;
302     case 's':  Color(CT_SkyBlue, CT_White);
303         cout << ""; break;
304     case 'd':  Color(CT_White, CT_Black);
305         cout << ""; break;
306     case 'f':   Color(CT_White, CT_Black);
307         cout << ""; break;
308     case 'm':  Color(CT_Grey, CT_Black);
309         cout << ""; break;
310     case 'n':  Color(CT_Green, CT_White);
311         cout << ""; break;
312     case '2':  Color(CT_White, CT_Black);
313         cout << ""; break;
314     case '1':  Color(CT_White, CT_Black);
315         cout << ""; break;
316     case '6':  Color(CT_White, CT_Black);
317         cout << ""; break;
318     case '7':  Color(CT_White, CT_Black);
319         cout << ""; break;
320     case '9':   Color(CT_SkyBlue, CT_Black);
321         cout << ""; break;
322     case 'q':
323         cout << ""; break;
324     case 'o':   Color(CT_White, CT_Black);
325         cout << ""; break;
326     case 'p':   Color(CT_White, CT_Black);
327         cout << ""; break;
328     case 'w':  Color(CT_Grey, CT_Black);
329         cout << ""; break;
330     case 'g':  Color(CT_White, CT_Red);
331         cout << ""; break;
332     case 'h':  Color(CT_White, CT_Red);
333         cout << ""; break;
334     case 'j':   Color(CT_White, CT_Red);
335         cout << ""; break;
336     case 'k':   Color(CT_White, CT_Red);
337         cout << ""; break;
338     case 'l':   Color(CT_White, CT_Black);
339         cout << ""; break;
340     case 'x':  Color(CT_White, CT_Black);
341         cout << "×"; break;
342 
343         //子弹、手雷
344     case '_':  Color(CT_White, CT_Black); cout << "о"; break;
345     case '+':  Color(CT_White, CT_Black); cout << "¤"; break;
346     case 'C':  Color(CT_White, CT_Black); cout << "·"; break;
347     case 'D':  Color(CT_White, CT_Black); cout << ""; break;
348 
349         //制表符
350     case '!':  Color(CT_Yellow, CT_Red);
351         cout << ""; break;
352     case '&':  Color(CT_Yellow, CT_Red);
353         cout << ""; break;
354     case '@': Color(CT_Yellow, CT_Red);
355         cout << ""; break;
356     case '=': Color(CT_Yellow, CT_Red);
357         cout << ""; break;
358     case '$':  Color(CT_Yellow, CT_Red);
359         cout << ""; break;
360     case ')':  Color(CT_TBlue, CT_Red);
361         cout << ""; break;
362     case '#': Color(CT_Yellow, CT_Red);
363         cout << ""; break;
364     case '-':  Color(CT_Yellow, CT_Red);
365         cout << ""; break;
366     case '(':  Color(CT_Yellow, CT_Red);
367         cout << ""; break;
368     case '*':  Color(CT_Yellow, CT_Red);
369         cout << ""; break;
370     case '%':  Color(CT_Yellow, CT_Red);
371         cout << ""; break;
372         //额外
373     case 'A':  Color(CT_Yellow, CT_White);
374         cout << ""; break;
375     case 'B':  Color(CT_Yellow, CT_White);
376         cout << ""; break;
377     }
378 }
MainMenu.cpp

下面是派生类,也就是登陆菜单中所有实际需要创建的选项

 1级菜单:NewGame 

 1 #ifndef _NEW_GAME_H_
 2 #define _NEW_GAME_H_
 3 
 4 #include "MainMenu.h"
 5 #include "..//Role//Hero.h"
 6 #include "..//Map/Map_1.h"
 7 #include "..//Map/Map_11.h"
 8 #include "..//Map/Map_111.h"
 9 #include "..//Map/Map_22.h"
10 #include "..//Map/Map_211.h"
11 
12 
13 class NewGame : public MainMenu
14 {
15 public:
16     NewGame()
17     {
18         GetButton()[0]="┏━━━━━━━━━┓";
19         GetButton()[1]="┃开  始  新  游  戏┃";
20         GetButton()[2]="┗━━━━━━━━━┛";
21 
22     }
23 
24     //执行按钮功能
25     void ButtonFunction()
26     {
27         int x = GetButtonX();
28         int y = GetButtonY();
29 
30         char name[255] = {};
31 
32         GotoXY(x - 2, y - 2);
33         cout << "┏━━━━━━━━━━━━━┓";
34         GotoXY(x - 1, y - 2);
35         cout << "┃                          ┃";
36         GotoXY(x , y - 2);
37         cout << "┃输入名字:_______________ ┃";
38         GotoXY(x + 1, y - 2);
39         cout << "┃                          ┃";
40         GotoXY(x + 2, y - 2);
41         cout << "┗━━━━━━━━━━━━━┛";
42         GotoXY(x , y + 5); cin >> name;
43 
44         // 音乐 mp3
45         WCHAR mciCmd[] = TEXT("open .//music//background//gamestartup.mp3 alias background"); //.mp3格式的
46         mciSendString(mciCmd, NULL, 0, NULL);
47         mciSendString(TEXT("play background repeat"), NULL, 0, NULL);
48 
49        //====== 游戏初始化 ==========================
50         system("cls");
51         Role* pRole = new Hero(5, RT_CHINA,18,64);
52         pRole->SetName(name);
53         {
54         Body* body = new SniperRifle(2);
55         pRole->GetBackpack()->PushBackBody(body);
56         };
57 
58 
59         Map* pMap = new Map_1();
60         pMap->OutputMap();
61         GameScene* gameScene = new GameScene(pRole, pMap);
62         pRole->InitShape(pMap->GetType().c_str());
63         pRole->GetGameOI()->OutputOI();
64         pRole->OutputRole(pMap);
65         gameScene->GameRuning();
66         
67         //GameRunning结束时返回菜单
68         this->GetFather()->OutputButton();
69         this->GetFather()->ChooseButton();
70     }
71 
72 };
73 
74 
75 #endif // _NEW_GAME_H_
NewGame.h
 1级菜单:OldGame 和2个2级菜单
 1 #ifndef _OLD_GAME_H_
 2 #define _OLD_GAME_H_
 3 
 4 #include "MainMenu.h"
 5 
 6 class OldGame : public MainMenu
 7 {
 8 public:
 9     OldGame()
10     {
11         GetButton()[0] = "┏━━━━━━━━━┓";
12         GetButton()[1] = "┃读  取  旧  游  戏┃";
13         GetButton()[2] = "┗━━━━━━━━━┛";
14     }
15 };
16 
17 
18 #endif // _OLD_GAME_H_
OldGame.h
 1 #ifndef _OLD_GAME1_H_
 2 #define _OLD_GAME1_H_
 3 
 4 #include "MainMenu.h"
 5 
 6 class OldGame1 : public MainMenu
 7 {
 8 public:
 9     OldGame1()
10     {
11         GetButton()[0] = "┏━━━━━━━━━┓";
12         GetButton()[1] = "┃读  取  进  度 一 ┃";
13         GetButton()[2] = "┗━━━━━━━━━┛";
14     }
15 
16 
17     //执行按钮功能
18     void ButtonFunction()
19     {
20         int x = GetButtonX();
21         int y = GetButtonY();
22 
23         GotoXY(x, y);
24         cout << "进度1加载中...";
25     }
26 };
27 
28 
29 #endif // _OLD_GAME1_H_
OldGame1.h
 1 #ifndef _OLD_GAME2_H_
 2 #define _OLD_GAME2_H_
 3 
 4 #include "MainMenu.h"
 5 
 6 class OldGame2 : public MainMenu
 7 {
 8 public:
 9     OldGame2()
10     {
11         GetButton()[0] = "┏━━━━━━━━━┓";
12         GetButton()[1] = "┃读  取  进  度 二 ┃";
13         GetButton()[2] = "┗━━━━━━━━━┛";
14     }
15 
16 
17     //执行按钮功能
18     void ButtonFunction()
19     {
20         int x = GetButtonX();
21         int y = GetButtonY();
22 
23         GotoXY(x, y);
24         cout << "进度2加载中...";
25 
26     }
27 };
28 
29 
30 #endif // _OLD_GAME2_H_
OldGame2.h
 1级菜单:SetGame 和2个2级菜单
 1 #ifndef _SET_GAME_H_
 2 #define _SET_GAME_H_
 3 
 4 #include "MainMenu.h"
 5 
 6 class SetGame : public MainMenu
 7 {
 8 public:
 9     SetGame()
10     {
11         GetButton()[0] = "┏━━━━━━━━━┓";
12         GetButton()[1] = "┃  游  戏  设  置  ┃";
13         GetButton()[2] = "┗━━━━━━━━━┛";
14     }
15 
16 
17 
18 
19 };
20 
21 
22 #endif // _SET_GAME_H_
SetGame.h
 1 #ifndef _VIDEO_H_
 2 #define _VIDEO_H_
 3 
 4 #include "MainMenu.h"
 5 
 6 class Video : public MainMenu
 7 {
 8 public:
 9     Video()
10     {
11         GetButton()[0] = "┏━━━━━━━━━┓";
12         GetButton()[1] = "┃  视  频  设  置  ┃";
13         GetButton()[2] = "┗━━━━━━━━━┛";
14     }
15 
16 
17     //执行按钮功能
18     void ButtonFunction()
19     {
20         int x = GetButtonX();
21         int y = GetButtonY();
22 
23         GotoXY(x, y);
24         cout << "按方向键调整亮度";
25 
26     }
27 };
28 
29 
30 #endif // _VIDEO_H_
Video.h
 1 #ifndef _AUDIO_H_
 2 #define _AUDIO_H_
 3 
 4 #include "MainMenu.h"
 5 
 6 class Audio : public MainMenu
 7 {
 8 public:
 9     Audio()
10     {
11         GetButton()[0] = "┏━━━━━━━━━┓";
12         GetButton()[1] = "┃  音  频  设  置  ┃";
13         GetButton()[2] = "┗━━━━━━━━━┛";
14     }
15 
16 
17     //执行按钮功能
18     void ButtonFunction()
19     {
20         int x = GetButtonX();
21         int y = GetButtonY();
22 
23         GotoXY(x, y);
24         cout << "按方向键调整大小";
25 
26     }
27 };
28 
29 
30 #endif // _AUDIO_H_
Audio.h

1级菜单:GameInfo

 1 #ifndef _Game_Info_H_
 2 #define _Game_Info_H_
 3 
 4 #include "MainMenu.h"
 5 
 6 //============= 登录界面 ===============
 7 
 8 class GameInfo : public MainMenu
 9 {
10 public:
11     GameInfo();
12 
13 public://==== 外部接口 ======
14     virtual void ChangingOver();        //切换界面
15 
16     virtual void ButtonFunction();        //执行按钮功能
17 
18 
19 
20 };
21 
22 #endif // _Game_Info_H_
GameInfo.h
  1 #include"..//Marco.h"
  2 #include"..//Tip.h"
  3 
  4 #include "GameInfo.h"
  5 using namespace std;
  6 
  7 
  8 GameInfo::GameInfo()
  9 {
 10     GetButton()[0]="┏━━━━━━━━━┓";
 11     GetButton()[1]="┃  关  于  我  们  ┃";
 12     GetButton()[2]="┗━━━━━━━━━┛";
 13 }
 14 
 15 
 16 //切换界面
 17 void GameInfo::ChangingOver()
 18 {
 19 
 20 }
 21 
 22 //执行按钮功能
 23 void GameInfo::ButtonFunction()
 24 {
 25     //游戏简介
 26     string introduction[26] = {};
 27     introduction[0] = "    自从前苏联时期美、苏两国实行“双方保证毁灭政策”之后,世界一直出于冷战与和平的状态......";
 28     introduction[1] = "爱因斯坦曾说“我不知道第三次世界大战用什么武器,但是第四次世界大战人类将只会用木棒和石头打”";
 29     introduction[2] = "也就是说以现在的科技文明爆发战争就等于自我毁灭。                                            ";
 30     introduction[3] = "    八十年代美国有个学者写过一本书《文明的冲突》,很出名,大致意思是未来世界冲突不再像冷战那";
 31     introduction[4] = "样,而是政治集团和意识形态的冲突,而最终归结到文明之间的冲突,世界主要分为基督教文明,佛教文";
 32     introduction[5] = "明和伊斯兰教文明。基督教文明和佛教文明与外界冲突很有限,更多表现是经济战争和领土纠纷,而且范";
 33     introduction[6] = "围和强度是可控的。只有伊斯兰教文明和外部世界有强烈的对抗性和排他性。未来伊斯兰教很可能会越来";
 34     introduction[7] = "越趋向保守和原教旨主义,瓦哈比之类的激进教派将逐步占据绝对主导,开明的穆斯林将逐步被排挤和屠";
 35     introduction[8] = "杀,当伊斯兰世界完成内部极端主义的整合和统一后,矛头将逐步对外,会在全世界掀起全面的圣战。新";
 36     introduction[9] = "的统一的阿拉伯帝国将会重新出现,它将在中东的边境将开展大肆的侵略,在全世界将进行全面的高强度";
 37     introduction[10] = "的有政府组织的自杀式恐怖袭击,试图用瓦哈比派统治全世界,到那个时候,全世界将被迫和伊斯兰文明";
 38     introduction[11] = "进行一场全面战争,甚至会相互爆发大规模种族屠杀,只有通过这种方式,文明的冲突才可最终得到解决";
 39     introduction[12] = "                                                                                            ";
 40     introduction[13] = "    历史历历在目......                                                                        ";
 41     introduction[14] = "    1979年,震惊世界的伊朗伊斯兰革命爆发,推翻了亲美的巴列维封建王朝。                        ";
 42     introduction[15] = "    同样在1979年末,苏联出兵入侵阿富汗,美国开始资助阿富汗及巴基斯坦的圣战者抗苏武装。        ";
 43     introduction[16] = "    2003年,美国总统小布什以伊拉克萨达姆政权拥有“大规模杀伤性武器”为由,出兵侵占伊拉克。尽";
 44     introduction[17] = "管推翻了萨达姆的独裁统治,最终却没有找到任何“大规模杀伤性武器”,美国此举的副作用是大规模摧";
 45     introduction[18] = "毁了伊拉克的各种社会机构,客观上促成伊境内恐怖主义组织如雨后春笋般涌现......                ";
 46     introduction[19] = "    2006年10月,本.拉登副手扎卡维宣布成立“伊拉克伊斯兰国”......                            ";
 47     introduction[20] = "    2011年,“阿拉伯之春”波及叙利亚,叙开始动乱,叙利亚从此陷入旷日持久的血腥宗派冲突。“伊";
 48     introduction[21] = "斯兰国”在血腥的叙利亚内战中“崛起”,他们在叙利亚东部地区建立了根据地,伊斯兰国袭击的范围不";
 49     introduction[22] = "断扩大,冲突次数不断增加,世界人民饱受极端组织的困扰......                                    ";
 50     introduction[23] = "    为了维护世界和平,2014年9月,美国组建了一个包括中、俄、英、法等54个国家和欧盟 、北约以及";
 51     introduction[24] = "阿盟等地区组织在内的国际联盟以打击IS;从此,第三次世界大战全面爆发……                        ";
 52     introduction[25] = "    虽然我们的生活暂未受到恐怖袭击的影响,但为了世界的和平,我避免不了卷入这场战争。        ";
 53 
 54     Color(CT_White, CT_Black);
 55 
 56     //打印信息
 57     system("cls");
 58     GotoXY(2, 21);
 59     cout << "【 游 戏 信 息 】";
 60     GotoXY(4, 3);
 61     cout << "●游戏名称:英文名  World War III";
 62     GotoXY(6, 3);
 63     cout << "            中文名 第三次世界大战";
 64     GotoXY(8, 3);
 65     cout << "●游戏类型: Adventure puzzle RPG";
 66     GotoXY(10, 3);
 67     cout << "●学生姓名: xx";
 68     GotoXY(12, 3);
 69     cout << "●版权所有:xxx";
 70     GotoXY(14, 21);
 71     cout << "【 游 戏 背 景 】";
 72 
 73     //printRow开始打印的行号 (开始行号会依次上升 -2)
 74     //indexMin当前打印最小角标(最小角标为0,但当总行数超过6行时依次增加)
 75     //indexMax当前打印最大角标(最大角标会依次递增 +1)
 76     //size 表示可现实最大行数
 77     int  size = 7;
 78     int  indexMin = 0;
 79     int  dTime = 2000;
 80     for (int printRow = 30, indexMax = 0; indexMax < 26; indexMax++)
 81     {
 82         //当总行速达到6时,最小角标开始递增 ,开始、结束打印的行号不再变化
 83         if (indexMax > size)
 84             indexMin = indexMax - size;
 85 
 86         for (int row = printRow, j = indexMin; j <= indexMax; j++, row += 2)
 87         {
 88             GotoXY(row, 3);
 89             //最新的一行一个字一个字打印
 90             if (j == indexMax)
 91             {
 92                 Color(CT_White, CT_Red);
 93                 cout << introduction[j];
 94                 Color(CT_White, CT_Black);
 95                 break;
 96             }
 97             cout << introduction[j];
 98         }
 99 
100         if (indexMax < size)
101             printRow -= 2;
102 
103         //停顿时间
104         _sleep(dTime);
105 
106         //按键修改速度
107         if (kbhit())
108         {
109             char ch = getch();
110             dTime = dTime / 2;
111         }
112     }
113     char ch = getch();
114     //结束时返回菜单
115     this->GetFather()->OutputFrame();
116     this->GetFather()->OutputButton();
117     this->GetFather()->ChooseButton();
118 }
GameInfo.cpp

 

1级菜单:退出游戏

 1 #ifndef _EXIT_GAME_H_
 2 #define _EXIT_GAME_H_
 3 
 4 #include "MainMenu.h"
 5 
 6 
 7 class ExitGame : public MainMenu
 8 {
 9 public:
10     ExitGame()
11     {
12         GetButton()[0] = "┏━━━━━━━━━┓";
13         GetButton()[1] = "┃太危险了还是离开吧┃";
14         GetButton()[2] = "┗━━━━━━━━━┛";
15     }
16 
17 
18 
19     //执行按钮功能
20     void ButtonFunction()
21     {
22         exit(0);
23     }
24 
25 };
26 
27 
28 #endif // _EXIT_GAME_H_
ExitGame.h

还有一个可以复用的菜单:返回上一层菜单

 1 #ifndef _RETURN_H_
 2 #define _RETURN_H_
 3 
 4 #include "MainMenu.h"
 5 
 6 
 7 class Return : public MainMenu
 8 {
 9 public:
10     Return()
11     {
12         GetButton()[0] = "┏━━━━━━━━━┓";
13         GetButton()[1] = "┃  返 回 上 一 级  ┃";
14         GetButton()[2] = "┗━━━━━━━━━┛";
15     }
16 
17     //执行按钮功能
18     void ButtonFunction()
19     {
20         this->RemoveButton();
21         this->GetFather()->GetFather()->OutputButton();
22         this->GetFather()->GetFather()->ChooseButton();
23     }
24 
25 };
26 
27 
28 #endif // _RETURN_H_
Return.h

 

2、通过上面的的类可以创建出菜单,然后通过一个登陆管理类,来设置这些按钮的层级关系(树结构中的位置关系)

 1 #ifndef _LAND_SURFACE_H_
 2 #define _LAND_SURFACE_H_
 3 
 4 #include "MainMenu.h"
 5 #include "GameInfo.h"
 6 #include "NewGame.h"
 7 #include "ExitGame.h"
 8 #include "Return.h"
 9 #include "OldGame.h"
10 #include "OldGame1.h"
11 #include "OldGame2.h"
12 #include "SetGame.h"
13 #include "Audio.h"
14 #include "Video.h"
15 //=======用来管理登陆系统============
16 class LandSurface
17 {
18 public:
19     //初始化登陆界面(静态函数,不用创建对象)
20     static MainMenu* InitLandSurface()
21     {
22         MainMenu* pMainMenu = new MainMenu();
23         //主菜单
24         MainMenu* pNewGame = new NewGame();
25         pMainMenu->LinkChild(pNewGame);
26         MainMenu* pOldGame = new OldGame();
27         pMainMenu->LinkChild(pOldGame);
28         MainMenu* pSetGame = new SetGame();
29         pMainMenu->LinkChild(pSetGame);
30         MainMenu* pGameInfo = new GameInfo();
31         pMainMenu->LinkChild(pGameInfo);
32         MainMenu* pExitGame = new ExitGame();
33         pMainMenu->LinkChild(pExitGame);
34         //OldGame
35         MainMenu* pOldGame1 = new OldGame1();
36         pOldGame->LinkChild(pOldGame1);
37         MainMenu* pOldGame2 = new OldGame2();
38         pOldGame->LinkChild(pOldGame2);
39         MainMenu* pReturn1 = new Return();
40         pOldGame->LinkChild(pReturn1);
41         //SetGame
42         MainMenu* pAudio = new Audio();
43         pSetGame->LinkChild(pAudio);
44         MainMenu* pVideo = new Video();
45         pSetGame->LinkChild(pVideo);
46         MainMenu* pReturn2 = new Return();
47         pSetGame->LinkChild(pReturn2);
48 
49         return pMainMenu;
50     }
51 
52 };
53 
54 
55 #endif // _LAND_SURFACE_H_
LandSurface.h

 

总结:通过这段代码,可以实现控制台中制作出一个自动排成1列的菜单目录,可以给任意菜单添加和删除子菜单,实现了菜单与子菜单之间的进入和返回操作

截图:

 

转载于:https://www.cnblogs.com/nanwei/p/7087683.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/371847.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

不存在_施文忠 | ”存在“与“不存在”——巴蜀文明概论

海德格尔有句名言&#xff1a;“存在者存在&#xff0c;不存在者不存在&#xff01;”四川&#xff0c;一个伟大的存在&#xff0c;偏偏存在于四川的口头禅却是“不存在”。在不存在中追求存在&#xff0c;在存在中摆脱存在。六月白鹿镇&#xff0c;书院学习了《李白与海德格尔…

Altium 原理图出现元件“Extra Pin…in Normal of part ”警告的解决方法

转载于&#xff1a; http://blog.csdn.net/idoming/article/details/45575627 使用Altium Designer的时候编译完后&#xff0c;只关注过错误没有关注过警告&#xff0c;现在认真排查一下有哪些警告。 正在进行的项目原理图编译完成后提示标题中的警告信息。经过在网上搜索&…

Zookeeper开源客户端框架Curator简介

Curator是Netflix开源的一套ZooKeeper客户端框架. Netflix在使用ZooKeeper的过程中发现ZooKeeper自带的客户端太底层, 应用方在使用的时候需要自己处理很多事情, 于是在它的基础上包装了一下, 提供了一套更好用的客户端框架. Netflix在用ZooKeeper的过程中遇到的问题, 我们也遇…

适当的Java堆大小的5个技巧

确定生产系统合适的Java堆大小不是一件容易的事。 在我的Java EE企业经验中&#xff0c;我发现由于Java堆容量和调整不足而导致的多个性能问题。 本文将为您提供5个技巧&#xff0c;这些技巧可以帮助您确定当前或新生产环境的最佳Java堆大小。 这些技巧中的一些对于预防和解决j…

曝光原理_泰国精戈咖啡效果反馈 作用原理曝光

我的男人才三十五六&#xff0c;两个人就开始分开睡了&#xff0c;自从咱们在一起以来&#xff0c;咱们的感情一向很好&#xff0c;这是十分调和的。但随着年纪的添加&#xff0c;我逐渐发现他身体阑珊的越来越凶猛&#xff0c;夫妻生活方面硬度逐渐下降&#xff0c;时间也越来…

EasyCriteria –使用JPA Criteria的简便方法

今天&#xff0c;我们将看到有关此工具的信息&#xff0c;该工具使使用JPA Criteria更加容易。 使用该库的应用程序将在JPA实现中更加简洁&#xff0c;易于使用和可移植。 在本文的结尾&#xff0c;您将找到要下载的源代码。 什么是标准&#xff1f; 当前是创建动态查询的最佳…

语言模拟蒲丰问题_R语言小数定律的保险业应用:泊松分布模拟索赔次数

原文链接&#xff1a;拓端数据科技 / Welcome to tecdat​tecdat.cn在保险业中&#xff0c;由于分散投资&#xff0c;通常会在合法的大型投资组合中提及大数定律。在一定时期内&#xff0c;损失“可预测”。当然&#xff0c;在标准的统计假设下&#xff0c;即有限的期望值和独立…

获取人口_「微科普」14亿人口数据是如何得到的?

中国经济交出了2019年终答卷GDP总量近百万亿元人均GDP突破1万美元……小伙伴们在关心经济发展的同时也非常关注人口数据14亿人口的话题嗖的一下就上了热搜大家想不想知道14亿人口的数据是怎么得到的&#xff1f;我们今天就来科普一下如何获取人口总量&#xff1f;通常情况下&am…

8.动态规划(1)——字符串的编辑距离

动态规划的算法题往往都是各大公司笔试题的常客。在不少算法类的微信公众号中&#xff0c;关于“动态规划”的文章屡见不鲜&#xff0c;都在试图用最浅显易懂的文字来描述讲解动态规划&#xff0c;甚至有的用漫画来解释&#xff0c;认真读每一篇公众号推送的文章实际上都能读得…

静态属性_Java面试题—内部类和静态内部类的区别

内部类和静态内部类的区别内部类&#xff1a;1、内部类中的变量和方法不能声明为静态的。2、内部类实例化&#xff1a;B是A的内部类&#xff0c;实例化B&#xff1a;A.B b new A().new B()。3、内部类可以引用外部类的静态或者非静态属性及方法。静态内部类&#xff1a;1、静态…

Eclipse安装以及JDK环境变量配置

首先是下载Eclipse&#xff1b;点击链接打开Eclipse官网eclipse官网点击DownLoad Packages&#xff0c;注意是点击“DownLoad Packages”点击你需要的版本开始下载&#xff08;一般是64bit Eclipse IDE&#xff09;等待几秒钟&#xff0c;开始下载这样Eclipse已经下载好了&…

完整的Web应用程序Tomcat JSF Primefaces JPA Hibernate –第1部分

我们创建了这篇文章&#xff0c;将展示如何使用以下工具创建完整的Web应用程序&#xff1a;Tomcat7&#xff0c;带有Primefaces的JSF2&#xff08;Facelets和Libraries&#xff09;&#xff08;具有AutoComplete&#xff09;&#xff0c;JPA / Hibernate&#xff08;具有NxN关系…

mysql主从架构升级_实战项目——mysql主从架构的实现

一主一从1.1 环境准备&#xff1a;centos系统服务器2台、 一台用户做Mysql主服务器&#xff0c; 一台用于做Mysql从服务器&#xff0c; 配置好yum源、 防火墙关闭、 各节点时钟服务同步、 各节点之间可以通过主机名互相通信1.2 准备步骤&#xff1a;1)iptables -F && s…

FastReport.Net使用:[30]对话框使用

使用对话框需要知道的地方 1.按钮的DialogResult属性。 假如DialogResult属性值为OK的按钮被点击&#xff0c;报表将会展现后面的对话框或者报表页&#xff1b;如果属性值为None&#xff0c;则停留在当前窗体&#xff1b;如果为其他值&#xff0c;则直接退出报表打印&#xff0…

改善Java EE生产支持技能的8种方法

参与Java EE生产支持的每个人都知道这项工作可能很困难。 7/24传呼机支持&#xff0c;定期处理的多个事件和错误修复&#xff0c;来自客户和管理团队的压力&#xff0c;要求它们尽快解决生产问题并防止再次发生。 在日常工作中&#xff0c;您还必须照顾由多个IT交付团队驱动的多…

varnish基础

varnish概念 初步认识 首先来跟我学习&#xff0c;v~a~r~n~i~s~h~~ &#xff0c;学会了没有~ 当然还有很重要的一个概念&#xff0c;它是高性能缓存服务器&#xff0c;举个例子。 好比我们要去买东西&#xff0c;所有的我们需要的东西是在超市厂家生产出来的&#xff0c;我们需…

基于Jenkins+Gitlab的自动化部署实战

故事背景 一个中小型企业&#xff0c;是典型的互联网公司&#xff0c;当初期的时候可能运维只能标配到2~3人&#xff0c;此时随着公司的发展&#xff0c;项目会逐渐增多。前期部署项目可能都是手动的&#xff0c; 俗称“人肉部署”&#xff0c;这简直是无比的痛苦&#xff0c;不…

cmd如何刷新MySQL数据库_怎样在cmd中用命令操作MySQL数据库 需要技巧

用命令来操作MySQL是工作必备的&#xff0c;今天我就来分享一下cmd命令操作MySQL数据库的方法&#xff0c;希望有帮助。工具/材料电脑xampp操作方法01首先&#xff0c;启动MySQL服务才行哦。这里我是用xampp集成的数据库&#xff0c;方便&#xff0c;点击‘start’。02如图&…

[BZOJ3529][Sdoi2014]数表

[BZOJ3529][Sdoi2014]数表 试题描述 有一张Nm的数表&#xff0c;其第i行第j列&#xff08;1 < i < n&#xff0c;1 < j < m&#xff09;的数值为能同时整除i和j的所有自然数之和。给定a&#xff0c;计算数表中不大于a的数之和。输入 输入包含多组数据。输入的第一行…

ZK的实际应用:MVVM –表单绑定

这是我们从头开始构建ZK应用程序的第二集。 上一篇文章涉及使用MVVM将数据加载和呈现到表中。 在本文中&#xff0c;我们将向您介绍ZK MVVM的表单绑定。 目的 我们将构建一个“添加”功能&#xff0c;使我们能够将新条目保存到清单中。 单击“添加”时出现表格 单击“保存”…