资深光能
//枪战(来真的)
#include<iostream>
#include<windows.h>
#include<conio.h>
#include<stdio.h>
#include<cstdlib>
#include<winuser.h>
#include<iomanip>
#include<cstring>
using namespace std;
int l,r;
int map1[100][100]={
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0,5,0,5,0,0,1,1,1,0,0,5,0,5,0,0,5,0,0,0,0,0,0,0,1},
{0,1,0,0,0,0,0,0,0,1,1,1,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,1,1,1,0,0,1},
{0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,9,1},
{0,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{0,1,2,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{0,1,1,1,1,1,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,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etConsoleCursorPosition( hConsole, coordScreen );
}
void output(){//输出地图
for(int i=1;i<=10;i++){
for(int j=1;j<=40;j++){
switch(map1[i][j]){
case 0:{
cout<<" ";
break;
}
case 1:{
cout<<"■";
break;
}
case 2:{
cout<<"♀";
l=i;r=j;
break;
}
case 3:{
cout<<"·";
break;
}
case 5:{
cout<<"㊣";
break;
}
case 6:{
cout<<"**";
break;
}
case 9:{
cout<<"‖";
break;
}
}
}
cout<<endl;
}
}
void output1(){//输出地图
for(int i=1;i<=10;i++){
for(int j=1;j<=40;j++){
switch(map2[i][j]){
case 0:{
cout<<" ";
break;
}
case 1:{
cout<<"■";
break;
}
case 2:{
cout<<"♀";
l=i;r=j;
break;
}
case 3:{
cout<<"·";
break;
}
case 5:{
cout<<"㊣";
break;
}
case 6:{
cout<<"**";
break;
}
case 9:{
cout<<"‖";
break;
}
}
}
cout<<endl;
}
}
//操作简介
void Introduction(){
cls();
printf("操作简介\n");
printf("往左移动:A 往右移动:D 跳跃:W 开枪:K\n");
printf("Z.退出");
while(1){
if(GetAsyncKeyState('Z')){
return ;
}
}
}
void initialization(){
printf("酷町枪战\n");
printf("经典小游戏\n");
printf("C.G出品\n");
//特殊符号┍┑┕┙‖═
printf("操作提示:上(W),下(S),确定(Z)\n");
printf("┍═════════════┑\n");
printf("‖> 开始游戏 ‖\n");
printf("‖ 操作简介 ‖\n");
printf("┕═════════════┙\n");
int flag=0;
while(1){
if(GetAsyncKeyState('W')){
cls();
printf("酷町枪战\n");
printf("经典小游戏\n");
printf("C.G出品\n");
//特殊符号┍┑┕┙‖═
printf("操作提示:上(W),下(S),确定(Z)\n");
printf("┍═════════════┑\n");
printf("‖> 开始游戏 ‖\n");
printf("‖ 操作简介 ‖\n");
printf("┕═════════════┙\n");
flag=0;
}else if(GetAsyncKeyState('S')){
cls();
printf("酷町枪战\n");
printf("经典小游戏\n");
printf("C.G出品\n");
//特殊符号┍┑┕┙‖═
printf("操作提示:上(W),下(S),确定(Z)\n");
printf("┍═════════════┑\n");
printf("‖ 开始游戏 ‖\n");
printf("‖> 操作简介 ‖\n");
printf("┕═════════════┙\n");
flag=1;
}else if(GetAsyncKeyState('Z')){
switch(flag){
case 0:{
return ;
break;
}
case 1:{
Introduction();
return ;
break;
}
}
}
}
}
bool u=true;//判断向左或是向右发射子弹。左:true 右:false
long long front,after; //分别记录子弹的个数。子弹个数增加,after++,反之,子弹减少,front++。
struct node{//子弹结构体
int coordinate_x;//子弹的x坐标
int coordinate_y;//子弹的y坐标
char direction;//记录是左边还是右边。f:左 a:右
}a[1000000];
bool Pass(){
if(map1[l][r+1]==9||map1[l][r-1]==9||map1[l-1][r]==9||map1[l+1][r]==9)return true;
return false;
}
void battle2(){
int flag=0;
front=0;
after=0;
u=true;
system("cls");
while(true){//无限循环
cls();
output1();
if(Pass())battle2();
if(map2[l+1][r]==6||map2[l+1][r]==5)break;
//判断是否按下子弹射击按键,即K
if(GetAsyncKeyState('K')&&map2[l][r-1]!=1&&u==false){
after++;//子弹个数++
a[after].direction='a';//将子弹的方向设置为右
a[after].coordinate_x=l;//记录下标
a[after].coordinate_y=r-1;//记录下标
map2[l][r-1]=3;//更改数字,生成子弹
}
if(GetAsyncKeyState('K')&&map2[l][r+1]!=1&&u==true){
after++;
a[after].direction='f';
a[after].coordinate_x=l;
a[after].coordinate_y=r+1;
map2[l][r+1]=3;
}
//向右移动
if(GetAsyncKeyState('D')&&map2[l][r+1]!=1){
if(map2[l][r+1]==5)break;
u=true;
map2[l][r]=0;
r++;
map2[l][r]=2;
}
//向左移动
if(GetAsyncKeyState('A')&&map2[l][r-1]!=1){
if(map2[l][r-1]==5)break;
u=false;
map2[l][r]=0;
r--;
map2[l][r]=2;
}
//跳跃
if(GetAsyncKeyState('W')&&map2[l-1][r]!=1&&flag==0){
map2[l][r]=0;
l--;
map2[l][r]=2;
flag++;
}
for(int i=front;i<=after;i++){
if(map2[a[i].coordinate_x][a[i].coordinate_y+1]==1||map2[a[i].coordinate_x][a[i].coordinate_y-1]==1){
front++;
map2[a[i].coordinate_x][a[i].coordinate_y]=0;
continue;
}
if(a[i].direction=='a'){
if(map2[a[i].coordinate_x][a[i].coordinate_y]!=2){
map2[a[i].coordinate_x][a[i].coordinate_y]=0;
a[i].coordinate_y--;
map2[a[i].coordinate_x][a[i].coordinate_y]=3;
}else{
a[i].coordinate_y--;
}
}
if(a[i].direction=='f'){
if(map2[a[i].coordinate_x][a[i].coordinate_y]!=2){
map2[a[i].coordinate_x][a[i].coordinate_y]=0;
a[i].coordinate_y++;
map2[a[i].coordinate_x][a[i].coordinate_y]=3;
}else{
a[i].coordinate_y++;
}
}
}
if(flag==1&&map2[l-1][r]!=1){
map2[l][r]=0;
l--;
map2[l][r]=2;
flag++;
continue;
}
if(flag==2&&map2[l+1][r]!=1){
map2[l][r]=0;
l++;
map2[l][r]=2;
flag++;
continue;
}else if(flag==2){
flag++;
}
if(flag==3&&map2[l+1][r]!=1){
map2[l][r]=0;
l++;
map2[l][r]=2;
flag=0;
continue;
}else if(flag==3){
flag=0;
}
while(map2[l+1][r]==0&&flag==0){
map2[l][r]=0;
l++;
map2[l][r]=2;
break;
}
}
system("cls");
cout<<"Game Over!!!";
Sleep(2000);
return ;
}
void battle(){
int flag=0;//对于跳跃的判断
cls();
output();
while(true){
while(true){//无限循环
cls();
output();
if(Pass())battle2();
if(map1[l+1][r]==6||map1[l+1][r]==5)break;
//判断是否按下子弹射击按键,即K
if(GetAsyncKeyState('K')&&map1[l][r-1]!=1&&u==false){
after++;//子弹个数++
a[after].direction='a';//将子弹的方向设置为右
a[after].coordinate_x=l;//记录下标
a[after].coordinate_y=r-1;//记录下标
map1[l][r-1]=3;//更改数字,生成子弹
}
if(GetAsyncKeyState('K')&&map1[l][r+1]!=1&&u==true){
after++;
a[after].direction='f';
a[after].coordinate_x=l;
a[after].coordinate_y=r+1;
map1[l][r+1]=3;
}
//向右移动
if(GetAsyncKeyState('D')&&map1[l][r+1]!=1){
if(map1[l][r+1]==5)break;
u=true;
map1[l][r]=0;
r++;
map1[l][r]=2;
}
//向左移动
if(GetAsyncKeyState('A')&&map1[l][r-1]!=1){
if(map1[l][r-1]==5)break;
u=false;
map1[l][r]=0;
r--;
map1[l][r]=2;
}
//跳跃
if(GetAsyncKeyState('W')&&map1[l-1][r]!=1&&flag==0){
map1[l][r]=0;
l--;
map1[l][r]=2;
flag++;
}
for(int i=front;i<=after;i++){
if(map1[a[i].coordinate_x][a[i].coordinate_y+1]==1||map1[a[i].coordinate_x][a[i].coordinate_y-1]==1){
front++;
map1[a[i].coordinate_x][a[i].coordinate_y]=0;
continue;
}
if(a[i].direction=='a'){
if(map1[a[i].coordinate_x][a[i].coordinate_y]!=2){
map1[a[i].coordinate_x][a[i].coordinate_y]=0;
a[i].coordinate_y--;
map1[a[i].coordinate_x][a[i].coordinate_y]=3;
}else{
a[i].coordinate_y--;
}
}
if(a[i].direction=='f'){
if(map1[a[i].coordinate_x][a[i].coordinate_y]!=2){
map1[a[i].coordinate_x][a[i].coordinate_y]=0;
a[i].coordinate_y++;
map1[a[i].coordinate_x][a[i].coordinate_y]=3;
}else{
a[i].coordinate_y++;
}
}
}
if(flag==1&&map1[l-1][r]!=1){
map1[l][r]=0;
l--;
map1[l][r]=2;
flag++;
continue;
}
if(flag==2&&map1[l+1][r]!=1){
map1[l][r]=0;
l++;
map1[l][r]=2;
flag++;
continue;
}else if(flag==2){
flag++;
}
if(flag==3&&map1[l+1][r]!=1){
map1[l][r]=0;
l++;
map1[l][r]=2;
flag=0;
continue;
}else if(flag==3){
flag=0;
}
while(map1[l+1][r]==0&&flag==0){
map1[l][r]=0;
l++;
map1[l][r]=2;
break;
}
}
system("cls");
cout<<"Game Over!!!";
Sleep(2000);
return ;
}
}
int main(){
initialization();
battle();
return 0;
}