记得点赞加关注啊,看在我写了十五万行的代码的份上,求求啦😭😭
1.2048小游戏
// @File : 2048.cpp
// @Author : Easylau
// @Time : 2022/02/08 11:13:16
#include <iostream>
using namespace std;
#include <conio.h> //console input/ouput
#include <ctime>
#include <cstdlib>
int randNum(); //产生2/4随机数
int randPosition(); //产生随机位置
void printArr(int *mainArr, int len); //打印数组
void upPile(int *mainArr, int len); //上移操作
void moveUp(int *mainArr, int len, int *score);
void downPile(int *mainArr, int len); //下移操作
void moveDown(int *mainArr, int len, int *score);
void leftPile(int *mainArr, int len); //左移操作
void moveLeft(int *mainArr, int len, int *score);
void rightPile(int *mainArr, int len); //右移操作
void moveRight(int *mainArr, int len, int *score);
void generateNum(int *mainArr, int len); //在随机位置上放置随机数
int checkResult(int *mainArr, int len); //通过返回值判断游戏状态(赢、输、继续)
int randNum()
{
srand((int)time(0));
return (rand() % 2 + 1) * 2;
}
int randPosition()
{
srand((int)time(0));
return rand() % 16;
}
void printArr(int *mainArr, int len)
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
cout << mainArr[i * 4 + j] << "\t";
}
cout << endl;
cout << endl;
}
}
void upPile(int *mainArr, int len)
{
for (int i = 1; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
for (int x = i - 1; x > 0; x--)
{
if (mainArr[x * 4 + j] == 0)
{
mainArr[x * 4 + j] = mainArr[(x + 1) * 4 + j];
mainArr[(x + 1) * 4 + j] = 0;
}
}
}
}
}
void moveUp(int *mainArr, int len, int *score)
{
upPile(mainArr, len);
for (int i = 1; i < 4; i++) //从第2行开始
{
for (int j = 0; j < 4; j++)
{
if (mainArr[i * 4 + j] == mainArr[(i - 1) * 4 + j] || mainArr[(i - 1) * 4 + j] == 0)
{
mainArr[(i - 1) * 4 + j] += mainArr[i * 4 + j];
mainArr[i * 4 + j] = 0;
*score += mainArr[(i - 1) * 4 + j];
}
}
}
}
void downPile(int *mainArr, int len)
{
for (int i = 3; i > -1; i--)
{
for (int j = 0; j < 4; j++)
{
for (int x = i + 1; x < 4; x++)
{
if (mainArr[x * 4 + j] == 0)
{
mainArr[x * 4 + j] = mainArr[(x - 1) * 4 + j];
mainArr[(x - 1) * 4 + j] = 0;
}
}
}
}
}
void moveDown(int *mainArr, int len, int *score)
{
downPile(mainArr, len);
for (int i = 3; i > 0; i--) //从最后一行开始
{
for (int j = 0; j < 4; j++)
{
if (mainArr[i * 4 + j] == mainArr[(i - 1) * 4 + j] || mainArr[i * 4 + j] == 0)
{
mainArr[i * 4 + j] += mainArr[(i - 1) * 4 + j];
mainArr[(i - 1) * 4 + j] = 0;
*score += mainArr[i * 4 + j];
}
}
}
}
void leftPile(int *mainArr, int len)
{
for (int j = 1; j < 4; j++)
{
for (int i = 0; i < 4; i++)
{
for (int x = j - 1; x > -1; x--)
{
if (mainArr[i * 4 + x] == 0)
{
mainArr[i * 4 + x] = mainArr[i * 4 + x + 1];
mainArr[i * 4 + x + 1] = 0;
}
}
}
}
}
void moveLeft(int *mainArr, int len, int *score)
{
leftPile(mainArr, len);
for (int j = 1; j < 4; j++) //从第二列开始
{
for (int i = 0; i < 4; i++)
{
if (mainArr[i * 4 + j] == mainArr[i * 4 + j - 1] || mainArr[i * 4 + j - 1] == 0)
{
mainArr[i * 4 + j - 1] += mainArr[i * 4 + j];
mainArr[i * 4 + j] = 0;
*score += mainArr[i * 4 + j - 1];
}
}
}
}
void rightPile(int *mainArr, int len)
{
for (int j = 2; j > -1; j--)
{
for (int i = 0; i < 4; i++)
{
for (int x = j + 1; x < 4; x++)
{
if (mainArr[i * 4 + x] == 0)
{
mainArr[i * 4 + x] = mainArr[i * 4 + x - 1];
mainArr[i * 4 + x - 1] = 0;
}
}
}
}
}
void moveRight(int *mainArr, int len, int *score)
{
rightPile(mainArr, len);
for (int j = 3; j > 0; j--) //从最后一列开始
{
for (int i = 0; i < 4; i++)
{
if (mainArr[i * 4 + j] == mainArr[i * 4 + j - 1] || mainArr[i * 4 + j] == 0)
{
mainArr[i * 4 + j] += mainArr[i * 4 + j - 1];
mainArr[i * 4 + j - 1] = 0;
*score += mainArr[i * 4 + j];
}
}
}
}
void generateNum(int *mainArr, int len)
{
while (1)
{
int p = randPosition();
if (mainArr[p] == 0)
{
mainArr[p] = randNum();
break;
}
}
}
int checkResult(int *mainArr, int len)
{
int count = 0;
for (int i = 0; i < len; i++)
{
if (mainArr[i] == 2048) //赢的条件
{
return 1; //赢了
}
else if (mainArr[i] == 0)
{
count = count;
}
else
{
count++;
}
}
if (count == 16) //输的条件
{
return 0; //输了
}
else
{
return 2; //继续
}
}
int main()
{
int mainArr[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int len = sizeof(mainArr) / sizeof(mainArr[0]); //行数
int score = 0;
char choice = ' ';
system("color 02");
cout << "按w上,s下,a左,d右。" << endl;
cout << endl;
generateNum(mainArr, len);
printArr(mainArr, len);
cout << "您的上一步操作是:" << choice << endl;
cout << "得分:" << score << endl;
while (1)
{
if (_kbhit())
{
switch (_getch())
{
case 119: // W
choice = 'W';
moveUp(mainArr, len, &score);
break;
case 115: // S
choice = 'S';
moveDown(mainArr, len, &score);
break;
case 97: // A
choice = 'A';
moveLeft(mainArr, len, &score);
break;
case 100: // D
choice = 'D';
moveRight(mainArr, len, &score);
break;
default:
choice = 'N';
}
if (choice != 'N')
{
generateNum(mainArr, len);
switch (checkResult(mainArr, len))
{
case 0:
system("cls");
cout << "您输了!" << endl;
cout << "得分:" << score << endl;
break;
case 1:
system("cls");
cout << "您赢了!" << endl;
cout << "得分:" << score << endl;
break;
case 2:
system("cls");
cout << "按w上,s下,a左,d右。" << endl;
cout << endl;
printArr(mainArr, len);
cout << "您的上一步操作是:" << choice << endl;
cout << "得分:" << score << endl;
break;
}
}
else
{
system("cls");
cout << "按w上,s下,a左,d右。" << endl;
cout << endl;
printArr(mainArr, len);
cout << "您的上一步操作不合法!" << endl;
cout << "得分:" << score << endl;
}
}
}
return 0;
}
2.吃豆人
#include <stdio.h>
#include <iostream>
#include <time.h>
#include <conio.h>
#include <windows.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
const int n = 809;
struct Point {
int x, y;
};
int dali;
int fx[4] = {-1, 27, 1, -27};
int fxfx[4][2] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}};
int dis[1000][1000]; //0:墙 1:有分的路 2:没分的路 3:怪物的家
int changdi[30][27] = {
{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, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
{0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0},
{0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0},
{0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 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, 0},
{0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0},
{0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1 ,0},
{0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0},
{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, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0},
{0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0},
{0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0},
{0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0},
{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0},
{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 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, 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}
};
int x, x1, x2, x3, x4, y, y1, y2, y3, y4;
int now, now1, now2, now3, now4;
int g1, g2, g3, g4;
int fangx, nextfx, last1, last2, last3, last4;
int fenshu, guozi, guaitimer;
int T1, T2, t1, t2, stopped; //T:计时 t1:玩家速度 t2:怪物速度
int f; //f:{0:继续 1:被吃 2:赢了 3:输了}
int beichi;
void color (int a) {//颜色函数
SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE), a);
}
void gotoxy(int x, int y) {//位置函数(行为x 列为y)
COORD pos;
pos.X=2*y;
pos.Y=x;
SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE),pos);
}
void begin () {
system ("cls");
color (11);
printf (" ★");
color (10);
printf ("吃豆人");
color (11);
printf ("★\n\n");
color(7);
printf (" 正在初始化,请耐心等待");
for (int i = 0; i <= n; i++) {
for (int j = 1; j <= n; j++) {
dis[i][j] = 900;
}
}
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= 3; j++) {
if (i + fx[j] >= 0 && i + fx[j] <= n) {
int k = i + fx[j], xx = k/27, yy = k % 27, kk;
if (changdi[i / 27][i % 27] && changdi[xx][yy]) {
dis[i][k] = kk = 1;
}
}
}
}
for (int k = 0; k <= n; k++) {
if (changdi[k]) {
for (int i = 0; i <= n; i++) {
if (changdi[i]) {
for (int j = 0; j <= n; j++) {
if (changdi[j]) {
if (dis[i][j] > dis[i][k] + dis[k][j]) {
dis[i][j] = dis[i][k] + dis[k][j];
}
}
}
}
}
if (k % 80 == 0) {
color (13);
gotoxy (3, 12);
printf("│");
} else if (k % 80 == 20) {
color (13);
gotoxy (3, 12);
printf ("╱");
} else if (k % 80 == 40) {
color (13);
gotoxy (3, 12);
printf ("─");
} else if (k % 80 == 60) {
color(13);
gotoxy (3, 12);
printf ("╲");
}
if (k % 60==0) {
color (11);
gotoxy (5, k / 60);
printf("●");
}
}
}
}
void shuru () {
char ch = getch ();
if (ch == 75) {
if (changdi[x + fxfx[0][0]][y + fxfx[0][1]] == 1 | changdi[x + fxfx[0][0]][y + fxfx[0][1]] == 2) {
fangx = nextfx = 0;
} else {
nextfx = 0;
}
} else if (ch == 80) {
if (changdi[x + fxfx[1][0]][y + fxfx[1][1]] == 1 | changdi[x + fxfx[1][0]][y + fxfx[1][1]] == 2) {
fangx = nextfx = 1;
} else {
nextfx = 1;
}
} else if (ch == 77) {
if (changdi[x + fxfx[2][0]][y + fxfx[2][1]] == 1 | changdi[x + fxfx[2][0]][y + fxfx[2][1]] == 2) {
fangx = nextfx = 2;
} else {
nextfx = 2;
}
} else if (ch == 72) {
if (changdi[x + fxfx[3][0]][y + fxfx[3][1]] == 1 | changdi[x + fxfx[3][0]][y + fxfx[3][1]] == 2) {
fangx = nextfx = 3;
} else {
nextfx = 3;
}
} else if (ch == ' ') {
stopped = (stopped + 1) % 2;
} else if (ch == '-') {
t1++;
} else if ((ch == '+') && t1 - 1 > 0) {
t1--;
}
else if (ch == '$') {
dali = (dali + 1) % 2;
}
}
void reset () {
system ("cls");
color (7);
x = 22;
y = 13;
x1 = x2 = x3 = x4 = 14;
y1 = 11;
y2 = 12;
y3 = 14;
y4 = 15;
now = 607;
now1 = 389;
now2 = 390;
now3 = 392;
now4 = 393;
for (int k = 0; k <= n; k++) {
int i = k / 27, j = k % 27;
gotoxy (i, j);
if (changdi[i][j] == 1) {
color (7);
printf("·");
} else if (!changdi[i][j]) {
color (1);
printf ("■");
}
if (j==26) {
gotoxy (i, 27);
color (7);
printf ("%d", i);
}
}
gotoxy (0, 0);
gotoxy (x, y);
color (14);
printf ("●");
gotoxy (x1, y1);
color (4);
printf ("◆");
gotoxy (x2, y2);
color (5);
printf ("◆");
gotoxy (x3, y3);
color (3);
printf ("◆");
gotoxy (x4, y4);
color (2);
printf ("◆");
fangx = 0;
T1 = T2 = guaitimer = 0;
t1 = 75;
t2 = 100;
stopped = 0;
fenshu = 0;
guozi = 237;
g1 = g2 = g3 = g4 = 0;
dali = 0;
gotoxy (14, 30);
printf (" ");
}
void move1 () {
int xx, yy;
xx = x + fxfx[nextfx][0];
yy = y + fxfx[nextfx][1];
if (changdi[xx][yy]) {
if (changdi[xx][yy] == 1) {
fenshu++;
changdi[xx][yy] = 2;
}
color (14);
gotoxy (x, y);
printf (" ");
gotoxy (xx, yy);
if (!dali) {
printf ("♀");
} else {
printf ("☆");
}
now = x * 27 + y;
x = xx;
y = yy;
fangx = nextfx;
} else {
if (x == 13 && y == 0 && fangx == 0) {
xx = x;
yy = 26;
} else if (x == 13 && y == 26 && fangx == 2) {
xx = x;
yy = 0;
} else {
xx = x + fxfx[fangx][0];
yy = y + fxfx[fangx][1];
}
if (changdi[xx][yy]) {
if (changdi[xx][yy] == 1) {
fenshu++;
changdi[xx][yy] = 2;
}
color (14);
gotoxy (x, y);
printf (" ");
gotoxy (xx, yy);
if (!dali) {
printf ("♀");
} else {
printf ("☆");
}
now = x * 27 + y;
x = xx;
y = yy;
}
}
color (7);
}
void move2 () {
int haha, minhaha, xx, yy, chi = 0;
if (g1) {
minhaha = 2147483647; //相当于INT_MAX
if (now1 % 27 == 0 | now1 % 27 == 26) {
haha = last1;
} else if (!dali) {
for (int i = 0; i <= 3; i++) {
if (changdi[(now1 + fx[i]) / 27][(now1 + fx[i]) % 27] && i != last1 &&
minhaha > dis[now1 + fx[i]][now]) {
minhaha = dis[now1 + fx[i]][now];
haha = i;
}
}
} else {
minhaha = -minhaha;
for (int i = 0; i <= 3; i++) {
if (changdi[(now1 + fx[i]) / 27][(now1 + fx[i]) % 27] && i != last1 &&
minhaha < dis[now1 + fx[i]][now]) {
minhaha = dis[now1 + fx[i]][now];
haha = i;
}
}
}
xx = now1 / 27;
yy = now1 % 27;
gotoxy (xx, yy);
if (changdi[xx][yy] == 1) {
printf ("·");
} else {
printf (" ");
}
now1 += fx[haha];
last1 = (haha + 2) % 4;
xx = now1 / 27;
yy = now1 % 27;
gotoxy (xx, yy);
color (4);
printf ("◆");
color (7);
if (xx == x && yy == y) {
if (!dali) {
chi++;
} else {
guozi += 50;
fenshu += 50;
last1 = 0;
gotoxy (now1 / 27, now1 % 27);
if (changdi[now1 / 27][now1 % 27] == 1) {
printf ("·");
} else {
printf (" ");
}
now1 = 389;
}
}
}
if (g2) {
int k;
minhaha = 2147483647;
if (fangx == 0 | fangx == 2) {
k = y + (fxfx[fangx][1]) * 3;
while (k > 25 | !changdi[x][k]) {
k--;
}
while (k < 1 | !changdi[x][k]) {
k++;
}
} else {
k = x + (fxfx[fangx][0]) * 3;
while (k > 28 | !changdi[k][y]) {
k--;
}
while (k < 1 | !changdi[k][y]) {
k++;
}
}
if (fangx == 0 | fangx == 2) {
k += x * 27;
} else {
k = k * 27 + y;
}
if (now2 % 27 == 0 | now2 % 27 == 26) {
haha = last2;
}
else if (!dali) {
for (int i = 0; i <= 3; i++) {
if (changdi[(now2 + fx[i]) / 27][(now2 + fx[i]) % 27] && i != last2 &&
minhaha > dis[now2 + fx[i]][k]) {
minhaha = dis[now2 + fx[i]][k];
haha = i;
}
}
} else {
minhaha = -minhaha;
for (int i = 0; i <= 3; i++) {
if (changdi[(now2 + fx[i]) / 27][(now2 + fx[i]) % 27] && i != last2 &&
minhaha < dis[now2 + fx[i]][k]) {
minhaha = dis[now2 + fx[i]][k];
haha = i;
}
}
}
xx = now2 / 27;
yy = now2 % 27;
gotoxy (xx, yy);
if (changdi[xx][yy] == 1) {
printf ("·");
} else {
printf (" ");
}
now2 += fx[haha];
last2 = (haha + 2) % 4;
gotoxy (18, 30);
xx = now2 / 27;
yy = now2 % 27;
gotoxy (xx, yy);
color (5);
printf ("◆");
color (7);
if (xx == x && yy == y) {
if (!dali) {
chi++;
} else {
guozi += 50;
fenshu += 50;
last2 = 0;
gotoxy (now2 / 27, now2 % 27);
if (changdi[now2 / 27][now2 % 27] == 1) {
printf ("·");
} else {
printf (" ");
}
now2 = 390;
}
}
}
if (g3) {
int k;
minhaha = 2147483647;
if (fangx == 0 | fangx == 2) {
k = y + (fxfx[(fangx + 1) % 4][1]) * 3;
while (k > 25 | !changdi[x][k]) {
k--;
}
while (k < 1 | !changdi[x][k]) {
k++;
}
} else {
k = x + (fxfx[(fangx + 1) % 4][0]) * 3;
while (k > 28 | !changdi[k][y]) {
k--;
}
while (k < 1 | !changdi[k][y]) {
k++;
}
}
if (fangx == 0 | fangx == 2) {
k += x * 27;
} else {
k = k * 27 + y;
}
if (now3 % 27 == 0 | now3 % 27 == 26) {
haha = last3;
} else if (!dali) {
for (int i = 0; i <= 3; i++) {
if (changdi[(now3 + fx[i]) / 27][(now3 + fx[i]) % 27] && i != last3 &&
minhaha > dis[now3 + fx[i]][k]) {
minhaha = dis[now3 + fx[i]][k];
haha = i;
}
}
} else {
minhaha = -minhaha;
for (int i = 0; i <= 3; i++) {
if (changdi[(now3 + fx[i]) / 27][(now3 + fx[i]) % 27] && i != last3 &&
minhaha < dis[now3 + fx[i]][k]) {
minhaha = dis[now3 + fx[i]][k];
haha = i;
}
}
}
xx = now3 / 27;
yy = now3 % 27;
gotoxy (xx, yy);
if (changdi[xx][yy] == 1) {
printf ("·");
} else {
printf (" ");
}
now3 += fx[haha];
last3 = (haha + 2) % 4;
gotoxy (18, 30);
xx = now3 / 27;
yy = now3 % 27;
gotoxy (xx, yy);
color (3);
printf ("◆");
color (7);
if (xx == x && yy == y) {
if (!dali) {
chi++;
} else {
guozi += 50;
fenshu += 50;
last3 = 0;
gotoxy (now3 / 27, now3 % 27);
if (changdi[now3 / 27][now3 % 27] == 1) {
printf ("·");
} else {
printf (" ");
}
now3 = 341;
}
}
}
if (chi) {
beichi++;
}
}
int main () {
MessageBox (NULL, "欢迎来到吃豆人游戏!", "温馨提示", MB_OK);
begin ();
int jixu = 1;
reset ();
string bb[4] = {"●", "①", "②" ,"③"};
color (7);
gotoxy (12, 12);
printf ("倒计时");
color (12);
for (int i = 3; i >= 0; i--) {
if (i==0) {
color (11);
}
gotoxy (13, 13);
cout << bb[i];
Sleep (1000);
}
gotoxy (12, 12);
printf (" ");
gotoxy (13, 13);
printf (" ");
while (!f) {
Sleep (1);
gotoxy (7, 30);
color (3);
printf ("得分:%d ", fenshu);
gotoxy (3, 30);
printf ("怪物速度:%d ", 300 - t2);
gotoxy (5, 30);
printf ("你的速度:%d ", 300 - t1);
gotoxy (9, 30);
printf ("被吃次数:%d ", beichi);
gotoxy (11, 30);
printf ("控制小人行走:方向键");
gotoxy (13, 30);
printf ("复活次数:无限次");
gotoxy (15, 30);
printf ("小人加速/减速:'+'/'-'");
gotoxy (17, 30);
printf ("大力丸:$键");
gotoxy (20, 10);
color (4);
if (kbhit ()) {
shuru ();
}
if (stopped) {
continue;
}
T1 = (T1 + 1) % t1;
T2 = (T2 + 1) % t2;
if (T1 % t1 == 0 && now + fx[fangx] > 0 && now + fx[fangx] < n) {
move1 ();
}
if (T2 % t2 == 0) {
if (guaitimer <= 8) {
if (guaitimer==0) {
g1 = 1;
}
if (guaitimer == 8) {
g2 = 1;
}
guaitimer++;
}
if (!g3 && fenshu >= 30) {
g3 = 1;
}
move2 ();
}
if (fenshu == guozi) {
f=2;
}
}
if (f == 2) {
Sleep (3000);
system ("cls");
gotoxy (10, 20);
color (3);
string str = "恭喜您吃完了所有豆子!";
for (int i = 0; i < str.size (); i++) {
Sleep (80);
cout << str[i];
}
Sleep (2000);
gotoxy (12, 20);
str = "您一共被怪物吃掉了";
for (int i = 0; i < str.size (); i++) {
Sleep (80);
cout << str[i];
}
Sleep (80);
cout << beichi;
Sleep (80);
cout << "次";
Sleep (80);
cout << "!";
gotoxy (14, 20);
Sleep (2000);
}
}
3.打方块
#include<bits/stdc++.h>//打方块 Windows10
#include<windows.h>
using namespace std;
int fen,mb[10][18],leaf;
void kg(int a) {
for(int i=0; i<a; i++)
cout<<' ';
}
void go(int x, int y) {
COORD p;
p.X=(x-1)*2;
p.Y=y-1;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),p);
}
void printtu(int x,int y,bool a) {
go(x,y);
cout<<"■";
if(x>2&&x<11) {
go(x-1,y+1);
cout<<"■■■";
} else if(x==2) {
go(x,y+1);
cout<<"■■";
} else if(x==11) {
go(x-1,y+1);
cout<<"■■";
} else;
if(a)
for(int i=0; i<18; i++) {
go(2,i+2);
kg(20);
}
Sleep(100);
go(x,y);
kg(2);
if(x>2&&x<11) {
go(x-1,y+1);
kg(6);
} else if(x==2) {
go(x,y+1);
kg(4);
} else if(x==11) {
go(x-1,y+1);
kg(4);
} else;
go(14,5);
kg(4);
cout<<"\b\b\b\b"<<fen;
if(a)
for(int i=0; i<18; i++) {
go(2,i+2);
for(int o=0; o<10; o++) {
if(mb[o][i])
cout<<"■";
else kg(2);
}
}
}
void sj(int x) {
int i;
for(i=19;; i--) {
go(x,i);
cout<<"■";
Sleep(10);
cout<<"\b\b";
kg(2);
if(i<3)break;
if(mb[x-2][i-3]==1)break;
}
mb[x-2][i-2]=1;
go(x,i);
cout<<"■";
fen-=10;
for(int o=0; o<10; o++)
if(mb[o][i-2]==0)return;
for(int o=0; o<10; o++)
mb[o][i-2]=0;
for(int o=i-2; o<17; o++)
for(int j=0; j<10; j++)
mb[j][o]=mb[j][o+1];
for(int o=0; o<10; o++)
mb[o][17]=0;
printtu(x,20,1);
fen+=100;
}
void mouse(int &x,int &y) {
POINT p;
HWND h=GetForegroundWindow();
GetCursorPos(&p);
ScreenToClient(h,&p);
x=p.x;
y=p.y;
}
void m(int wt) {
lkr:
;
fen=-500;
leaf=8;
srand(time(0));
system("mode con cols=33 lines=24");
system("cls");
cout<<"┌ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┐"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆ 分数"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆ 生命"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆ ";
printf("%c %c %c %c\n",3,3,3,3);
cout<<"┆ ";
kg(20);
cout<<"┆ ";
printf("%c %c %c %c\n",3,3,3,3);
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"┆ ";
kg(20);
cout<<"┆"<<endl;
cout<<"└ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┄ ┘"<<endl;
lk:
;
for(int i=0; i<10; i++)
for(int o=0; o<18; o++)
mb[i][o]=0;
int x=6;
for(int i=wt*10;;) {
if(i<wt*10)goto asd;
for(int i=0; i<10; i++)
for(int o=0; o<18; o++)
if(mb[i][o]!=0)goto qwe;
fen+=500;
qwe:
;
for(int o=0; o<10; o++)
if(mb[o][17]==1)goto as;
for(int o=17; o>0; o--)
for(int j=0; j<10; j++)
mb[j][o]=mb[j][o-1];
for(int o=0; o<10; o++)
mb[o][0]=rand()%2;
asd:
;
if(GetAsyncKeyState(VK_RIGHT)!=0&&x<11)x++;
if(GetAsyncKeyState(VK_LEFT)!=0&&x>2)x--;
if(GetAsyncKeyState(VK_UP)!=0)sj(x);
printtu(x,20,i>=wt*10);
if(i<wt*10)i++;
else i=1;
}
as:
;
for(int i=2; i<22; i++) {
go(2,i);
kg(20);
}
fen-=600;
switch(leaf) {
case 1:
go(13,8);
cout<<' '<<' ';
break;
case 2:
leaf--;
go(14,8);
cout<<' '<<' ';
goto lk;
case 3:
leaf--;
go(15,8);
cout<<' '<<' ';
goto lk;
case 4:
leaf--;
go(16,8);
cout<<' '<<' ';
goto lk;
case 5:
leaf--;
go(13,9);
cout<<' '<<' ';
goto lk;
case 6:
leaf--;
go(14,9);
cout<<' '<<' ';
goto lk;
case 7:
leaf--;
go(15,9);
cout<<' '<<' ';
goto lk;
case 8:
leaf--;
go(16,9);
cout<<' '<<' ';
goto lk;
}
go(5,7);
cout<<"你输了!";
go(3,8);
cout<<" ┆ 再来[R]┆ ┆ 返回[E]┆";
for(;;) {
if(GetAsyncKeyState('R')!=0||GetAsyncKeyState('r')!=0)goto lkr;
if(GetAsyncKeyState('E')!=0||GetAsyncKeyState('e')!=0)return;
}
}
void dafangkuai() {}
int main() {
SetConsoleTitle("打方块Windows10");
int q=3;
a:
;
system("mode con cols=80 lines=25");
system("cls");
bool jh[8][27]= {0,0,1,0,0,1,1,1,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1,1,1,1,0,0,1,0,0,1,1,1,1,1,1,1,0,1,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,1,0,0,1,1,1,1,1,0,0,0,1,1,1,0,0,1,0,0,0,0,1,1,1,1,0,1,1,1,0,0,0,1,0,1,0,1,1,1,0,0,0,0,1,0,0,0,0,1,0,0,1,0,0,1,0,1,1,1,1,1,1,1,0,0,1,0,0,0,0,1,0,0,0,0,1,0,0,1,0,0,1,1,0,0,0,1,0,0,0,0,1,1,0,0,0,1,1,0,0,0,1,0,0,1,1,0,0,1,0,0,0,1,0,1,0,0,0,0,1,0,0,0,0,1,0,0,1,0,0,0,0,1,0,1,0,0,0,1,0,0,0,1,0};
for(int i=2; i<10; i++) {
go(7,i);
for(int o=0; o<27; o++) {
if(jh[i-2][o])
cout<<"■";
else cout<<' '<<' ';
}
}
go(17,11);
cout<<"|开始游戏|";
go(17,13);
cout<<"|设置游戏|";
go(17,15);
cout<<"|游戏规则|";
go(17,17);
cout<<"|退出游戏|";
go(1,23);
cout<<"[L]确定";
int y=1;
for(;;) {
if(GetAsyncKeyState(VK_DOWN)!=0)y+=((y==4)?-3:1);
if(GetAsyncKeyState(VK_UP)!=0)y-=((y==1)?-3:1);
if(GetAsyncKeyState('l')!=0||GetAsyncKeyState('L')!=0)
switch(y) {
case 1:
system("cls");
m(q);
goto a;
case 2:
system("cls");
go(16,11);
cout<<' '<<q<<"秒增加一行";
go(16,10);
printf("[%c]",30);
go(16,12);
printf("[%c]",31);
go(1,23);
cout<<"[K]确定";
for(;;) {
if(GetAsyncKeyState(VK_UP)!=0&&q<9) {
q++;
go(16,11);
cout<<' '<<q;
}
if(GetAsyncKeyState(VK_DOWN)!=0&&q>1) {
q--;
go(16,11);
cout<<' '<<q;
}
if(GetAsyncKeyState('k')!=0||GetAsyncKeyState('K')!=0)goto a;
Sleep(100);
}
case 3:
MessageBox(0,"点确定浏览规则" ,"规则",MB_OK);
MessageBox(0,"←→控制炮台","规则",MB_OK);
MessageBox(0,"满一行即消除","规则",MB_OK);
MessageBox(0,"每消除一行+100","规则",MB_OK);
MessageBox(0,"少一条命-100","规则",MB_OK);
MessageBox(0,"全部消除+500","规则",MB_OK);
MessageBox(0,"发射一炮-10","规则",MB_OK);
case 4:
return 0;
}
go(16,11);
cout<<' '<<' ';
go(22,11);
cout<<' ';
go(16,13);
cout<<' '<<' ';
go(22,13);
cout<<' ';
go(16,15);
cout<<' '<<' ';
go(22,15);
cout<<' ';
go(16,17);
cout<<' '<<' ';
go(22,17);
cout<<' ';
go(16,9+2*y);
cout<<' '<<'>';
go(22,9+2*y);
cout<<'<';
Sleep(100);
}
}
4.打飞机
#include<iostream>
#include<windows.h>
#include<conio.h>
#include<time.h>
#include<string>
using namespace std;
/*=============== all the structures ===============*/
typedef struct Frame
{
COORD position[2];
int flag;
}Frame;
/*=============== all the functions ===============*/
void SetPos(COORD a)// set cursor
{
HANDLE out=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(out, a);
}
void SetPos(int i, int j)// set cursor
{
COORD pos={i, j};
SetPos(pos);
}
void HideCursor()
{
CONSOLE_CURSOR_INFO cursor_info = {1, 0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
//把第y行,[x1, x2) 之间的坐标填充为 ch
void drawRow(int y, int x1, int x2, char ch)
{
SetPos(x1,y);
for(int i = 0; i <= (x2-x1); i++)
cout<<ch;
}
//在a, b 纵坐标相同的前提下,把坐标 [a, b] 之间填充为 ch
void drawRow(COORD a, COORD b, char ch)
{
if(a.Y == b.Y)
drawRow(a.Y, a.X, b.X, ch);
else
{
SetPos(0, 25);
cout<<"error code 01:无法填充行,因为两个坐标的纵坐标(x)不相等";
system("pause");
}
}
//把第x列,[y1, y2] 之间的坐标填充为 ch
void drawCol(int x, int y1, int y2, char ch)
{
int y=y1;
while(y!=y2+1)
{
SetPos(x, y);
cout<<ch;
y++;
}
}
//在a, b 横坐标相同的前提下,把坐标 [a, b] 之间填充为 ch
void drawCol(COORD a, COORD b, char ch)
{
if(a.X == b.X)
drawCol(a.X, a.Y, b.Y, ch);
else
{
SetPos(0, 25);
cout<<"error code 02:无法填充列,因为两个坐标的横坐标(y)不相等";
system("pause");
}
}
//左上角坐标、右下角坐标、用row填充行、用col填充列
void drawFrame(COORD a, COORD b, char row, char col)
{
drawRow(a.Y, a.X+1, b.X-1, row);
drawRow(b.Y, a.X+1, b.X-1, row);
drawCol(a.X, a.Y+1, b.Y-1, col);
drawCol(b.X, a.Y+1, b.Y-1, col);
}
void drawFrame(int x1, int y1, int x2, int y2, char row, char col)
{
COORD a={x1, y1};
COORD b={x2, y2};
drawFrame(a, b, row, col);
}
void drawFrame(Frame frame, char row, char col)
{
COORD a = frame.position[0];
COORD b = frame.position[1];
drawFrame(a, b, row, col);
}
void drawPlaying()
{
drawFrame(0, 0, 48, 24, '=', '|');// draw map frame;
drawFrame(49, 0, 79, 4, '-', '|');// draw output frame
drawFrame(49, 4, 79, 9, '-', '|');// draw score frame
drawFrame(49, 9, 79, 20, '-', '|');// draw operate frame
drawFrame(49, 20, 79, 24, '-', '|');// draw other message frame
SetPos(52, 6);
cout<<"得分:";
SetPos(52, 7);
cout<<"称号:";
SetPos(52,10);
cout<<"操作方式:";
SetPos(52,12);
cout<<" a,s,d,w 控制战机移动。";
SetPos(52,14);
cout<<" p 暂停游戏。";
SetPos(52,16);
cout<<" e 退出游戏。";
}
//在[a, b)之间产生一个随机整数
int random(int a, int b)
{
int c=(rand() % (a-b))+ a;
return c;
}
//在两个坐标包括的矩形框内随机产生一个坐标
COORD random(COORD a, COORD b)
{
int x=random(a.X, b.X);
int y=random(a.Y, b.Y);
COORD c={x, y};
return c;
}
bool judgeCoordInFrame(Frame frame, COORD spot)
{
if(spot.X>=frame.position[0].X)
if(spot.X<=frame.position[1].X)
if(spot.Y>=frame.position[0].Y)
if(spot.Y<=frame.position[0].Y)
return true;
return false;
}
void printCoord(COORD a)
{
cout <<"( "<<a.X<<" , "<<a.Y<<" )";
}
void printFrameCoord(Frame a)
{
printCoord(a.position[0]);
cout <<" - ";
printCoord(a.position[1]);
}
int drawMenu()
{
SetPos(30, 1);
cout<<"P l a n e W a r";
drawRow(3, 0, 79, '-');
drawRow(5, 0, 79, '-');
SetPos(28, 4);
cout<<"w 和 s 选择, k 确定";
SetPos(15, 11);
cout<<"1. 简单的敌人";
SetPos(15, 13);
cout<<"2. 冷酷的敌人";
drawRow(20, 0, 79, '-');
drawRow(22, 0, 79, '-');
SetPos(47, 11);
cout<<"简单的敌人:";
SetPos(51, 13);
cout<<"简单敌人有着较慢的移动速度。";
SetPos(24, 21);
cout<<"制作:王子岳";
int j=11;
SetPos(12, j);
cout<<">>";
//drawFrame(45, 9, 79, 17, '=', '|');
while(1)
{ if( _kbhit() )
{
char x=_getch();
switch (x)
{
case 'w' :
{
if( j == 13)
{
SetPos(12, j);
cout<<" ";
j = 11;
SetPos(12, j);
cout<<">>";
SetPos(51, 13);
cout<<" ";
SetPos(47, 11);
cout<<"简单的敌人:";
SetPos(51, 13);
cout<<"简单敌人有较慢的移动速度,比较容易对付";
}
break;
}
case 's' :
{
if( j == 11 )
{
SetPos(12, j);
cout<<" ";
j = 13;
SetPos(12, j);
cout<<">>";
SetPos(51, 13);
cout<<" ";
SetPos(47, 11);
cout<<"冷酷的敌人:";
SetPos(51, 13);
cout<<"冷酷的敌人移动速度较快,不是很好对付哟。";
}
break;
}
case 'k' :
{
if (j == 8) return 1;
else return 2;
}
}
}
}
}
/*
DWORD WINAPI MusicFun(LPVOID lpParamte)
{
//DWORD OBJ;
sndPlaySound(TEXT("bgm.wav"), SND_FILENAME|SND_ASYNC);
return 0;
}
*/
/*================== the Game Class ==================*/
class Game
{
public:
COORD position[10];
COORD bullet[10];
Frame enemy[8];
int score;
int rank;
int rankf;
string title;
int flag_rank;
Game ();
//初始化所有
void initPlane();
void initBullet();
void initEnemy();
//初始化其中一个
//void initThisBullet( COORD );
//void initThisEnemy( Frame );
void planeMove(char);
void bulletMove();
void enemyMove();
//填充所有
void drawPlane();
void drawPlaneToNull();
void drawBullet();
void drawBulletToNull();
void drawEnemy();
void drawEnemyToNull();
//填充其中一个
void drawThisBulletToNull( COORD );
void drawThisEnemyToNull( Frame );
void Pause();
void Playing();
void judgePlane();
void judgeEnemy();
void Shoot();
void GameOver();
void printScore();
};
Game::Game()
{
initPlane();
initBullet();
initEnemy();
score = 0;
rank = 25;
rankf = 0;
flag_rank = 0;
}
void Game::initPlane()
{
COORD centren={39, 22};
position[0].X=position[5].X=position[7].X=position[9].X=centren.X;
position[1].X=centren.X-2;
position[2].X=position[6].X=centren.X-1;
position[3].X=position[8].X=centren.X+1;
position[4].X=centren.X+2;
for(int i=0; i<=4; i++)
position[i].Y=centren.Y;
for(int i=6; i<=8; i++)
position[i].Y=centren.Y+1;
position[5].Y=centren.Y-1;
position[9].Y=centren.Y-2;
}
void Game::drawPlane()
{
for(int i=0; i<9; i++)
{
SetPos(position[i]);
if(i!=5)
cout<<"O";
else if(i==5)
cout<<"|";
}
}
void Game::drawPlaneToNull()
{
for(int i=0; i<9; i++)
{
SetPos(position[i]);
cout<<" ";
}
}
void Game::initBullet()
{
for(int i=0; i<10; i++)
bullet[i].Y = 30;
}
void Game::drawBullet()
{
for(int i=0; i<10; i++)
{
if( bullet[i].Y != 30)
{
SetPos(bullet[i]);
cout<<"^";
}
}
}
void Game::drawBulletToNull()
{
for(int i=0; i<10; i++)
if( bullet[i].Y != 30 )
{
COORD pos={bullet[i].X, bullet[i].Y+1};
SetPos(pos);
cout<<" ";
}
}
void Game::initEnemy()
{
COORD a={1, 1};
COORD b={45, 15};
for(int i=0; i<8; i++)
{
enemy[i].position[0] = random(a, b);
enemy[i].position[1].X = enemy[i].position[0].X + 3;
enemy[i].position[1].Y = enemy[i].position[0].Y + 2;
}
}
void Game::drawEnemy()
{
for(int i=0; i<8; i++)
drawFrame(enemy[i].position[0], enemy[i].position[1], '-', '|');
}
void Game::drawEnemyToNull()
{
for(int i=0; i<8; i++)
{
drawFrame(enemy[i].position[0], enemy[i].position[1], ' ', ' ');
}
}
void Game::Pause()
{
SetPos(61,2);
cout<<" ";
SetPos(61,2);
cout<<"暂停中...";
char c=_getch();
while(c!='p')
c=_getch();
SetPos(61,2);
cout<<" ";
}
void Game::planeMove(char x)
{
if(x == 'a')
if(position[1].X != 1)
for(int i=0; i<=9; i++)
position[i].X -= 2;
if(x == 's')
if(position[7].Y != 23)
for(int i=0; i<=9; i++)
position[i].Y += 1;
if(x == 'd')
if(position[4].X != 47)
for(int i=0; i<=9; i++)
position[i].X += 2;
if(x == 'w')
if(position[5].Y != 3)
for(int i=0; i<=9; i++)
position[i].Y -= 1;
}
void Game::bulletMove()
{
for(int i=0; i<10; i++)
{
if( bullet[i].Y != 30)
{
bullet[i].Y -= 1;
if( bullet[i].Y == 1 )
{
COORD pos={bullet[i].X, bullet[i].Y+1};
drawThisBulletToNull( pos );
bullet[i].Y=30;
}
}
}
}
void Game::enemyMove()
{
for(int i=0; i<8; i++)
{
for(int j=0; j<2; j++)
enemy[i].position[j].Y++;
if(24 == enemy[i].position[1].Y)
{
COORD a={1, 1};
COORD b={45, 3};
enemy[i].position[0] = random(a, b);
enemy[i].position[1].X = enemy[i].position[0].X + 3;
enemy[i].position[1].Y = enemy[i].position[0].Y + 2;
}
}
}
void Game::judgePlane()
{
for(int i = 0; i < 8; i++)
for(int j=0; j<9; j++)
if(judgeCoordInFrame(enemy[i], position[j]))
{
SetPos(62, 1);
cout<<"坠毁";
drawFrame(enemy[i], '+', '+');
Sleep(1000);
GameOver();
break;
}
}
void Game::drawThisBulletToNull( COORD c)
{
SetPos(c);
cout<<" ";
}
void Game::drawThisEnemyToNull( Frame f )
{
drawFrame(f, ' ', ' ');
}
void Game::judgeEnemy()
{
for(int i = 0; i < 8; i++)
for(int j = 0; j < 10; j++)
if( judgeCoordInFrame(enemy[i], bullet[j]) )
{
score += 5;
drawThisEnemyToNull( enemy[i] );
COORD a={1, 1};
COORD b={45, 3};
enemy[i].position[0] = random(a, b);
enemy[i].position[1].X = enemy[i].position[0].X + 3;
enemy[i].position[1].Y = enemy[i].position[0].Y + 2;
drawThisBulletToNull( bullet[j] );
bullet[j].Y = 30;
}
}
void Game::Shoot()
{
for(int i=0; i<10; i++)
if(bullet[i].Y == 30)
{
bullet[i].X = position[5].X;
bullet[i].Y = position[5].Y-1;
break;
}
}
void Game::printScore()
{
if(score == 120 && flag_rank == 0)
{
rank -= 3;
flag_rank = 1;
}
else if( score == 360 && flag_rank == 1)
{
rank -= 5;
flag_rank = 2;
}
else if( score == 480 && flag_rank == 2)
{
rank -= 5;
flag_rank = 3;
}
int x=rank/5;
SetPos(60, 6);
cout<<score;
if( rank!=rankf )
{
SetPos(60, 7);
if( x == 5)
title="初级飞行员";
else if( x == 4)
title="中级飞行员";
else if( x == 3)
title="高级飞行员";
else if( x == 2 )
title="王牌飞行员";
cout<<title;
}
rankf = rank;
}
void Game::Playing()
{
//HANDLE MFUN;
//MFUN= CreateThread(NULL, 0, MusicFun, NULL, 0, NULL);
drawEnemy();
drawPlane();
int flag_bullet = 0;
int flag_enemy = 0;
while(1)
{
Sleep(8);
if(_kbhit())
{
char x = _getch();
if ('a' == x || 's' == x || 'd' == x || 'w' == x)
{
drawPlaneToNull();
planeMove(x);
drawPlane();
judgePlane();
}
else if ('p' == x)
Pause();
else if( 'k' == x)
Shoot();
else if( 'e' == x)
{
//CloseHandle(MFUN);
GameOver();
break;
}
}
/* 处理子弹 */
if( 0 == flag_bullet )
{
bulletMove();
drawBulletToNull();
drawBullet();
judgeEnemy();
}
flag_bullet++;
if( 5 == flag_bullet )
flag_bullet = 0;
/* 处理敌人 */
if( 0 == flag_enemy )
{
drawEnemyToNull();
enemyMove();
drawEnemy();
judgePlane();
}
flag_enemy++;
if( flag_enemy >= rank )
flag_enemy = 0;
/* 输出得分 */
printScore();
}
}
void Game::GameOver()
{
system("cls");
COORD p1={28,9};
COORD p2={53,15};
drawFrame(p1, p2, '=', '|');
SetPos(36,12);
string str="Game Over!";
for(int i=0; i<str.size(); i++)
{
Sleep(80);
cout<<str[i];
}
Sleep(1000);
system("cls");
drawFrame(p1, p2, '=', '|');
SetPos(31, 11);
cout<<"击落敌机:"<<score/5<<" 架";
SetPos(31, 12);
cout<<"得 分:"<<score;
SetPos(31, 13);
cout<<"获得称号:"<<title;
SetPos(30, 16);
Sleep(1000);
cout<<"继续? 是(y)| 否(n)制作:王子岳";
as:
char x=_getch();
if (x == 'n')
exit(0);
else if (x == 'y')
{
system("cls");
Game game;
int a = drawMenu();
if(a == 2)
game.rank = 20;
system("cls");
drawPlaying();
game.Playing();
}
else goto as;
}
/*================== the main function ==================*/
int main()
{
//游戏准备
srand((int)time(0)); //随机种子
HideCursor(); //隐藏光标
Game game;
int a = drawMenu();
if(a == 2)
game.rank = 20;
system("cls");
drawPlaying();
game.Playing();
}
5.俄罗斯方块
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
#include <windows.h>
#include <conio.h>
using namespace std;
int block00[4][4] = { { 10, 0, 0, 0 }, { 1, 1, 1, 1 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } };
int block01[4][4] = { { 11, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 } };
int block02[4][4] = { { 12, 0, 0, 0 }, { 0, 0, 0, 0 }, { 1, 1, 1, 0 }, { 0, 1, 0, 0 } };
int block03[4][4] = { { 13, 0, 0, 0 }, { 0, 1, 0, 0 }, { 1, 1, 0, 0 }, { 0, 1, 0, 0 } };
int block04[4][4] = { { 14, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 1, 0, 0 }, { 1, 1, 1, 0 } };
int block05[4][4] = { { 15, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 1, 1, 0 }, { 0, 1, 0, 0 } };
int block06[4][4] = { { 16, 0, 0, 0 }, { 0, 0, 0, 0 }, { 1, 1, 1, 0 }, { 1, 0, 0, 0 } };
int block07[4][4] = { { 17, 0, 0, 0 }, { 1, 1, 0, 0 }, { 0, 1, 0, 0 }, { 0, 1, 0, 0 } };
int block08[4][4] = { { 18, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 1, 0 }, { 1, 1, 1, 0 } };
int block09[4][4] = { { 19, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 1, 0, 0 }, { 0, 1, 1, 0 } };
int block10[4][4] = { { 20, 0, 0, 0 }, { 0, 0, 0, 0 }, { 1, 1, 1, 0 }, { 0, 0, 1, 0 } };
int block11[4][4] = { { 21, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 1, 0, 0 }, { 1, 1, 0, 0 } };
int block12[4][4] = { { 22, 0, 0, 0 }, { 0, 0, 0, 0 }, { 1, 0, 0, 0 }, { 1, 1, 1, 0 } };
int block13[4][4] = { { 23, 0, 0, 0 }, { 0, 1, 1, 0 }, { 0, 1, 0, 0 }, { 0, 1, 0, 0 } };
int block14[4][4] = { { 24, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 1, 1, 0 }, { 1, 1, 0, 0 } };
int block15[4][4] = { { 25, 0, 0, 0 }, { 1, 0, 0, 0 }, { 1, 1, 0, 0 }, { 0, 1, 0, 0 } };
int block16[4][4] = { { 26, 0, 0, 0 }, { 0, 0, 0, 0 }, { 1, 1, 0, 0 }, { 0, 1, 1, 0 } };
int block17[4][4] = { { 27, 0, 0, 0 }, { 0, 0, 1, 0 }, { 0, 1, 1, 0 }, { 0, 1, 0, 0 } };
int block18[4][4] = { { 28, 0, 0, 0 }, { 0, 0, 0, 0 }, { 1, 1, 0, 0 }, { 1, 1, 0, 0 } };
void initialWindow (HANDLE hOut);//初始化窗口
void initialPrint (HANDLE hOut);//初始化界面
void gotoXY (HANDLE hOut, int x, int y);//移动光标
void roundBlock (HANDLE hOut, int block[4][4]);//随机生成方块并打印到下一个方块位置
bool collisionDetection (int block[4][4], int map[21][12], int x, int y);//检测碰撞
void printBlock (HANDLE hOut, int block[4][4], int x, int y);//打印方块
void clearBlock (HANDLE hOut, int block[4][4], int x, int y);//消除方块
void myLeft (HANDLE hOut, int block[4][4], int map[21][12], int x, int &y);//左移
void myRight (HANDLE hOut, int block[4][4], int map[21][12], int x, int &y);//右移
void myUp (HANDLE hOut, int block[4][4], int map[21][12], int x, int &y);//顺时针旋转90度
int myDown (HANDLE hOut, int block[4][4], int map[21][12], int &x, int y);//加速下落
void myStop (HANDLE hOut, int block[4][4]);//游戏暂停
void gameOver (HANDLE hOut, int block[4][4], int map[21][12]);//游戏结束
//判断是否能消行并更新分值
void eliminateRow (HANDLE hOut, int map[21][12], int &val, int &fraction, int &checkpoint);
int main () {
MessageBox (NULL, "欢迎来到俄罗斯方块游戏!", "温馨提示", MB_OK);
system ("mode coon cols=200 lines=100");
system ("mode con cols=70 lines=35");
int map[21][12];
int blockA[4][4];//候选区的方块
int blockB[4][4];//下落中的方块
int positionX, positionY;//方块左上角的坐标
bool check;//检查方块还能不能下落
char key;//用来存储按键
int val;//用来控制下落速度
int fraction;//用来存储得分
int checkpoint;//用来存储关卡
int times;
HANDLE hOut = GetStdHandle (STD_OUTPUT_HANDLE);//获取标准输出设备句柄
initialWindow (hOut);
initial:
gotoXY (hOut, 0, 0);
initialPrint (hOut);
check = true;
val = 50;
fraction = 0;
checkpoint = 1;
times = val;
for (int i = 0; i < 20; i++) {
for (int j = 1; j < 11; j++) {
map[i][j] = 0;
}
}
for (int i = 0; i < 20; i++) {
map[i][0] = map[i][11] = 1;
}
for (int i = 0; i < 12; i++) {
map[20][i] = 1;
}
srand ((unsigned) time (NULL));
roundBlock (hOut, blockA);
while (true) {
if (check) {
eliminateRow (hOut, map, val, fraction, checkpoint);
check = false;
positionX = -3;
positionY = 4;
if (collisionDetection (blockA, map, positionX, positionY)) {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
blockB[i][j] = blockA[i][j];
}
}
roundBlock (hOut, blockA);
} else {
gameOver (hOut, blockA, map);
goto initial;
}
}
printBlock (hOut, blockB, positionX, positionY);
if (_kbhit ()) {
key = _getch ();
switch (key) {
case 72:
myUp (hOut, blockB, map, positionX, positionY);
break;
case 75:
myLeft (hOut, blockB, map, positionX, positionY);
break;
case 77:
myRight (hOut, blockB, map, positionX, positionY);
break;
case 80:
switch (myDown (hOut, blockB, map, positionX, positionY)) {
case 0:
check = false;
break;
case 1:
check = true;
break;
case 2:
gameOver (hOut, blockB, map);
goto initial;
default:
break;
}
break;
case 32:
myStop (hOut, blockA);
break;
case 27:
exit (0);
default:
break;
}
}
Sleep (20);
if (--times == 0) {
switch (myDown (hOut, blockB, map, positionX, positionY)) {
case 0:
check = false;
break;
case 1:
check = true;
break;
case 2:
gameOver (hOut, blockB, map);
goto initial;
default:
break;
}
times = val;
}
}
cin.get ();
return 0;
}
void initialWindow (HANDLE hOut) {
SetConsoleTitle ("俄罗斯方块");
COORD size = { 80, 25 };
SetConsoleScreenBufferSize (hOut, size);
SMALL_RECT rc = { 0, 0, 79, 24 };
SetConsoleWindowInfo (hOut, true, &rc);
CONSOLE_CURSOR_INFO cursor_info = { 1, 0 };
SetConsoleCursorInfo (hOut, &cursor_info);
}
void initialPrint(HANDLE hOut) {
SetConsoleTextAttribute (hOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
for (int i = 0; i < 20; i++) {
cout << "■ ■☆ ☆" << endl;
}
gotoXY (hOut, 26, 0);
cout << "☆☆☆☆☆☆☆☆☆☆☆";
gotoXY (hOut, 0, 20);
cout << "■■■■■■■■■■■■☆☆☆☆☆☆☆☆☆☆☆☆☆";
gotoXY (hOut, 26, 1);
cout << "分 数: ";
gotoXY (hOut, 26, 2);
cout << "关 卡: ";
gotoXY (hOut, 26, 4);
cout << "下一方块:";
gotoXY (hOut, 26, 9);
cout << "操作方法:";
gotoXY (hOut, 30, 11);
cout << "↑:旋转 ↓:速降";
gotoXY (hOut, 30, 12);
cout << "→:右移 ←:左移";
gotoXY (hOut, 30, 13);
cout << "空格键:开始/暂停";
gotoXY (hOut, 30, 14);
cout << "Esc 键:退出";
gotoXY (hOut, 26, 16);
cout << "关 于:";
gotoXY (hOut, 30, 18);
cout << "俄罗斯方块V1.0";
gotoXY (hOut, 35, 19);
}
void gotoXY (HANDLE hOut, int x, int y) {
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition (hOut, pos);
}
void roundBlock(HANDLE hOut, int block[4][4]) {
clearBlock (hOut, block, 5, 15);
switch (rand() % 19) {
case 0:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block00[i][j];
}
}
break;
case 1:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block01[i][j];
}
}
break;
case 2:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block02[i][j];
}
}
break;
case 3:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block03[i][j];
}
}
break;
case 4:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block04[i][j];
}
}
break;
case 5:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block05[i][j];
}
}
break;
case 6:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block06[i][j];
}
}
break;
case 7:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block07[i][j];
}
}
break;
case 8:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block08[i][j];
}
}
break;
case 9:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++)
{
block[i][j] = block09[i][j];
}
}
break;
case 10:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block10[i][j];
}
}
break;
case 11:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block11[i][j];
}
}
break;
case 12:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block12[i][j];
}
}
break;
case 13:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block13[i][j];
}
}
break;
case 14:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block14[i][j];
}
}
break;
case 15:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block15[i][j];
}
}
break;
case 16:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block16[i][j];
}
}
break;
case 17:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block17[i][j];
}
}
break;
case 18:
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block18[i][j];
}
}
break;
default:
break;
}
printBlock(hOut, block, 5, 15);
}
bool collisionDetection (int block[4][4], int map[21][12], int x, int y) {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (x + i >= 0 && y + j >= 0 && map[x + i][y + j] == 1 && block[i][j] == 1) {
return false;
}
}
}
return true;
}
void printBlock (HANDLE hOut, int block[4][4], int x, int y) {
switch (block[0][0]) {
case 10:
case 11:
SetConsoleTextAttribute (hOut, FOREGROUND_GREEN);
break;
case 12:
case 13:
case 14:
case 15:
SetConsoleTextAttribute (hOut, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
break;
case 16:
case 17:
case 18:
case 19:
SetConsoleTextAttribute (hOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
break;
case 20:
case 21:
case 22:
case 23:
SetConsoleTextAttribute (hOut, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
break;
case 24:
case 25:
SetConsoleTextAttribute (hOut, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
break;
case 26:
case 27:
SetConsoleTextAttribute (hOut, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
break;
case 28:
SetConsoleTextAttribute (hOut, FOREGROUND_RED | FOREGROUND_INTENSITY);
break;
default:
break;
}
for (int i = 0; i < 4; i++) {
if (i + x >= 0) {
for (int j = 0; j < 4; j++) {
if (block[i][j] == 1) {
gotoXY (hOut, 2 * (y + j), x + i);
cout << "■";
}
}
}
}
}
void clearBlock (HANDLE hOut, int block[4][4], int x, int y) {
for (int i = 0; i < 4; i++) {
if (i + x >= 0) {
for (int j = 0; j < 4; j++) {
if (block[i][j] == 1) {
gotoXY (hOut, 2 * (y + j), x + i);
cout << " ";
}
}
}
}
}
void gameOver (HANDLE hOut, int block[4][4], int map[21][12]) {
SetConsoleTextAttribute (hOut, FOREGROUND_RED | FOREGROUND_INTENSITY);
gotoXY (hOut, 9, 8);
string s = "GAME OVER";
for (int i = 0; i < s.size (); i++) {
Sleep (80);
cout << s[i];
}
gotoXY (hOut, 8, 9);
s = "空格键:重来";
for (int i = 0; i < s.size (); i++) {
Sleep (80);
cout << s[i];
}
cout << endl;
gotoXY (hOut, 8, 10);
s = "ESC键:退出";
MessageBox (NULL, "很遗憾,您输了!", "温馨提示", MB_OK);
for (int i = 0; i < s.size (); i++) {
Sleep (80);
cout << s[i];
}
char key;
while (true) {
key = _getch ();
if (key == 32) {
return;
} else if (key == 27) {
exit(0);
}
}
}
int myDown (HANDLE hOut, int block[4][4], int map[21][12], int &x, int y) {
if (collisionDetection(block, map, x + 1, y)) {
clearBlock (hOut, block, x, y);
++x;
return 0;
}
if (x < 0) {
return 2;
}
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (block[i][j] == 1) {
map[x + i][y + j] = 1;
SetConsoleTextAttribute (hOut, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
gotoXY (hOut, 2 * (y + j), x + i);
cout << "■";
}
}
}
return 1;
}
void myLeft (HANDLE hOut, int block[4][4], int map[21][12], int x, int &y) {
if (collisionDetection (block, map, x, y - 1)) {
clearBlock (hOut, block, x, y);
--y;
}
}
void myRight (HANDLE hOut, int block[4][4], int map[21][12], int x, int &y) {
if (collisionDetection (block, map, x, y + 1)) {
clearBlock (hOut, block, x, y);
++y;
}
}
void myUp (HANDLE hOut, int block[4][4], int map[21][12], int x, int &y) {
switch (block[0][0]) {
case 10:
if (collisionDetection (block01, map, x, y)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block01[i][j];
}
}
}
break;
case 11:
if (collisionDetection (block00, map, x, y)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block00[i][j];
}
}
} else if (collisionDetection (block00, map, x, y - 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block00[i][j];
}
}
--y;
} else if (collisionDetection (block00, map, x, y + 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block00[i][j];
}
}
++y;
} else if (collisionDetection (block00, map, x, y - 2)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block00[i][j];
}
}
y -= 2;
} else if (collisionDetection (block00, map, x, y + 2)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block00[i][j];
}
}
y += 2;
}
break;
case 12:
if (collisionDetection (block03, map, x, y)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block03[i][j];
}
}
} else if (collisionDetection (block03, map, x, y - 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block03[i][j];
}
}
--y;
} else if (collisionDetection (block03, map, x, y + 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block03[i][j];
}
}
++y;
}
break;
case 13:
if (collisionDetection (block04, map, x, y)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block04[i][j];
}
}
} else if (collisionDetection (block04, map, x, y - 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block04[i][j];
}
}
--y;
} else if (collisionDetection (block04, map, x, y + 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block04[i][j];
}
}
++y;
}
break;
case 14:
if (collisionDetection (block05, map, x, y)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block05[i][j];
}
}
} else if (collisionDetection (block05, map, x, y - 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block05[i][j];
}
}
--y;
} else if (collisionDetection (block05, map, x, y + 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block05[i][j];
}
}
++y;
}
break;
case 15:
if (collisionDetection (block02, map, x, y)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block02[i][j];
}
}
} else if (collisionDetection (block02, map, x, y - 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block02[i][j];
}
}
--y;
} else if (collisionDetection (block02, map, x, y + 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block02[i][j];
}
}
++y;
}
break;
case 16:
if (collisionDetection (block07, map, x, y)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block07[i][j];
}
}
} else if (collisionDetection (block07, map, x, y - 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block07[i][j];
}
}
--y;
} else if (collisionDetection (block07, map, x, y + 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block07[i][j];
}
}
++y;
}
break;
case 17:
if (collisionDetection (block08, map, x, y)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block08[i][j];
}
}
} else if (collisionDetection (block08, map, x, y - 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block08[i][j];
}
}
--y;
} else if (collisionDetection (block08, map, x, y + 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block08[i][j];
}
}
++y;
}
break;
case 18:
if (collisionDetection (block09, map, x, y)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block09[i][j];
}
}
} else if (collisionDetection (block09, map, x, y - 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block09[i][j];
}
}
--y;
} else if (collisionDetection (block09, map, x, y + 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block09[i][j];
}
}
++y;
}
break;
case 19:
if (collisionDetection (block06, map, x, y)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block06[i][j];
}
}
} else if (collisionDetection (block06, map, x, y - 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block06[i][j];
}
}
--y;
} else if (collisionDetection(block06, map, x, y + 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block06[i][j];
}
}
++y;
}
break;
case 20:
if (collisionDetection (block11, map, x, y)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block11[i][j];
}
}
} else if (collisionDetection (block11, map, x, y - 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block11[i][j];
}
}
--y;
} else if (collisionDetection (block11, map, x, y + 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block11[i][j];
}
}
++y;
}
break;
case 21:
if (collisionDetection (block12, map, x, y)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block12[i][j];
}
}
} else if (collisionDetection(block12, map, x, y - 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block12[i][j];
}
}
--y;
} else if (collisionDetection (block12, map, x, y + 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block12[i][j];
}
}
++y;
}
break;
case 22:
if (collisionDetection (block13, map, x, y)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block13[i][j];
}
}
} else if (collisionDetection (block13, map, x, y - 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block13[i][j];
}
}
--y;
} else if (collisionDetection (block13, map, x, y + 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block13[i][j];
}
}
++y;
}
break;
case 23:
if (collisionDetection (block10, map, x, y)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block10[i][j];
}
}
} else if (collisionDetection (block10, map, x, y - 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block10[i][j];
}
}
--y;
} else if (collisionDetection (block10, map, x, y + 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block10[i][j];
}
}
++y;
}
break;
case 24:
if (collisionDetection (block15, map, x, y)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block15[i][j];
}
}
} else if (collisionDetection (block15, map, x, y - 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block15[i][j];
}
}
--y;
} else if (collisionDetection (block15, map, x, y + 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block15[i][j];
}
}
++y;
}
break;
case 25:
if (collisionDetection (block14, map, x, y)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block14[i][j];
}
}
} else if (collisionDetection (block14, map, x, y - 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block14[i][j];
}
}
--y;
} else if (collisionDetection (block14, map, x, y + 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block14[i][j];
}
}
++y;
}
break;
case 26:
if (collisionDetection (block17, map, x, y)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block17[i][j];
}
}
} else if (collisionDetection (block17, map, x, y - 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block17[i][j];
}
}
--y;
} else if (collisionDetection (block17, map, x, y + 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block17[i][j];
}
}
++y;
}
break;
case 27:
if (collisionDetection (block16, map, x, y)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block16[i][j];
}
}
} else if (collisionDetection (block16, map, x, y - 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block16[i][j];
}
}
--y;
} else if (collisionDetection (block16, map, x, y + 1)) {
clearBlock (hOut, block, x, y);
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
block[i][j] = block16[i][j];
}
}
++y;
}
break;
default:
break;
}
}
void myStop (HANDLE hOut, int block[4][4]) {
clearBlock (hOut, block, 5, 15);
SetConsoleTextAttribute (hOut, FOREGROUND_RED | FOREGROUND_INTENSITY);
gotoXY (hOut, 30, 7);
cout << "游戏暂停";
char key;
while (true) {
key = _getch ();
if (key == 32) {
gotoXY (hOut, 30, 7);
cout << " ";
printBlock (hOut, block, 5, 15);
return;
}
if (key == 27) {
exit (0);
}
}
}
void eliminateRow (HANDLE hOut, int map[21][12], int &val, int &fraction, int &checkpoint) {
SetConsoleTextAttribute(hOut, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
for (int i = 19; i >= 0; i--) {
int x = 0;
for (int j = 1; j < 11; j++) {
x += map[i][j];
}
if (x == 10) {
fraction += 100;
if (val > 1 && fraction / 1000 + 1 != checkpoint) {
checkpoint = fraction / 1000 + 1;
val -= 5;
}
for (int m = i; m > 0; m--) {
for (int n = 1; n < 11; n++) {
map[m][n] = map[m - 1][n];
gotoXY (hOut, 2 * n, m);
if (map[m][n] == 1) {
cout << "■";
} else {
cout << " ";
}
}
}
i++;
}
}
gotoXY (hOut, 36, 1);
cout << fraction;
gotoXY (hOut, 36, 2);
cout << checkpoint;
}
6.飞翔的小鸟
#include<bits/stdc++.h>
#include<Windows.h>
#define PR_Box printf("■")
#define PR_Gold printf("★")
#define PR_Ag printf("☆")
#define PR_FBird printf("Ю")
#define PR_DBird printf("Ф")
#define PR_Land printf("┳┳┯")
#define PR_Bg_TL printf("╔")
#define PR_Bg_TR printf("╗")
#define PR_Bg_DL printf("╚")
#define PR_Bg_DR printf("╝")
#define PR_Bg_X printf("═")
#define PR_Bg_Y printf("║")
#define PR_Blank printf(" ");
int Grade=1,C_Gold=0,C_Ag=0,Score=0,Delay_time=1000,Max_blank=9,Distance=18;
struct Birds {
int x,y;
int condition;
};
Birds*Bird=(Birds*)malloc(sizeof(Birds));
struct Bg {
int x,y;
int l_blank;
int reward[9];
Bg*pri;
Bg*next;
};
Bg*Bg1=new Bg[sizeof(Bg)];
void Position(int x,int y) {
COORD pos= {x-1,y-1};
HANDLE Out=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(Out,pos);
}
void CreatBird() {
Bird->x=41;
Bird->y=10;
Bird->condition=0;
}
void CreatBg() {
Bg*Bg2=(Bg*)malloc(sizeof(Bg));
Bg1->x=90;
Bg1->y=8;
Bg2->x=Bg1->x+Distance;
Bg2->y=9;
Bg1->l_blank=Max_blank-Grade;
Bg2->l_blank=Max_blank-Grade;
Bg1->next=Bg2;
Bg1->pri=Bg2;
Bg2->next=Bg1;
Bg2->pri=Bg1;
}
void InsertBg(Bg*p) {
int temp;
Bg*Bgs=(Bg*)malloc(sizeof(Bg));
Bgs->x=p->pri->x+Distance;
Bgs->l_blank=Max_blank-Grade;
srand((int)time(0));
temp=rand();
if(temp%2==0) {
if((temp%4+p->pri->y+Max_blank-Grade)<21)Bgs->y=p->pri->y+temp%4;
else Bgs->y=p->pri->y;
} else {
if((p->pri->y-temp%4)>2)Bgs->y=p->pri->y-temp%4;
else Bgs->y=p->pri->y;
}
Bgs->pri=p->pri;
Bgs->next=p;
p->pri->next=Bgs;
p->pri=Bgs;
}
void Check_Bg(Bg*q) {
Bg*p=q;
int i=0,temp;
while(++i<=5) {
if(p->x>-4)p=p->next;
else {
srand((int)time(0));
temp=rand();
if(temp%2==0) {
if((temp%4+p->y+Max_blank-Grade)<21)p->y=p->y+temp%4;
else p->y=p->y;
p->x=p->pri->x+Distance;
p->l_blank=Max_blank-Grade;
} else {
if((p->y-temp%4)>2)p->y=p->y-temp%4;
else p->y=p->y;
p->x=p->pri->x+Distance;
p->l_blank=Max_blank-Grade;
}
}
}
}
void Loop_Bg(Bg*q) {
Bg*p=q;
int i=0;
while(++i<=5) {
p->x=p->x-1;
p=p->next;
if(Bird->x==p->x) {
Score+=1;
if(Score%4==0&&Grade<4)Grade++;
}
}
}
void Prt_Bg(Bg*q) {
Bg*p=q;
int i=0,k,j;
while(++i<=5) {
if(p->x>0&&p->x<=78) {
for(k=2; k<p->y; k++) {
Position(p->x+1,k);
PR_Box;
PR_Box;
PR_Blank
}
Position(p->x,p->y);
PR_Box;
PR_Box;
PR_Box;
PR_Blank;
Position(p->x,p->y+p->l_blank);
PR_Box;
PR_Box;
PR_Box;
PR_Blank;
k=k+p->l_blank+1;
for(k; k<=22; k++) {
Position(p->x+1,k);
PR_Box;
PR_Box;
PR_Blank;
}
Position(p->x,23);
for(k=1; k<Distance/3-2; k++)PR_Land;
}
p=p->next;
if(p->x==0) {
for(j=2; j<p->y; j++) {
Position(p->x+1,j);
PR_Blank;
PR_Blank;
}
Position(p->x+1,p->y);
PR_Blank;
PR_Blank;
PR_Blank;
Position(p->x+1,p->y+Max_blank-Grade);
PR_Blank;
PR_Blank;
PR_Blank;
j=j+Max_blank-Grade+1;
for(j; j<=22; j++) {
Position(p->x+1,j);
PR_Blank;
PR_Blank;
}
}
}
}
void PrtBg() {
int i;
Position(1,1);
PR_Bg_TL;
Position(79,1);
PR_Bg_TR;
Position(1,24);
PR_Bg_DL;
Position(79,24);
PR_Bg_DR;
for(i=3; i<=78; i+=2) {
Position(i,1);
PR_Bg_X;
Position(i,24);
PR_Bg_X;
}
}
void PrtBird() {
Position(Bird->x,Bird->y-1);
PR_Blank;
Position(Bird->x,Bird->y);
PR_FBird;
Position(38,2);
printf("Score:%d",Score);
}
int CheckYN(Bg*q) {
Bg*p=q;
int i=0;
while(++i<=5) {
if(Bird->y>23)return 0;
if(Bird->x==p->x&&Bird->y<=p->y)return 0;
if((Bird->x==p->x||Bird->x==p->x+1||Bird->x==p->x+2)&&Bird->y==p->y)return 0;
if(Bird->x==p->x&&Bird->y>p->y+p->l_blank)return 0;
if((Bird->x==p->x||Bird->x==p->x+1||Bird->x==p->x+2)&&Bird->y==p->y+p->l_blank)return 0;
p=p->next;
}
return 1;
}
void Prtfirst() {
printf("══════════════════════════════════════\n");
printf(" ■■ ■■\n");
printf(" ■■ ■■\n");
printf(" ■■ ■■\n");
printf(" ■■ ■■\n");
printf(" ■■ ■■ C++语言版 Flappy Bird\n");
printf(" ■■ ■■ 制作人:王子岳\n");
printf(" ■■ ■■ 瞎搞日期:2024.8.2\n");
printf(" ■■ ■■ 耗时:2.46小时\n");
printf(" ■■■ ■■ 游戏说明:\n");
printf(" ■■ 1-按上箭头使鸟起飞\n");
printf(" ■■ 2-等级越高,难度越大!\n");
printf(" Ю ■■■\n");
printf("\n");
printf(" \n\n\n\n\n\n\n\n");
printf(" ┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳\n");
system("pause");
Position(1,1);
int i=0;
while(i++<40*25)PR_Blank;
}
int main() {
int i=0;
char ch;
Prtfirst();
PrtBg();
CreatBg();
InsertBg(Bg1);
InsertBg(Bg1);
InsertBg(Bg1);
CreatBird();
while(1) {
if(!CheckYN(Bg1))break;
Check_Bg(Bg1);
Prt_Bg(Bg1);
PrtBird();
Loop_Bg(Bg1);
Bird->y=Bird->y+1;
if(GetAsyncKeyState(VK_UP)) {
Position(Bird->x,Bird->y-1);
PR_Blank;
Bird->y=Bird->y-4;
}
while(i++<500);
{
Sleep(100);
}
i=0;
}
Position(38,10);
printf("Game Over!");
Position(1,25);
system("pause");
}
7.谷歌小恐龙(有亿点难)
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
#include<windows.h>
#define N 80
#define up 72
#define left 75
#define right 77
#define down 80
void run();
void yn();
void print(int [][N]);
void menu();
int scr[22][N]={0},pl=9,shit,width=70,score=0,death=0,jump_time=0,game_time=0,day=0,jump_height=0,shift_time=0;
int main(){
menu();
run();
}
void drawplayer(int a[][N],int xlu,int ylu)
{
for(int i=1;i<=3;i++)
a[xlu][ylu+i]=1;
for(int i=0;i<=4;i++)
a[xlu+1][ylu+i]=1;
a[xlu+2][ylu+1]=1;
a[xlu+2][ylu+3]=1;
}
bool search_player(int a[][N],int xlu,int ylu)
{
for(int i=1;i<=3;i++)
if(a[xlu][ylu+i]==2 || a[xlu][ylu+i]==3)
return false;
for(int i=0;i<=4;i++)
if(a[xlu+1][ylu+i]==2 || a[xlu+1][ylu+i]==3)
return false;
if(a[xlu+2][ylu+1]==2 || a[xlu+2][ylu+1]==3)
return false;
if(a[xlu+2][ylu+3]==2 || a[xlu+2][ylu+3]==3)
return false;
return true;
}
void days(int q,int a[][N]){//太阳&月亮
for(int i=3;i<=7;i++){
for(int j=51;j<=55;j++){
a[i][j]=0;
}
}
if(q==1){//月亮,开启昼夜才有
a[4][52]=4;
a[7][52]=4;
for(int i=53;i<=54;i++){
a[4][i]=4;
a[5][i]=4;
a[6][i]=4;
a[7][i]=4;
}
a[4][54]=0;
a[7][54]=0;
a[5][55]=4;
a[6][55]=4;
}
else{
for(int i=3;i<=7;i++){
for(int j=51;j<=56;j++){
a[i][j]=4;
}
}
a[4][51]=0;
a[4][56]=0;
a[7][51]=0;
a[7][56]=0;
}
}
void print(int a[][N]){//绘图函数
COORD c={0,0};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c);
int i,j;
for(i=4;i<22;i++){
a[i][width-1]=4;
for(j=0;j<width;j++){
if(a[i][j]==0){
printf(" ");
}
if(a[i][j]==1)
printf("@");
if(a[i][j]==2)
printf("#");
if(a[i][j]==3)
printf("<");
if(a[i][j]==4){
printf("*");
}
if(i==4&&j==width-1)
printf("score:%d",score/20);
if(i==5&&j==width-1)
printf("Press Esc to exit");
}
printf("\n");
}
for(j=0;j<width;j++)
printf("~");
}
void yn(){//死亡界面
system("cls");
system("color 07");
printf("\n");
printf("\n");
printf("\t\t\t\t *****GAME OVER*****\n\a");
printf("\t\t\t\t *****YOU DIED!***** \n");
printf("\t\t\t\t*****YOUR SCORE:%4d*****\n\n",score/20);
printf("\t\t\t press y to continue,n to close(y/n)?\n");
printf("\t\t\t");
end:;
switch(getch()){
case 'y':
case 'Y':death=0,score=0,memset(scr,0,sizeof(scr)),run();break;
case 'n':
case 'N':break;
default :goto end;break;
}
}
void generate_block(int a[][N],int lala=rand()%6+1){//生成障碍,有三种依次为:从上至下的墙,飞弹,从下至上随机高度的墙。。。
if(lala==5){
for(int i=0;i<=19;i++){
a[i][69]=2;
}
}
else if(lala==6){
int hehe=rand()%5+1;
if(hehe<=1){
a[19][69]=3;
}
else if(hehe<=4){
a[14][69]=3;
}
else if(hehe==5){
a[21][69]=3;
}
}
else{
for(int i=0;i<=lala;i++)
a[21-i][69]=2;
}
}
void run() {//主函数
//system("color 70");
shit=0;
day=0;
system("cls");
srand(time(0));
while(1){
score++;
game_time++;
if(game_time%60==0)//墙
generate_block(scr);
if(game_time%80==0)//飞弹
generate_block(scr,6);
//if(game_time/1000>=1 && day==0)
//system("color 07"),game_time=0,day=1; //去掉这些注释(run函数里的所有)可开启昼夜更替(但我觉得不好看)。。。
//else if(game_time/1000>=1 && day==1)
//system("color 70"),game_time=0,day=0;
days(day,scr);
if(kbhit()) //读取输入
switch(getch()){
case down:
case 's':
case 'S':if(jump_time<=15)shift_time=20,jump_time=0;break;
case up:
case 'W':
case 'w':if(jump_time<=0)jump_time=25,jump_height=-1,shift_time=0;break;
case 13 :system("pause");break;
}
if(jump_time<=0 && shift_time<=0){//正常
if(search_player(scr,19,pl))
drawplayer(scr,19,pl);
else
goto end;//新科技goto...感觉比break好用...
}
else if(jump_time>0){//跳
jump_time--;
if(jump_time<10){
jump_height--;
}
else if(jump_time>15){
jump_height++;
}
if(search_player(scr,19-jump_height,pl)){
drawplayer(scr,19-jump_height,pl);
}
else
goto end;
}
else if(shift_time>0){//蹲
shift_time--;
if(search_player(scr,20,pl))
drawplayer(scr,20,pl);
else
goto end;
}
for(int i=4;i<22;i++)//移墙
for(int j=0;j<=80;j++){
if(scr[i][j]==2){
scr[i][j]=0;
if(j-1>=0)
scr[i][j-1]=2;
}
}
for(int i=4;i<22;i++)//移飞弹,可见速度较墙快了一倍
for(int j=0;j<=80;j++){
if(scr[i][j]==3){
scr[i][j]=0;
if(scr[i][j-1]==1)
goto end;
else if(scr[i][j-2]==1)
goto end;
else if(j-2>=0)
scr[i][j-2]=3;
}
}
print(scr);
for(int i=4;i<22;i++)
for(int j=0;j<=80;j++){
if(scr[i][j]==1)
scr[i][j]=0;
}
}
end:;
yn();
}
void menu(){
system("color 07");
ShowCursor(false);//这一节照抄,指消去光标
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cci;
GetConsoleCursorInfo(hOut,&cci);
cci.bVisible=false;
SetConsoleCursorInfo(hOut,&cci);//一直到这里照抄
}
8.球球飞车
#include <bits/stdc++.h>
#include <stdio.h>
#include <conio.h>
#include <cstdlib>
#include <windows.h>
#include <iostream>
#include <fstream>
using namespace std;
int map2[1700][3];
void gotoxy(int x, int y) {
COORD pos = {y,x};
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);// 获取标准输出设备句柄
SetConsoleCursorPosition(hOut, pos);//两个参数分别是指定哪个窗体,具体位置
}
//============================================================================
void ClearConsoleToColors(int ForgC, int BackC) {
WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord = {0, 0};
DWORD count;
CONSOLE_SCREEN_BUFFER_INFO csbi;
SetConsoleTextAttribute(hStdOut, wColor);
if(GetConsoleScreenBufferInfo(hStdOut, &csbi)) {
FillConsoleOutputCharacter(hStdOut, (TCHAR) 32, csbi.dwSize.X * csbi.dwSize.Y, coord, &count);
FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, csbi.dwSize.X * csbi.dwSize.Y, coord, &count);
SetConsoleCursorPosition(hStdOut, coord);
}
}
void ClearConsole() {
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord = {0, 0};
DWORD count;
CONSOLE_SCREEN_BUFFER_INFO csbi;
if(GetConsoleScreenBufferInfo(hStdOut, &csbi)) {
FillConsoleOutputCharacter(hStdOut, (TCHAR) 32, csbi.dwSize.X * csbi.dwSize.Y, coord, &count);
FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, csbi.dwSize.X * csbi.dwSize.Y, coord, &count);
SetConsoleCursorPosition(hStdOut, coord);
}
}
void gotoXY(int x, int y) {
COORD coord = {y, x};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void SetColor(int ForgC) {
WORD wColor;
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
if(GetConsoleScreenBufferInfo(hStdOut, &csbi)) {
wColor = (csbi.wAttributes & 0xF0) + (ForgC & 0x0F);
SetConsoleTextAttribute(hStdOut, wColor);
}
}
void SetColorAndBackground(int ForgC, int BackC) {
WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
}
void ConPrint(char *CharBuffer, int len) {
DWORD count;
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), CharBuffer, len, &count, NULL);
}
void ConPrintAt(int x, int y, char *CharBuffer, int len) {
DWORD count;
COORD coord = {x, y};
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hStdOut, coord);
WriteConsole(hStdOut, CharBuffer, len, &count, NULL);
}
void HideTheCursor() {
CONSOLE_CURSOR_INFO cciCursor;
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
if(GetConsoleCursorInfo(hStdOut, &cciCursor)) {
cciCursor.bVisible = FALSE;
SetConsoleCursorInfo(hStdOut, &cciCursor);
}
}
void ShowTheCursor() {
CONSOLE_CURSOR_INFO cciCursor;
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
if(GetConsoleCursorInfo(hStdOut, &cciCursor)) {
cciCursor.bVisible = TRUE;
SetConsoleCursorInfo(hStdOut, &cciCursor);
}
}
void k() {
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
GetConsoleCursorInfo(handle, &CursorInfo);
CursorInfo.bVisible = false;
SetConsoleCursorInfo(handle, &CursorInfo);
}
void rectangle(int x1,int y1,int x2,int y2) {
for(int i=1; i<=y2-y1+1; i++) {
gotoxy(x1,y1+i-1);
if(i==1)cout<<"╔";
else if(i==y2-y1+1)cout<<"╗";
else cout<<"═";
}
for(int i=1; i<=x2-x1; i++) {
gotoxy(x1+i,y1);
cout<<"║";
gotoxy(x1+i,y2);
cout<<"║";
}
for(int i=1; i<=y2-y1+1; i++) {
gotoxy(x2,y1+i-1);
if(i==1)cout<<"╚";
else if(i==y2-y1+1)cout<<"╝";
else cout<<"═";
}
}
void print(string a,int i,int j,int color=0) {
int i2;
for(i2=0; i2<=a.size(); i2++) {
if(a[i2]=='a') {
SetColorAndBackground(15, color);
gotoxy(i,j+i2*2);
cout<<" ";
}
if(a[i2]==' ') {
SetColorAndBackground(15, color);
gotoxy(i,j+i2*2);
cout<<" ";
}
}
}
void write(string a,int i,int j,int color1=0,int color2=15) {
int i2;
gotoxy(i,j);
for(i2=0; i2<a.size(); i2++) {
SetColorAndBackground(color1, color2);
cout<<a[i2];
}
}
void picture(int i=10,int j=23,int color1=15,int color2=0) {
SetColorAndBackground(color1, color2);
gotoxy(i,j);
cout<<" ╔═══════╗ ";
gotoxy(i+1,j);
cout<<" ║ ║ ";
gotoxy(i+2,j);
cout<<"╔═══╩═══╗ ╠═══╗ ";
gotoxy(i+3,j);
cout<<"║ ║ ║ ║ ";
gotoxy(i+4,j);
cout<<"║ ╔═══╬═══╝ ║ ";
gotoxy(i+5,j);
cout<<"║ ║ ║ ║ ";
gotoxy(i+6,j);
cout<<"╚═══╣ ╚═══╦═══╝ ";
gotoxy(i+7,j);
cout<<" ║ ║ ";
gotoxy(i+8,j);
cout<<" ╚═══════╝ ";
}
void button(string a,int i,int j,int color,int color2=0) {
SetColorAndBackground(color,color2);
rectangle(i,j,i+2,j+20);
SetColorAndBackground(color,0);
write(a,i+1,j+(10-(a.size()/2)),color,color2);
}
void xian(int x,int y,bool x2,int h,int color=0) {
for(int i=0; i<h; i++) {
SetColorAndBackground(15,color);
if(x2==0)gotoxy(x+i,y);
else gotoxy(x,y+i*2);
cout<<" ";
}
}
void choose(int i,int x) {
write(">>>",i,x+47-46,11,8);
write("<<<",i,x+75-46,11,8);
}
void choose_clear(int i,int x) {
write(" ",i,x+47-46,11,8);
write(" ",i,x+75-46,11,8);
}
void clear(int color=15) {
int i,j;
for(i=32; i<=94; i++) {
for(j=5; j<=28; j++) {
SetColorAndBackground(15,color);
gotoxy(j,i);
cout<<" ";
}
}
}
void clear2(int color=15,int x1=32,int x2=94,int y1=5,int y2=28) {
int i,j;
for(i=y1; i<=y2; i++) {
for(j=x1; j<=x2; j++) {
SetColorAndBackground(15,color);
gotoxy(j,i);
cout<<" ";
}
}
}
//=============================================================================
void rand_map(int a,int pd) {
srand(time(0));
int s;
int rand1,rand2,rand3,rand4,rand5;
if(a<=10)s=100;
else if(a<=50)s=200;
else if(a<=100)s=500;
else if(a<=300)s=800;
else if(a<=500)s=1100;
else s=1500;
for(int m=0; m<=s; m++) {
if(m%5==0&&m!=0) {
if(m==5||m==s) {
if(m==5) {
map2[m][0]=5;
map2[m][1]=5;
map2[m][2]=5;
} else if(m==s) {
map2[m][0]=4;
map2[m][1]=4;
map2[m][2]=4;
}
} else {
rand1=rand()%3;
map2[m][rand1]=pd;
rand2=rand()%3;
while(rand2==rand1)rand2=rand()%3;
rand3=rand()%3+1;
while(rand3==pd)rand3=rand()%3+1;
map2[m][rand2]=rand3;
rand4=rand2;
rand2=rand()%3;
while(rand2==rand4||rand2==rand1)rand2=rand()%3;
rand3=rand()%3+1;
while(rand3==pd)rand3=rand()%3+1;
map2[m][rand2]=rand3;
}
} else {
map2[m][0]=0;
map2[m][1]=0;
map2[m][2]=0;
}
}
}
void clear_map() {
for(int i=0; i<=2; i++) {
for(int j=0; j<=1600; j++) {
map2[i][j]=0;
}
}
}
void clear_middle() {
for(int i=0; i<=2; i++) {
for(int j=0; j<=29; j++) {
write(" ",j,i*2+44,15,15);
}
}
}
void text(string str,string title="游戏通知",string str2="",int x=3,int y=27) {
int size1,size2,size3;
int i,j;
size1=str.size();
size2=str2.size();
size3=title.size();
for(i=0; i<=20-size3/2; i++)write(" ",x-1,y+i,15,4);
write(title,x-1,y+(20-size3/2),15,4);
for(i=0; i<=20-size3/2-1; i++)write(" ",x-1,y+size3+(20-size3/2)+i,15,4);
for(i=0; i<=20-size1/2; i++)write(" ",x,y+i,15,8);
write(str,x,y+(20-size1/2),15,8);
for(i=0; i<=20-size1/2-1; i++)write(" ",x,y+size1+(20-size1/2)+i,15,8);
for(i=0; i<=20-size2/2; i++)write(" ",x+1,y+i,15,8);
write(str2,x+1,y+(20-size2/2),15,8);
for(i=0; i<=20-size2/2-1; i++)write(" ",x+1,y+size2+(20-size2/2)+i,15,8);
}
void clear_text(string str="目前暂无通知",string title="游戏通知",int x=3,int y=27) {
int i,j;
int size1=str.size();
int size3=title.size();
for(i=0; i<=20-size3/2; i++)write(" ",x-1,y+i,15,4);
write(title,x-1,y+(20-size3/2),15,4);
for(i=0; i<=20-size3/2-1; i++)write(" ",x-1,y+size3+(20-size3/2)+i,15,4);
for(i=0; i<=20-size1/2; i++)write(" ",x,y+i,15,8);
write(str,x,y+(20-size1/2),15,8);
for(i=0; i<=20-size1/2-1; i++)write(" ",x,y+size1+(20-size1/2)+i,15,8);
for(i=0; i<=39; i++)write(" ",x+1,y+i,15,8);
}
void hide_mouse() {
HideTheCursor();
}
void true_mouse() {
CONSOLE_CURSOR_INFO cciCursor;
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
if(GetConsoleCursorInfo(hStdOut, &cciCursor)) {
cciCursor.bVisible = TRUE;
SetConsoleCursorInfo(hStdOut, &cciCursor);
}
}
/*//============================================================================
ifstream fr; //读
ofstream fw; //写
int a; //定义a
fr.open("读入.in"); //打开 读入.in
fr >> a; //读取文件,一个数字
cout<<"文件内容:"<<a<<endl; //导入文件内容
cout<<"输入内容:"; //更改文件内容
cin>>a; //输入文件内容
cout<<"载入内容完成"; //载如完成
fw.open("读入.in"); //导入文件
fw << a << endl; //输入内容
fw.close(); //关闭文件
fr.close(); //关闭文件
//============================================================================*/
//1 0 4 1 3 0 0 0 0 0 0
void game() {
int i=1,i2=1;
int rand1=8,rand2,rand3;
int gk=1,gk2=0;
int xy1=4,xy2=1,sl;
int sm=210000000,jb=210000000,jl=210000000,jl2=210000000,jd=210000000,sd=210000000,dj=210000000,maxsm=210000000;
string pfs="10000000000000000000";
string pf="●";
char x;
rand1=8;
while(rand1==8||rand1==4)rand1=rand()%13+1;
rand2=rand1+1;
for(int i=0; i<=29; i++) {
for(int j=0; j<=47; j++) {
print("a",i,j*2,rand1);
}
}
for(int i=0; i<=29; i++) {
for(int j=0; j<=15; j++) {
print("a",i,j*2+31,15);
}
}
for(int i=0; i<=29; i++) {
for(int j=0; j<=31; j++) {
print("a",i,j+95,8);
}
}
for(int i=0; i<=29; i++) {
print("a",i,42,0);
print("a",i,50,0);
}
ifstream fr; //读
fr.open("球球飞车.txt"); //打开 读入.in
fr >> gk>>gk2>>xy1>>xy2>>sm>>jb>>jl>>jl2>>jd>>sd>>dj>>maxsm>>pf>>pfs; //读取文件,一个数字
fr.close(); //关闭文件
while(1) {
srand(time(0));
clear_map();
rand3=rand()%3+1;
rand_map(gk,rand3);
print("aaaaaaaaaaaaaaaa ",3,95,4);
write("球球飞车",1,107,11,8);
while(1) {
clear_middle();
if(gk!=gk2) {
clear_map();
rand3=rand()%3+1;
rand_map(gk,rand3);
gk2++;
rand1=8;
while(rand1==8||rand1==4)rand1=rand()%13+1;
rand2=rand1+1;
for(int i=0; i<=29; i++) {
for(int j=0; j<=47; j++) {
print("a",i,j*2,rand1);
}
}
for(int i=0; i<=29; i++) {
for(int j=0; j<=15; j++) {
print("a",i,j*2+31,15);
}
}
for(int i=0; i<=29; i++) {
for(int j=0; j<=31; j++) {
print("a",i,j+95,8);
}
}
for(int i=0; i<=29; i++) {
print("a",i,42,0);
print("a",i,50,0);
}
}
for(int i=0; i<=29; i++) {
for(int j=0; j<=2; j++) {
if(map2[i][j]==1)write(pf,29-i,j*2+44,14,15);
if(map2[i][j]==2)write(pf,29-i,j*2+44,12,15);
if(map2[i][j]==3)write(pf,29-i,j*2+44,9,15);
if(map2[i][j]==4)write("↑",29-i,j*2+44,8,15);
if(map2[i][j]==5)write("↑",29-i,j*2+44,8,15);
}
}
clear_text();
write("第",0,0,0,7);
SetColorAndBackground(4, 7);
if(gk>=0&&gk<10)cout<<"0000";
if(gk>=10&&gk<100)cout<<"000";
if(gk>=100&&gk<1000)cout<<"00";
if(gk>=1000&&gk<10000)cout<<"0";
if(gk>=10000&&gk<100000)cout<<"";
cout<<gk;
write("关",0,7,0,7);
if(rand3==1)write(pf,26,46,14,15);
if(rand3==2)write(pf,26,46,12,15);
if(rand3==3)write(pf,26,46,9,15);
print("aaaaaaaaaaaaaaaa ",3,95,4);
write("球球飞车",1,107,11,8);
button("开始游戏",5,101,11,8);
button("游戏玩法",9,101,11,8);
button("查看状态",13,101,11,8);
button("商店",17,101,11,8);
button("退出",21,101,11,8);
choose(i*4+2,95);
x=getch();
i2=i;
if(x=='w'&&i>1)i--;
else if(x=='s'&&i<5)i++;
else if(x==' ') {
if(i==1) {
int s;
if(gk<=10) {
dj=1;
s=100;
} else if(gk<=50) {
dj=2;
s=200;
} else if(gk<=100) {
dj=3;
s=500;
} else if(gk<=300) {
dj=4;
s=800;
} else if(gk<=500) {
dj=5;
s=1100;
} else {
dj=6;
s=1500;
}
xy2=1;
sm=maxsm;
jl2=0;
clear2(8,0,29,95,126);
print("aaaaaaaaaaaaaaaa ",0,95,4);
write("关卡",0,106,15,4);
SetColorAndBackground(7, 4);
if(gk>=0&&gk<10)cout<<"0000";
if(gk>=10&&gk<100)cout<<"000";
if(gk>=100&&gk<1000)cout<<"00";
if(gk>=1000&&gk<10000)cout<<"0";
if(gk>=10000&&gk<100000)cout<<"";
cout<<gk;
write("生命:",1,95,15,8);
cout<<sm<<"条";
write("金币:",2,95,15,8);
cout<<jb<<"元";
write("距离:",3,95,15,8);
cout<<(jl*1.0)/1000<<"千米 ";
write("进度:",4,95,15,8);
cout<<jd<<"%";
write("速度:",5,95,15,8);
cout<<dj*2<<"米/秒";
write("等级:",6,95,15,8);
cout<<dj<<"级 (6级满级)";
sl=0;
for(int k=0;; k++) {
if(sl%((10-dj)*250)==0) {
jl++;
jl2++;
jd=(jl2*1.0)/s*100;
sd=2;
SetColorAndBackground(15,8);
gotoxy(1,101);
cout<<sm<<"条";
gotoxy(2,101);
cout<<jb<<"元";
gotoxy(3,101);
cout<<(jl*1.0)/1000<<"千米";
gotoxy(4,101);
cout<<"已完成"<<jl2<<"米 ("<<jd<<"%)";
gotoxy(5,101);
cout<<sd*2<<"米/秒";
gotoxy(6,101);
cout<<dj<<"级 (6级满级)";
if(map2[3+k][xy2]==rand3) {
jb++;
map2[3+k][xy2]=0;
} else if(map2[3+k][xy2]==5)map2[3+k][xy2]=5;
else if(map2[3+k][xy2]==4) {
text("成功,游戏结束");
Sleep(1000);
gk++;
ofstream fw; //写
fw.open("球球飞车.txt"); //打开 读入.in
fw << gk<<" "<<gk2<<" "<<xy1<<" "<<xy2<<" "<<sm<<" "<<jb<<" "<<jl<<" "<<jl2<<" "<<jd<<" "<<sd<<" "<<dj<<" "<<maxsm<<" "<<pf<<" "<<pfs<<endl; //输入内容
fw.close();
clear2(8,0,29,95,126);
break;
} else if(map2[3+k][xy2]==0)map2[3+k][xy2]=0;
else {
sm--;
text("横冲直撞,生命扣一");
if(sm==0) {
text("失败,游戏结束");
Sleep(1000);
clear2(8,0,29,95,126);
break;
}
}
for(int i=0; i<=29; i++) {
for(int j=0; j<=2; j++) {
if(!(i<=27&&i>=25)) {
if(map2[i+k][j]==0&&(map2[i+k-1][j]!=map2[i+k][j]||j==xy2||i==3))write(" ",29-i,j*2+44,8,15);
if(map2[i+k][j]==1)write(pf,29-i,j*2+44,14,15);
if(map2[i+k][j]==2)write(pf,29-i,j*2+44,12,15);
if(map2[i+k][j]==3)write(pf,29-i,j*2+44,9,15);
if(map2[i+k][j]==4)write("↑",29-i,j*2+44,8,15);
if(map2[i+k][j]==5)write("↑",29-i,j*2+44,8,15);
}
if(j==xy2&&i==3) {
if(rand3==1)write(pf,26,j*2+44,14,15);
if(rand3==2)write(pf,26,j*2+44,12,15);
if(rand3==3)write(pf,26,j*2+44,9,15);
}
}
}
} else k--;
if(kbhit()) {
x=getch();
if(x=='a'&&xy2>0) {
text("左转,加速!");
xy2--;
} else if(x=='d'&&xy2<2) {
text("右转,加速!");
xy2++;
} else if(x==' ') {
if(MessageBox(NULL,TEXT("确定要退出吗?\n退出将删除当前关卡的进度,无法继续\t\t\t\t\t"),TEXT("游戏通知"),MB_ICONINFORMATION|MB_OKCANCEL)==1) {
clear2(8,0,29,95,126);
break;
}
}
}
sl++;
}
} else if(i==2) {
clear2(8,0,29,95,126);
print("aaaaaaaaaaaaaaaa ",0,95,4);
write("游戏玩法",0,107,15,4);
write("【按键操作】",1,95,15,8);
write("1 - a左移,d右移",2,95,15,8);
write("2 - 点击屏幕任意位置暂停",3,95,15,8);
write("3 - 按Enter键继续游戏",4,95,15,8);
write("4 - 按Space键退出游戏(丢失进度)",5,95,15,8);
write("5 - 按w键可以加速(注意大小写)",6,95,15,8);
write("【规则介绍】",8,95,15,8);
write("1 - 撞到与自身颜色一样的球得金币",9,95,15,8);
write("2 - 撞到与自身颜色不同的球生命-1",10,95,15,8);
write("3 - 生命为0时失败,游戏结束",11,95,15,8);
write("4 - 达到终点线时游戏胜利",12,95,15,8);
write("5 - 等级会随着关卡变化",13,95,15,8);
write("6 - 金币可以用来买东西",14,95,15,8);
write("【注意事项】",16,95,15,8);
write("1 - 移动为小写字母",17,95,15,8);
write("2 - 注意是英文输入",18,95,15,8);
write("【游戏通知】",20,95,15,8);
write("1 - 祝你游玩愉快!",21,95,15,8);
button("返回",24,101,11,8);
choose(25,95);
while(1) {
x=getch();
if(x==' ') {
i=1;
clear2(8,0,29,95,126);
break;
}
}
} else if(i==3) {
clear2(8,0,29,95,126);
print("aaaaaaaaaaaaaaaa ",0,95,4);
write("查看状态",0,107,15,4);
if(gk<=10)dj=1;
else if(gk<=50)dj=2;
else if(gk<=100)dj=3;
else if(gk<=300)dj=4;
else if(gk<=500)dj=5;
else dj=6;
write("关卡:",1,95,15,8);
cout<<"第"<<gk<<"关";
write("金币:",2,95,15,8);
cout<<jb<<"元";
write("距离:",3,95,15,8);
cout<<(jl*1.0)/1000<<"千米";
write("等级:",4,95,15,8);
cout<<dj<<"级 (6级满级)";
write("皮肤:",5,95,15,8);
cout<<pf;
i=1;
while(1) {
i2=i;
button("更改参数",20,101,11,8);
button("返回",24,101,11,8);
choose(i*4+17,95);
x=getch();
if(x=='w'&&i>1)i--;
else if(x=='s'&&i<2)i++;
else if(x==' ') {
if(i==1) {
clear2(8,0,29,95,126);
print("aaaaaaaaaaaaaaaa ",0,95,4);
write("输入密码",0,107,15,4);
write("输入密码:",1,95,15,8);
string mm;
cin>>mm;
if(mm=="qwertyuiop") {
clear2(8,0,29,95,126);
print("aaaaaaaaaaaaaaaa ",0,95,4);
write("密码正确",0,107,15,4);
button("逐个更改",5,101,11,8);
button("全部还原",9,101,11,8);
button("返回",13,101,11,8);
i=1;
while(1) {
choose(i*4+2,95);
i2=i;
x=getch();
if(x=='w'&&i>1)i--;
else if(x=='s'&&i<3)i++;
else if(x==' ') {
if(i==1) {
MessageBox(NULL,TEXT("此游戏暂不支持\n\n"),TEXT("游戏提醒"),MB_ICONINFORMATION|MB_OK);
continue;
} else if(i==2) {
if(MessageBox(NULL,TEXT("还原将删除目前所有数据\n\n是否还原"),TEXT("游戏提醒"),MB_ICONINFORMATION|MB_YESNO)==6) {
ofstream fw; //写
fw.open("球球飞车.txt"); //打开 读入.in
fw <<"1 1 4 1 3 0 0 0 0 0 0 3"<<endl; //输入内容
fw.close();
}
} else if(i==3) {
clear2(8,0,29,95,126);
i=1;
break;
}
}
if(i2!=i)choose_clear(i2*4+2,95);
}
} else {
clear2(8,0,29,95,126);
print("aaaaaaaaaaaaaaaa ",0,95,4);
write("密码错误",0,107,15,4);
button("返回",24,101,11,8);
choose(i*4+21,95);
x=getch();
if(x=='w'&&i>1)i--;
else if(x=='s'&&i<1)i++;
else if(x==' ') {
clear2(8,0,29,95,126);
break;
}
}
} else if(i==2) {
clear2(8,0,29,95,126);
break;
}
}
if(i2!=i)choose_clear(i2*4+17,95);
}
} else if(i==4) {
clear2(8,0,29,95,126);
i=1;
while(1) {
i2=i;
print("aaaaaaaaaaaaaaaa ",0,95,4);
write("商店",0,109,15,4);
button("购买生命",3,101,11,8);
button("解锁皮肤",7,101,11,8);
button("返回",11,101,11,8);
i2=i;
choose(i*4,95);
x=getch();
if(x=='w'&&i>1)i--;
else if(x=='s'&&i<3)i++;
else if(x==' ') {
if(i==1) {
clear2(8,0,29,95,126);
print("aaaaaaaaaaaaaaaa ",0,95,4);
write("购买生命",0,107,15,4);
write("购买多少条生命:",1,95,15,8);
int gmsm=0,gmjb=0;
true_mouse();
cin>>gmsm;
hide_mouse();
gmjb=gmsm*500;
write("正在结算价格中",3,95,15,8);
int randddd=rand()%40+50;
for(i=0; i<=randddd; i++) {
write(". ",3,109+(i%6+1),4,8);
Sleep(100);
}
write("结算完成 ",3,95,15,8);
Sleep(1000);
write("结算结果:",4,95,15,8);
Sleep(700);
write("名称| 单价 |数量|单位|总价",6,95,15,8);
write(" | | | | ",7,95,15,8);
write("生命",7,95,11,8);
write("500金币",7,100,11,8);
gotoxy(7,108);
cout<<gmsm;
write("(条)",7,113,11,8);
gotoxy(7,118);
cout<<gmsm*500;
Sleep(700);
write("需要付钱:",9,95,15,8);
cout<<gmsm*500;
write("拥有金币:",10,95,15,8);
cout<<jb;
Sleep(500);
if(jb>=gmsm*500) {
write("金币足够,剩余",11,95,15,8);
cout<<jb-gmsm*500<<"元!是否购买?";
button("是",15,101,11,8);
button("否",19,101,11,8);
i=1;
while(1) {
i2=i;
choose(i*4+12,95);
x=getch();
if(x=='w'&&i>1)i--;
else if(x=='s'&&i<2)i++;
else if(x==' ') {
if(i==1) {
jb-=gmsm*500;
maxsm+=gmsm;
MessageBox(NULL,TEXT("购买成功"),TEXT("游戏通知"),MB_OK);
i=1;
clear2(8,0,29,95,126);
break;
}
if(i==2) {
i=1;
clear2(8,0,29,95,126);
break;
}
}
if(i2!=i)choose_clear(i2*4+12,95);
}
} else {
write("金币不够!",12,95,15,8);
button("返回↖",15,101,11,8);
choose(16,95);
while(1) {
x=getch();
if(x==' ') {
i=1;
clear2(8,0,29,95,126);
break;
}
}
}
continue;
} else if(i==2) {
clear2(8,0,29,95,126);
print("aaaaaaaaaaaaaaaa ",0,95,4);
write("解锁皮肤",0,107,15,4);
//●★▲■◆▼♀♂↗↘↙
write("选择你想要的皮肤吧!",1,95,15,8);
write("注: 红色表示未解锁",2,95,12,8);
write(" 绿色表示已解锁",3,95,10,8);
write(" Enter键返回,Space键选定",4,95,15,8);
write(" 购买过的皮肤不用付钱",5,95,15,8);
string pff[30]= {"●","★","▲","■","◆","▼","♀","♂","↗","↘","↙","↖","←","↑","→","↓"};
int iii1,iii2;
for(int i=0; i<16; i++) {
if(pfs[i]=='0')write(pff[i],7,96+i*2,15,12);
else write(pff[i],7,96+i*2,15,10);
if(pff[i]==pf) {
iii1=i;
write("︽",8,96+i*2,15,8);
}
}
while(1) {
iii2=iii1;
write("︽",8,96+iii1*2,15,8);
write(pff[iii1],10,95,15,8);
write("状态:",11,95,15,8);
if(pfs[iii1]=='1')cout<<"已购买";
else cout<<"未购买";
write("价格:",12,95,15,8);
cout<<iii1*150+850<<" ";
write("作用:装饰",13,95,15,8);
write("评价:",14,95,15,8);
for(int i2=1; i2<=(int)(iii1*1.0/4)+2; i2++)cout<<"★";
cout<<" ";
write("当前金币:",16,95,15,8);
cout<<jb<<",剩余金币:"<<jb-(iii1*150+850)<<" ";
if(jb>=(iii1*150+850))write("金币足够!按Space键购买装备此皮肤",17,95,15,8);
else write("金币不够!请选择其他皮肤 ",17,95,15,8);
x=getch();
if(x=='a'&&iii1>=1) {
iii1--;
} else if(x=='d'&&iii1<=14) {
iii1++;
} else if(x==13) {
clear2(8,0,29,95,126);
break;
} else if(x==' ') {
if(jb>=(iii1*150+850)||pfs[iii1]=='1') {
if(pfs[iii1]=='0') {
if(MessageBox(NULL,TEXT("购买将消耗大量金币\n\n是否购买"),TEXT("游戏提醒"),MB_ICONINFORMATION|MB_YESNO)==6) {
jb-=(iii1*150+850);
pfs[iii1]='1';
pf=pff[iii1];
MessageBox(NULL,TEXT("购买成功,已为您自动装备\n\n"),TEXT("游戏提醒"),MB_OK);
clear2(8,0,29,95,126);
break;
} else {
continue;
}
} else {
pf=pff[iii1];
MessageBox(NULL,TEXT("该装备已经购买了!\n已为您装备\n"),TEXT("游戏提醒"),MB_OK);
clear2(8,0,29,95,126);
break;
}
} else {
MessageBox(NULL,TEXT("金币不足\n请继续赚钱!!\n"),TEXT("游戏提醒"),MB_OK);
clear2(8,0,29,95,126);
break;
}
}
write(" ",8,96+iii2*2,15,8);
}
i=1;
} else if(i==3) {
clear2(8,0,29,95,126);
i=1;
break;
}
}
if(i2!=i)choose_clear(i2*4,95);
}
} else if(i==5) {
if(MessageBox(NULL,TEXT("退出将删除部分数据\n\n是否退出"),TEXT("游戏提醒"),MB_ICONINFORMATION|MB_YESNO)==6) {
ofstream fw; //写
fw.open("球球飞车.txt"); //打开 读入.in
fw << gk<<" "<<gk2<<" "<<xy1<<" "<<xy2<<" "<<sm<<" "<<jb<<" "<<jl<<" "<<jl2<<" "<<jd<<" "<<sd<<" "<<dj<<" "<<maxsm<<" "<<pf<<" "<<pfs<<endl; //输入内容
fw.close(); //关闭文件
clear();
gotoxy(17,52);
SetColorAndBackground(4,15);
cout<<"正在删除数据......";
for(int ii=1; ii<=100; ii++) {
SetColorAndBackground(4,15);
gotoxy(17,70);
cout<<ii<<"%";
Sleep(50);
}
Sleep(1000);
system("cls");
gotoxy(17,52);
SetColorAndBackground(4,15);
cout<<"正在删除数据......100%";;
Sleep(1000);
system("大厅.exe");
}
}
}
if(i2!=i)choose_clear(i2*4+2,95);
}
}
}
int main() {
system("mode 128,30");
clear();
ClearConsoleToColors(0, 15);
k();
game();
while(1)Sleep(1000);
}
9.忍者(我在网上修一下)
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<conio.h>
#include<windows.h>
#include<cstdlib>
#include<ctime>
using namespace std;
#define MAXN 35
#define MIDX 10
#define MIDY 40
#define CG 25
#define CK 80
int G,K,Lnum,Wnum;//G为地图高,K为地图,Lnum为地图中的雷数,Wnum为剩余的小旗数
int nx,ny;//现在光标所在的位置
bool QR=0,Lose=0,is_flag_true[MAXN][MAXN];//QR为确认模式是否打开,Lose为是否输,第三个是这个位置上的旗是否放对
char map[MAXN][MAXN],tmap[MAXN][MAXN];//第一个是只有雷和空地的地图,第二个是玩家能看到的地图
int map1[MAXN][MAXN],mapc[MAXN][MAXN];//map1为数字的地图,其中0代表空地,-1为雷,1-8为周围雷的个数
//mapc为当前格子的颜色
int col[10]={240,249,242,252,241,244,243,240,248};//col[i]表示windows扫雷中i的颜色,col[0]为空格的颜色
int d[10][4]={{0},{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};//8个方向
bool ZB;//作弊是否打开
/*各种函数*/
void color(int);//颜色
void gto(int,int);//光标位置
void make();//制作随机地图
void print();//打印地图等
bool check(int,int);//判断坐标是否合法
bool is_win();//判断是否赢
bool is_lose();//是否输
void dfs(int,int);//用深搜来打开方块
void st(int,int);//试探,即windows扫雷中的左右键同时按
void flag(int,int);//小旗
void bj(int,int);//标记
void swt();//确认模式
void again();//重新开始
void zb();//作弊模式
void mainmain();//主函数
void print_real_map();//打印最终的地图
void begin();//各种操作
int main()
{
mainmain();
}
void color(int a){SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);}
void gto(int x,int y)
{
COORD pos;pos.X=y;pos.Y=x;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
void make()
{
for(int i=1;i<=G;i++)
for(int j=1;j<=K;j++)
map[i][j]='#';//初始化
for(int i=1;i<=Lnum;i++)
{
int x=rand()%G+1,y=rand()%K+1;
while(map[x][y]=='O')
x=rand()%G+1,y=rand()%K+1;
map[x][y]='O';
}//随机放雷
for(int i=1;i<=G;i++)
for(int j=1;j<=K;j++)
{
if(map[i][j]=='O')map1[i][j]=-1,mapc[i][j]=240;//如果是雷
else
{
for(int k=1;k<=8;k++)
if(map[i+d[k][0]][j+d[k][1]]=='O')
map1[i][j]++;//计算周围雷的个数
mapc[i][j]=col[map1[i][j]];//根据格子上的数设置颜色
}
}
for(int i=1;i<=G;i++)
for(int j=1;j<=K;j++)
if(mapc[i][j]==0)//空地
mapc[i][j]=240;
}
void print()
{
system("cls");
gto(0,MIDY-4); color(233); printf("扫雷");
color(240);
gto(1,MIDY);
for(int i=2;i<=G+1;i++)
{
gto(i,0);
for(int j=1;j<=K;j++)
printf("#"),tmap[i-1][j]='#';//初始化玩家所看到的地图
}
gto(2,0);
nx=2,ny=0;
color(15);
printf("@");
color(15);
gto(2,2*K+5);printf("-----规则-----");
gto(3,2*K+5);printf("wasd:选择位置");
gto(4,2*K+5);printf("空格:打开");
gto(5,2*K+5);printf("1键:试探周围8个方块,如果其中有雷则不会打开,无");
gto(6,2*K+5);printf(" 雷或旗帜标对了则会将周围无雷的位置打开,");
gto(7,2*K+5);printf(" 如果试探时周围有标错的旗帜,则会游戏失败");
gto(8,2*K+5);printf(" 必须额外确认一次,以便查看周围被试探的区域");
gto(9,2*K+5);printf("2键:放置/取消小旗(F)");
gto(10,2*K+5);printf("3键:放置/取消标记(?)");
gto(11,2*K+5);printf("4键:打开/关闭确认模式,即每次操作需再按一次确认");
gto(12,2*K+5);printf("5键:打开/关闭作弊模式,即显示原本地图");
gto(13,2*K+5);printf("0键:重新开始");//打印规则
gto(G+4,0);printf("-----操作提示-----\n");
printf("请选择方块进行操作");
gto(1,2*K+10);color(12);printf("剩余小旗数:%d",Wnum=Lnum);
}
bool check(int x,int y){return y>=0&&y<K&&x>=2&&x<G+2;}
//因为地图是从2行0列开始打的,而地图是从1行1列开始存的,所以gto(x,y)走到的是map[x-1][y+1]
bool is_win()
{
int cnt=0;
for(int i=1;i<=G;i++)
for(int j=1;j<=K;j++)
if(map[i][j]=='#'&&map1[i][j]==-1)
cnt++;
if(cnt==Lnum) return 1;
//所有没被打开的方块都是雷=>胜利
for(int i=1;i<=G;i++)
for(int j=1;j<=K;j++)
if((tmap[i][j]!='F'&&map1[i][j]==-1)||(tmap[i][j]=='F'&&map1[i][j]!=-1))
return 0;
return 1;
//所有雷都标有旗
}
bool is_lose(){return Lose;}
void dfs(int x,int y)
{
if(map1[x-1][y+1]>0)//只要边界全部是数字就return
{
gto(x,y),color(mapc[x-1][y+1]),printf("%d",map1[x-1][y+1]);
tmap[x-1][y+1]=map1[x-1][y+1]+'0';
return;
}
gto(x,y);color(255);
tmap[x-1][y+1]=' ';
printf(" ");//因为下面判断了雷,上面判断了数字,这里就一定是空地
for(int i=1;i<=8;i++)
{
int xx=x+d[i][0]-1,yy=y+d[i][1]+1;//这里的xx和yy是在map中的,而不是gto中的
if(check(xx+1,yy-1)&&tmap[xx][yy]=='#'&&map1[xx][yy]!=-1)//所以check和dfs的参数要变化
dfs(xx+1,yy-1);
}
}
void st(int x,int y)
{
for(int i=1;i<=8;i++)
{
int xx=x+d[i][0],yy=y+d[i][1];
if(check(xx,yy))
{
gto(xx,yy);
if(tmap[xx-1][yy+1]!='#')
color(mapc[xx-1][yy+1]-128);//减去128使周围的8个格子的背景颜色变为灰色
else
color(112);//这里特判一下'#',应该可以不用
printf("%c",tmap[xx-1][yy+1]);
}
}
gto(G+5,0),color(15),printf("请确认 ");
//试探必须额外确认一次,规则上有说
char c=getch();
if(c=='1')
{
for(int i=1;i<=8;i++)
{
int xx=x+d[i][0],yy=y+d[i][1];
if(check(xx,yy))
if(tmap[xx-1][yy+1]=='F'&&map1[xx-1][yy+1]!=-1)//试探时有格子的小旗标错了=>失败
{
Lose=1;
return;
}
}
for(int i=1;i<=8;i++)
{
int xx=x+d[i][0],yy=y+d[i][1];
if(check(xx,yy))
if(map1[xx-1][yy+1]==-1&&tmap[xx-1][yy+1]!='F')//试探是有格子为雷=>取消打开
return;
}
for(int i=1;i<=8;i++)
{
int xx=x+d[i][0],yy=y+d[i][1];
if(check(xx,yy)&&tmap[xx-1][yy+1]=='#')//打开周围8个格子
dfs(xx,yy);
}
}
}
void flag(int x,int y)
{
x-=1,y+=1;
if(tmap[x][y]=='F')//原本为小旗=>取消小旗
{
tmap[x][y]='#';mapc[x][y]=240;
gto(x+1,y-1),color(240),printf("#");
Wnum++;//更新小旗数
}
else//否则就放置小旗
{
is_flag_true[x][y]=map1[x][y]==-1;//判断小旗是否放对
tmap[x][y]='F';mapc[x][y]=253;
gto(x+1,y-1),color(253),printf("F");
Wnum--;//更新小旗数
}
gto(1,2*K+10);color(12);printf("剩余小旗数: ");
gto(1,2*K+22);printf("%d",Wnum);//更新小旗数
}
void bj(int x,int y)//和放小旗差不多,只是不用更新is_flag_true
{
x-=1,y+=1;
if(tmap[x][y]=='?')
{
gto(x+1,y-1),color(240),printf("#");
tmap[x][y]='#';mapc[x][y]=240;
}
else
{
if(tmap[x][y]=='F')//如果原本这个位置上是小旗,而你把它变为了标记,就要更新小旗数
{
Wnum++;
gto(1,2*K+10);color(12);printf("剩余小旗数: ");
gto(1,2*K+22);printf("%d",Wnum);
}
gto(x+1,y-1),color(240),printf("?");
tmap[x][y]='?';mapc[x][y]=240;
}
}
void swt(){QR=!QR;}
void zb()
{
if(ZB)//如果本来作弊打开了就把作弊地图清除
{
for(int i=1;i<=G;i++)
{
gto(i+1,K+2);
for(int j=1;j<=K;j++)
color(15),printf(" ");
}
ZB=0;
}
else//否则打印作弊地图
{
for(int i=1;i<=G;i++)
{
gto(i+1,K+2);
for(int j=1;j<=K;j++)
{
color(mapc[i][j]);
if(map1[i][j]==-1) printf("O");
else if(map1[i][j]>0) printf("%d",map1[i][j]);
else printf(" ");
}
}
ZB=1;
}
}
void again()
{
G=K=Lnum=nx=ny=Lose=ZB=0;
QR=0;
memset(is_flag_true,0,sizeof(is_flag_true));
memset(map,0,sizeof(map));
memset(tmap,0,sizeof(tmap));
memset(map1,0,sizeof(map1));
memset(mapc,0,sizeof(mapc));
color(15);
system("cls");//初始化
mainmain();
}
void begin()//各种操作
{
char c=getch();
gto(G+5,0),color(15),printf("请选择方块进行操作");
color(240);
if(c=='w'&&check(nx-1,ny))
{
gto(nx,ny);
if(tmap[nx-1][ny+1]!='#'||tmap[nx-1][ny+1]==' ')
color(mapc[nx-1][ny+1]);
printf("%c",tmap[nx-1][ny+1]);
gto(nx-=1,ny);color(15);printf("@");
}
else if(c=='s'&&check(nx+1,ny))
{
gto(nx,ny);if(tmap[nx-1][ny+1]!='#'||tmap[nx-1][ny+1]==' ')color(mapc[nx-1][ny+1]);printf("%c",tmap[nx-1][ny+1]);
gto(nx+=1,ny);color(15);printf("@");
}
else if(c=='a'&&check(nx,ny-1))
{
gto(nx,ny);if(tmap[nx-1][ny+1]!='#'||tmap[nx-1][ny+1]==' ')color(mapc[nx-1][ny+1]);printf("%c",tmap[nx-1][ny+1]);
gto(nx,ny-=1);color(15);printf("@");
}
else if(c=='d'&&check(nx,ny+1))
{
gto(nx,ny);if(tmap[nx-1][ny+1]!='#'||tmap[nx-1][ny+1]==' ')color(mapc[nx-1][ny+1]);printf("%c",tmap[nx-1][ny+1]);
gto(nx,ny+=1);color(15);printf("@");
}
//上下左右移动
else
{
if(c==' '&&(!(tmap[nx-1][ny+1]<='9'&&tmap[nx-1][ny+1]>='0'))&&tmap[nx-1][ny+1]!='F')
{
mapc[nx-1][ny+1]=col[map1[nx-1][ny+1]];//如果本来放了标记,mapc[nx-1][ny+1]的颜色为黑色,在打开时里面的颜色却不一定是黑色
if(QR)
{
gto(G+5,0),color(15),printf("请确认 ");
if(getch()==' ')
{
if(map1[nx-1][ny+1]==-1) {Lose=1;return;}
dfs(nx,ny);
}
}
else
{
if(map1[nx-1][ny+1]==-1) {Lose=1;return;}
dfs(nx,ny);
}
}
else if(c=='1')
{
if(QR)
{
gto(G+5,0),color(15),printf("请确认 ");
if(getch()=='1') st(nx,ny);
}
else st(nx,ny);
for(int i=1;i<=8;i++)
{
int xx=nx+d[i][0],yy=ny+d[i][1];
if(check(xx,yy))
{
gto(xx,yy);
if(tmap[xx-1][yy+1]!='#') color(mapc[xx-1][yy+1]);
else color(240);
printf("%c",tmap[xx-1][yy+1]);
}
}
}
else if(c=='2'&&(tmap[nx-1][ny+1]>'9'||tmap[nx-1][ny+1]<'1'))
{
if(QR)
{
gto(G+5,0),color(15),printf("请确认 ");
if(getch()=='2') flag(nx,ny);
}
else flag(nx,ny);
}
else if(c=='3'&&(tmap[nx-1][ny+1]>'9'||tmap[nx-1][ny+1]<'1'))
{
if(QR)
{
gto(G+5,0),color(15),printf("请确认 ");
if(getch()=='3') bj(nx,ny);
}
else bj(nx,ny);
}
else if(c=='4')
{
if(QR)
{
gto(G+5,0),color(15),printf("请确认 ");
if(getch()=='4') swt();
}
else swt();
}
else if(c=='5')
{
if(QR)
{
gto(G+5,0),color(15),printf("请确认 ");
if(getch()=='5') zb();
}
else zb();
}
else if(c=='0')
{
if(QR)
{
gto(G+5,0),color(15),printf("请确认 ");
if(getch()=='0') again();
}
else again();
}
}
}
void mainmain()
{
system("mode con cols=120 lines=35");//设置窗口大小
srand((unsigned)time(NULL));
int mode;
printf("1.初级\n2.中级\n3.高级\n4.自定义\n");
scanf("%d",&mode);if(mode>4) mode=4;
if(mode==1) G=9,K=9,Lnum=10;
else if(mode==2) G=16,K=16,Lnum=40;
else if(mode==3) G=16,K=30,Lnum=99;//三种等级的参数
else
{
printf("请输入雷区高度:");scanf("%d",&G);
printf("请输入雷区宽度:");scanf("%d",&K);
printf("请输入雷个数(建议不超过总大小的三分之一):");scanf("%d",&Lnum);
if(G>24) G=24;if(K>30) K=30;
if(G<9) G=9;if(K<9) K=9;
if(Lnum<10) Lnum=10;if(Lnum>G*K*9/10) Lnum=G*K*9/10;
//控制参数的范围,最后一个if是雷的数量不超过地图大小的9/10
}
make();
print();
while(1)
{
begin();
bool f1=is_win(),f2=is_lose();
if(f1||f2)
{
gto(0,0);
if(f1)
color(202),gto(0,0),printf("你 赢 了!!是否重来?(y/n)");
if(f2)
color(137),gto(0,0),printf("你 输 了!!是否重来?(y/n)");//输赢
print_real_map();
char c=getch();
if(c=='y'||c=='Y') again();
else
{
color(15);
system("cls");
gto(MIDX,MIDY-5);
printf("欢迎下次再来");
return;
}
}
}
}
void print_real_map()
{
color(240);
for(int i=1;i<=G;i++)
{
gto(i+1,0);
for(int j=1;j<=K;j++)
{
if(tmap[i][j]=='F'&&is_flag_true[i][j]==0)//如果旗标错了显示红色的X
color(252),printf("X");
else if(map1[i][j]==-1)//雷为黑色O
color(240),printf("O");
else if(map1[i][j]==0)//空
color(240),printf(" ");
else//数字
color(mapc[i][j]),printf("%d",map1[i][j]);
}
}
}
10.双人对战
#include<iostream>
#include<cstdio>
#include<windows.h>
#include<conio.h>
using namespace std;
int SIZ = 20;
HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord;
HANDLE hCon;
enum Color { DARKBLUE = 1, DARKGREEN, DARKTEAL, DARKRED, DARKPINK, DARKYELLOW, GRAY, DARKGRAY, BLUE, GREEN, TEAL, RED, PINK, YELLOW, WHITE };
void SetColor(Color c) {
if(hCon == NULL)
hCon = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hCon, c);
}
SYSTEMTIME sys;
//sys.wYear,sys.wMonth,sys.wDay,sys.wHour,sys.wMinute, sys.wSecond,sys.wMilliseconds,sys.wDayOfWeek
struct PLAYER {
int x,y;
int hp;
int gun;
int direct;
} p1,p2;
int map[1005][1005];
int abs(int x) {
if(x < 0) return -x;
return x;
}
void locate(int x,int y) {
coord.X=y - 1;
coord.Y=x - 1;
SetConsoleCursorPosition(hout,coord);
}
void print_map() {
locate(1,1);
SetColor(GRAY);
for(int i = 1; i <= SIZ; i++) cout<<"■";
locate(SIZ,1);
for(int i = 1; i <= SIZ; i++) cout<<"■";
for(int i = 2; i < SIZ; i++) {
locate(i,1);
cout<<"■";
locate(i,SIZ*2-1);
cout<<"■";
}
locate(SIZ+1,1);
SetColor(WHITE);
}
void create_tree(int x,int y) {
map[x][y] = map[x+1][y] = map[x-1][y] = map[x][y+1] = map[x][y-1] = 2;
}
void use_map(int x) {
if(x == 1) {
SIZ = 20;
SetColor(DARKGREEN);
map[16][6]=map[15][6]=map[17][6]=map[16][7]=map[16][5]=map[14][13]=map[13][12]=map[13][13]=2;
for(int i = 2; i < SIZ; i++) {
for(int j = 2; j < SIZ; j++) {
if(map[i][j] == 2) {
locate(i,j*2-1);
cout<<"■";
}
}
}
SetColor(GRAY);
for(int i = 5; i <= 15; i++) {
map[i][i] = 1;
locate(i,i*2-1);
cout<<"■";
}
SetColor(WHITE);
} else if(x == 2) {
SIZ = 30;
SetColor(GRAY);
for(int i = 4; i <= 26; i++) {
if(i == 13 || i == 14 ||i == 15) continue;
map[i][4] = map[4][i] = map[26][i] = map[i][26] = 1;
}
for(int i = 1; i <= SIZ; i++) {
for(int j = 1; j <= SIZ; j++) {
if(map[i][j] == 1) {
locate(i,j*2-1);
cout<<"■";
}
}
}
SetColor(DARKGREEN);
for(int i = 10; i<=20; i++) {
if(i == 13 || i == 17) continue;
map[i][10] = map[10][i] = map[20][i] = map[i][20] = 2;
}
create_tree(5,5);
create_tree(18,18);
for(int i = 1; i <= SIZ; i++) {
for(int j = 1; j <= SIZ; j++) {
if(map[i][j] == 2) {
locate(i,j*2-1);
cout<<"■";
}
}
}
SetColor(WHITE);
}
}
void cleanbody(int x,int y);
void putbody(int x,int y,int z);
void player_init() {
p1.hp = p2.hp = 300;
p1.gun = p2.gun = 1;
p1.direct = 4;
p2.direct = 2;
p1.x = 2;
p1.y = 2;
p2.x = SIZ - 1;
p2.y = SIZ - 1;
putbody(p1.x,p1.y,1);
putbody(p2.x,p2.y,2);
}
void mapinit() {
for(int i = 1; i <= SIZ; i++) {
map[i][1] = map[1][i] = map[SIZ][i] = map[i][SIZ] = 1;
}
}
void init() {
printf("Use Which Map?\n");
int x;
cin>>x;
system("cls");
use_map(x);
mapinit();
print_map();
player_init();
}
void putbody(int x,int y,int z) {
if(z == 1) SetColor(BLUE);
else if(z == 2) SetColor(RED);
locate(x,y*2-1);
cout<<"■";
SetColor(WHITE);
}
void cleanbody(int x,int y) {
locate(x,y*2-1);
cout<<" ";
}
/*
LIST
direct:
w 1
a 2
s 3
d 4
gun:
usp 1
mimigun 2
awp 3
block:
void 0
stone 1
tree 2
player 3
clip 4
*/
bool judge(int x,int y) {
if(map[x][y] == 1) return false;
if(map[x][y] == 2) return false;
if(map[x][y] == 3) return false;
return true;
}
bool judge_gun(int x,int y) {
if(map[x][y] == 1) return 0;
if(map[x][y] == 2) return 0;
if(map[x][y] == 3) {
if(p1.x == x && p1.y == y) p1.hp -= 50;//此处暂时不管威力
else p2.hp -= 50;
return 0;
}
return 1;
}
int cnt;
struct Clip {
int x,y;
int derect;
int force;
int start;
bool flag;
} clip[1000000];
void create_clip(int y,int x,int a,int b) {
int X,Y;
if(y == 1) {
if(!judge_gun(a-1,b)) return;
X = a-1;
Y = b;
} else if(y == 2) {
if(!judge_gun(a,b-1)) return;
X = a;
Y = b-1;
} else if(y == 3) {
if(!judge_gun(a+1,b)) return;
X = a+1;
Y = b;
} else if(y == 4) {
if(!judge_gun(a,b+1)) return;
X = a;
Y = b+1;
}
cnt++;
GetLocalTime( &sys );
clip[cnt].start = sys.wMilliseconds + sys.wSecond * 60 + sys.wHour * 3600;
clip[cnt].x = X;
clip[cnt].y = Y;
if(x == 1) {
clip[cnt].derect = p1.direct;
} else if(x == 2) {
clip[cnt].derect = p2.direct;
}
}
void shoot(int x) {
if(x == 1) {
create_clip(p1.direct,1,p1.x,p1.y);
} else if(x == 2) {
create_clip(p2.direct,2,p2.x,p2.y);
}
}
void clean_clip(int x,int y) {
locate(x,y*2-1);
cout<<" ";
locate(1,1);
}
void print_clip(int x,int y,int i) {
if(clip[i].flag) {
clean_clip(x,y);
return;
}
locate(x,y*2-1);
SetColor(YELLOW);
cout<<"''";
locate(1,1);
// system("pause");
}
void clipmove() {
GetLocalTime( &sys );
int t = sys.wMilliseconds + sys.wSecond * 60 + sys.wHour * 3600;
for(int i = 1; i <= cnt; i++) {
if(clip[i].flag) continue;
if(abs(clip[i].start - t) > 50) {
clip[i].start = t;
int x = clip[i].x;
int y = clip[i].y;
if(clip[i].derect==1) {
if(!judge_gun(clip[i].x-1,clip[i].y)) {
clip[i].flag = 1;
clean_clip(x,y);
continue;
}
clean_clip(clip[i].x,clip[i].y);
clip[i].x--;
print_clip(clip[i].x,clip[i].y,i);
} else if(clip[i].derect==2) {
if(!judge_gun(clip[i].x,clip[i].y-1)) {
clip[i].flag = 1;
clean_clip(x,y);
continue;
}
clean_clip(clip[i].x,clip[i].y);
clip[i].y--;
print_clip(clip[i].x,clip[i].y,i);
} else if(clip[i].derect==3) {
if(!judge_gun(clip[i].x+1,clip[i].y)) {
clip[i].flag = 1;
clean_clip(x,y);
continue;
}
clean_clip(clip[i].x,clip[i].y);
clip[i].x++;
print_clip(clip[i].x,clip[i].y,i);
} else if(clip[i].derect==4) {
if(!judge_gun(clip[i].x,clip[i].y+1)) {
clip[i].flag = 1;
clean_clip(x,y);
continue;
}
clean_clip(clip[i].x,clip[i].y);
clip[i].y++;
print_clip(clip[i].x,clip[i].y,i);
}
}
}
}
void judge_hp() {
int x = p1.hp;
int y = p2.hp;
if(x<0 && y<0 && x > y) swap(x,y);
if(x <= 0) {
locate(1,1);
system("cls");
printf("GAME OVER!\nTHE WINNER IS P2!");
Sleep(5000);
printf("\n-MADE BY Floatiy-");
exit(0);
} else if(y <= 0) {
locate(1,1);
system("cls");
printf("GAME OVER!\nTHE WINNER IS P1!");
Sleep(5000);
printf("\n-MADE BY Floatiy-");
exit(0);
}
}
void prog() {
char ch;
while(true) {
if(kbhit()) {
ch=getch();
if(ch == 'w' && judge(p1.x-1,p1.y)) {
p1.direct = 1;
cleanbody(p1.x,p1.y);
map[p1.x][p1.y] = 0;
putbody(--p1.x,p1.y,1);
map[p1.x][p1.y] = 3;
} else if(ch == '8' && judge(p2.x-1,p2.y)) {
p2.direct = 1;
cleanbody(p2.x,p2.y);
map[p2.x][p2.y] = 0;
putbody(--p2.x,p2.y,2);
map[p2.x][p2.y] = 3;
} else if(ch == 'a' && judge(p1.x,p1.y-1)) {
p1.direct = 2;
cleanbody(p1.x,p1.y);
map[p1.x][p1.y] = 0;
putbody(p1.x,--p1.y,1);
map[p1.x][p1.y] = 3;
} else if(ch == '4' && judge(p2.x,p2.y-1)) {
p2.direct = 2;
cleanbody(p2.x,p2.y);
map[p2.x][p2.y] = 0;
putbody(p2.x,--p2.y,2);
map[p2.x][p2.y] = 3;
} else if(ch == 's' && judge(p1.x+1,p1.y)) {
p1.direct = 3;
cleanbody(p1.x,p1.y);
map[p1.x][p1.y] = 0;
putbody(++p1.x,p1.y,1);
map[p1.x][p1.y] = 3;
} else if(ch == '5' && judge(p2.x+1,p2.y)) {
p2.direct = 3;
cleanbody(p2.x,p2.y);
map[p2.x][p2.y] = 0;
putbody(++p2.x,p2.y,2);
map[p2.x][p2.y] = 3;
} else if(ch == 'd' && judge(p1.x,p1.y+1)) {
p1.direct = 4;
cleanbody(p1.x,p1.y);
map[p1.x][p1.y] = 0;
putbody(p1.x,++p1.y,1);
map[p1.x][p1.y] = 3;
} else if(ch == '6' && judge(p2.x,p2.y+1)) {
p2.direct = 4;
cleanbody(p2.x,p2.y);
map[p2.x][p2.y] = 0;
putbody(p2.x,++p2.y,2);
map[p2.x][p2.y] = 3;
} else if(ch == '0') {
shoot(2);
} else if(ch == ' ') {
shoot(1);
}
Sleep(20);
}
clipmove();
judge_hp();
}
}
void welcome() {
Sleep(2000);
}
int main() {
welcome();
GetLocalTime( &sys );
init();
prog();
system("pause");
return 0;
}
11.双人跑酷
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
const long long dts=3+1;
long long wj1x,wj1y,wj2x,wj2y,cs=0,dtbh,wx1,wy1,wx2,wy2;
bool f=1,t1=1,t2=1,sy;
long long csx[dts+1]={
0,
14,
1,
1,
1
};
long long csy[dts+1]={
0,
1,
37,
1,
1
};
string dt[dts+1][21]={
{},
{
"",
" ",
" ",
" == === == ",
" === === < ",
" == < ",
" < ",
" == ==^^^^^^^^^^^== < ",
" ====== < ",
" == === ======= < ",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^< ",
" == < ",
" < ",
" == < ",
" ^ $",
" ========> <=== === === == = === = == === ==== ^ ==== === == = == = =====",
" ",
" ",
" ",
" ",
" ",
},
{
"",
" > < = = ",
" > < = = ",
" = > < = = = ",
" ^^^^^ = > === < = == = ",
" <= > = =^ = === = ",
" < = ^^^^^^^^^^^^^^^ < =$ = ",
" < = < = === ",
" ^^^< = = ^^^ =^^^^^^^^== = ",
" < = = ^^^ ============= = ",
" < = === == < = ",
" < ======^^^^^^^^^^^^^ ^^^^ ^^ ================ ",
" < ",
" ^^^^ < == == ",
" < = ",
" < = == ",
" ==== ^^^ = ",
" = == ",
" ========== ======= ",
" ",
" "
},
{
"",
" =",
" =",
" =",
" ====^=====^=====^=====^=====^=====^=====^=====^=====^=====^=====^=====^== =",
" =",
" ===== <> =",
" = <> <> =",
" ============================== =============================^=",
" < ^^^^^^^^^^^^ =",
" < == == =",
" < = = =",
" ^^^ < = = =",
" < = = =",
" < = = =",
" ^^^^< = = =",
" < = = =",
" < = = =",
" = = =",
" ============== ===== $=",
" ="
},
{
"",
" < =",
" < =",
" < =",
" < =",
" < ============================= =",
" < = = = = ===================== =",
" < == == = $= == = = == =",
" < = = = = = = = =",
" < = == ^^^^== = == = ===",
" < = = = ^^^^^= = = === === =",
" < == = =============== = = =",
" < = =^^ = = == =",
" < = =========================== = === =",
" < = = = =",
" < ^ =============================== = =",
" < => === =",
" ==> ===",
" ==================================================================== =",
" =",
" ="
}
};
void csh()
{
f=1,t1=1,t2=1;
cs=0;
return ;
}
void color(int c)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),c);
return ;
}
void gb()
{
CONSOLE_CURSOR_INFO cursor;
cursor.bVisible=FALSE;
cursor.dwSize=sizeof(cursor);
HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorInfo(handle, &cursor);
return ;
}
void ydgb(int x, int y)
{
COORD pos = {x,y};
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);// 获取标准输出设备句柄
SetConsoleCursorPosition(hOut, pos);//两个参数分别是指定哪个窗体,具体位置
return ;
}
void out();
void in();
void lx();
void js();
void gx();
int main()
{
system("mode con cols=75 lines=20");
srand(time(0));
while(1)
{
csh();
dtbh=rand()%dts+1;
wj1x=wj2x=csx[dtbh];
wj1y=wj2y=csy[dtbh];
color(240);
gb();
system("cls");
out();
while(f)
{
in();
js();
if(cs==1)
lx();
gx();
Sleep(75);
if(cs==1)cs=-1;
cs++;
}
system("cls");
if(!sy)
{
color(9);
system("cls");
cout<<"*赢了!";
cout<<"\n按Enter结束";
char t=getch();
while(t!=13)t=getch();
color(153);
}
else
{
color(12);
system("cls");
cout<<"+赢了!";
cout<<"\n按Enter结束";
char t=getch();
while(t!=13)t=getch();
color(204);
}
system("cls");
}
return 0;
}
void out()
{
for(long long i=1;i<=20;i++)
{
for(long long j=1;j<=75;j++)
{
if(i==wj1x&&j==wj1y)
{
color(9);
cout<<"*";
}
else
if(i==wj2x&&j==wj2y)
{
color(12);
cout<<"+";
}
else
{
if(dt[dtbh][i][j]=='$')
color(10);
else
color(240);
cout<<dt[dtbh][i][j];
}
}
cout<<endl;
}
color(240);
return ;
}
void in()
{
wx1=wj1x,wy1=wj1y;
wx2=wj2x,wy2=wj2y;
if(GetKeyState('A')<0&&(dt[dtbh][wj1x][wj1y-1]==' '||dt[dtbh][wj1x][wj1y-1]=='$')&&wj1y-1>0)
{
wj1y--;
}
if(GetKeyState('D')<0&&(dt[dtbh][wj1x][wj1y+1]==' '||dt[dtbh][wj1x][wj1y+1]=='$')&&wj1y-1<=100)
{
wj1y++;
}
if(GetKeyState('W')<0&&(dt[dtbh][wj1x-1][wj1y]==' '||dt[dtbh][wj1x-1][wj1y]=='$')&&t1)
{
wj1x--;
for(long long i=1;i<=2;i++)
if(dt[dtbh][wj1x-1][wj1y]==' ')wj1x--;
t1=0;
}
if(GetKeyState(37)<0&&(dt[dtbh][wj2x][wj2y-1]==' '||dt[dtbh][wj2x][wj2y-1]=='$')&&wj2y-1>0)
{
wj2y--;
}
if(GetKeyState(39)<0&&(dt[dtbh][wj2x][wj2y+1]==' '||dt[dtbh][wj2x][wj2y+1]=='$')&&wj1y-1<=100)
{
wj2y++;
}
if(GetKeyState(38)<0&&(dt[dtbh][wj2x-1][wj2y]==' '||dt[dtbh][wj2x-1][wj2y]=='$')&&t2)
{
wj2x--;
for(long long i=1;i<=2;i++)
if(dt[dtbh][wj2x-1][wj2y]==' ')wj2x--;
t2=0;
}
return ;
}
void lx()
{
if(dt[dtbh][wj1x+1][wj1y]==' '||dt[dtbh][wj1x+1][wj1y]=='$')wj1x++;
else t1=1;
if(dt[dtbh][wj2x+1][wj2y]==' '||dt[dtbh][wj2x+1][wj2y]=='$')wj2x++;
else t2=1;
return ;
}
void js()
{
if(dt[dtbh][wj1x][wj1y]=='$')
{
f=0;
sy=0;
}
if(dt[dtbh][wj2x][wj2y]=='$')
{
f=0;
sy=1;
}
if(wj1x==20)
{
wj1x=csx[dtbh];wj1y=csy[dtbh];
}
if(wj2x==20)
{
wj2x=csx[dtbh];wj2y=csy[dtbh];
}
if(dt[dtbh][wj1x+1][wj1y]=='^')
{
wj1x=csx[dtbh];wj1y=csy[dtbh];
}
if(dt[dtbh][wj2x+1][wj2y]=='^')
{
wj2x=csx[dtbh];wj2y=csy[dtbh];
}
if(dt[dtbh][wj1x][wj1y+1]=='<')
{
wj1x=csx[dtbh];wj1y=csy[dtbh];
}
if(dt[dtbh][wj2x][wj2y+1]=='<')
{
wj2x=csx[dtbh];wj2y=csy[dtbh];
}
if(dt[dtbh][wj1x][wj1y-1]=='>')
{
wj1x=csx[dtbh];wj1y=csy[dtbh];
}
if(dt[dtbh][wj2x][wj2y-1]=='>')
{
wj2x=csx[dtbh];wj2y=csy[dtbh];
}
return ;
}
void gx()
{
color(240);
ydgb(wy1,wx1-2);
cout<<"\b";
cout<<" ";
ydgb(wy2,wx2-2);
cout<<"\b";
cout<<" ";
color(11);
ydgb(wj1y,wj1x-2);
cout<<"\b";
cout<<"*";
color(12);
ydgb(wj2y,wj2x-2);
cout<<"\b";
cout<<"+";
return ;
}
12.贪吃蛇
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <conio.h>
#include <cmath>
#include <windows.h>
using namespace std;
/*** 光标定位 ***/
HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord;
void locate(int x,int y)
{
coord.X=y;
coord.Y=x;
SetConsoleCursorPosition(hout,coord);
};
/*** 隐藏光标 ***/
void hide()
{
CONSOLE_CURSOR_INFO cursor_info={1,0};
SetConsoleCursorInfo(hout, &cursor_info);
}
/*** 生成随机数 ***/
double random(double start, double end)
{
return start+(end-start)*rand()/(RAND_MAX + 1.0);
}
/*** 定义地图的长宽,蛇的坐标,长度,方向,食物的位置 ***/
int m,n;
struct node
{
int x,y;
}snake[1000];
int snake_length,dir;
node food;
int direct[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
/*** 输出墙 ***/
void print_wall()
{
cout << " ";
for (int i=1;i<=n;i++)
cout << "-";
cout << endl;
for (int j=0;j<=m-1;j++)
{
cout << "|";
for (int i=1;i<=n;i++) cout << " ";
cout << "|" << endl;
}
cout << " ";
for (int i=1;i<=n;i++)
cout << "-";
}
/*** 首次输出蛇,其中snake[0]代表头 ***/
void print_snake()
{
locate(snake[0].x,snake[0].y);
cout << "@";
for (int i=1;i<=snake_length-1;i++)
{
locate(snake[i].x,snake[i].y);
cout << "*";
}
}
/*** 判断是否撞墙或者自撞 ***/
bool is_correct()
{
if (snake[0].x==0 || snake[0].y==0 || snake[0].x==m+1 || snake[0].y==n+1) return false;
for (int i=1;i<=snake_length-1;i++)
{
if (snake[0].x==snake[i].x && snake[0].y==snake[i].y) return false;
}
return true;
}
/*** 随机生成并输出食物位置 ***/
bool print_food()
{
srand((unsigned)time(0));
bool e;
while (1)
{
e=true;
int i=(int) random(0,m)+1,j=(int) random(0,n)+1;
food.x=i;food.y=j;
for (int k=0;k<=snake_length-1;k++)
{
if (snake[k].x==food.x && snake[k].y==food.y)
{
e=false;break;
}
}
if (e) break;
}
locate(food.x,food.y);
cout << "$";
return true;
}
/*** 蛇的前进 ***/
bool go_ahead()
{
node temp;
bool e=false;
temp=snake[snake_length-1];
for (int i=snake_length-1;i>=1;i--)
snake[i]=snake[i-1];
snake[0].x+=direct[dir][0];
snake[0].y+=direct[dir][1];
locate(snake[1].x,snake[1].y);
cout << "*";
/*** 吃到了食物 ***/
if (snake[0].x==food.x && snake[0].y==food.y)
{
snake_length++;
e=true;
snake[snake_length-1]=temp;
}
/*** 输出此时蛇状态 ***/
if (!e)
{
locate(temp.x,temp.y);
cout << " ";
}
else
print_food();
locate(snake[0].x,snake[0].y);
cout << "@";
/*** 如果自撞 ***/
if (!is_correct())
{
system("cls");
cout << "You lose!" << endl << "Length: " << snake_length << endl;
return false;
}
return true;
}
/*** 主函数 ***/
int main()
{
system("mode con cols=80 lines=30"); //设置cmd窗口大小
system("color 0"); //设置字符颜色:0 黑;1 深蓝;2 深绿;3 深青;4 深红;5 深紫;6 深褐
cout << "--------------------贪吃蛇---------------------" << endl;
cout << "先选择难度.请在1-10中输入1个数,1最简单,10则最难" << endl;
cout << "然后进入游戏画面,以方向键控制方向.祝你游戏愉快!" << endl;
cout << "-----------------------------------------------" << endl;
cout<<"作者:王子岳"<<endl;
cout << "请输入难度级别:" ;
m=25;
n=40;
if (m<10 || n<10 || m>25 || n>40)
{
cout << "ERROR" << endl;
system("pause");
return 0;
}
int hard;
cin >> hard;
if (hard<=0 || hard>100)
{
cout << "ERROR" << endl;
system("pause");
return 0;
}
/*** 数据全部初始化,包括蛇长,位置,方向 ***/
snake_length=5;
clock_t a,b;
char ch;
double hard_len;
for (int i=0;i<=4;i++)
{
snake[i].x=1;
snake[i].y=5-i;
}
dir=3;
/*** 输出初始地图,蛇与食物 ***/
system("cls");
hide();
print_wall();
print_food();
print_snake();
locate(m+2,0);
cout << "现在长度是: ";
/*** 开始游戏 ***/
while (1)
{
/*** 难度随长度增加而提高 ***/
hard_len=(double)snake_length/(double) (m*n);
/*** 调节时间,单位是ms ***/
a=clock();
while (1)
{
b=clock();
if (b-a>=(int)(400-30*hard)*(1-sqrt(hard_len))) break;
}
/*** 接受键盘输入的上下左右,并以此改变方向 ***/
if (kbhit())
{
ch=getch();
if (ch==-32)
{
ch=getch();
switch(ch)
{
case 72:
if (dir==2 || dir==3)
dir=0;
break;
case 80:
if (dir==2 || dir==3)
dir=1;
break;
case 75:
if (dir==0 || dir==1)
dir=2;
break;
case 77:
if (dir==0 || dir==1)
dir=3;
break;
}
}
}
/*** 前进 ***/
if (!go_ahead()) break;
/*** 在最后输出此时长度 ***/
locate(m+2,12);
cout << snake_length;
}
system("pause");
return 0;
}
13.坦克大战
#include <stdio.h>
#include <windows.h>
#include <time.h>
//里规格:长39*2=78 (真坐标)(假坐标宽为39) 高39
//外规格:长41*2=82 (真坐标)(假坐标宽为41) 高41
#define UP 1
#define DOWN 2
#define LEFT 3
#define RIGHT 4
#define MAX_LEVEL 8
#define BULLET_NUM 20
#define MAX_LIFE 4
//程序中未写入函数参数表中且未说明的变量只有map二维数组,level_info数组和level
/*
此程序中涉及的x,y类的坐标值,分为以下两种:
假坐标:这里的坐标指的是以一个■长度为单位的坐标,而不是真正的coord坐标 (用于map数组的坐标)
真坐标:头文件自带的坐标结构coord中的坐标(也可以说是控制台里的真正坐标值)
区别:纵坐标y两值一致,假横坐标x值与真正coord横坐标(真坐标)关系是 x * 2 = coord 横坐标
coord横坐标既指GoTo函数中的x参数,因为本程序游戏界面以一个■长度为基本单位,
可以说涉及的coord横坐标全是偶数。既假坐标要变真坐标(变真坐标才能发挥真正作用),横坐标须乘以2
*/
typedef struct //这里的出现次序指的是一个AI_tank变量中的次序,游戏共有四个AI_tank变量
{ //∵设定每个AI_tank每种特殊坦克只出现一次 ∴fast_tank & firm_tank 最多出现次数不超过1
int fast_tank_order; //fast_tank出现的次序(在第fast_tank_order次复活出现,从第0次开始),且每个AI_tank只出现一次
int firm_tank_order; //firm_tank出现的次序,同上
} LevInfo; //关卡信息(准确说是该关出现的坦克信息)
LevInfo level_info [MAX_LEVEL] = {{-1,-1},{3,-1},{-1,3},{2,3},{2,3},{2,3},{2,3},{2,3}}; //初始化,-1代表没有该类型坦克
typedef struct //子弹结构体
{
int x,y; //子弹坐标,假坐标
int direction; //子弹方向变量
bool exist; //子弹存在与否的变量,1为存在,0不存在
bool initial; //子弹是否处于建立初状态的值,1为处于建立初状态,0为处于非建立初状态
bool my; //区分AI子弹与玩家子弹的标记,0为AI子弹,1为玩家(我的)子弹
} Bullet;
Bullet bullet [BULLET_NUM]; //考虑到地图上不太可能同时存在20颗子弹,所以数组元素设置20个
typedef struct //坦克结构体
{
int x,y; //坦克中心坐标
int direction; //坦克方向
int color; //颜色参方向数,1到6分别代表不同颜色,具体在PrintTank函数定义有说明
int model; //坦克图案模型,值为1,2,3,分别代表不同的坦克图案,0为我的坦克图案,AI不能使用
int stop; //只能是AI坦克使用的参数,非0代表坦克停止走动,0为可以走动
int revive; //坦克复活次数
int num; //AI坦克编号(固定值,为常量,初始化函数中定下)0~3
int CD; //发射子弹冷却计时
bool my; //是否敌方坦克参数,我的坦克此参数为1,为常量
bool alive; //存活为1,不存活为0
} Tank;
Tank AI_tank[4] , my_tank; //my_tank为我的坦克,Ai_tank 代表AI坦克
//∵所有的函数都有可能对全局变量map进行读写(改变),
//∴函数中不另说明是否会对全局变量map读写
//基本操作与游戏辅助函数
void GoToxy(int x,int y); //光标移动
void HideCursor(); //隐藏光标
void keyboard (); //接受键盘输入
void Initialize(); //初始化(含有对多个数据的读写)
void Stop(); //暂停
void Getmap(); //地图数据存放与获取
void Frame (); //打印游戏主体框架
void PrintMap(); //打印地图(地图既地图障碍物)(含对level的读取)
void SideScreen (); //副屏幕打印
void GameCheak(); //检测游戏输赢
void GameOver( bool home ); //游戏结束
void ClearMainScreen(); //主屏幕清屏函数∵system("cls")后打印框架有一定几率造成框架上移一行的错误∴单独编写清屏函数
void ColorChoose(int color); //颜色选择函数
void NextLevel(); //下一关(含有对level全局变量的读写)
//子弹部分
void BuildAIBullet(Tank *tank); //AI坦克发射子弹(含有对my_tank的读取,只读取了my_tank坐标)
void BuildBullet (Tank tank); //子弹发射(建立)(人机共用)(含全局变量bullet的修改)我的坦克发射子弹直接调用该函数,AI通过AIshoot间接调用
void BulletFly (Bullet bullet[BULLET_NUM]); //子弹移动和打击(人机共用),
void BulletHit (Bullet* bullet); //子弹碰撞(人机共用)(含Tank全局变量的修改),只通过BulletFly调用,子弹间的碰撞不在本函数,子弹间碰撞已在BulletShoot中检测并处理
void PrintBullet (int x,int y,int T); //打印子弹(人机共用)
void ClearBullet (int x,int y,int T); //清除子弹(人机共用)
int BulletCheak (int x,int y); //判断子弹前方情况(人机共用)
//坦克部分
void BuildAITank (int* position, Tank* AI_tank); //建立AI坦克
void BuildMyTank (Tank* my_tank); //建立我的坦克
void MoveAITank (Tank* AI_tank); //AI坦克移动
void MoveMyTank (int turn); //我的坦克移动,只通过keyboard函数调用,既键盘控制
void ClearTank (int x,int y); //清除坦克(人机共用)
void PrintTank (Tank tank); //打印坦克(人机共用)
bool TankCheak (Tank tank,int direction); //检测坦克dirtection方向的障碍物,返值1阻碍,0 畅通
int AIPositionCheak (int position); //检测AI坦克建立位置是否有障碍物AIPositionCheak
//DWORD WINAPI InputX(LPVOID lpParameter); //声明线程函数,用于检查X键输入并设置X键的输入冷却时间
//注意map数组应是纵坐标在前,横坐标在后,既map[y][x],(∵数组行长度在前,列长度在后)
//map里的值: 个位数的值为地图方块部分,百位数的值为坦克,子弹在map上没有值(子弹仅仅是一个假坐标)
//map里的值: 0为可通过陆地,1为红砖,2黄砖,5为水,100~103为敌方坦克,200为我的坦克,
//全局变量
int map[41][41]; //地图二维数组
int key_x; // X键是否被“读入”的变量,也是子弹是否可以发射的变,
int bul_num; //子弹编号
int position; //位置计数,对应AI坦克生成位置,-1为左位置,0为中间,1为右,2为我的坦克位置
int speed=7; //游戏速度,调整用
int level=1; //游戏关卡数
int score=0; //游戏分数
int remain_enemy; //剩余敌人(未出现的敌人)
char* tank_figure[4][3][4]=
{
{
{"◢┃◣", "◢━◣", "◢┳◣", "◢┳◣"},
{"┣●┫", "┣●┫", "━●┃", "┃●━"},
{"◥━◤", "◥┃◤", "◥┻◤", "◥┻◤"}
},
{
{"┏┃┓", "┏┳┓", "┏┳┓", "┏┳┓"},
{"┣●┫", "┣●┫", "━●┫", "┣●━"},
{"┗┻┛", "┗┃┛", "┗┻┛", "┗┻┛"}
},
{
{"┏┃┓", "◢━◣", "┏┳◣", "◢┳┓"},
{"┣●┫", "┣●┫", "━●┃", "┃●━"},
{"◥━◤", "┗┃┛", "┗┻◤", "◥┻┛"}
},
{
{"╔┃╗", "╔╦╗", "╔╦╗", "╔╦╗"},
{"╠█╣", "╠█╣", "━█╣", "╠█━"},
{"╚╩╝", "╚┃╝", "╚╩╝", "╚╩╝"}
}
};
int main () //主函数
{
int i;
unsigned int interval[12]={1,1,1,1,1,1,1,1,1,1,1,1} ; //间隔计数器数组,用于控制速度
srand(time(NULL)); //设置随机数种子(若不设置种子而调用rand会使每次运行的随机数序列一致)随机数序列指:如首次调用rand得到1,第二次得2,第三次3,则此次随机数序列为1,2,3
HideCursor(); //隐藏光标
system("mode con cols=112 lines=42"); //控制窗口大小
Frame (); //打印游戏主体框架
Initialize(); //初始化,全局变量level初值便是1
// HANDLE h1 , h2 ; //定义句柄变量
for(;;)
{
if(interval[0]++%speed==0) //速度调整用,假设interval[0]为a, 语句意为 a % 2==0,a=a+1;
{
GameCheak(); //游戏胜负检测
BulletFly ( bullet );
for(i=0 ; i<=3 ; i++) //AI坦克移动循环
{
if(AI_tank[i].model==2 && interval[i+1]++%2==0) //四个坦克中的快速坦克单独使用计数器1,2,3,4
MoveAITank( & AI_tank[i]);
if(AI_tank[i].model!=2 && interval[i+5]++%3==0) //四个坦克中的慢速坦克单独使用计数器5,6,7,8
MoveAITank( & AI_tank[i]);
}
for(i=0;i<=3;i++) //建立AI坦克部分
if(AI_tank[i].alive==0 && AI_tank[i].revive<4 && interval[9]++%90==0) //一个敌方坦克每局只有4条命
{ //如果坦克不存活。计时,每次建立有间隔 1750 ms
BuildAITank( &position, & AI_tank[i] ); //建立AI坦克(复活)
break; //每次循环只建立一个坦克
}
for(i=0;i<=3;i++)
if(AI_tank[i].alive)
BuildAIBullet(&AI_tank[i]); //AIshoot自带int自增计数CD,不使用main中的CD interval
if(my_tank.alive && interval[10]++%2==0 )
keyboard ();
if(my_tank.alive==0 && interval[11]++%30==0 && my_tank.revive < MAX_LIFE)
BuildMyTank( &my_tank );
}
Sleep(5);
}
return 0;
}
/*//这里的多线程暂时不用 //x键用于子弹发射,x键的冷却时间不能和上下左右一同设置,那样就太快了
DWORD WINAPI InputX(LPVOID lpParameter) //如果不用多线程运行,那么在x键冷却时间内程序会因Sleep将会挂起,暂停运行
{ //因为只有一个变量改变,而且变量改变先后顺序是显而易见的,所以不必设置缓冲区
for(;;)
{
if(GetAsyncKeyState( 88 )& 0x8000) //88为x键键值,当摁下x并且x键处于可输入状态
{
key_x=1; // X键是否允许被“读入”的变量,也是子弹是否可以发射的变量
Sleep(600); // 子线程Sleep中,x就不能被"读入",主线程每操作完一次子弹发射,key_x会归零
}
Sleep(10);
}
return 0;
}*/
void keyboard ()
{ // kbhit() getch() 用法可用但是不好用
/*
函数功能:该函数判断在此函数被调用时,某个键是处于UP状态还是处于DOWN状态,及前次调用GetAsyncKeyState函数后,
是否按过此键.如果返回值的最高位被置位,那么该键处于DOWN状态;如果最低位被置位,那么在前一次调用此函数后,此键被按过,
否则表示该键没被按过.
这里GetAsyncKeyState比 kbhit() + getch() 好用,操作更顺畅. GetAsyncKeyState的返回值表示两个内容,
一个是最高位bit的值,代表这个键是否被按下。一个是最低位bit的值,代表上次调用GetAsyncKeyState后,这个键是否被按下。
&为与操作,&0x8000就是判断这个返回值的高位字节。如果high-order bit是1,则是按下状态,否则是弹起状态,为0
*/
int count=0;
if (GetAsyncKeyState(VK_UP)& 0x8000)
MoveMyTank( UP );
else if (GetAsyncKeyState(VK_DOWN)& 0x8000)
MoveMyTank( DOWN );
else if (GetAsyncKeyState(VK_LEFT)& 0x8000)
MoveMyTank( LEFT );
else if (GetAsyncKeyState(VK_RIGHT)& 0x8000)
MoveMyTank( RIGHT );
else if (GetAsyncKeyState( 0x1B )& 0x8000) // Esc键
exit(0); //退出程序函数
else if (GetAsyncKeyState( 0x20 )& 0x8000) //空格
Stop();
else if (count++%7==0) //这里添加计数器是为了防止按键粘连不能达到微调效果
{
if (speed>1 && GetAsyncKeyState( 0x6B )& 0x8000) // +键
{
speed--;
GoToxy(102,11); //在副屏幕打印出当前速度
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE|FOREGROUND_RED);
printf("%d ",21-speed); //副屏幕显示的速度为1~10
}
else if (speed<20 && GetAsyncKeyState( 0x6D )& 0x8000) // - 键
{
speed++;
GoToxy(102,11); //在副屏幕打印出当前速度
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE|FOREGROUND_RED);
printf("%d ",21-speed); //副屏幕显示的速度为1~10
}
}
if(my_tank.CD==7)
{
if(GetAsyncKeyState( 88 )& 0x8000)
{
BuildBullet(my_tank);
my_tank.CD=0;
}
}
else
my_tank.CD++;
}
void BuildAIBullet(Tank *tank) //AI子弹发射(建立)含有对my_tank的读取
{
if(tank->CD==15)
{
if(!(rand()%11)) //冷却结束后在随后的每个游戏周期中有10分之一的可能发射子弹
{
BuildBullet(*tank);
tank->CD=0;
}
}
else
tank->CD++;
if(tank->CD >= 14) //AI强化部分,在冷却到达一定范围即可使用
{
if(tank->y==38 ) //如果坦克在底部(这个最优先)
{
if(tank->x < 20) //在老家左边
{
if(tank->direction==RIGHT) //坦克方向朝左
{
BuildBullet(*tank); //发射子弹
tank->CD=0;
}
}
else //在老家右边
if(tank->direction==LEFT) //坦克方向朝右
{
BuildBullet(*tank); //发射子弹
tank->CD=0;
}
}
else if(tank->x==my_tank.x+1 || tank->x==my_tank.x || tank->x==my_tank.x-1) //AI坦克在纵向上"炮口"对准我的坦克
{
if(tank->direction==DOWN && my_tank.y > tank->y || tank->direction==UP && my_tank.y < tank->y)
{ //若是AI朝下并且我的坦克在AI坦克下方(数值大的在下面)或者AI朝上我的坦克在AI上方
int big=my_tank.y , smal=tank->y , i;
if(my_tank.y < tank->y)
{
big=tank->y;
smal=my_tank.y;
}
for(i=smal+2;i<=big-2;i++) //判断AI炮口的直线上两坦克间有无障碍
if(map[i][tank->x]!=0 || map[i][tank->x]!=5) //若有障碍
break;
if(i==big-1) //若i走到big-1说明无障碍
{
BuildBullet(*tank); //则发射子弹
tank->CD=0;
}
}
}
else if(tank->y==my_tank.y+1 || tank->y==my_tank.y || tank->y==my_tank.y-1) //AI坦克在横向上"炮口"对准我的坦克
{
if(tank->direction==RIGHT && my_tank.x > tank->x || tank->direction==LEFT && my_tank.x < tank->x)
{ //若是AI朝右并且我的坦克在AI坦克右方(数值大的在下面)或者AI朝左我的坦克在AI左方
int big=my_tank.y , smal=tank->y , i;
if(my_tank.x < tank->x)
{
big=tank->x;
smal=my_tank.x;
}
for(i=smal+2;i<=big-2;i++) //判断AI炮口的直线上两坦克间有无障碍
if(map[tank->y][i]!=0 || map[tank->y][i]!=5) //若有障碍
break;
if(i==big-1) //若i走到big-1说明无障碍
{
BuildBullet(*tank); //则发射子弹
tank->CD=0;
}
}
}
}
}
void BuildBullet(Tank tank) //子弹发射(建立),传入结构体Tank,这里包含改变了全局变量结构体bullet
{ //∵实现方式为顺序循环建立子弹,每次调用改变的bullet数组元素都不同
switch(tank.direction) //∴为了方便,不将bullet放入参数,bullet作为全局变量使用
{
case UP :
bullet [bul_num].x = tank.x;
bullet [bul_num].y = tank.y-2;
bullet [bul_num].direction=1;
break;
case DOWN :
bullet [bul_num].x = tank.x;
bullet [bul_num].y = tank.y+2;
bullet [bul_num].direction=2;
break;
case LEFT :
bullet [bul_num].x = tank.x-2;
bullet [bul_num].y = tank.y;
bullet [bul_num].direction=3;
break;
case RIGHT :
bullet [bul_num].x = tank.x+2;
bullet [bul_num].y = tank.y;
bullet [bul_num].direction=4;
break;
}
bullet [bul_num].exist = 1; //子弹被建立,此值为1则此子弹存在
bullet [bul_num].initial = 1; //子弹处于初建立状态
bullet [bul_num].my=tank.my; //如果是我的坦克发射的子弹bullet.my=1,否则为0
bul_num++;
if(bul_num==BULLET_NUM) //如果子弹编号增长到20号,那么重头开始编号
bul_num=0; //考虑到地图上不可能同时存在20颗子弹,所以数组元素设置20个
}
void BulletFly(Bullet bullet[BULLET_NUM]) //子弹移动和打击
{ //含有全局变量Bullet的改变
for(int i =0; i<BULLET_NUM;i++)
{
if(bullet [i].exist) //如果子弹存在
{
if(bullet [i].initial==0) //如果子弹不是初建立的
{
if(map[bullet[i].y] [bullet[i].x]==0 || map[bullet[i].y] [bullet[i].x]==5) //如果子弹坐标当前位置无障碍
ClearBullet( bullet[i].x , bullet[i].y , BulletCheak(bullet[i].x , bullet[i].y )); //抹除子弹图形
switch(bullet [i].direction) //然后子弹坐标变化(子弹变到下一个坐标)
{
case UP :(bullet [i].y)--;break;
case DOWN :(bullet [i].y)++;break;
case LEFT :(bullet [i].x)--;break;
case RIGHT :(bullet [i].x)++;break;
}
}
int collide = BulletCheak ( bullet [i].x , bullet [i].y ); //判断子弹当前位置情况,判断子弹是否碰撞,是否位于水面上。
if( collide ) //如果检测到当前子弹坐标无障碍(无碰撞)(包括在地面上与在水面上)
PrintBullet( bullet[i].x , bullet[i].y , collide); //则打印子弹,若有碰撞则不打印
else
BulletHit( & bullet [i] ); //若有碰撞则执行子弹碰撞函数
if(bullet [i].initial) //若子弹初建立,则把初建立标记去除
bullet [i].initial = 0;
for(int j=0; j< BULLET_NUM ; j++) //子弹间的碰撞判断,若是我方子弹和敌方子弹碰撞则都删除,若为两敌方子弹则无视
if(bullet [j].exist && j!=i && (bullet[i].my || bullet[j].my) && bullet[i].x==bullet[j].x && bullet[i].y==bullet[j].y)
{ //同样的两颗我方子弹不可能产生碰撞
bullet [j].exist=0;
bullet [i].exist=0;
ClearBullet( bullet[j].x , bullet[j].y , BulletCheak(bullet[j].x , bullet[j].y )); //抹除j子弹图形,子弹i图形已被抹除
break;
}
}
}
}
void BulletHit(Bullet* bullet) //含有Tank全局变量的修改,子弹间的碰撞不在本函数,子弹间碰撞已在BulletShoot中检测并处理
{ //∵每次打中的坦克都不一样,不可能把所有坦克放在参数表中
int x=bullet->x; //∴这里的Tank使用全局变量
int y=bullet->y; //这里传入的值是子弹坐标,这两个值不需要改变
int i;
if(map[y][x]==1 || map[y][x]==2) //子弹碰到砖块
{
if(bullet->direction==UP || bullet->direction==DOWN) //如果子弹是纵向的
for(i = -1 ; i<=1 ; i++)
if(map[y][x+i]==1 || map[y][x+i]==2) //如果子弹打中砖块两旁为砖块,则删除砖,若不是(一旁为坦克或其他地形)则忽略
{
map[y][x+i]=0; //砖块碎
GoToxy(2*x+2*i,y);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED); //背景黑色
printf(" ");
}
if(bullet->direction==LEFT || bullet->direction==RIGHT) //若子弹是横向的 (与子弹纵向实现同理)
for(i = -1 ; i<=1 ; i++)
if(map[y+i][x]==1 || map[y+i][x]==2)
{
map[y+i][x]=0;
GoToxy(2*x,y+i);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED); //背景黑色
printf(" ");
}
bullet->exist=0; //这颗子弹已经不存在了
}
else if(map[y][x]==4 || map[y][x]==6 ) //子弹碰到边框或者不可摧毁方块
bullet->exist=0;
else if(bullet->my && map[y][x]>=100 && map[y][x]<104 ) //若我的子弹碰到了敌方坦克
{
int num = map[y][x]%100; //map[y][x]%100 等同于 tank.num ,可通过map值读取该坦克信息
if(AI_tank[num].model==3 && AI_tank[num].color==2) //若为firm tank,且color==2。该坦克为绿色,表明没有受到伤害
AI_tank[num].color=3; //则变成黄色,color=3为黄色
else if (AI_tank[num].model==3 && AI_tank[num].color==3)
AI_tank[num].color=4; //4为红色
else //其他类型的坦克或者firm tank为红色的情况
{
AI_tank[num].alive=0;
ClearTank(AI_tank[num].x , AI_tank[num].y); //清除该坦克
}
bullet->exist=0;
score+=100;
GoToxy(102,5); //在副屏幕上打印出分数
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
printf("%d ",score);
}
else if(map[y][x]==200 && bullet->my==0 ) //若敌方子弹击中我的坦克
{
my_tank.alive=0;
ClearTank(my_tank.x , my_tank.y);
bullet->exist=0;
my_tank.revive++; //我的坦克复活次数+1(∵我的坦克复活次数与生命值有关∴放在这里自减)
score-=100; //分数减少
GoToxy(102,5); //在副屏幕上打印出分数
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
printf("%d ",score);
GoToxy(102,7); //在副屏幕打印出我的剩余生命值
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);
printf("%d ", MAX_LIFE-my_tank.revive);
}
// else if(bullet->my==0 && map[y][x]>=100 && map[y][x]<104) //敌方子弹击中敌方坦克,可以设置两种子弹运行方式,这种暂时不用
// bullet->exist=0;
else if(map[y][x]==9) //子弹碰到家(无论是谁的子弹)
{
bullet->exist=0;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_GREEN);
GoToxy(38,37); printf(" ");
GoToxy(38,38); printf("◢◣ ");
GoToxy(38,39); printf("███");
GameOver(1); //游戏结束,传入1代表老家被毁
}
}
int BulletCheak (int x,int y) //判断子弹当前位置情况,判断子弹是否碰撞,是否位于水面上。
{ //有障碍返回0,无障碍且子弹在地面返回1,子弹在水面上返回2
if(map[y][x]==0)
return 1;
else if(map[y][x]==5)
return 2;
else
return 0;
}
void PrintBullet (int x,int y,int T) //当前坐标BulletCheak 的值做参量 T
{
if(T==1) // T==1 表示子弹当前坐标在陆地上
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_INTENSITY);
else if(T==2) // T==2 表示子弹当前坐标在水面上
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
GoToxy(2*x,y);
printf("●");
}
void ClearBullet(int x,int y,int T) //当前坐标BulletCheak 的值做参量 T
{
GoToxy(2*x,y);
if(T==2) // T==2 表示子弹当前坐标在水面上
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|BACKGROUND_BLUE|FOREGROUND_BLUE|FOREGROUND_GREEN);
printf("~");
}
else if(T==1) // T==1 表示子弹当前坐标在陆地上
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE);
printf("●");
}
}
//position为坦克生成位置,-1为左位置,0为中间,1为右,2为我的坦克位置
void BuildAITank(int* position, Tank* AI_tank) //执行一次该函数只建立一个坦克
{ //rand函数公式:0<=rand()%(a+1)<=a 0+m<=rand()%(n-m+1)+m<=n
//rand函数实现1到n:1<=rand()%(n)+1<=n
if(AIPositionCheak(*position)) //若此位置无障碍,可生成。position参数详见AIPositionCheak函数定义
{
AI_tank->x= 20 + 18*(*position); //20 + 18 * position 对应三个生成位置的x假坐标
AI_tank->y=2;
if(AI_tank->revive==level_info[level-1].firm_tank_order) //坦克出现(复活)次序==关卡信息(level_info)中firm tank的出现次序
{
AI_tank->model = 3; //3为firm tank的模型(外观)
AI_tank->color = 2; //颜色参数2为绿色,具体详见函数ColorChoose
}
else if(AI_tank->revive==level_info[level-1].fast_tank_order) //同上if,这里是fast_tank的
{
AI_tank->model = 2;
AI_tank->color = rand()%6+1; //若不是firm tank则随机颜色,颜色参数为1~6,分别代表不同颜色,详见函数ColorChoose
}
else //普通坦克
{
AI_tank->model = 1;
AI_tank->color = rand()%6+1; //若不是firm tank则随机颜色
}
AI_tank->alive = 1; //坦克变为存在
AI_tank->direction = 2 ; //方向朝下
AI_tank->revive++; //复活次数+1
PrintTank(*AI_tank);
(*position)++;
remain_enemy--;
GoToxy(102,9); //在副屏幕上打印剩余坦克数
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
printf("%d ",remain_enemy);
if(*position==2) //position只能为0,1,-1,这里position循环重置
*position = -1;
return ; //若生成了一辆坦克,则结束该函数
}
}
int AIPositionCheak( int position ) //position为坦克生成位置2为我的坦克位置,其余为AI位,-1为左位,0为中间位置,1为右位
{
int x,y;
if(position==2) //2为我的坦克位置,现在暂时用不到
x=15,y=38;
else
y=2 , x= 20 + 18 * position ; //20 + 18 * position 对应三个生成位置的x假坐标
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
if( map[y+j-1][x+i-1]!=0) //如果遍历的九宫格里有障碍物
return 0; //则返回0,表示此生成位置有阻碍
return 1; //否则生成1,表示此生成位置无阻碍
}
void MoveAITank(Tank* AI_tank) //AI专用函数,该函数主要为AI加强
{
if(AI_tank->alive) //如果坦克活着
{
if(AI_tank->stop!=0) //坦克是否停止运动的判断,若stop参数不为0
{
AI_tank->stop--; //则此坦克本回合停止运动
return;
}
if( !(rand()%23) ) //22分之1的概率执行方向重置
{
AI_tank->direction = rand()%4+1;
if( rand()%3 ) //在方向重置后有2分之1的概率停止走动3步的时间
{
AI_tank->stop=2;
return;
}
}
ClearTank (AI_tank->x , AI_tank->y);
if(TankCheak ( *AI_tank , AI_tank->direction)) //如果前方无障碍
switch ( AI_tank->direction )
{
case UP : AI_tank->y--; break; //上前进一格
case DOWN : AI_tank->y++; break; //下前进一格
case LEFT : AI_tank->x--; break; //左前进一格
case RIGHT: AI_tank->x++; break; //右前进一格
}
else //前方有障碍
{
if(!(rand()%4)) //3分之1的概率乱转
{
AI_tank->direction=rand()%4+1;
AI_tank->stop=2; //乱转之后停止走动3步的时间
PrintTank(*AI_tank);
return; //∵continue会跳过下面的打印函数,∴这里先打印
}
else //另外3分之2的几率选择正确的方向
{
int j;
for(j=1;j<=4;j++)
if(TankCheak ( *AI_tank , j )) //循环判断坦克四周有无障碍,此函数返值1为可通过
break;
if(j==5) //j==5说明此坦克四周都有障碍物,无法通行
{
PrintTank(*AI_tank);
return; //则跳过下面的while循环以防程序卡死
}
while(TankCheak ( *AI_tank , AI_tank->direction) == 0) //如果前方仍有障碍
AI_tank->direction=(rand()%4+1); //则换个随机方向检测
}
}
PrintTank(*AI_tank); //打印AI坦克
}
}
void BuildMyTank (Tank* my_tank) //建立我的坦克
{
my_tank->x=15;
my_tank->y=38;
my_tank->stop=NULL;
my_tank->direction=1;
my_tank->model=0;
my_tank->color=1;
my_tank->alive=1;
my_tank->my=1;
my_tank->CD=7;
PrintTank (*my_tank) ; //打印我的坦克
}
void MoveMyTank(int turn ) //玩家专用函数,turn为keyboard函数里因输入不同方向键而传入的不同的值
{
ClearTank(my_tank.x , my_tank.y); //map 数组中“我的坦克”参数清除工作已在此函数中完成
my_tank.direction=turn; //将键盘输入的方向值传入我的坦克方向值
if(TankCheak ( my_tank , my_tank.direction )) //若此时我的坦克当前方向上无障碍
switch (turn)
{
case UP : my_tank.y--; break; //上前进一格
case DOWN : my_tank.y++; break; //下前进一格
case LEFT : my_tank.x--; break; //左前进一格
case RIGHT: my_tank.x++; break; //右前进一格
} //若坦克当前方向上有障碍则跳过坐标变化直接打印该转向的坦克
PrintTank (my_tank);
}
bool TankCheak(Tank tank,int direction) //检测坦克前方障碍函数,参量为假坐标。返值1为可通过,返值0为阻挡(人机共用)
{
switch(direction) //direction变量 1上,2下,3左,4右
{
case UP:
if (map[tank.y-2][tank.x]==0 && map[tank.y-2][tank.x-1]==0 && map[tank.y-2][tank.x+1]==0)
return 1;
else
return 0;
case DOWN:
if (map[tank.y+2][tank.x]==0 && map[tank.y+2][tank.x-1]==0 && map[tank.y+2][tank.x+1]==0)
return 1;
else
return 0;
case LEFT:
if (map[tank.y][tank.x-2]==0 && map[tank.y-1][tank.x-2]==0 && map[tank.y+1][tank.x-2]==0)
return 1;
else
return 0;
case RIGHT:
if (map[tank.y][tank.x+2]==0 && map[tank.y-1][tank.x+2]==0 && map[tank.y+1][tank.x+2]==0)
return 1;
else
return 0;
default:
printf("错误!!");
Sleep(5000);
return 0;
}
}
void ClearTank(int x,int y) //清除坦克函数(人机共用)
{
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
{ //将坦克占用的地图上的九格去掉
map[y+j-1][x+i-1]=0;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN);
GoToxy(2*x+2*j-2,y+i-1);
printf(" ");
}
}
void PrintTank(Tank tank) //打印坦克(人机共用) 由于读取的Tank参数较多,故就不将参数一一传入了
{ // tank.color参数对应不同的颜色,范围 1 ~ 6
ColorChoose(tank.color); //颜色选择函数 定义一个数组里装着字符指针(既装字符串)的数组指针(指向一维数组首地址的指针)
char *(*tankF)[4] = tank_figure[tank.model]; //将二维数组首址赋初值给数组指针 model==0为我的坦克,4为电脑1坦克,8为电脑2,类推
for(int i = 0; i < 3; i++)
{
GoToxy((tank.x-1)*2 , tank.y-1+i); //在坦克中心坐标的左边,上中下三行打印
printf("%s", tankF[i][tank.direction-1]); //打印的是地址,地址既字符串
for(int j=0;j<3;j++)
if(tank.my) //若为我的坦克
map[tank.y+j-1][tank.x+i-1]=200; //在map上把"坦克"九格填满代表敌我坦克的参数。敌方此值为100~103,我方为200
else
map[tank.y+j-1][tank.x+i-1]=100+tank.num; //这样可以通过map值读取坦克编号,读取操作在BulletHit 函数
}
}
void HideCursor() //隐藏光标
{ //CONSOLE_CURSOR_INFO结构体包含控制台光标的信息,DWORD dwSize光标百分比厚度(1~100)和BOOL bVisible光标是否可见
CONSOLE_CURSOR_INFO cursor_info={1,0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info); //SetConsoleCursorInfo用来设置指定的控制台光标的大小和可见性。
}
void GoToxy(int x,int y) //光标移动函数,X表示横坐标,Y表示纵坐标。
{
COORD coord; //使用头文件自带的坐标结构
coord.X=x; //这里将int类型值传给short,不过程序中涉及的坐标值均不会超过short范围
coord.Y=y;
HANDLE a=GetStdHandle(STD_OUTPUT_HANDLE); //获得标准输出句柄
SetConsoleCursorPosition(a,coord); //以标准输出的句柄为参数设置控制台光标坐标
}
void ColorChoose(int color) //颜色选择函数
{
switch(color)
{
case 1: //天蓝色(我的坦克颜色)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE);
break;
case 2: //绿色
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);
break;
case 3: //黄色
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);
break;
case 4: //红色
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
break;
case 5: //紫色
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE);
break;
case 6: //白色
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN);
break;
case 7: //深蓝色(∵颜色深难与黑色背景辨识度不高 ∴坦克颜色不选用此颜色),只用在字体颜色闪烁中
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE);
break;
}
}
void Stop() //暂停
{
int color=1,timing=0;
while(1)
{
if(timing++%30==0)
{
ColorChoose(color); //颜色选择
GoToxy(100,13); //副屏幕打印
printf("游戏暂停");
GoToxy(88,17);
printf("按回车键回到游戏");
GoToxy(88,18);
printf("或按 Esc键退出游戏");
if(++color==8)
color=1;
}
if (GetAsyncKeyState( 0xD )& 0x8000) //回车键
{
GoToxy(100,13); //副屏幕打印
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE);
printf("正在进行"); //覆盖掉原来的提示
GoToxy(88,17);
printf(" ");
GoToxy(88,18);
printf(" ");
break;
}
else if(GetAsyncKeyState( 0x1B )& 0x8000) //Esc键退出
exit(0);
Sleep(20);
}
}
void ClearMainScreen() //主屏幕清屏函数,因使用system("cls");再打印框架有一定几率造成框架上移一行的错误,所以单独编写清屏函数
{
for(int i=1;i<40;i++)
{
GoToxy(2,i);
printf(" ");
}
}
void Frame () //打印游戏主体框架
{ //SetConsoleTextAttribute为设置文本颜色和文本背景颜色函数
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY);
printf(" ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_BLUE);
printf(" ▂▂▂▂▂▂▂▂▂▂▂▂▂ \n");
for(int i=0;i<14;i++)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN|FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_INTENSITY);
printf("▕ ▏");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_BLUE);
printf(" | |\n");
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN|FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_INTENSITY);
printf("▕ ▏");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_BLUE);
printf(" |═════════════|\n");
for(int i=0;i<24;i++)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN|FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_INTENSITY);
printf("▕ ▏");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_BLUE);
printf(" | |\n");
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN|FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_INTENSITY);
printf(" ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔ ");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY| FOREGROUND_BLUE);
printf(" ﹊﹊﹊﹊﹊﹊﹊﹊﹊﹊﹊﹊﹊﹊\n");
SideScreen (); //打印副屏幕
}
void PrintMap() // 打印地图(地图既地图障碍物)
{
for(int j=0;j<41;j++)
for(int i=0;i<41;i++)
if(map[i][j]==6)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN
|FOREGROUND_RED|FOREGROUND_BLUE|BACKGROUND_GREEN|BACKGROUND_RED|BACKGROUND_BLUE);
GoToxy(2*j,i);
printf("■");
}
else if(map[i][j]==2)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_RED|BACKGROUND_GREEN|BACKGROUND_RED);
GoToxy(2*j,i);
printf("▓");
}
else if(map[i][j]==1)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|BACKGROUND_GREEN|BACKGROUND_RED);
GoToxy(2*j,i);
printf("▓");
}
else if(map[i][j]==5)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|BACKGROUND_BLUE|FOREGROUND_BLUE|FOREGROUND_GREEN);
GoToxy(2*j,i);
printf("~");
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE|FOREGROUND_RED|FOREGROUND_GREEN);
GoToxy(38,37); printf("◣◢");
GoToxy(38,38); printf("███"); //∵无论地图怎么变,家所在位置不变,且家的字符多种,不方便用上述方式打印
GoToxy(38,39); printf("◢█◣"); //∴直接打印(且家的map值与符号无关)
}
void GetMap() //地图存放函数
{ //map里的值: 个位数的值为地图方块部分,百位数的值为坦克
int i ,j; //map里的值: 0为可通过陆地,1为红砖,2待定,5为水,100为敌方坦克,200为我的坦克,
int Map[8][41][41]=
{
{
{4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4},
{4,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,4},
{4,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,4},
{4,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,4},
{4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4},
{4,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4},
{4,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4},
{4,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,9,9,9,1,1,0,0,0,0,0,0,0,1,1,1,6,6,6,0,0,0,4},
{4,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,9,9,9,1,1,0,0,0,0,0,0,0,1,1,1,6,6,6,0,0,0,4},
{4,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,9,9,9,1,1,0,0,0,0,0,0,0,1,1,1,6,6,6,0,0,0,4},
{4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4}
},
};
for(i=0;i<41;i++)
for(j=0;j<41;j++)
map[i][j]=Map[level-1][i][j];
PrintMap(); //打印地图
}
void GameOver(bool home)
{
int timing=0,color=1;
while(1)
{
if(timing++%30==0) //游戏结束原因为生命值为0
{
ColorChoose(color); //颜色选择
if(home) //游戏结束原因为老家被毁,则多打印一行字以提示玩家
{
GoToxy(37,19); //主屏幕中心打印
printf("老家被毁!");
}
GoToxy(37,20); //主屏幕中心打印
printf("游戏结束!");
GoToxy(100,13); //副屏幕打印
printf("游戏结束");
GoToxy(88,17);
printf("请按回车键重新开始!");
GoToxy(88,18);
printf("或按 Esc键退出游戏!");
if(++color==8)
color=1;
}
if (GetAsyncKeyState( 0xD )& 0x8000) //回车键
{
// system("cls"); //清屏,这里清屏后再次打印框架有一定几率造成框架上移一行的bug,因此选用自建清屏函数
// Frame (); //重新打印游戏框架
score-=500; //分数-500
ClearMainScreen(); //主屏清屏函数,无需再次打印框架
Initialize(); //从本关重新开始
break;
}
else if(GetAsyncKeyState( 0x1B )& 0x8000) //Esc键退出
exit(0);
Sleep(20);
}
}
void NextLevel()
{
int timing=0,color=1;
level++;
if(level<=MAX_LEVEL)
while(1)
{
if(timing++%10==0)
{
ColorChoose(color); //颜色选择
GoToxy(37,20); //主屏幕中心打印
printf("恭喜过关!");
GoToxy(100,13); //副屏幕打印
printf("等待下关");
GoToxy(87,17);
printf("请按回车键进入下一关!");
GoToxy(88,18);
printf("或按 Esc键退出游戏!");
if(++color==8)
color=1;
}
if (GetAsyncKeyState( 0xD )& 0x8000) //回车键
{
GoToxy(88,17); //抹除副屏幕中的提示
printf(" ");
GoToxy(88,18);
printf(" ");
ClearMainScreen(); //主屏清屏函数,无需再次打印框架
Initialize(); //初始化从下一关开始,level已++
break;
}
else if(GetAsyncKeyState( 0x1B )& 0x8000) //Esc键退出
exit(0);
Sleep(20);
}
else //level>8 通关
while(1)
{
if(timing++%5==0)
{
ColorChoose(color);
GoToxy(33,20); //主屏幕中心打印
printf("恭喜通过全部关卡!");
GoToxy(100,13); //副屏幕打印
printf("已通全关");
GoToxy(88,17);
printf("恭喜通过全部关卡!");
GoToxy(88,19);
printf("按 Esc键退出游戏!");
if(++color==8)
color=1;
}
if(GetAsyncKeyState( 0x1B )& 0x8000) //Esc键退出
exit(0);
Sleep(10);
}
}
void GameCheak()
{ //剩余敌人为0且四坦克全部不存活
if(remain_enemy<=0 && !AI_tank[0].alive && !AI_tank[1].alive && !AI_tank[2].alive && !AI_tank[3].alive )
NextLevel(); //进入下一关
if(my_tank.revive>=MAX_LIFE) //我的生命值(复活次数)全部用完 MAX_LIFE
GameOver(0); //游戏结束,传入0代表我的复活次数用光(生命值为0)。游戏结束有两种判断,另一种是老家被毁
}
void SideScreen () //副屏幕 行(84起,110末,若双字符宽则在108打印最后一个字)列(11上屏末,13下屏初,39下屏末。为美观最好打在38)
{ // | 第 d 关 | " | |\n"
GoToxy(93,2);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_RED);
printf("第 关");
GoToxy(92,5);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_BLUE);
printf("分 数:");
GoToxy(92,7);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);
printf("生 命:");
GoToxy(86,9);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
printf("剩余敌方坦克:");
GoToxy(86,11);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE);
printf("当前游戏速度: %d",21-speed);
GoToxy(86,13);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE);
printf("当前游戏状态:");
GoToxy(94,19);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_RED);
GoToxy(94,24);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_RED);
printf("帮 助");
GoToxy(86,27);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);
printf("方向键 ←↑→↓ 移动");
GoToxy(93,29);
printf("x 键 射击");
GoToxy(89,31);
printf("+ - 调整游戏速度");
GoToxy(90,33);
printf("游戏速度范围1~20");
GoToxy(90,35);
printf("回车键 暂停游戏");
GoToxy(90,37);
printf("Esc键 退出游戏");
/* printf("帮 助"); //这是第二种详细说明的样式
GoToxy(86,21);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);
printf("方向键 ←↑→↓ 移动");
GoToxy(93,23);
printf("x 键 射击");
GoToxy(89,25);
printf("+ - 调整游戏速度");
GoToxy(90,27);
printf("游戏速度范围1~20");
GoToxy(90,29);
printf("回车键 暂停游戏");
GoToxy(90,31);
printf("Esc键 退出游戏");
GoToxy(86,33);
printf("敌方坦克全部消灭则过关");
GoToxy(87,34);
printf("己方坦克生命值为0 或");
GoToxy(86,35);
printf("正下方的老家被毁则失败");
GoToxy(86,36);
printf("己坦克与敌坦克子弹碰撞");
GoToxy(87,37);
printf("则抵消,敌坦克间子弹碰");
GoToxy(86,38);
printf("撞不抵消且可穿过敌坦克");*/
}
void Initialize() //初始化
{
remain_enemy=16;
my_tank.revive=0; //我的坦克复活次数为0
position=0;
bul_num=0;
GetMap();
BuildMyTank( &my_tank );
for(int i=0;i<12;i++) //子弹初始化
{
bullet [i].exist=0;
bullet [i].initial=0;
}
for(int i=0;i<=3;i++) //AI坦克初始化
{
AI_tank [i].revive=0;
AI_tank [i].alive=0; //初始化坦克全是不存活的,BuildAITank()会建立重新建立不存活的坦克
AI_tank [i].stop=0;
AI_tank [i].num=i;
AI_tank [i].my=0;
AI_tank [i].CD=0;
}
GoToxy(97,2); //在副屏幕上关卡数
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);
printf("%d",level);
GoToxy(102,5); //在副屏幕上打印分数
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_BLUE);
printf("%d ",score);
GoToxy(102,7); //在副屏幕打印我的剩余生命值
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);
printf("%d", MAX_LIFE-my_tank.revive);
GoToxy(102,9); //在副屏幕上打印剩余坦克数
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
printf("%d ",remain_enemy);
GoToxy(100,13); //在副屏幕上打印状态
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE|FOREGROUND_GREEN);
printf("正在游戏");
}
14.五子棋
#include <cstdio>
#include <windows.h>
#include <cstdlib>
#include <conio.h>
#include <iostream>
#include <cstring>
using namespace std;
#define Forij(x) for(int i=1;i<=x;i++)for(int j=1;j<=x;j++)
#define N 25
typedef long long LL;
LL fx[4][2]={{1,1},{1,0},{0,1},{1,-1}};
LL Q,GG;
string C[20]={"●","○","﹢","═","║","╔","╚","╗","╝","?"};//╋
void color(LL a){//颜色函数
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
void gotoxy(LL x,LL y){
COORD pos;
pos.X=2*x;
pos.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
struct Gomoku{
LL m[50][50],nx,ny;
void reset(){
system("cls");
memset(m,-1,sizeof(m));
color(7);
for (LL i=1; i<=N; i++){
gotoxy(0,i);cout<<C[4]; gotoxy(N+1,i);cout<<C[4];
gotoxy(i,0);cout<<C[3]; gotoxy(i,N+1);cout<<C[3];
}
gotoxy(0,0);cout<<C[5]; gotoxy(0,N+1);cout<<C[6];
gotoxy(N+1,0);cout<<C[7]; gotoxy(N+1,N+1);cout<<C[8];
color(3);
Forij(N){
gotoxy(i,j); cout<<C[2];
}
nx=ny=N/2+1; gotoxy(nx,ny);
}
void _drop(LL x,LL i,LL j){
m[i][j]=x;
gotoxy(i,j);
color(15); cout<<C[x];
}
LL check(){
Forij(N){
for (LL Fx=0,tmp,lst,xx,yy; Fx<4; Fx++) if(m[i][j]!=-1){
xx=i,yy=j,tmp=0,lst=m[i][j];
for (LL k=1; k<=5; k++){
if (xx>N || yy>N) break;
if (m[xx][yy]==(lst^1)){break;}
if (m[xx][yy]==lst) tmp++;
xx+=fx[Fx][0],yy+=fx[Fx][1];
}
if (tmp==5){
return lst;
}
}
}
return -1;
}
LL arnd(LL x,LL y){
LL cnt=0;
for (LL i=x-1; i<=x+1; i++) if (i>0 && i<=N)
for (LL j=y-1; j<=y+1; j++) if (j>0 && j<=N)
if (m[i][j]>-1) cnt++;
return cnt;
}
void get_val(LL x,LL y,LL &val){
val=0;
Forij(N){
for (LL Fx=0,tmp,tk,xx,yy; Fx<4; Fx++){
xx=i,yy=j,tmp=tk=0;
for (LL k=1; k<=5; k++){
if (xx>N || yy>N){tmp=0; break;}
if (m[xx][yy]==(x^1)){tmp=0; break;}
if (m[xx][yy]==x) tmp++,tk+=(1<<(k-1));
xx+=fx[Fx][0],yy+=fx[Fx][1];
}
switch(tmp){
case 5:
val+=8000000000; break;
case 4:
val+=1000+350*y; break;
case 3:
val+=(tk==14)?(300+600*y):(300+200*y); break;
case 2:
val+=3+2*y; break;
case 1:
val+=1+y; break;
}
}
}
}
void AI(LL x){
LL best,brnd,bi,bj,v1,v2,kkk;
best=-2147483647;
brnd=-2147483647;
Forij(N) if (m[i][j]==-1){
m[i][j]=x;
get_val(x,10,v1); //gotoxy(N+5,N/2);printf("%d ",v1);
get_val(x^1,80,v2); //gotoxy(N+5,N/2+1);printf("%d ",v2);
if (v1-v2>best) bi=i,bj=j,best=v1-v2;
if (v1-v2==best)
if ((kkk=arnd(i,j))>brnd)
brnd=kkk,bi=i,bj=j;
m[i][j]=-1;
}
_drop(x,bi,bj);
}
void HM(LL x){
char ch=getch();
for (;;ch=getch()){
if (ch=='w') {if (ny>1) ny--;}
else if (ch=='s') {if (ny<N) ny++;}
else if (ch=='a') {if (nx>1) nx--;}
else if (ch=='d') {if (nx<N)nx++;}
else if (m[nx][ny]==-1){_drop(x,nx,ny); return;}
gotoxy(nx,ny);
}
}
} A;
int main(){
for (;;){
A.reset();
for (GG=-1;;){
gotoxy(A.nx,A.ny);
A.HM(0); GG=A.check(); if (GG>-1) break;
A.AI(1); GG=A.check(); if (GG>-1) break;
}
gotoxy(5,N+3);
if (GG==0) printf("AI_1 win!");
if (GG==1) printf("AI_2 wins!");
while (kbhit()) getch();
Sleep(500);
gotoxy(5,N+3);
printf("Press anything to continue.");
getch();
}
}