游戏开发日志支线3
2026-02-12 22:26:27
发布于:香港
接上回
游戏:Typing Game
更新版本:0.3
代码:李伙子ia
美术:也没美术啊
翻译:Artificial Intelligence
团队:新手团
这次更新了1条内容:地狱模式
首先,我们引入了一项新技术
#include<string>
#include<regex> //正则表达式头文件
std::string show_newline(const std::string& str){
return std::regex_replace(str,std::regex("\r")," [Enter]");
}
#include<iostream>
int main(){
std::cout<<show_newline("Hello World!\r"); //Hello World! [Enter]
return 0;
}
你可能觉得没啥用,毕竟这东西只有一个‘替换文本’的作用
但他可以保持原本的作用,所以……
#include<string>
#include<regex> //正则表达式头文件
std::string show_newline(const std::string& str){
return std::regex_replace(str,std::regex("\r")," [Enter]");
}
#include<iostream>
#include<conio.h>
int main(){
std::string str="\r";
std::cout<<show_newline(str)<<std::endl; // [Enter]
int key=_getch();
if(key==str.at(0)){ //(key==str.at(0))==true
std::cout<<"Pressed '\\r'";
}else{
std::cout<<"Didn't press '\\r' yet";
}
}
So……
//<vector>已included
std::vector<std::string> _levels_[]={ //地狱模式关卡
{"Typing Game"},
{
"//cpp\r",
"#include<iostream>\r",
"using namespace std;\r",
"int main(){\r",
" cout<<\"Hello World!\"<<endl;\r",
" return 0;\r",
"}\r"
},
{
"#py\r",
"# -*- coding: utf-8 -*-\r",
"#welcome message\r",
"def welcome_message():\r",
" print(\"************************\")\r",
" print(\"* *\")\r",
" print(\"* Welcome to Typing!! *\")\r",
" print(\"* *\")\r",
" print(\"************************\")\r",
"if __name__==\"__main__\":\r",
" welcome_message()\r"
}
};
const int32_t _L_=1,_R_=2; //选择关卡范围:1~2
int32_t _typing_level_(int32_t _level_){ //和函数typing_level原理差不多
int32_t _wrong_=0;
if(_level_<_L_||_level_>R)return -1;
std::vector<std::string> _typing_words_lines_=_levels_[_level_];
size_t _lines_=_typing_words_lines_.size();
for(size_t i=0;i<_lines_;i++){ //双层循环
std::string _typing_words_=_typing_words_lines_.at(i);
size_t _len_=_typing_words_.size();
std::cout<<show_newline(_typing_words_)<<std::endl;
for(size_t j=0;j<_len_;){
unsigned char _typing_key_=_getch();
if(_typing_key_==_typing_words_.at(j)){std::cout<<"_";j++;}
else _wrong_++;
type_word_cnt++;
}
std::cout<<std::endl; //模拟[Enter]循环
}
return _wrong_;
}
成品:
#include<iostream>
#include<string>
#include<conio.h>
#include<windows.h>
#include<chrono>
#include<vector>
#include<regex>
std::string show_newline(const std::string& str){
return std::regex_replace(str,std::regex("\r")," [Enter]");
}
unsigned char main_menu_key,game_setting_key;
std::string timing_unit="s";
std::string name="";
int32_t type_word_cnt=0,pass_level_cnt=0;
std::string levels[]={
"Typing Game",
"fj",
"f f j j f j f j f f f j j j f j j j j f",
"ffff jjjj fff jjj ff jj fjfj jfjf fjjf jffj",
"dk",
"d d k k d k d k d d d k k k d k k k k d",
"dddd kkkk ddd kkk dd kk dkdk kdkd dkkd kddk",
"ff jj fj dd kk dk jf jjff kd kkdd fjdk kdjf fkjd kfdj ffffjjjjddddkkkk",
"sl",
"s s l l s l s l s s s l l l s l l l l s",
"ssss llll sss lll ss ll slsl lsls slls lssl",
"a;",
"a a ; ; a ; a ; a a a ; ; ; a ; ; ; ; a",
"aaaa ;;;; aaa ;;; aa ;; a;a; ;a;a a;;a ;aa;",
"ss ll sl aa ;; a; sl ssll a; aa;; sla; ;als s;la ;sal ssssllllaaaa;;;;",
"gh",
"g g h h g h g h g g g h h h g h h h h g",
"gggg hhhh ggg hhh gg hh ghgh hghg ghhg hggh",
"glad dad had half a glass as salad; dad shall ask glass flags had glass ask shall flask had slash jaff" //Level 18
"ru",
"r r u u r u r u r r r u u u r u u u u r",
"rrrr uuuu rrr uuu rr uu ruru urur ruur urru",
"ei",
"e e i i e i e i e e e i i i e i i i i e",
"eeee iiii eee iii ee ii eiei ieie eiie ieei",
"rr uu ru ee ii ei ru rruu ei eeii ruei ieur riue ireu rrrruuuueeeeiiii",
};
const int32_t L=1,R=24;
std::vector<std::string> _levels_[]={
{"Typing Game"},
{
"//cpp\r",
"#include<iostream>\r",
"using namespace std;\r",
"int main(){\r",
" cout<<\"Hello World!\"<<endl;\r",
" return 0;\r",
"}\r"
},
{
"#py\r",
"# -*- coding: utf-8 -*-\r",
"#welcome message\r",
"def welcome_message():\r",
" print(\"************************\")\r",
" print(\"* *\")\r",
" print(\"* Welcome to Typing!! *\")\r",
" print(\"* *\")\r",
" print(\"************************\")\r",
"if __name__==\"__main__\":\r",
" welcome_message()\r"
}
};
const int32_t _L_=1,_R_=2;
int32_t typing_level(int32_t level){
int32_t wrong=0;
if(level<L||level>R)return -1;
std::string typing_words=levels[level];
size_t len=typing_words.size();
std::cout<<typing_words<<std::endl;
for(size_t i=0;i<len;){
unsigned char typing_key=_getch();
if(typing_key==typing_words.at(i)){std::cout<<"_";i++;}
else wrong++;
type_word_cnt++;
}
return wrong;
}
int32_t _typing_level_(int32_t _level_){
int32_t _wrong_=0;
if(_level_<_L_||_level_>R)return -1;
std::vector<std::string> _typing_words_lines_=_levels_[_level_];
size_t _lines_=_typing_words_lines_.size();
for(size_t i=0;i<_lines_;i++){
std::string _typing_words_=_typing_words_lines_.at(i);
size_t _len_=_typing_words_.size();
std::cout<<show_newline(_typing_words_)<<std::endl;
for(size_t j=0;j<_len_;){
unsigned char _typing_key_=_getch();
if(_typing_key_==_typing_words_.at(j)){std::cout<<"_";j++;}
else _wrong_++;
type_word_cnt++;
}
std::cout<<std::endl;
}
return _wrong_;
}
int main(){
std::cout<<"What is your name?"<<std::endl;
std::cout<<"Your answer: ";
std::getline(std::cin,name);
system("cls");
while(1){
std::cout<<"Typing Game"<<std::endl;
std::cout<<"Version: 0.3"<<std::endl;
std::cout<<"ID: 001"<<std::endl;
std::cout<<"Name: "+name<<std::endl;
std::cout<<"Main Menu"<<std::endl;
std::cout<<"Press [space] start the game"<<std::endl;
std::cout<<"Press 'x' go to hell mode"<<std::endl;
std::cout<<"Press [Esc] exit the game"<<std::endl;
std::cout<<"Press 's' change game settings"<<std::endl;
main_menu_key=_getch();
system("cls");
switch(main_menu_key){
case 32:{
std::cout<<"Please choose a level"<<std::endl;
std::cout<<"Level "<<L<<"~"<<R<<": ";
int32_t level;
std::cin>>level;
std::cin.ignore();
system("cls");
std::cout<<"level "<<level<<std::endl;
auto start=std::chrono::high_resolution_clock::now();
int32_t wrong=typing_level(level);
auto end=std::chrono::high_resolution_clock::now();
if(wrong==-1)std::cout<<"Level cannot be find it"<<std::endl;
else if(timing_unit=="s"){
auto use_time=std::chrono::duration_cast<std::chrono::seconds>(end-start).count();
std::cout<<std::endl<<"Congratulation on pass the level!"<<std::endl;
std::cout<<"Used time: "<<use_time<<"s, Wrong words: "<<wrong<<std::endl;
pass_level_cnt++;
}else if(timing_unit=="ms"){
auto use_time=std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
std::cout<<std::endl<<"Congratulation on pass the level!"<<std::endl;
std::cout<<"Used time: "<<use_time<<"ms, Wrong words: "<<wrong<<std::endl;
pass_level_cnt++;
}else if(timing_unit=="mus"){
auto use_time=std::chrono::duration_cast<std::chrono::microseconds>(end-start).count();
std::cout<<std::endl<<"Congratulation on pass the level!"<<std::endl;
std::cout<<"Used time: "<<use_time<<"mus, Wrong words: "<<wrong<<std::endl;
pass_level_cnt++;
}else if(timing_unit=="ns"){
auto use_time=std::chrono::duration_cast<std::chrono::nanoseconds>(end-start).count();
std::cout<<std::endl<<"Congratulation on pass the level!"<<std::endl;
std::cout<<"Used time: "<<use_time<<"ns, Wrong words: "<<wrong<<std::endl;
pass_level_cnt++;
}else{
auto use_time=std::chrono::duration_cast<std::chrono::seconds>(end-start).count();
std::cout<<std::endl<<"Congratulation on pass the level!"<<std::endl;
std::cout<<"Used time: "<<use_time<<"s, Wrong words: "<<wrong<<std::endl;
pass_level_cnt++;
}
std::cout<<"Press any keys to contiune . . . ";
_getch();
system("cls");
break;
}
case 'X':
case 'x':{
std::cout<<"Please choose a level"<<std::endl;
std::cout<<"Level "<<_L_<<"~"<<_R_<<": ";
int32_t _level_;
std::cin>>_level_;
std::cin.ignore();
system("cls");
std::cout<<"level "<<_level_<<std::endl;
auto _start_=std::chrono::high_resolution_clock::now();
int32_t _wrong_=_typing_level_(_level_);
auto _end_=std::chrono::high_resolution_clock::now();
if(_wrong_==-1)std::cout<<"Level cannot be find it"<<std::endl;
else if(timing_unit=="s"){
auto _use_time_=std::chrono::duration_cast<std::chrono::seconds>(_end_-_start_).count();
std::cout<<std::endl<<"Congratulation on pass the level!"<<std::endl;
std::cout<<"Used time: "<<_use_time_<<"s, Wrong words: "<<_wrong_<<std::endl;
pass_level_cnt++;
}else if(timing_unit=="ms"){
auto _use_time_=std::chrono::duration_cast<std::chrono::milliseconds>(_end_-_start_).count();
if(_wrong_==-1)std::cout<<"Level cannot be find it"<<std::endl;
else{
std::cout<<std::endl<<"Congratulation on pass the level!"<<std::endl;
std::cout<<"Used time: "<<_use_time_<<"ms, Wrong words: "<<_wrong_<<std::endl;
pass_level_cnt++;
}
}else if(timing_unit=="mus"){
auto _use_time_=std::chrono::duration_cast<std::chrono::microseconds>(_end_-_start_).count();
std::cout<<std::endl<<"Congratulation on pass the level!"<<std::endl;
std::cout<<"Used time: "<<_use_time_<<"mus, Wrong words: "<<_wrong_<<std::endl;
pass_level_cnt++;
}else if(timing_unit=="ns"){
auto _use_time_=std::chrono::duration_cast<std::chrono::nanoseconds>(_end_-_start_).count();
std::cout<<std::endl<<"Congratulation on pass the level!"<<std::endl;
std::cout<<"Used time: "<<_use_time_<<"ns, Wrong words: "<<_wrong_<<std::endl;
pass_level_cnt++;
}else{
auto _use_time_=std::chrono::duration_cast<std::chrono::seconds>(_end_-_start_).count();
std::cout<<std::endl<<"Congratulation on pass the level!"<<std::endl;
std::cout<<"Used time: "<<_use_time_<<"s, Wrong words: "<<_wrong_<<std::endl;
pass_level_cnt++;
}
std::cout<<"Press any keys to contiune . . . ";
_getch();
system("cls");
break;
}
case 'S':
case 's':{
std::cout<<"Game Settings"<<std::endl;
std::cout<<"Credits"<<std::endl;
std::cout<<"Author: Li Huozi IA"<<std::endl;
std::cout<<"Art: No"<<std::endl;
std::cout<<"English translation: Artificial Intelligence"<<std::endl;
std::cout<<std::endl;
std::cout<<"Change setting"<<std::endl;
std::cout<<"Press 't' change the timing unit"<<std::endl;
std::cout<<"Press [Esc] exit the game setting"<<std::endl;
std::cout<<std::endl;
std::cout<<"Suffer"<<std::endl;
std::cout<<"Typed Words: "<<type_word_cnt<<std::endl;
std::cout<<"Passed Levels: "<<pass_level_cnt<<std::endl;
game_setting_key=_getch();
system("cls");
switch(game_setting_key){
case 'T':
case 't':{
std::cout<<"Using timing unit: "<<timing_unit<<std::endl;
std::cout<<"Support units"<<std::endl;
std::cout<<"- s: second"<<std::endl;
std::cout<<"- ms: millisecond (1/1,000s)"<<std::endl;
std::cout<<"- mus: microsecond (1/1,000,000s)"<<std::endl;
std::cout<<"- ns: nanosecond (1/1,000,000,000s)"<<std::endl;
std::cout<<"Change to (s, ms, mus, ns): ";
std::cin>>timing_unit;
std::cout<<"Setting finish!"<<std::endl;
std::cout<<"Press any keys to contiune . . . ";
_getch();
system("cls");
break;
}
case 27:{break;}
}
break;
}
case 27:{
std::cout<<"Goodbye!";
return 0;
}
}
}
}
最后你能打出'╬'吗?
#include<conio.h>
bool @=...;
bool 关注=...;
bool 点赞=...;
bool 新手团团员=...;
int main(){
int key=_getch();
if(key=='╬'||@||关注||点赞){
新手团团员=true;
}else{
新手团团员=true;
}
}
全部评论 2
刚刚发布还热乎
1周前 来自 河北
0太快了太快了
1周前 来自 香港
0哈哈,我闲的没事干,就来灌水看看,刚看到
1周前 来自 河北
01周前 来自 香港
1
Windows答案:按住[Alt]->键盘右侧数字键打9166->松开[Alt]->就打出'╬'了!
1周前 来自 香港
0
























有帮助,赞一个