c++如何自创扫雷小游戏

#今天给大家看看如何十二步自创一个扫雷小游戏

1.载入需要的库文件( windows.h等不在bits/stdc++.h内部的库文件需要自行载入)代码如下:

#include <iostream>//本文代码原创-吝旭涵 
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <time.h>
#include <bits/stdc++.h>
using namespace std;
int sy=9;
int board[15][15]; 
int show[15][15]; 

2.创建color方法,来给地雷,旗子等特殊标记进行上色。

#为了简洁,我们直接将需要的颜色全部写出来,后面直接调用color(n)即可。

void Color(int colorpaint){
    if(colorpaint==0) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
    if(colorpaint==1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE);
    if(colorpaint==4) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);
}

3.编写输出打开游戏界面

void intro()
{
    cout << "╔═══════════════════════════════════════════════════════════════════╗" << endl;
    cout << "║                                                                   ║" << endl;
    cout << "║     ***欢迎运行扫雷游戏!***                                       ║" << endl;
    cout << "║                                                                   ║" << endl;
    cout << "║   【游戏规则如下:】                                               ║" << endl;
    cout << "║                                                                   ║" << endl;
    cout << "║                                                                   ║" << endl;
    cout << "║                                                                   ║" << endl;
    cout << "║   在这个游戏里会有一个 9*9 的网格,网格中埋着 10颗雷                 ║" << endl;
    cout << "║                                                                   ║" << endl;
    cout << "║   游戏目标是找出所有的雷,如果触雷,则游戏失败                       ║" << endl;
    cout << "║                                                                   ║" << endl;
    cout << "║   每次输入要操作的格子 行、列,1表示翻开,2表示标记/取消旗子??       ║" << endl;
    cout << "║                                                                   ║" << endl;
    cout << "║   格子中的数字表示它周围八个格中有几个雷                            ║" << endl;
    cout << "║                                                                   ║" << endl; 
    cout << "║   *第一次翻格子不会是雷                                            ║" << endl;
    cout << "║                                                                   ║" << endl;
    cout << "║                                                                   ║" << endl;
    cout << "║                                                                   ║" << endl; 
    cout << "║   按下 回车键 开始游戏                                             ║" << endl; 
    cout << "╚═══════════════════════════════════════════════════════════════════╝" << endl;
    getchar();
}

4.创建方法,打印棋盘。

void drawBoard()
{
    cout << "\033c" << flush;
    // 输出行号
    cout<<"剩余地雷数量:"<<sy<<"个"<<endl;
    cout << "     ";
    for (int i = 1; i <= 9; i++) cout << "   " << i;
    cout << "  \n";
    // 输出上边框
    cout <<
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值