#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
#include <time.h>
#include <string.h>
HANDLE hout;
char zt;
int yz,xz,ht,wz,fen,jb;
int hp=10;
void gotoxy(int x,int y)
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(handle,pos);
}
char getInput()
{
int ch;
COORD coord;
CONSOLE_SCREEN_BUFFER_INFO csbi;
coord.X=10;
coord.Y=10;
if(3-fen==0)
{
system("cls");
gotoxy(26,12);
printf("你赢了!");
gotoxy(26,14);
printf("最终得分:%d分",fen);
while(1)
{
Sleep(32767);
}
}
if(hp==0)
{
Sleep(20);
system("cls");
gotoxy(26,12);
printf("你输了!");
gotoxy(26,14);
printf("最终得分:%d分",fen);
while(1)
{
Sleep(32767);
}
}
if(coord.X>40&&coord.Y<10)
{
hp=hp-1;
gotoxy(72,1);
printf("%d滴",hp);
gotoxy(76,3);
printf("%d辆",3-fen);
gotoxy(67,5);
printf("%d分",fen);
}
if(coord.X>40&&coord.Y>20)
{
hp=hp-1;
gotoxy(72,1);
printf("%d滴",hp);
gotoxy(76,3);
printf("%d辆",3-fen);
gotoxy(67,5);
printf("%d分",fen);
}
if(coord.Y>20&&coord.X<18)
{
hp=hp-1;
gotoxy(72,1);
printf("%d滴",hp);
gotoxy(76,3);
printf("%d辆",3-fen);
gotoxy(67,5);
printf("%d分",fen);
}
if(coord.X<10&&coord.Y<10)
{
hp=hp+2;
gotoxy(72,1);
printf("%d滴",hp);
}
ch=getch();
while(ch==0xE0||ch==0x0d)
{
GetConsoleScreenBufferInfo(hout,&csbi);
coord.X=csbi.dwCursorPosition.X;
coord.Y=csbi.dwCursorPosition.Y;
gotoxy(72,1);
printf("%d滴",hp);
gotoxy(76,3);
printf("%d辆",3-fen);
gotoxy(67,5);
printf("%d分",fen);
wz=coord.X*coord.Y;
if(3-fen==0)
{
system("cls");
gotoxy(26,12);
printf("你赢了!");
gotoxy(26,14);
printf("最终得分:%d分",fen);
while(1)
{
Sleep(32767);
}
}
if(hp==0)
{
Sleep(20);
system("cls");
gotoxy(26,12);
printf("你输了!");
gotoxy(26,14);
printf("最终得分:%d分",fen);
while(1)
{
Sleep(32767);
}
}
if(coord.X>40&&coord.Y<10)
{
hp=hp-1;
gotoxy(72,1);
printf("%d滴",hp);
gotoxy(76,3);
printf("%d辆",3-fen);
gotoxy(67,5);
printf("%d分",fen);
}
if(coord.X>40&&coord.Y>20)
{
hp=hp-1;
gotoxy(72,1);
printf("%d滴",hp);
gotoxy(76,3);
printf("%d辆",3-fen);
gotoxy(67,5);
printf("%d分",fen);
}
if(coord.Y>20&&coord.X<18)
{
hp=hp-1;
gotoxy(72,1);
printf("%d滴",hp);
gotoxy(76,3);
printf("%d辆",3-fen);
gotoxy(67,5);
printf("%d分",fen);
}
if(coord.X<10&&coord.Y<10)
{
hp=hp+2;
gotoxy(72,1);
printf("%d滴",hp);
}
//如果是回车
if(ch==0x0d)
{
coord.X=0;
coord.Y++;
SetConsoleCursorPosition(hout,coord);
break;
}
ch=getch();
//上
if(ch==0x48)
{
if(coord.Y!=0)
{
if (zt==1)
{
yz=coord.Y;
yz=yz-1;
xz=coord.X;
system("cls");
system("type map.map");
gotoxy(xz,yz);
coord.Y--;
printf(" =[0]");
}else{
yz=coord.Y;
yz=yz-1;
xz=coord.X;
system("cls");
system("type map.map");
gotoxy(xz,yz);
coord.Y--;
printf("[0]= ");
}
}
}
//下
else if(ch==0x50)
{
if (zt==1)
{
yz=coord.Y;
yz=yz+1;
xz=coord.X;
system("cls");
system("type map.map");
gotoxy(xz,yz);
coord.Y++;
printf(" =[0]");
}else{
yz=coord.Y;
yz=yz+1;
xz=coord.X;
system("cls");
system("type map.map");
gotoxy(xz,yz);
coord.Y++;
printf("[0]= ");
}
}
//左
else if(ch==0x4b)
{
if(coord.X!=0){xz=coord.X--;yz=coord.Y;gotoxy(0,0);system("type map.map");gotoxy(xz,yz);printf("=[0] \b");zt=1;}
}
//右
else if(ch==0x4d)
{
if(coord.X!=79){xz=coord.X++;yz=coord.Y;gotoxy(0,0);system("type map.map");gotoxy(xz,yz);printf("\b [0]=");zt=2;}
else
{
coord.X=0;
coord.Y++;
}
}
SetConsoleCursorPosition(hout,coord);
ch=getch();
}
return ch;
}
void main()
{
system("mode con cols=80 lines=42");
CONSOLE_CURSOR_INFO cursor_info = {1,0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
system("title 坦克大战");
system("color 27");
system("type map.map");
gotoxy(4,2);
printf("[0]=\b\b\b");
char ch;
gotoxy(72,1);
printf("%d滴",hp);
gotoxy(76,3);
printf("%d辆",3-fen);
gotoxy(67,5);
printf("%d分",fen);
hout=GetStdHandle(STD_OUTPUT_HANDLE);
gotoxy(4,2);
MessageBox(NULL, TEXT("恭喜你获得上线大奖——穿墙外挂!按确定键领取大奖。"), TEXT("坦克大战"), MB_OK);
while(1)
{
ch=getInput();
if (ch=='g')
{
CONSOLE_CURSOR_INFO cursor_info = {1,1};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
if (ch=='h')
{
CONSOLE_CURSOR_INFO cursor_info = {1,0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
if (ch==' ')
{
if (zt==1)
{
fen=fen+1;
ht=36;
while(ht-1)
{
ht=ht-1;
printf("*");
Sleep(20);
printf("\b \b\b");
}
printf(" \b=[0]\b\b\b\b\b");
}
if (zt==2)
{
fen=fen+1;
printf("[0]=");
ht=24;
while(ht-1)
{
ht=ht-1;
printf("*");
Sleep(20);
printf("\b ");
}
printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
}
}
}
getchar();
}
11-28
1396
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-12
589
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-12
222
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-12
319
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)