游戏开发日志支线1
2026-02-01 19:38:03
发布于:香港
好消息:游戏开发日志更新了
坏消息:是“游戏开发日志支线1”
新游戏:Typing Game
版本:0.1
代码:李伙子ia
美术:也没美术啊
翻译:Artificial Intelligence
团队:新手团
“Typing Game”,顾名思义,是以打字为主题的游戏。
头文件解析:
#include<iostream> //输入输出流
#include<string> //字符串
#include<conio.h> //函数_getch(void):获取用户键盘输入
#include<windows.h> //函数system(/*窝不知道*/):"cls"用于清屏
#include<chrono> //计时
全局变量解析:
unsigned char system_key; //储存用户键盘输入
std::string name=""; //你的名字
int32_t type_word_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;;;;",
"Level 16"
};
const int32_t L=1,R=14; //选择关卡范围:1~14
std::string _levels_[]={}; //待办项目:???
函数解析:
int32_t typing_level(int32_t level){ //用于游玩关卡(配合std::string level[])
int32_t wrong=0; //记录打错的字数
if(level<L||level>R)return -1; //检测level是否超出范围
/*关卡模板*/
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++;} //如果正确:索引+1
else wrong++; //否则:错字+1
type_word_cnt++;
}
/*关卡模板*/
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.1"<<std::endl;
std::cout<<"ID: 001"<<std::endl;
std::cout<<"Name: "+name<<std::endl;
std::cout<<"system"<<std::endl;
std::cout<<"Palse [space] start the game"<<std::endl;
std::cout<<"Palse [Esc] exit the game"<<std::endl;
system_key=_getch(); //储存用户键盘输入
system("cls");
switch(system_key){
case 32:{ //[space]的ascii码是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(); //开始计时,auto:自动适配数据类型
int32_t wrong=typing_level(level); //关卡
auto end=std::chrono::high_resolution_clock::now(); //结束计时
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;
}
std::cout<<"Palse any keys to contiune . . . ";
_getch();
system("cls");
break;
}
case 27:{ //[Esc]的ascii码是27
std::cout<<"Goodbye!";
return 0; //退出程序
}
}
}
}
成品:
#include<iostream>
#include<string>
#include<conio.h>
#include<windows.h>
#include<chrono>
unsigned char system_key;
std::string name="";
int32_t type_word_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;;;;",
"Level 16"
};
const int32_t L=1,R=15;
std::string _levels_[]={};
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;
}
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.1"<<std::endl;
std::cout<<"ID: 001"<<std::endl;
std::cout<<"Name: "+name<<std::endl;
std::cout<<"system"<<std::endl;
std::cout<<"Palse [space] start the game"<<std::endl;
std::cout<<"Palse [Esc] exit the game"<<std::endl;
system_key=_getch();
system("cls");
switch(system_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();
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;
}
std::cout<<"Palse any keys to contiune . . . ";
_getch();
system("cls");
break;
}
case 27:{
std::cout<<"Goodbye!";
return 0;
}
}
}
}
这里空空如也















有帮助,赞一个