|
1 | | -#ifndef SCREEN_H_H |
2 | | -#define SCREEN_H_H |
3 | | -#include<windows.h> |
4 | | -#include<string> |
5 | | -#include<conio.h> |
6 | | -#include<iostream> |
7 | | -#include<fstream> |
8 | | -#include<direct.h> |
9 | | -#include "def" |
10 | | -class Egg; |
11 | | -class Map; |
12 | | -class People; |
13 | | -class Screen{ |
14 | | -private: |
15 | | - Egg &egg; |
16 | | - Map ↦ |
17 | | - People &people; |
18 | | - HANDLE handle; |
19 | | -public: |
20 | | - struct Data{ |
21 | | - int lang,mode; |
22 | | - char * savefile_name; |
23 | | - }; |
24 | | -private: |
25 | | - Data data; |
26 | | -public: |
27 | | - void title(const std::string &s){ |
28 | | - system(("title "+s).c_str()); |
29 | | - } |
30 | | - void set_length_width(const int &length,const int &width){ |
31 | | - system(("mode "+std::to_string(length)+","+std::to_string(width)).c_str()); |
32 | | - } |
33 | | - void clear(){ |
34 | | - system("CLS"); |
35 | | - } |
36 | | - void init_lang(int &lang); |
37 | | - void import(); |
38 | | - Screen(Egg &_egg,Map &_m,People &_p,bool isedit,int argc,char ** argv); |
39 | | - ~Screen(); |
40 | | - Data &get_data(){return data;} |
41 | | - void setting(); |
42 | | - void alert(const std::string &title,const std::string &content); |
43 | | - void save(); |
44 | | -}; |
45 | | -#include "Map.h" |
46 | | -#include "People.h" |
47 | | -#include "Eggs.h" |
48 | | -void Screen::init_lang(int &lang){ |
49 | | - clear(); |
50 | | - lang=unable; |
51 | | - ask:std::cout << "Please Choose language.\n请设置语言。\n" |
52 | | - "English[E]\tChinese[C]\n" |
53 | | - "英文[E]\t中文[C]\n"; |
54 | | - lang=getch(); |
55 | | - if(lang=='c' || lang=='C') lang=Chinese; |
56 | | - else if(lang=='e' || lang=='E') lang=English; |
57 | | - else if(lang==224) lang=unable;//egg |
58 | | - else{ |
59 | | - std::cout << "Error:cannot set this language.\n" |
60 | | - "错误:不能设置为此语言。\n"; |
61 | | - goto ask; |
62 | | - } |
63 | | -} |
64 | | -void Screen::import(){ |
65 | | - std::ifstream fin(data.savefile_name); |
66 | | - map.imports(fin); |
67 | | - people.imports(fin); |
68 | | - egg.imports(fin); |
69 | | - fin >> data.mode >> data.lang; |
70 | | - fin.close(); |
71 | | -} |
72 | | -Screen::Screen(Egg &_egg,Map &_m,People &_p,bool isedit,int argc,char ** argv):egg(_egg),map(_m),people(_p){ |
73 | | - handle=GetStdHandle(STD_OUTPUT_HANDLE); |
74 | | - if(isedit){ |
75 | | - title("我的地图(My-Map)"); |
76 | | - } else{ |
77 | | - title("MapReader[read only]"); |
78 | | - } |
79 | | - set_length_width(COLS,LINES+ADD_LINE); |
80 | | - string background_music_name=argv[0]; |
81 | | - while(background_music_name.back()!='\\'){ |
82 | | - background_music_name.pop_back(); |
83 | | - } |
84 | | - background_music_name+="defines\\sound\\1st.mp3"; |
85 | | -// alert("提示","background_music_name="+background_music_name); |
86 | | - system(("cd \""+std::string(_getcwd(NULL,0))+"\"").c_str()); |
87 | | - system(("start "+background_music_name).c_str()); |
88 | | - if(argc==1){ |
89 | | - data.savefile_name=SAVE_NAME; |
90 | | - init_lang(data.lang); |
91 | | - clear(); |
92 | | - if(data.lang==Chinese){ |
93 | | - cout << "请问您是否要导入存档?如果不导入,存档可能丢失。(本功能测试中)\n"; |
94 | | - cout << "按'y'键导入存档。"; |
95 | | - if(getch()=='y'){ |
96 | | - cout << "加载中……"; |
97 | | - import(); |
98 | | - } |
99 | | - } else if(data.lang==English){ |
100 | | - cout << "Do you want to import the archive? If you do not import, the archive may be lost.(in this function test)\n"; |
101 | | - cout << "Press the 'y' key to import the archive."; |
102 | | - if(getch()=='y'){ |
103 | | - cout << "loading..."; |
104 | | - import(); |
105 | | - } |
106 | | - } |
107 | | - |
108 | | - } else if(argc==2){ |
109 | | - data.savefile_name=argv[1]; |
110 | | - import(); |
111 | | - } |
112 | | - clear(); |
113 | | -} |
114 | | -Screen::~Screen(){ |
115 | | - save(); |
116 | | -} |
117 | | -void Screen::setting(){ |
118 | | - int choose; |
119 | | - do{ |
120 | | - system("CLS"); |
121 | | - if(data.lang==Chinese){ |
122 | | - //language:Chinese |
123 | | - //语言:中文 |
124 | | - std::cout << "模式:"; |
125 | | - } else if(data.lang==English){ |
126 | | - //language:English |
127 | | - //语言:英文 |
128 | | - std::cout << "pattern:"; |
129 | | - } |
130 | | - std::cout << mode_content[data.lang][data.mode]; |
131 | | - if(data.lang==Chinese){ |
132 | | - //language:Chinese |
133 | | - //语言:中文 |
134 | | - std::cout << "\n按左右键选择,按q键退出。"; |
135 | | - } else if(data.lang==English){ |
136 | | - //language:English |
137 | | - //语言:英文 |
138 | | - std::cout << "\nPress the left and right keys to select, and press the q key to exit."; |
139 | | - } |
140 | | - choose=getch(); |
141 | | - if(choose==224){ |
142 | | - choose=getch(); |
143 | | - } |
144 | | - switch(choose){ |
145 | | - case 77://右键 |
146 | | - data.mode=(data.mode+1)%MODE_COUNT; |
147 | | - break; |
148 | | - case 75://左键 |
149 | | - data.mode=(data.mode-1+MODE_COUNT)%MODE_COUNT; |
150 | | - break; |
151 | | - } |
152 | | - } while(choose!='q' && choose!='Q'); |
153 | | -} |
154 | | -void Screen::alert(const std::string &title,const std::string &content){ |
155 | | - MessageBox(NULL,content.c_str(),title.c_str(),MB_OK); |
156 | | -} |
157 | | -void Screen::save(){ |
158 | | - std::ofstream fout(data.savefile_name); |
159 | | - map.save(fout); |
160 | | - people.save(fout); |
161 | | - egg.save(fout); |
162 | | - fout << data.mode << ' ' << data.lang << endl; |
163 | | - fout.close(); |
164 | | -} |
165 | | -#endif |
| 1 | +#ifndef SCREEN_H_H |
| 2 | +#define SCREEN_H_H |
| 3 | +#include<windows.h> |
| 4 | +#include<string> |
| 5 | +#include<conio.h> |
| 6 | +#include<iostream> |
| 7 | +#include<fstream> |
| 8 | +#include<direct.h> |
| 9 | +#include "def" |
| 10 | +class Egg; |
| 11 | +class Map; |
| 12 | +class People; |
| 13 | +class Screen{ |
| 14 | +private: |
| 15 | + Egg &egg; |
| 16 | + Map ↦ |
| 17 | + People &people; |
| 18 | + HANDLE handle; |
| 19 | +public: |
| 20 | + struct Data{ |
| 21 | + int lang,mode; |
| 22 | + char * savefile_name; |
| 23 | + }; |
| 24 | +private: |
| 25 | + Data data; |
| 26 | +public: |
| 27 | + void title(const std::string &s){ |
| 28 | + system(("title "+s).c_str()); |
| 29 | + } |
| 30 | + void set_length_width(const int &length,const int &width){ |
| 31 | + system(("mode "+std::to_string(length)+","+std::to_string(width)).c_str()); |
| 32 | + } |
| 33 | + void clear(){ |
| 34 | + system("CLS"); |
| 35 | + } |
| 36 | + void init_lang(int &lang); |
| 37 | + void import(); |
| 38 | + Screen(Egg &_egg,Map &_m,People &_p,bool isedit,int argc,char ** argv); |
| 39 | + ~Screen(); |
| 40 | + Data &get_data(){return data;} |
| 41 | + void setting(); |
| 42 | + void alert(const std::string &title,const std::string &content); |
| 43 | + void save(); |
| 44 | +}; |
| 45 | +#include "Map.h" |
| 46 | +#include "People.h" |
| 47 | +#include "Eggs.h" |
| 48 | +void Screen::init_lang(int &lang){ |
| 49 | + clear(); |
| 50 | + lang=unable; |
| 51 | + ask:std::cout << "Please Choose language.\n请设置语言。\n" |
| 52 | + "English[E]\tChinese[C]\n" |
| 53 | + "英文[E]\t中文[C]\n"; |
| 54 | + lang=getch(); |
| 55 | + if(lang=='c' || lang=='C') lang=Chinese; |
| 56 | + else if(lang=='e' || lang=='E') lang=English; |
| 57 | + else if(lang==224) lang=unable;//egg |
| 58 | + else{ |
| 59 | + std::cout << "Error:cannot set this language.\n" |
| 60 | + "错误:不能设置为此语言。\n"; |
| 61 | + goto ask; |
| 62 | + } |
| 63 | +} |
| 64 | +void Screen::import(){ |
| 65 | + std::ifstream fin(data.savefile_name); |
| 66 | + map.imports(fin); |
| 67 | + people.imports(fin); |
| 68 | + egg.imports(fin); |
| 69 | + fin >> data.mode >> data.lang; |
| 70 | + fin.close(); |
| 71 | +} |
| 72 | +Screen::Screen(Egg &_egg,Map &_m,People &_p,bool isedit,int argc,char ** argv):egg(_egg),map(_m),people(_p){ |
| 73 | + handle=GetStdHandle(STD_OUTPUT_HANDLE); |
| 74 | + if(isedit){ |
| 75 | + title("我的地图(My-Map)"); |
| 76 | + } else{ |
| 77 | + title("MapReader[read only]"); |
| 78 | + } |
| 79 | + set_length_width(COLS,LINES+ADD_LINE); |
| 80 | + string background_music_name=argv[0]; |
| 81 | + while(background_music_name.back()!='\\'){ |
| 82 | + background_music_name.pop_back(); |
| 83 | + } |
| 84 | + background_music_name+="defines\\sound\\1st.mp3"; |
| 85 | +// alert("提示","background_music_name="+background_music_name); |
| 86 | + system(("cd \""+std::string(_getcwd(NULL,0))+"\"").c_str()); |
| 87 | + system(("start "+background_music_name).c_str()); |
| 88 | + if(argc==1){ |
| 89 | + data.savefile_name=SAVE_NAME; |
| 90 | + init_lang(data.lang); |
| 91 | + clear(); |
| 92 | + if(data.lang==Chinese){ |
| 93 | + cout << "请问您是否要导入存档?如果不导入,存档可能丢失。(本功能测试中)\n"; |
| 94 | + cout << "按'y'键导入存档。"; |
| 95 | + char ch=getch(); |
| 96 | + if(ch=='y' || ch=='Y'){ |
| 97 | + cout << "加载中……"; |
| 98 | + import(); |
| 99 | + } |
| 100 | + } else if(data.lang==English){ |
| 101 | + cout << "Do you want to import the archive? If you do not import, the archive may be lost.(in this function test)\n"; |
| 102 | + cout << "Press the 'y' key to import the archive."; |
| 103 | + char ch=getch(); |
| 104 | + if(ch=='y' || ch=='Y'){ |
| 105 | + cout << "loading..."; |
| 106 | + import(); |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + } else if(argc==2){ |
| 111 | + data.savefile_name=argv[1]; |
| 112 | + import(); |
| 113 | + } |
| 114 | + clear(); |
| 115 | +} |
| 116 | +Screen::~Screen(){ |
| 117 | + save(); |
| 118 | +} |
| 119 | +void Screen::setting(){ |
| 120 | + int choose; |
| 121 | + do{ |
| 122 | + system("CLS"); |
| 123 | + if(data.lang==Chinese){ |
| 124 | + //language:Chinese |
| 125 | + //语言:中文 |
| 126 | + std::cout << "模式:"; |
| 127 | + } else if(data.lang==English){ |
| 128 | + //language:English |
| 129 | + //语言:英文 |
| 130 | + std::cout << "pattern:"; |
| 131 | + } |
| 132 | + std::cout << mode_content[data.lang][data.mode]; |
| 133 | + if(data.lang==Chinese){ |
| 134 | + //language:Chinese |
| 135 | + //语言:中文 |
| 136 | + std::cout << "\n按左右键选择,按q键退出。"; |
| 137 | + } else if(data.lang==English){ |
| 138 | + //language:English |
| 139 | + //语言:英文 |
| 140 | + std::cout << "\nPress the left and right keys to select, and press the q key to exit."; |
| 141 | + } |
| 142 | + choose=getch(); |
| 143 | + if(choose==224){ |
| 144 | + choose=getch(); |
| 145 | + } |
| 146 | + switch(choose){ |
| 147 | + case 77://右键 |
| 148 | + data.mode=(data.mode+1)%MODE_COUNT; |
| 149 | + break; |
| 150 | + case 75://左键 |
| 151 | + data.mode=(data.mode-1+MODE_COUNT)%MODE_COUNT; |
| 152 | + break; |
| 153 | + } |
| 154 | + } while(choose!='q' && choose!='Q'); |
| 155 | +} |
| 156 | +void Screen::alert(const std::string &title,const std::string &content){ |
| 157 | + MessageBox(NULL,content.c_str(),title.c_str(),MB_OK); |
| 158 | +} |
| 159 | +void Screen::save(){ |
| 160 | + std::ofstream fout(data.savefile_name); |
| 161 | + map.save(fout); |
| 162 | + people.save(fout); |
| 163 | + egg.save(fout); |
| 164 | + fout << data.mode << ' ' << data.lang << endl; |
| 165 | + fout.close(); |
| 166 | +} |
| 167 | +#endif |
0 commit comments