Memory Game v0.1.0
2026-05-16 09:54:35
发布于:辽宁
不要偷看
受到TypingGame的启发,也想做一个游戏就是没事闲的
于是就有了——
Memory Game!
正如代码开头写的UNCODING WITH GB2312,请使用Mac OS/Linux/除简体中文外语言的进行编码转换以适配中文(好像也没中文
/* UNCODING WITH GB2312 */
#include<cstdio>
#include<windows.h>
#include<string>
#include<iostream>
#define unsnd unsigned
#define l long
#define unsdll unsigned long long
using std::cout,std::cin,std::string;
const unsdll LEVEL_COUNT=6; // This is the count of levels,update notice
const string ADMIN_PASSWORD="_Pbbf^aSnZVbZaYVbVXPRUnPS\\X]"; // admin password
const unsdll MAX_WRONG_LETTER_CNT=5; // max wrong letter count(edit able), used in function playLevel(),levelFail(),levelPass()(update notice)
const string version = "0.1.0_Release";
const string lang = "en";
unsdll _score = 0;
bool _is_admin = false;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtrigraphs"
string levels[]={
"These are texts to remember,sort by alphabet",
"abcdefg",
"I love cpp",
"Hello my friend, long time no see.",
"OHHHHHHHHHH MY PCCCCCCCCCCCCCCCC",
"No one play Minecraft? REALLY??!",
"This level is harder than other. Guess why? 'Cause it have many letters~!"
};
#pragma GCC diagnostic pop
/*string production_team_list[]={
"[== CREDITS ==]",
"Code: DH8105",
"English translation: DH8105 & Microsoft Translator",
"Artist(?): DH8105"
};*/
void output(string s,int time){
// One by one output
for(auto c:s){
printf("%c",c);
Sleep(time);
}
}
void tourtoal(){
// Tourtoal function(in fact I think too long in main lol)
system("cls");
output("*Tourtoal start*\n",50);
cout<<"DH8105: ";
Sleep(300);
output("I will teach you how to play this game.\n",50);
cout<<"[Any key]: Continue";
_getwch();
cout<<"\nYou: ";
output("I'm OK.",50);
cout<<"\nDH8105: ";
output("This(point the edge of the window)is called \"Console\".\n",50);
cout<<"[Any key]: Continue";
_getwch();
cout<<"DH8105: ";
output("Your goal is: Remember the words before countdown, and type it.\n",50);
cout<<"[Any key]: Continue";
_getwch();
cout<<"DH8105: ";
output("When you type a correct letter, the \"Console\" will show you a letter you type to help you to remember.\n",50);
cout<<"[Any key]: Continue";
_getwch();
cout<<"DH8105: ";
output("And when you type a wrong letter, the \"Console\" won't show you any letter.",50);
_getwch();
cout<<"DH8105: ";
output("If you typed wrong letter count out of 5,game will over.",50); // update notice(Line 8)
cout<<"\n[Any key]: \"I remember how to play.\"";
_getwch();
cout<<"\nDH8105: ";
output("Great.You can play Memory Game now. See you later~!",50);
cout<<"\n[Any key]: Back to choose other level";
_getwch();
system("cls");
}
void start();void chooseLevel();void levelFail(unsdll level);void levelPass(unsdll level,unsdll score);
void playLevel(unsdll level){ // Use a function to play a level
int countdown = levels[level].size()/4; // Mean the difficult of the game. Bigger number mean harder gameplay.
if(countdown < 3) countdown=3;
system("cls");
cout<<"Texts to remember:\n"<<levels[level]<<"\n\nLoading countdown...";
Sleep(1000);
for(auto i=countdown;i>=0;i--){
system("cls");
cout<<"Texts to remember:\n"<<levels[level]<<"\n\n";
cout<<"Countdown:"<<countdown<<'\n';
countdown--;
Sleep(1000);
}
system("cls");
string curr=levels[level];
string display="";
unsigned long long wrong_cnt=0;
for(auto i=0;i<curr.size();i++){
char input=_getwch();
if(input == curr[i]){
putchar(curr[i]);
}else wrong_cnt++;
if(wrong_cnt > MAX_WRONG_LETTER_CNT){
levelFail(level);
return;
}
}
levelPass(level,curr.size()/2);
}
void levelFail(unsdll level){
putchar('\n');
cout<<"Your wrong letter count is out of "<<MAX_WRONG_LETTER_CNT<<".\nYou are failed in level"<<level<<".\nScore get: 0\n\n";
cout<<"[R]:Replay this level\n";
cout<<"[H]:Go to main menu\n";
int userKey = _getwch();
// r:114 R:82 h:104 H:72
switch(userKey){
case 114:
case 82:
cout<<"Replay in 3 seconds. . .";
Sleep(3000);
playLevel(level);
break;
case 104:
case 72:
start();
break;
default:
system("cls");
cout<<"Invalid key: "<<userKey<<" .\n[Any key]:Back to main menu";
_getwch();
start();
}
}
void levelPass(unsdll level,unsdll score){
putchar('\n');
cout<<"Congratulations! Your wrong letter count is less of "<<MAX_WRONG_LETTER_CNT<<".\nYou are passed level "<<level<<".\nScore get: "<<score<<"\n\n";
_score += score;
cout<<"[R]:Replay this level\n";
cout<<"[H]:Go to main menu\n";
int userKey = _getwch();
// r:114 R:82 h:104 H:72
switch(userKey){
case 114:
case 82:
cout<<"Replay in 3 seconds. . .";
Sleep(3000);
playLevel(level);
break;
case 104:
case 72:
start();
break;
default:
system("cls");
cout<<"Invalid key: "<<userKey<<" .\n[Any key]:Back to main menu";
_getwch();
start();
}
}
void chooseLevel(){
system("cls");
unsdll userLevel;
cout<<"Avaliable levels:0(Tourtoal),1~"<<LEVEL_COUNT<<"\n";
cout<<"Choose a level or input -1 to quit: ";
cin>>userLevel;
if(userLevel == -1){
start();
return;
}
if(userLevel == 0){tourtoal();chooseLevel();}
else if(userLevel >= 1 && userLevel <= LEVEL_COUNT){
playLevel(userLevel);
}else{
cout<<"Unknown level: "<<userLevel<<" .\n";
cout<<"[Any key]:Back to choose level\n";
_getwch();
chooseLevel();
}
}
/*void productionTeam(){
for(string s:production_team_list){
output(s,50);
Sleep(300);
putchar('\n');
}
cout<<"[Any key]: Back to main menu";
_getwch();
system("cls");
start();
}*/
bool adminCheck(string password){
for(auto i=0;i<password.size();i++){
password[i]+=15;
}
return password == ADMIN_PASSWORD;
}
void start(){
//string homepage = "https://www.acgo.cn/person/4960237";
system("cls");
output("--Memory Game--",50);
Sleep(300);
cout<<"\nVersion: "<<version<<"\nScore: "<<_score<<"\nAuthor: DH8105 on QQ & ACGO\nBug report: message author on ACGO\n\n";
cout<<"[Space]: Start playing\n";
cout<<"[H]: Goto author homepage(ACGO)\n";
// cout<<"[P]: Production team\n";
cout<<"[A]: Login as administrator\n";
cout<<"[Esc]: Quit game";
int userKey = _getwch();
system("cls");
switch(userKey){
case 27:
cout<<"See you next time!";break;
case 72:
case 104:
system("cls");
system("start https://www.acgo.cn/person/4960237");
start();
break;
case 32:
case 13:
chooseLevel();
break;
/*case 112:
case 80:
productionTeam();
break;*/
case 65:
case 97:{
system("cls");
if(_is_admin){
cout<<"You are already logined as administrator.\n[Shift + C]:Logout administrator\n[Any other key]:Back to main menu";
int usrKeyInAdmin = _getwch();
if(usrKeyInAdmin == 67){
system("cls");
cout<<"Are you sure to LOGOUT ADMINISTRATOR??\n[Shift + C]:Sure\n[Any other key]:Back to main menu";
int usrKeyInLogoutSure = _getwch();
if(usrKeyInLogoutSure == 67){
cout<<"\n\nLogouted administrator.\n[Any key]:Back to main menu";
_is_admin = false;
_getwch();
}
}
start();
}
cout<<"Enter admin password: ";
string userPassword;
while(1){
cin>>userPassword;
for(auto i=0;i<userPassword.size();i++) userPassword[i]+=15;
if(userPassword == ADMIN_PASSWORD){
cout<<"\nLogined as administrator!\n[Any key]:Back to main menu";
_is_admin = true;
_getwch();
start();
break;
}else{
cout<<"\nPassword incorrect!\n[Any key]:Back to main menu";
_getwch();
start();
break;
}
}
}
default:
system("cls");
cout<<"Invalid key: "<<userKey<<" .\n[Any key]:Back to main menu";
_getwch();
start();
}
}
int main(){
/*language check*/
if(lang != "en"){
cout<<"--Memory Game Fatal Error--\nUnsuppout language: "<<lang<<" .\n";
return 0;
}
/*admin password check(seems like not used idk why lol)*/
if(ADMIN_PASSWORD != "_Pbbf^aSnZVbZaYVbVXPRUnPS\\X]"){
cout<<"--Memory Game Fatal Error--\nAdmin password edited. Go to where you get this code and correct it";
}
system("cls");
start();
return 0;
}
全部评论 2
急修:
Line 279~281改为以下内容:if(ADMIN_PASSWORD != "_Pbbf^aSnZVbZaYVbVXPRUnPS\\X]"){ cout<<"--Memory Game Fatal Error--\nAdmin password edited. \nFor security, this is not allowed. \nGo to where you get this code and correct it."; return 0; }昨天 来自 辽宁
0555
昨天 来自 浙江
0























有帮助,赞一个