Напишите код на C++ про гру маріо

Ответы

Ответ дал: dimaayastremskuy4510
1

Ответ:

#include <iostream>

#include <string>

#include <cstdlib>

#include <ctime>

using namespace std;

const int ROW = 10;

const int COL = 10;

void drawMaze(char maze[][COL]) {

cout << "Welcome to Mario Game!" << endl;

for (int i = 0; i < ROW; i++) {

for (int j = 0; j < COL; j++) {

cout << maze[i][j];

}

cout << endl;

}

}

void initMaze(char maze[][COL]) {

for (int i = 0; i < ROW; i++) {

for (int j = 0; j < COL; j++) {

if (i == 0 || i == ROW - 1 || j == 0 || j == COL - 1) {

maze[i][j] = '#';

} else {

maze[i][j] = ' ';

}

}

}

srand(time(0));

int obstacleRow = rand() % (ROW - 2) + 1;

int obstacleCol = rand() % (COL - 2) + 1;

maze[obstacleRow][obstacleCol] = '*';

}

int main() {

char maze[ROW][COL];

int x = 1, y = 1;

char direction;

bool gameOver = false;

initMaze(maze);

maze[x][y] = 'M';

drawMaze(maze);

while (!gameOver) {

cout << "Enter direction (W - up, S - down, A - left, D - right): ";

cin >> direction;

switch (direction) {

case 'w':

case 'W':

if (maze[x - 1][y] == '#') {

cout << "Cannot move up, wall blocking the way." << endl;

} else if (maze[x - 1][y] == '*') {

cout << "You hit an obstacle and lost the game." << endl;

gameOver = true;

} else {

maze[x][y] = ' ';

x--;

maze[x][y] = 'M';

}

break;

case 's':

case 'S':

if (maze[x + 1][y] == '#') {

cout << "Cannot move down, wall blocking the way." << endl;

} else if (maze[x + 1][y] == '*') {

cout << "You hit an obstacle and lost the game." << endl;

gameOver = true;

} else {

maze[x][y] = ' ';

x++;

maze[x][y] = 'M';

}

break;

case 'a':

case 'A':

if (maze[x][y - 1] ==

Вас заинтересует