话不多说,上代码!
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int Ge,Fen,timp,F,a[22][6];
double Shi,B;
void S(int ForgC,int BackC){
WORD wColor=((BackC & 0x0F)<<4)+(ForgC&0x0F);
SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE),wColor);
}
void G(int x, int y){
COORD pos={x,y};
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut,pos);
return ;
}
void HC(){
CONSOLE_CURSOR_INFO cur={1,0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cur);
}
void SC(){
CONSOLE_CURSOR_INFO cur={1,1};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cur);
}
struct J{
int x,y,f;
}Jiant[114514];
int my_find(int x,int y){
for(int i=1;i<=Ge;i++)if(x==Jiant[i].x&&y==Jiant[i].y)return Jiant[i].f+5;
return 0;
}
int my_find2(int x,int y){
for(int i=1;i<=Ge;i++)if(x==Jiant[i].x&&y==Jiant[i].y)return i;
return 0;
}
void js(){
system("cls");
int x;
while(true){
if(B<=0){
x=rand()%14+1;
B=0.5;
}
G(0,0);
S(x,0);
cout<<" "<<(char)12;
printf("音游");
cout<<(char)12<<endl;
S(15,0);
if(B>0)B-=0.1;
else B=0;
S(11,0);cout<<"有手不行"<<endl;
S(15,0);cout<<"按回车返回";
if(GetAsyncKeyState(VK_RETURN))return;
Sleep(50);
}
}
void play(){
system("cls");
Fen=0;Ge=0;
while(true){
G(0,0);
for(int i=1;i<=21;i++){
for(int j=1;j<=4;j++){
if(i==20)a[i][j]=1;
else if(i==21)a[i][j]=j+1;
else if(my_find(i,j)!=0)a[i][j]=my_find(i,j);
else a[i][j]=0;
}
}
for(int i=1;i<=21;i++){
for(int j=1;j<=4;j++){
if(a[i][j]==0){cout<<" ";}
if(a[i][j]==1){cout<<"┄┄";}
if(a[i][j]==2){S(12,0);cout<<"↑";S(15,0);}
if(a[i][j]==3){S(14,0);cout<<"↓";S(15,0);}
if(a[i][j]==4){S(11,0);cout<<"←";S(15,0);}
if(a[i][j]==5){S(19,0);cout<<"→";S(15,0);}
if(a[i][j]==6){S(12,0);cout<<"↑";S(15,0);}
if(a[i][j]==7){S(14,0);cout<<"↓";S(15,0);}
if(a[i][j]==8){S(11,0);cout<<"←";S(15,0);}
if(a[i][j]==9){S(19,0);cout<<"→";S(15,0);}
}
cout<<endl;
}
for(int i=21;i>=1;i--){
for(int j=1;j<=4;j++){
if(my_find2(i,j)!=0){
if(Jiant[my_find2(i,j)].x<=20)Jiant[my_find2(i,j)].x++;
else{
Fen-=10;
for(int i=1;i<=Ge-1;i++){
Jiant[i].x=Jiant[i+1].x;
Jiant[i].y=Jiant[i+1].y;
Jiant[i].f=Jiant[i+1].f;
}
Ge--;
}
}
}
}
if(Shi>0)Shi-=0.2;
else Shi=0;
if(Shi<=0){
timp=rand()%6+1;
Shi=timp*1.0/10;
Ge++;
Jiant[Ge].x=1;
Jiant[Ge].y=rand()%4+1;
Jiant[Ge].f=Jiant[Ge].y;
}
if(GetAsyncKeyState(VK_UP)){
if(a[20][1]==6){
Fen+=50;
}else if(a[19][1]==6)Fen+=30;
else if(a[18][1]==6)Fen+=20;
else if(a[17][1]==6)Fen+=10;
G(0,19);
cout<<"+";
}
if(GetAsyncKeyState(VK_DOWN)){
if(a[20][2]==7){
Fen+=50;
}else if(a[19][2]==7)Fen+=30;
else if(a[18][2]==7)Fen+=20;
else if(a[17][2]==7)Fen+=10;
G(2,19);
cout<<"+";
}
if(GetAsyncKeyState(VK_LEFT)){
if(a[20][3]==8)Fen+=50;
else if(a[19][3]==8)Fen+=30;
else if(a[18][3]==8)Fen+=20;
else if(a[17][3]==8)Fen+=10;
G(4,19);
cout<<"+";
}
if(GetAsyncKeyState(VK_RIGHT)){
if(a[20][4]==9)Fen+=50;
else if(a[19][4]==9)Fen+=30;
else if(a[18][4]==9)Fen+=20;
else if(a[17][4]==9)Fen+=10;
G(6,19);
cout<<"+";
}
if(GetAsyncKeyState(VK_SPACE)){
Sleep(100);
while(true)if(GetAsyncKeyState(VK_SPACE))break;
}
Sleep(250);
G(1,21);
cout<<"分数 "<<Fen<<" "<<endl;
}
}
bool kt(){
int i=1;
system("cls");
while(true){
G(0,0);
printf("\n\n\n");
printf(" ┍┄┄┄┄┄┄┄┄┑\n");
if(i==1){
S(14,0);
printf(" ●");
S(15,0);
}else cout<<" ";
printf("┆");
if(i==1)S(14,0);
printf("开始游戏");
S(14,0);
printf("┆");
if(i==1){
S(14,0);
printf("●");
S(15,0);
}else cout<<" ";
printf("\n");
if(i==2){
S(14,0);
printf(" ●");
S(15,0);
}else cout<<" ";
printf("┆");
if(i==2)S(14,0);
printf("游戏介绍");
S(15,0);
printf("┆");
if(i==2){
S(14,0);
printf("●");
S(15,0);
}else cout<<" ";
printf("\n ┕┄┄┄┄┄┄┄┄┙");
if(GetAsyncKeyState(VK_UP))i=max(i-1,1);
if(GetAsyncKeyState(VK_DOWN))i=min(i+1,2);
if(GetAsyncKeyState(VK_SPACE)){
if(i==1)play();
else js();
break;
}
}
kt();
}
int main(){
HC();
srand(time(0));
if(kt())play();
else js();
SC();
return 0;
}
蚌。
标签:游戏,int,C++,旋转,else,Shi,include,BackC From: https://blog.csdn.net/2401_84857706/article/details/140463238