最近做了一个不怎么好玩的游戏——
player1: Tab 往左走 shift 往右走
player2: ← 往左走 → 往右走
上代码:
#include<bits/stdc++.h>
#include<windows.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
int life1=200,life2=200,zuo=15,jian=10,you=15,hhh=5,chu1=0,chu2=0;
void h();
void z();
void j();
void y();
int main(){
int mima;
// cin>>mima;
// if(mima!=200272){
// cout<<200272;
// return 0;
//
cout<<3;
_sleep(1000);
system("CLS");
cout<<2;
_sleep(1000);
system("CLS");
cout<<1;
_sleep(1000);
system("CLS");
while(life1>0&&life2>0){
system("CLS");
cout<<"player1:"<<life1<<endl;
cout<<"player2:"<<life2<<endl;
h();
z();
cout<<" o ";
j();
cout<<" o ";
y();
cout<<endl;
z();
cout<<"/|";
if(chu1==1){
cout<<"_-";
if(jian==0) life2-=20;
}
else{
cout<<"-";
}
j();
if(chu2==1){
cout<<"-_";
if(jian==0) life1-=20;
}
else{
cout<<"-";
}
cout<<"|\\ ";
y();
cout<<endl;
z();
cout<<"/ \\";
j();
cout<<"/ \\";
y();
cout<<endl;
cout<<"__________________________________________________________"<<endl;
if(chu1==1) chu1=0;
if(chu2==1) chu2=0;
if(KEY_DOWN(VK_TAB)&&zuo>0){
zuo--;
jian++;
}
if(KEY_DOWN(VK_SHIFT)&&jian>0){
zuo++;
jian--;
}
if(KEY_DOWN(VK_LEFT)&&jian>0){
jian--;
you++;
}
if(KEY_DOWN(VK_RIGHT)&&you>0){
jian++;
you--;
}
if(KEY_DOWN(VK_INSERT)) chu1=1;
if(KEY_DOWN(VK_DELETE)) chu2=1;
}
if(life1>life2){
cout<<"player1 win!";
_sleep(2000);
}
else if(life1==life2){
cout<<"lose-lose";
_sleep(2000);
}
else{
cout<<"player2 win!";
_sleep(2000);
}
return 0;
}
void h(){
for(int i=1;i<=hhh;i++) cout<<endl;
}
void z(){
for(int i=1;i<=zuo;i++) cout<<" ";
}
void j(){
for(int i=1;i<=jian;i++) cout<<" ";
}
void y(){
for(int i=1;i<=you;i++) cout<<" ";
}