#include <bits/stdc++.h>
#include <conio.h>
#include <windows.h>
using namespace std;
int jump[20] = {0, -1, -1, -1, -1};
char mmp[21][42] = {"\nO # # @",
"\n## ##",
"\n ### ### ",
"\n # # ",
"\n#### # # ####",
"\n # # ",
"\n ################################ ",
"\n ",
"\n ",
"\n############ ############",
"\n ",
"\n ",
"\n ###### ###### ",
"\n ",
"\n ",
"\n ################ ",
"\n ",
"\n######## ########",
"\n ###### ###### ",
"\n "
};
int main() {
int xp1 = 0, yp1 = 1, xp2 = 0, yp2 = 40, tick = 0;
char ch;
int score1 = 0, score2 = 0, jumpdelay1 = 0, jumpdelay2 = 0;
while (1) {
Sleep(40);
HANDLE hout;
COORD coord;
coord.X=0;
coord.Y=0;
hout=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hout,coord);
fwrite(mmp, 1, 20 * 40, stdout);
printf("\nscore: 1:%d 2:%d", score1, score2);
if (jumpdelay1 > 0) {
if (xp1 + jump[jumpdelay1] > 0 && mmp[xp1 + jump[jumpdelay1]][yp1] == ' ') {
mmp[xp1][yp1] = ' ';
xp1 += jump[jumpdelay1];
mmp[xp1][yp1] = 'O';
}
if (xp1 + jump[jumpdelay1] > 0 && (mmp[xp1 + jump[jumpdelay1]][yp1] == '<' || mmp[xp1 + jump[jumpdelay1]][yp1] == '>')) {
mmp[xp1][yp1] = ' ';
xp1 = 0, yp1 = 1;
mmp[xp1][yp1] = 'O';
score2++;
}
if (xp1 + jump[jumpdelay1] > 0 && mmp[xp1 + jump[jumpdelay1]][yp1] == '#') {
jumpdelay1 = 1;
}
if (xp1 + jump[jumpdelay1] > 0 && mmp[xp1 + jump[jumpdelay1]][yp1] == '@') {
jumpdelay1 = 1;
}
jumpdelay1--;
} else {
if (xp1 == 19) {
mmp[xp1][yp1] = ' ';
xp1 = 0, yp1 = 1;
mmp[xp1][yp1] = 'O';
score2++;
} else {
if (mmp[xp1 + 1][yp1] == ' ') {
mmp[xp1][yp1] = ' ';
xp1++;
mmp[xp1][yp1] = 'O';
}
if (mmp[xp1 + 1][yp1] == '<' || mmp[xp1 + 1][yp1] == '>') {
mmp[xp1][yp1] = ' ';
xp1 = 0, yp1 = 1;
mmp[xp1][yp1] = 'O';
score2++;
}
}
}
if (jumpdelay2 > 0) {
if (xp2 + jump[jumpdelay2] > 0 && mmp[xp2 + jump[jumpdelay2]][yp2] == ' ') {
mmp[xp2][yp2] = ' ';
xp2 += jump[jumpdelay2];
mmp[xp2][yp2] = '@';
}
if (xp2 + jump[jumpdelay2] >=0 && (mmp[xp2 + jump[jumpdelay2]][yp2] == '<' || mmp[xp2 + jump[jumpdelay2]][yp2] == '>')) {
mmp[xp2][yp2] = ' ';
xp2 = 0, yp2 = 40;
mmp[xp2][yp2] = '@';
score1++;
}
if (xp2 + jump[jumpdelay2] >=0 && mmp[xp2 + jump[jumpdelay2]][yp2] == '#') {
jumpdelay2 = 1;
}
if (xp2 + jump[jumpdelay2] >=0 && mmp[xp2 + jump[jumpdelay2]][yp2] == '#') {
jumpdelay2 = 1;
}
jumpdelay2--;
} else {
if (xp2 == 19) {
mmp[xp2][yp2] = ' ';
xp2 = 0, yp2 = 40;
mmp[xp2][yp2] = '@';
score1++;
} else {
if (mmp[xp2 + 1][yp2] == ' ') {
mmp[xp2][yp2] = ' ';
xp2++;
mmp[xp2][yp2] = '@';
}
if (mmp[xp2 + 1][yp2] == '<' || mmp[xp2 + 1][yp2] == '>') {
mmp[xp2][yp2] = ' ';
xp2 = 0, yp2 = 40;
mmp[xp2][yp2] = '@';
score1++;
}
}
}
for (register int i = 0; i < 20; i++) {
for (register int j = 1; j <= 40; j++) {
if (mmp[i][j] == '<') {
if (j - 1 <= 0) {
mmp[i][j] = ' ';
continue;
}
if (mmp[i][j - 1] == 'O') {
mmp[xp1][yp1] = ' ';
xp1 = 0, yp1 = 1;
mmp[xp1][yp1] = 'O';
score2++;
mmp[i][j - 1] = '<';
}
if (mmp[i][j - 1] == '@') {
mmp[xp2][yp2] = ' ';
xp2 = 0, yp2 = 40;
mmp[xp2][yp2] = '@';
score1++;
}
if (mmp[i][j - 1] == '#') {
mmp[i][j] = ' ';
}
if (mmp[i][j - 1] == ' ') {
mmp[i][j] = ' ';
mmp[i][j - 1] = '<';
}
if (mmp[i][j - 1] == '>') {
mmp[i][j] = mmp[i][j - 1] = ' ';
}
}
}
}
for (register int i = 19; i >= 0; i--) {
for (register int j = 40; j >= 1; j--) {
if (mmp[i][j] == '>') {
if (j + 1 >= 41) {
mmp[i][j] = ' ';
continue;
}
if (mmp[i][j + 1] == 'O') {
mmp[xp1][yp1] = ' ';
xp1 = 0, yp1 = 1;
mmp[xp1][yp1] = 'O';
score2++;
mmp[i][j + 1] = '>';
}
if (mmp[i][j + 1] == '@') {
mmp[xp2][yp2] = ' ';
xp2 = 0, yp2 = 40;
mmp[xp2][yp2] = '@';
score1++;
}
if (mmp[i][j + 1] == '#') {
mmp[i][j] = ' ';
}
if (mmp[i][j + 1] == ' ') {
mmp[i][j] = ' ';
mmp[i][j + 1] = '>';
}
if (mmp[i][j + 1] == '<') {
mmp[i][j] = mmp[i][j + 1] = ' ';
}
}
}
}
if (kbhit()) {
ch = getch();
switch (ch) {
case 27 :
exit(0);
break;
case 'a' :
if (yp1 - 1 > 0 && mmp[xp1][yp1 - 1] == ' ') {
mmp[xp1][yp1] = ' ';
yp1--;
mmp[xp1][yp1] = 'O';
}
if (yp1 - 1 > 0 && (mmp[xp1][yp1 - 1] == '<' || mmp[xp1][yp1 - 1] == '>')) {
mmp[xp1][yp1] = ' ';
xp1 = 0, yp1 = 1;
mmp[xp1][yp1] = 'O';
score2++;
}
break;
case 'd' :
if (yp1 + 1 <= 40 && mmp[xp1][yp1 + 1] == ' ') {
mmp[xp1][yp1] = ' ';
yp1++;
mmp[xp1][yp1] = 'O';
}
if (yp1 + 1 <= 40 && (mmp[xp1][yp1 + 1] == '<' || mmp[xp1][yp1 + 1] == '>')) {
mmp[xp1][yp1] = ' ';
xp1 = 0, yp1 = 1;
mmp[xp1][yp1] = 'O';
score2++;
}
break;
case 'w' :
if (jumpdelay1 == 0 && mmp[xp1 + 1][yp1] == '#') {
jumpdelay1 = 4;
}
break;
case -32 :
ch = getch();
switch (ch) {
case 75 :
if (yp2 - 1 > 0 && mmp[xp2][yp2 - 1] == ' ') {
mmp[xp2][yp2] = ' ';
yp2--;
mmp[xp2][yp2] = '@';
}
if (yp2 - 1 > 0 && (mmp[xp2][yp2 - 1] == '*' || mmp[xp2][yp2 - 1] == '*')) {
mmp[xp2][yp2] = ' ';
xp2 = 0, yp2 = 40;
mmp[xp2][yp2] = '@';
score1++;
}
break;
case 77 :
if (yp2 + 1 <= 40 && mmp[xp2][yp2 + 1] == ' ') {
mmp[xp2][yp2] = ' ';
yp2++;
mmp[xp2][yp2] = '@';
}
if (yp2 + 1 <= 40 && (mmp[xp2][yp2 + 1] == '<' || mmp[xp2][yp2 + 1] == '>')) {
mmp[xp2][yp2] = ' ';
xp2 = 0, yp2 = 40;
mmp[xp2][yp2] = '@';
score1++;
}
break;
case 72 :
if (jumpdelay2 == 0 && mmp[xp2 + 1][yp2] == '#') {
jumpdelay2 = 4;
}
break;
}
break;
case '2' :
if (yp1 > 1) {
if (mmp[xp1][yp1 - 1] == '@') {
mmp[xp2][yp2] = ' ';
xp2 = 0, yp2 = 40;
mmp[xp2][yp2] = '@';
score1++;
}
if (mmp[xp1][yp1 - 1] == ' ') {
mmp[xp1][yp1 - 1] = '<';
}
}
break;
case '3' :
if (yp1 < 40) {
if (mmp[xp1][yp1 + 1] == '@') {
mmp[xp2][yp2] = ' ';
xp2 = 0, yp2 = 40;
mmp[xp2][yp2] = '@';
score1++;
}
if (mmp[xp1][yp1 + 1] == ' ') {
mmp[xp1][yp1 + 1] = '>';
}
}
break;
case 'j' :
if (yp2 > 1) {
if (mmp[xp2][yp2 - 1] == 'O') {
mmp[xp1][yp1] = ' ';
xp1 = 0, yp1 = 1;
mmp[xp1][yp1] = 'O';
score2++;
}
if (mmp[xp2][yp2 - 1] == ' ') {
mmp[xp2][yp2 - 1] = '<';
}
}
break;
case 'k' :
if (yp2 < 40) {
if (mmp[xp2][yp2 + 1] == 'O') {
mmp[xp1][yp1] = ' ';
xp1 = 0, yp1 = 1;
mmp[xp1][yp1] = 'O';
score2++;
}
if (mmp[xp2][yp2 + 1] == ' ') {
mmp[xp2][yp2 + 1] = '>';
}
}
break;
}
}
}
return 0;
}
枪战改编版
于 2024-08-14 17:30:00 首次发布