博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【长期维护】C++休闲(修仙)躲方块小游戏
阅读量:4315 次
发布时间:2019-06-06

本文共 10444 字,大约阅读时间需要 34 分钟。

左右键控制小球左右移动,上键加速,Esc退出。

一个‘@’20分

 

#include 
#include
#include
using namespace std;char mmp[10000001][6], putmmp[16][8];int main() { system("color 70"); srand(time(NULL)); for (register int i = 1; i <= 10000000; i++) { mmp[i][0] = mmp[i][1] = mmp[i][2] = mmp[i][3] = mmp[i][4] = ' '; if (i % 3 == 0 && i > 30) { mmp[i][rand() % 5] = '#'; if (i % 20 == 0) { mmp[i][rand() % 5] = '@'; } } } int j = 1, x = 2, score = 1, delay = 10; char ch; mmp[j][x] = 'O'; for (register int i = 1; i <= 100000000; i++) { Sleep(delay); if (i == 500)//500帧后加速(10帧一动) delay = 8; if (i == 1000)//1000帧后加速(10帧一动) delay = 6; if (i == 1500)//1500帧后加速(10帧一动) delay = 4; if (i % 10 == 0) { j++; score++; if (mmp[j][x] == '#') { system("cls"); printf("score:%d", score); Sleep(1000); system("cls"); printf("again?(Y/N)"); ch = 1; while(ch ^ 'Y' && ch ^ 'y') { ch = getch(); if (ch == 'N' || ch == 'n') { exit(0); } } main(); } if (mmp[j][x] == '@') score += 20; mmp[j][x] = 'O'; system("cls"); putmmp[0][0] = '+', putmmp[0][1] = putmmp[0][2] = putmmp[0][3] = putmmp[0][4] = putmmp[0][5] = '-', putmmp[0][6] = '+', putmmp[0][7] = '\n'; int p = 1; for (register int k = j + 15; k >= j; k--, p++) { putmmp[p][0] = '|'; for (register int l = 0; l < 5; l++) { putmmp[p][l + 1] = mmp[k][l]; } putmmp[p][6] = '|', putmmp[p][7] = '\n'; } putmmp[15][x + 1] = 'O'; fwrite(putmmp, 1, 18 * 7, stdout); puts("|\n+-----+"); } if (kbhit()) { ch = getch(); switch(ch) { case 27 : exit(0); break; case -32: ch = getch(); switch(ch) { case 75 : if (x > 0) { if (mmp[j][x - 1] == '#') { system("cls"); printf("score:%d", j); Sleep(1000); system("cls"); printf("again?(Y/N)"); ch = 1; while(ch ^ 'Y' && ch ^ 'y') { ch = getch(); if (ch == 'N' || ch == 'n') { exit(0); } } main(); } if (mmp[j][x - 1] == '@') { score += 20; } mmp[j][x] = ' '; x--; mmp[j][x] = 'O'; } break; case 77 : if (x < 4) { if (mmp[j][x + 1] == '#') { system("cls"); printf("score:%d", j); Sleep(1000); system("cls"); printf("again?(Y/N)"); ch = 1; while(ch ^ 'Y' && ch ^ 'y') { ch = getch(); if (ch == 'N' || ch == 'n') { exit(0); } } main(); } if (mmp[j][x + 1] == '@') { score += 20; } mmp[j][x] = ' '; x++; mmp[j][x] = 'O'; } break; case 72: j++; score++; if (mmp[j][x] == '#') { system("cls"); printf("score:%d", j); Sleep(1000); system("cls"); printf("again?(Y/N)"); ch = 1; while(ch ^ 'Y' && ch ^ 'y') { ch = getch(); if (ch == 'N' || ch == 'n') { exit(0); } } main(); } mmp[j][x] = 'O'; Sleep(5); system("cls"); putmmp[0][0] = '+', putmmp[0][1] = putmmp[0][2] = putmmp[0][3] = putmmp[0][4] = putmmp[0][5] = '-', putmmp[0][6] = '+', putmmp[0][7] = '\n'; int p = 1; for (register int k = j + 15; k >= j; k--, p++) { putmmp[p][0] = '|'; for (register int l = 0; l < 5; l++) { putmmp[p][l + 1] = mmp[k][l]; } putmmp[p][6] = '|', putmmp[p][7] = '\n'; } putmmp[15][x + 1] = 'O'; fwrite(putmmp, 1, 18 * 7, stdout); puts("|\n+-----+"); break; } break; } mmp[j][x] = 'O'; system("cls"); putmmp[0][0] = '+', putmmp[0][1] = putmmp[0][2] = putmmp[0][3] = putmmp[0][4] = putmmp[0][5] = '-', putmmp[0][6] = '+', putmmp[0][7] = '\n'; int p = 1; for (register int k = j + 15; k >= j; k--, p++) { putmmp[p][0] = '|'; for (register int l = 0; l < 5; l++) { putmmp[p][l + 1] = mmp[k][l]; } putmmp[p][6] = '|', putmmp[p][7] = '\n'; } putmmp[15][x + 1] = 'O'; fwrite(putmmp, 1, 18 * 7, stdout); puts("|\n+-----+"); } } return 0;}

 

更新于二〇一九年八月六日(星期二)

#include <windows.h>#include <bits/stdc++.h>#include <conio.h>

using namespace std;
char mmp[10000001][6], putmmp[16][8];
int main() {
system("color 70");srand(time(NULL));
for (register int i = 1; i <= 10000000; i++) {
mmp[i][0] = mmp[i][1] = mmp[i][2] = mmp[i][3] = mmp[i][4] = ' ';
if (i % 3 == 0 && i > 30) {
mmp[i][rand() % 5] = '#';if (i % 20 == 0) {
mmp[i][rand() % 5] = '@';
}
}
}
int j = 1, x = 2, score = 1, delay = 10;char ch;
mmp[j][x] = 'O';
for (register int i = 1; i <= 100000000; i++) {
Sleep(delay);if (i == 500)//500帧后加速(10帧一动)delay = 8;if (i == 1000)//1000帧后加速(10帧一动)delay = 6;if (i == 1500)//1500帧后加速(10帧一动)delay = 4;
if (i % 10 == 0) {
j++;score++;if (mmp[j][x] == '#') {
system("cls");printf("score:%d", score);Sleep(1000);system("cls");printf("again?(Y/N)");ch = 1;while(ch ^ 'Y' && ch ^ 'y') {
ch = getch();if (ch == 'N' || ch == 'n') {
exit(0);
}
}main();
}if (mmp[j][x] == '@')score += 20;mmp[j][x] = 'O';system("cls");putmmp[0][0] = '+', putmmp[0][1] = putmmp[0][2] = putmmp[0][3] = putmmp[0][4] = putmmp[0][5] = '-', putmmp[0][6] = '+', putmmp[0][7] = '\n';int p = 1;for (register int k = j + 15; k >= j; k--, p++) {
putmmp[p][0] = '|';
for (register int l = 0; l < 5; l++) {
putmmp[p][l + 1] = mmp[k][l];
}
putmmp[p][6] = '|', putmmp[p][7] = '\n';
}putmmp[15][x + 1] = 'O';fwrite(putmmp, 1, 18 * 7, stdout);puts("|\n+-----+");
}
if (kbhit()) {
ch = getch();
switch(ch) {
case 27 :
exit(0);
break;
case -32:
ch = getch();
switch(ch) {
case 75 :
if (x > 0) {
if (mmp[j][x - 1] == '#') {
system("cls");printf("score:%d", j);Sleep(1000);system("cls");printf("again?(Y/N)");ch = 1;while(ch ^ 'Y' && ch ^ 'y') {
ch = getch();if (ch == 'N' || ch == 'n') {
exit(0);
}
}main();
}if (mmp[j][x - 1] == '@') {
score += 20;
}mmp[j][x] = ' ';x--;mmp[j][x] = 'O';}
break;
case 77 :
if (x < 4) {
if (mmp[j][x + 1] == '#') {
system("cls");printf("score:%d", j);Sleep(1000);system("cls");printf("again?(Y/N)");ch = 1;while(ch ^ 'Y' && ch ^ 'y') {
ch = getch();if (ch == 'N' || ch == 'n') {
exit(0);
}
}main();
}if (mmp[j][x + 1] == '@') {
score += 20;
}mmp[j][x] = ' ';x++;mmp[j][x] = 'O';}
break;
case 72:
j++;score++;
if (mmp[j][x] == '#') {
system("cls");printf("score:%d", j);Sleep(1000);system("cls");printf("again?(Y/N)");ch = 1;while(ch ^ 'Y' && ch ^ 'y') {
ch = getch();if (ch == 'N' || ch == 'n') {
exit(0);
}
}main();
}
mmp[j][x] = 'O';Sleep(5);system("cls");putmmp[0][0] = '+', putmmp[0][1] = putmmp[0][2] = putmmp[0][3] = putmmp[0][4] = putmmp[0][5] = '-', putmmp[0][6] = '+', putmmp[0][7] = '\n';int p = 1;for (register int k = j + 15; k >= j; k--, p++) {
putmmp[p][0] = '|';
for (register int l = 0; l < 5; l++) {
putmmp[p][l + 1] = mmp[k][l];
}
putmmp[p][6] = '|', putmmp[p][7] = '\n';
}putmmp[15][x + 1] = 'O';fwrite(putmmp, 1, 18 * 7, stdout);puts("|\n+-----+");
break;
}
break;
}
mmp[j][x] = 'O';system("cls");putmmp[0][0] = '+', putmmp[0][1] = putmmp[0][2] = putmmp[0][3] = putmmp[0][4] = putmmp[0][5] = '-', putmmp[0][6] = '+', putmmp[0][7] = '\n';int p = 1;for (register int k = j + 15; k >= j; k--, p++) {
putmmp[p][0] = '|';
for (register int l = 0; l < 5; l++) {
putmmp[p][l + 1] = mmp[k][l];
}
putmmp[p][6] = '|', putmmp[p][7] = '\n';
}putmmp[15][x + 1] = 'O';fwrite(putmmp, 1, 18 * 7, stdout);puts("|\n+-----+");
}
}
return 0;
}

转载于:https://www.cnblogs.com/Ice-watermelon233/p/C_with_Class_xiuxian_dfkxiaoyouxi.html

你可能感兴趣的文章
MySQL(四)--练习题
查看>>
高效掌握C#第五回---猜单词游戏
查看>>
07-Java 中的IO操作
查看>>
uclibc,eglibc,glibc之间的区别和联系【转】
查看>>
Java魔法堂:找外援的利器——Runtime.exec详解
查看>>
mysql数据库存放路径
查看>>
TestNG(五)常用元素的操作
查看>>
解决 Visual Studio 点击添加引用无反应的问题
查看>>
通过镜像下载Android系统源码
查看>>
python字符串格式化 %操作符 {}操作符---总结
查看>>
windows 不能在 本地计算机 启动 Apache
查看>>
iOS开发报duplicate symbols for architecture x86_64错误的问题
查看>>
Chap-6 6.4.2 堆和栈
查看>>
【Java学习笔记之九】java二维数组及其多维数组的内存应用拓展延伸
查看>>
C# MySql 连接
查看>>
网络抓包分析方法大全
查看>>
sql 数据类型
查看>>
android 截图
查看>>
WebServicer接口类生成方法。
查看>>
POJ 1740
查看>>