1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
#include <iostream>
#include <conio.h>
#include <windows.h>
#include"Mapa.h"
#define W 119
#define A 65
#define S 83
#define D 68
using namespace std;
int main()
{
int **Arreglo = new int*[10];
iniciaMapa(Laberinto, Arreglo);
for (size_t i = 0; i < 10; i++)
{
for (size_t j = 0; j < 10; j++)
{
if (Fog[i][j] == 3)
{
Arreglo[i][j] = 3;
}
}
}
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
if (Arreglo[i][j] == 3)
{
int mX = (i - 1) >= 0 ? 0 : 1;
int MX = (i + 1) <= 9 ? 2 : 1;
int mY = (j - 1) >= 0 ? 0 : 1;
int MY = (j + 1) <= 9 ? 2 : 1;
for (int k = mX; k < MX + 1; k++)
{
for (int m = mY; m < MY + 1; m++)
{
if (fog[k][m] == 0)
{
Arreglo[i + (k - 1)][j + (m - 1)] = 5;
}
}
}
}
}
}
int x = 1;
int y = 1;
printMap(Arreglo, 10, 10);
for (;; ) {
switch (_getch()) {
case W:
if (y >= 0 && y <= 10){
system("CLS");
y++;
Laberinto[x][y] = '*';
printMap(Arreglo, 10, 10);
}
/*case A:
if(){}
case S:
if(){}
case D:
if(){}*/
}
}
return 0;
}
//And this is my class Mapa.h
#pragma once
#include<iostream>
int Laberinto[10][10] = { { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 2, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } };
int Fog[10][10] = { { 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },
{ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },
{ 0 ,0 ,0 ,0 ,0 ,0 ,3 ,0 ,0 ,0 },
{ 0 ,0 ,0 ,3 ,0 ,0 ,0 ,0 ,0 ,0 },
{ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },
{ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },
{ 0 ,0 ,0 ,0 ,3 ,0 ,0 ,0 ,0 ,0 },
{ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },
{ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 },
{ 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0, 0 } };
int fog[3][3] = { { 0 ,0 ,0 },
{ 0 ,1 ,0 },
{ 0 ,0 ,0 } };
void iniciaMapa(int baseMapa[10][10], int **miMapa)
{
for (int fila = 0; fila < 10; fila++)
{
miMapa[fila] = new int[10];
for (int columna = 0; columna < 10; columna++)
{
miMapa[fila][columna] = baseMapa[fila][columna];
}
}
}
void printMap(int **map, int fila, int columna)
{
for (int fila = 0; fila < 10; fila++)
{
for (int columna = 0; columna < 10; columna++)
{
switch (map[fila][columna]) {
case 0:
std::cout << 'x';
break;
case 1:
std::cout << '|';
break;
case 2:
std::cout << '*';
break;
case 3:
std::cout << '$';
break;
case 4:
std::cout << '-';
break;
case 5:
std::cout << ' ';
break;
case 6:
std::cout << '_';
break;
case 7:
std::cout << '@';
break;
default:
std::cout << (int)map[fila][columna];
break;
}
}
std::cout << std::endl;
}
}
|