实例介绍
【实例简介】这是一款避开炸弹清除界面所有非炸弹物体的游戏
【实例截图】
【核心代码】
#include <Windows.h>
#include <stdlib.h>
#include <time.h>
#include <bits/stdc .h>
#include <stdlib.h>
#include <conio.h>
#include <fstream>
using namespace std;
int hiscore = 10000000;
void gotoxy(int x,int y){
COORD pos = {x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
bool confirm() {
char ch;
while (true) {
ch = getch();
switch(ch) {
case'y':
return true;
case'n':
return false;
default:
break;
}
}
}
void ask_hint(){
cout << "是否开启提示? (y/n)" << endl;
if(confirm()){
system("cls");
cout << "欢迎来到清理游戏!" << endl;
Sleep(1800);
cout << "目标是清除棋盘上的所有字母(炸弹除外)。" << endl;
Sleep(2400);
system("cls");
cout << "按'w'向上,'a'向左移动,'s'向下移动然后'd'向右移动。" << endl;
Sleep(3000);
cout << "谨防! 有一封炸弹信条,一旦你在炸弹上面就输了!" << endl;
Sleep(2000);
system("cls");
return;
}
}
int main(){
system("cls");
ask_hint();
system("cls");
Sleep(1000);
int n;
int comp = false;
char s;
cout << "选择尺寸(1 ~ 10)" << endl;
cin >> n;
char mm[n][n];
int ran[n][n];
char bomb;
clock_t start, end;
double dur;
srand(time(NULL));
bomb = char(rand() % 26 97);
system("cls");
for(int i = 0; i < n; i ){
for(int j = 0; j < n; j ){
ran[i][j] = rand() % 26 97;
mm[i][j] = char(ran[i][j]);
}
}
for(int i = 0; i < n; i ){
for(int j = 0; j < n; j ){
gotoxy(10 i, 10 j);
cout << mm[i][j];
}
cout << endl;
}
int x = 0;
int y = 0;
gotoxy(0, 21);
cout << "代表炸弹的是字母 " << bomb << endl;
if(comp){
gotoxy(10, 0);
cout << "最快的时间:" << hiscore / 1000 << endl;
}
start = clock();
cycle:
char ch = 'p';
gotoxy(10 x, 10 y);
if(kbhit()){
gotoxy(0, 20);
ch = getche();
if(mm[x][y] == bomb){
goto boom;
}else{
mm[x][y] = ' ';
gotoxy(10 x, 10 y);
cout << mm[x][y];
}
}
switch(ch){
case 'w':{
if(!(y-1<0))
y--;
break;
}
case 's':{
if(!(y 1>=n))
y ;
break;
}
case 'a':{
if(!(x-1<0))
x--;
break;
}
case 'd':{
if(!(x 1>=n))
x ;
break;
}
default: break;
}
for(int i = 0; i < n; i ){
for(int j = 0; j < n; j ){
if(mm[i][j] != ' ' && mm[i][j] != bomb){
goto cycle;
}
}
}
goto win;
boom:
system("cls");
cout << "轰!" << endl;
cout << "你踩到了炸弹" << endl;
return 0;
win:
end = clock();
dur = end - start;
system("cls");
cout << "你获得了胜利" << endl;
cout << "使用时间: ";
printf("%. 3f", dur / 1000.0);
cout << " 秒" << endl;
system("pause");
return 0;
}
标签: 游戏
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


网友评论
我要评论