原创小游戏——1碰1
fcy20180201 · · 学习·文化课
原创 by @fcy20180201,有 bug 请私聊,赏关!!!
UPD1:2024.2.18 添加了一些魔怔的东西
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
int vis[15][15];
void Slow_Print(string s,int x,int y){
for(char c:s)putchar(c),Sleep(x);
Sleep(y);
return ;
}
void Rule(){
system("cls");
Slow_Print("You and the Computer both have two numbers, which are initially 1.\n",20,500);
Slow_Print("You and the Computer choose one of his numbers and increase it by one of the other's numbers then mod 10 in turn.\n",20,500);
Slow_Print("You start first.\n",20,500);
Slow_Print("After every turn, if one number becomes 0, then that number disappears.\n",20,500);
Slow_Print("If one of the player doesn't have any numbers, he WINS.\n",20,500);
Slow_Print("If both players have one number, and they get into an endless loop, then the players DRAW.\n",20,500);
system("pause");return ;
}
bool check(char c,int a,int b){
if(c=='e')return true;
if(c=='1')return (a);
if(c=='2')return (b);
return false;
}
void Start(){
system("cls");
int s[3]={0,1,1},t[3]={0,1,1};
bool flag=true;
while(true){
printf(" You: ");
if(!s[1])putchar(' ');
else printf("%d",s[1]);
printf(" ");
if(!s[2])putchar(' ');
else printf("%d",s[2]);
puts("");
printf("Computer: ");
if(!t[1])putchar(' ');
else printf("%d",t[1]);
printf(" ");
if(!t[2])putchar(' ');
else printf("%d",t[2]);
puts("");
if(!s[1] && !s[2]){
Slow_Print("You WIN!!!",10,1000);
Sleep(3000);
break;
}
if(!t[1] && !t[2]){
Slow_Print("The Computer WINs!!!",10,1000);
Sleep(3000);
break;
}
if((!s[1] || !s[2]) && (s[1] || s[2]) && (!t[1] || !t[2]) && (t[1] || t[2])){
if(vis[(s[1]?s[1]:s[2])][(t[1]?t[1]:t[2])]){
Slow_Print("You fall in an endless loop and DRAW!!!",10,1000);
Sleep(3000);
break;
}
vis[(s[1]?s[1]:s[2])][(t[1]?t[1]:t[2])]=true;
}
if(flag){
printf("Which number will you use? Input ");
if(!s[1])printf("2 or e(for exit).");
else if(!s[2])printf("1 or e(for exit).");
else printf("1, 2 or e(for exit).");puts("");
char c;
while(!check(c=getchar(),s[1],s[2]));
if(c=='e')break;
int ss,tt;
if(c=='1')ss=1;
else ss=2;
printf("Which the Computer's number will you add? Input ");
if(!t[1])printf("2 or e(for exit).");
else if(!t[2])printf("1 or e(for exit).");
else printf("1, 2 or e(for exit).");puts("");
while(!check(c=getchar(),t[1],t[2]));
if(c=='e')break;
if(c=='1')tt=1;
else tt=2;
Slow_Print(to_string(s[ss])+" + "+to_string(t[tt])+" = "+to_string(s[ss]+t[tt])+"\n",50,1000);
if((s[ss]+t[tt])%10==0)printf("You win your %d%s number.\n",ss,(ss==1?"st":"nd"));
s[ss]=(s[ss]+t[tt])%10;
}
else{
int ans1,ans2;
vector<int>al,nl;
for(int i=1;i<3;i++)for(int j=1;j<3;j++){
if(!t[i] || !s[j])continue;
al.push_back((i-1)*2+j-1);
if((t[i]+s[j])%10==0){
ans1=i,ans2=j;
goto END;
}
if((t[i]+s[j]+s[1])%10 && (t[i]+s[j]+s[2])%10)nl.push_back((i-1)*2+j-1);
}
if(!nl.size()){
int x=rand()%al.size();
ans1=al[x]/2+1,ans2=al[x]%2+1;
}
else{
int x=rand()%nl.size();
ans1=nl[x]/2+1,ans2=nl[x]%2+1;
}
END:;
printf("The Computer's %d%s number increased by your %d%s number.\n",ans1,(ans1==1?"st":"nd"),ans2,(ans2==1?"st":"nd"));
Slow_Print(to_string(t[ans1])+" + "+to_string(s[ans2])+" = "+to_string(t[ans1]+s[ans2])+"\n",50,1000);
if((t[ans1]+s[ans2])%10==0)printf("The computer wins the %d%s number.\n",ans1,(ans1==1?"st":"nd"));
t[ans1]=(t[ans1]+s[ans2])%10;
}
flag^=1;
Sleep(3000);
system("cls");
}
}
void End(){
printf("\
We're no strangers to love\n\
You know the rules and so do I\n\
A full commitment's what I'm thinking of\n\
You wouldn't get this from any other guy\n\
I just wanna tell you how I'm feeling\n\
Gotta make you understand\n\
Never gonna give you up never gonna let you down\n\
Never gonna run around and desert you\n\
Never gonna make you cry never gonna say goodbye\n\
Never gonna tell a lie and hurt you\n\
We've known each other for so long\n\
Your heart's been aching but you're too shy to say it\n\
Inside we both know what's been going on\n\
We know the game and we're gonna play it\n\
And if you ask me how I'm feeling\n\
Don't tell me you're too blind to see\n\
Never gonna give you up never gonna let you down\n\
Never gonna run around and desert you\n\
Never gonna make you cry never gonna say goodbye\n\
Never gonna tell a lie and hurt you\n\
Never gonna give you up never gonna let you down\n\
Never gonna run around and desert you\n\
Never gonna make you cry never gonna say goodbye\n\
Never gonna tell a lie and hurt you\n\
(Ooh give you up)\n\
(Ooh give you up)\n\
(Ooh) never gonna give never gonna give (give you up)\n\
(Ooh) never gonna give never gonna give (give you up)\n\
We've known each other for so long\n\
Your heart's been aching but you're too shy to say it\n\
Inside we both know what's been going on\n\
We know the game and we're gonna play it\n\
I just wanna tell you how I'm feeling\n\
Gotta make you understand\n\
Never gonna give you up never gonna let you down\n\
Never gonna run around and desert you\n\
Never gonna make you cry never gonna say goodbye\n\
Never gonna tell a lie and hurt you\n\
Never gonna give you up never gonna let you down\n\
Never gonna run around and desert you\n\
Never gonna make you cry never gonna say goodbye\n\
Never gonna tell a lie and hurt you\n\
Never gonna give you up never gonna let you down\n\
Never gonna run around and desert you\n\
Never gonna make you cry never gonna say goodbye\n\
Never gonna tell a lie and hurt you");
}
int main(){
srand(time(0));
double tb=clock();
printf("Prepare: Turn Your Input Method into English.\n");
system("pause");
while(true){
memset(vis,0,sizeof(vis));
system("cls");
printf("\
/| /| #### # ## ## ##### \n\
/ | | / | # # # # # # # # \n\
/ | | / | # # # # # # # # \n\
| -----|----- | # #### ####### # # # #####\n\
| | | # # # # # # # # \n\
| | | # # # # # # # # \n\
----- ----- ## # # # ## ## #####\n\n\
[r] Rules\n\
[s] Start Game!!!\n\
[e] Exit\n");
char c;
while((c=getch())!='r' && c!='s' && c!='e');
if(c=='r')Rule();
else if(c=='s')Start();
else{
system("cls");
printf("Exit?(y/n)");
char cc;
while((cc=getch())!='y' && cc!='n');
if(cc=='y'){
system("cls");
Slow_Print("ByeBye!!!\n",300,1000);
printf("--------------------------------\nProcess exited after %.3lf seconds with return value 0\n",(clock()-tb)/1000.0);
system("pause");
printf("\n\n");
End();
return 0;
}
}
}
return 0;
}