C++移动小游戏

用二维数组来控制移动,变量x和y表示坐标。
还有发炮方向,由上一个方向发炮。

(没有那些3D2D图像,也没有那么牛的发炮特效,单纯的是一个文本移动游戏)
wsad控制,在最后一关,r键拆弹,Space(空格)键发炮。
在最后的一关,|是墙壁,%是炸弹。
地图中,$和&是敌人(不能移动)。
#是你。
地图上随机出现的.是敌方随机地雷,每关2条命,最后一关命增加。
MUBIAO是每关的终点,但需要打掉要求的敌人才能通过。

#include <iostream>
#include <iomanip>
#include <conio.h>
#include <windows.h>
#include <ctime>
using namespace std;
void  cpp1()
{
   
  int  xueliang = 2;
  long  long  diren = 4;
  int  x=0, y=0;
  string  see;
  char  map1[10][20] =
  {
   
    "******MUBIAO*******",
    "**&************&***",
    "*****$******$******",
    "*******************",
    "*******************",
    "*******************",
    "*******************",
    "*******************",
    "*******************",
    "*******************"
  };
  map1[x][y] = '#';
  char  ch;
  int  o, q;
  for (; true;)
  {
   
    system("cls");
    for(; true;)
    {
   
      o = rand() % 9;
      q = rand() % 19;
      if (map1[o][q] != '#' &&map1[o][q]!='*')
        continue;
      map1[o][q] = '.';
      break;
    }
    for (int j = 0; j < 10; j++)
    {
   
      cout << endl;
      for (int i = 0; i < 20; i++)
        cout << map1[j][i];
    }
    if (map1[o][q] == '#')
      xueliang--;
    if (xueliang <= 0)
    {
   
      cout << "GAME  OVER!" << endl;
      break;
    }
    cout << endl;
    ch = _getch();
    if (map1[x - 1][y] == 'M' || map1[x - 1][y] == 'U' || map1[x - 1][y] == 'B' || map1[x - 1][y] == 'I' || map1[x - 1][y] == 'A' || map1[x - 1][y] == 'O')
    {
   
      if (diren <= 0 && ch == 'w')
      {
   
        cout << "GOOD JOB!" << endl;
        Sleep(1000);
        break;
      }
    }
    if (map1[x + 1][y] == 'M' || map1[x + 1][y] == 'U' || map1[x + 1][y] == 'B' || map1[x + 1][y] == 'I' || map1[x + 1][y] == 'A' || map1[x + 1][y] == 'O')
    {
   
      if (diren <= 0 && ch == 's')
      {
   
        cout << "GOOD JOB!" << endl;
        Sleep(1000);
        break;
      }
    }
    if (map1[x][y - 1] == 'M' || map1[x][y - 1] == 'U' || map1[x][y - 1] == 'B' || map1[x][y - 1] == 'I' || map1[x][y - 1] == 'A' || map1[x][y - 1] == 'O')
    {
   
      if (diren <= 0 && ch == 'a')
      {
   
        cout << "GOOD JOB!" << endl;
        Sleep(1000);
        break;
      }
    }
    if (map1[x][y + 1] == 'M' || map1[x][y + 1] == 'U' || map1[x][y + 1] == 'B' || map1[x][y + 1] == 'I' || map1[x][y + 1] == 'A' || map1[x][y + 1] == 'O')
    {
   
      if (diren <= 0 && ch == 'd')
      {
   
        cout << "GOOD JOB!" << endl;
        Sleep(1000);
        break;
      }
    }
    if (ch == 'w' && map1[x - 1][y] == '*')
    {
   
      map1[x][y] = '*';
      x--;
      map1[x][y] = '#';
      see = "up";
    }
    if (ch == 's' && map1[x + 1][y] == '*')
    {
   
      map1[x][y] = '*';
      x++;
      map1[x][y] = '#';
      see = "down";
    }
    if (ch == 'a' && map1[x][y - 1] == '*')
    {
   
      map1[x][y] = '*';
      y--;
      map1[x][y] = '#';
      see = "left";
    }
    if (ch == 'd' && map1[x][y + 1] == '*')
    {
   
      map1[x][y] = '*';
      y++;
      map1[x][y] = '#';
      see = "right";
    }
    if (ch == 32)
    {
   
      if (see == "up" || see == "down")
      {
   
        for (int i = 0; i < x; i++)
          if (map1[i][y] == '$' || map1[i][y] == '&')
          {
   
            map1[i][y] = '*';
            diren--;
            break;
          }
      };
      if (see == "left" || see == "right")
      {
   
        for (int i = 0; i < y; i++)
          if (map1[x][i] == '$' || map1[x][i] == 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值