Introducci贸n a C++

1

Todo lo que aprender谩s sobre C++

2

驴Qu茅 es programar y por qu茅 aprender C++?

Conceptos Generales de C++

3

La Historia de C++ y sus diferencias con C

Preparando el entorno de trabajo

4

Instalando Codeblocks

5

Pasos para instalar en mac

6

Ejecutando nuestro primer programa

7

驴Qu茅 son las librer铆as STD? - Portada del Proyecto

Manejo de memoria

8

驴Qu茅 es la memoria y tipos de datos?

9

Alojando variables en memoria

10

驴C贸mo usar operadores?

11

驴Qu茅 son los apuntadores?

12

Reto: Escribir un programa que calcule 谩reas.

Entrada de datos y funciones

13

驴C贸mo introducir datos a nuestro programa?

14

驴C贸mo usar condicionales?

15

Usando condicionales

16

驴C贸mo encapsular c贸digo en funciones ?

17

驴Qu茅 son los par谩metros y como usarlos?

18

Reto: Juego narrativo implementando condicionales y entrada de datos.

Loops y arreglos

19

驴Qu茅 son los arreglos?

20

驴Qu茅 son los Loops?

21

Programando Loops

22

Loops , arreglos y arreglos bidimensionales

23

Dibujando el mapa de nuestro juego con arreglos

24

Manipulando mi jugador con inputs en arreglos unidimensionales

25

Arreglos bidimensionales

26

Reto: Moviendo a mi personaje en mi arreglo bidimensional

Lectura de Archivos

27

Creando y leyendo un archivo externo

28

Leyendo archivos externos

29

Reto: En el mapa, crear punto de inicio y salida del jugador

Programaci贸n Orientada a Objetos

30

驴Qu茅 es POO?

31

Definiendo una clase y creando sus instancias

32

Encapsulaci贸n

33

Abstracci贸n

34

Herencia

35

Propiedades de clase en herencia

36

Polimorfismo

Finalizando nuestro proyecto

37

Creaci贸n de personaje y archivo de encabezado

38

Moviendo mi personaje con entrada de datos

39

Mapa

40

Interacci贸n entre el personaje y el mapa

41

Paredes

42

Optimizando trazado de mapa

43

Colisiones

44

Creando nuestra portada de juego

45

Tesoro y victoria

46

Conclusiones

47

Proyecto final

No tienes acceso a esta clase

隆Contin煤a aprendiendo! 脷nete y comienza a potenciar tu carrera

Arreglos bidimensionales

25/47
Recursos

En esta clase debemos crear un mapa (un arreglo bidimensional) con todas las posibles posiciones de nuestro h茅roe. Esto significa que, adem谩s de nuestro ciclo for para imprimir cada posici贸n de nuestra columnas, debemos crear otro ciclo para imprimir las columnas (o al rev茅s).

Adem谩s, debemos verificar la posici贸n de nuestro h茅roe en ambas partes, filas y columnas. La forma m谩s r谩pida de hacerlo es creando dos nuevas variables, heroPosX y heroPosY, para validar sus posiciones en sus respectivos ciclos.

En reto de esta clase es programar la funcionalidad de que nuestro jugador pueda moverse por todo el mapa, incluyendo hacia arriba y abajo, no solo a la izquierda y a la derecha.

Puntos extra si puedes evitar que el jugador salga del mapa, es decir, que la posici贸n de nuestro h茅roe no pueda ser menor ni mayor que las posiciones de nuestro arreglo bidimensional.

C贸digo de la clase:

void DrawMap(int HeroPosX, int HeroPosY, char GameMap[5][5]) {
  for(int i = 0; i < 5; i++) {
     for(int p = 0; p < 5; p++) {
      if (i != HeroPosY)
      {
        cout << GameMap[p][i];
      }
      else
      {
        if (i != HeroPosY)
        {
          cout << GameMap[p][i];
        }
        else
        {
          cout << 'H';
        }
      }
    }

    // Necesitamos un salto de l铆nea para diferenciar
    // las filas de las columnas:
    cout << endl;
  }
}

int main()
{
  // ...

  int HeroPosX = 1;
  int HeroPosy = 1;
  char GameMap[5][5] =
  {
    {'1','1','1','1','1'},
    {'1','1','1','1','1'},
    {'1','1','1','1','1'},
    {'1','1','1','1','1'},
    {'1','1','1','1','1'},
  }

  // ...
}

Aportes 75

Preguntas 5

Ordenar por:

驴Quieres ver m谩s aportes, preguntas y respuestas de la comunidad?

o inicia sesi贸n.

Me gusta m谩s como se ve con Switch Case 馃槂

#include <iostream>
using namespace std;


void drawMap(int posX,int posY,char gameMap[5][5]){
  for(int i=0;i<5;i++){
    for(int j=0;j<5;j++){
      if(posX==j && posY==i){
        cout<<"H";
      }
      else{
	cout<<gameMap[i][j];
      }
    } 
    cout<<endl;
  }
}



int main(){

  int posX=0;
  int posY=0;
  char map[5][5]={{'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'}};
  char teclado;
  bool gameOver= false;

  drawMap(posX,posY,map);
  while(!gameOver){
  cin>>teclado;
  switch (teclado)
  {
  case 'a':
       posX-=1;
       break;
  case 'd':
	 posX+=1;
       break;
  case 'w':
         posY-=1;
       break;
  case 's':
         posY+=1;
       break;
  case 'p':
	 gameOver=true;
  default:
      break;
  }
  drawMap(posX,posY,map);
  }
 
 return 0;
}

Agregu茅 la librer铆a stdlib para usar la funci贸n de sistema "cls"y mantener el mapa en el mismo lugar

<
#include <iostream>
#include <stdlib.h> // Libreria para funcion de sistema cls
using namespace std;

void DrawMap(int HeroPosX,int HeroPosY,char GameMap[5][5]) {
     system("cls"); //llamada a funcion de sistema
    for(int i = 0;i < 5; i++) {
      for(int p = 0;p < 5; p++) {
       if(i != HeroPosX)
     {
         cout << GameMap[p][i];
     }
     else
     {
         if(p != HeroPosY)
         {
          cout << GameMap[p][i];
         }
         else
         {
         cout << 'H';
         }
      }
    }
    cout <<endl;
  }
}

int main()
{
    int HeroPosX =1;
    int HeroPosY =1;
    bool isGameOver = false;
    char Input = ' ';
    char GameMap[5][5] =
    {
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
    };


    DrawMap(HeroPosX, HeroPosY, GameMap);


    while(isGameOver == false)
    {
        cin >> Input;
        if(Input == 'd')
        {
          HeroPosY++;
        }
         else if(Input == 'a')
         {
             HeroPosY--;
         }
         if(Input == 'w')
        {
          HeroPosX++;
        }
         else if(Input == 's')
         {
             HeroPosX--;
         }
         else if(Input == 'p')
         {
             isGameOver = true;
         }
        DrawMap(HeroPosX,HeroPosY,GameMap);
        }

 return 0;
}
>

Cuando dijo lo del reto ya lo hab铆a hecho jaja. Espero que le sirva a alguien.

#include <iostream>
#include <conio.h>
using namespace std;
typedef unsigned int uint;

void drawMap(const int * pheroPosX, const int * pheroPosY, char pmap[5][5]);

bool mover(char pinput, int &pheroPosX, int &pheroPosY);

int main()
{
    bool isGamerOver = false;
    int* heroPosX = new int;
    *heroPosX = 1;
    int* heroPosY = new int;
    *heroPosY = 1;
    char input = ' ';
    char mapa[5][5] = {
            {'1', '1', '1', '1', '1'},
            {'1', '1', '1', '1', '1'},
            {'1', '1', '1', '1', '1'},
            {'1', '1', '1', '1', '1'},
            {'1', '1', '1', '1', '1'}
    };

    drawMap(heroPosX, heroPosY, mapa);

    while (!isGamerOver){
        cout << endl;
        cin >> input;
        isGamerOver = mover(input, *heroPosX, *heroPosY);
        drawMap(heroPosX, heroPosY, mapa);
    }



    delete heroPosX;

//    cout << endl << "\nPresione enter para terminar" << endl;
//    getch();
    return 0;
}

void drawMap(const int * pheroPosX, const int * pheroPosY, char pmap[5][5]){
    for(uint col = 0; col < 5; col++){
        for(uint row = 0; row < 5; row++){
            if(col != *pheroPosY){
                cout << pmap[row][col];
            }
            else {
                if(row != *pheroPosX){
                    cout << pmap[row][col];
                } else{
                    cout << 'H';
                }
            }
        }
        cout << endl;
    }
}

bool mover(char pinput, int &pheroPosX, int &pheroPosY){
    bool terminar = false;
    switch(pinput){
        case 'd':
            pheroPosX++;
            break;
        case 'a':
            pheroPosX--;
            break;
        case 'w':
            pheroPosY--;
            break;
        case 's':
            pheroPosY++;
            break;
        case 'p':
            terminar = true;
            break;
        default:
            terminar = true;
            break;
    }
    return terminar;
}

listo, limitado para que el heroe no salga del mapa y con funcion de finalizado:

#include <iostream>

using namespace std;

void DrawMap(int PlayerPosX, int PlayerPosY, char GameMap[5][5])
{
    for (int i = 0; i < 5; i++)
    {
        for(int p = 0; p < 5; p++)
        {
            if(i == PlayerPosX && p == PlayerPosY )
            {

                cout << 'H';
            }
            else
            {

                cout << GameMap[i][p];

            }


        }

        cout << endl;
    }

}

int main()
{
    int PlayerPosX = 0;
    int PlayerPosY = 0;
    char input;
    bool IsPlayerDead = false;
    char GameMap[5][5] =
    {
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'}
    };
 

    while(!IsPlayerDead)
    {
        if (PlayerPosX == 5)
        {
            PlayerPosX--;
        }
        else if(PlayerPosX == -1)
        {
            PlayerPosX++;
        }
        else if(PlayerPosY == 5)
        {
            PlayerPosY--;
        }
        else if(PlayerPosY == -1)
        {
            PlayerPosY++;
        }
        DrawMap(PlayerPosY, PlayerPosX, GameMap);
        cin >> input;

        if ( ( (PlayerPosX + 1) * (PlayerPosY + 1)) == 25 )
        {
            cout << "felicidades as completado el juego\n" << endl;
            IsPlayerDead = true;

        }
        if (input == 'd')
        {
            PlayerPosX++;
        }
        else if (input == 'a')
        {
            PlayerPosX--;
        }
        else if(input == 's')
        {
            PlayerPosY++;
        }
        else if(input == 'w')
        {
            PlayerPosY--;
        }
        else if (input == 'p')
        {
            IsPlayerDead = true;
        }
        else if(PlayerPosX == 5)
        {
            PlayerPosX = PlayerPosX - 2;

        }


    }




    return 0;
}```

Aporte: La respuesta al reto esta en la clase solamente hace falta prestar atencion y practicar

Mi soluci贸n del reto incluyendo las funcionalidades de moverse hacia arriba y abajo y no poder salirse del mapa: https://repl.it/repls/TrimIndelibleParticle

C贸digo:

#include <iostream>

char ask_move() {
  char lastMove;
  
  std::cout << "Up/Down/Left/Right (u/d/l/r): ";
  std::cin >> lastMove;

  return lastMove;
}

void draw_world(
  int lives, char map[3][3],
  int heroPosRow, int heroPosCol
) {
  std::cout << "\n";

  std::cout << "Vidas: " << lives << "\n";

  // MAPA BIDIMENSIONAL
  for (int row = 0; row < 3; row++) {
    // Salto de linea por cada row
    std::cout << "\n";

    for (int col = 0; col < 3; col++) {
      char rowColPos = map[row][col];

      if (heroPosRow == row && heroPosCol == col) {
        std::cout << "X";
      } else {
        std::cout << rowColPos;
      }
    }
  }

  std::cout << "\n\n";
}

int main() {
  std::cout << "Hello World!\n";

  char map[3][3] = {
    {'-', '-', '-'},
    {'o', '-', '-'},
    {'-', '-', 'o'},
  };
  int heroPosRow = 0;
  int heroPosCol = 0;
  char lastMove = ' ';
  int lives = 5;

  do {
    draw_world(
      lives, map,
      heroPosRow, heroPosCol
    );

    char move = ask_move();

    switch (move) {
      case 'u':
        if ((heroPosRow - 1) < 0) {
          std::cout << "\nNO TE PUEDES SALIR DEL MAPA\n";
          lives--;
        } else {
          heroPosRow--;
        }
      break;

      case 'd':
        if ((heroPosRow + 1) > 2) {
          std::cout << "\nNO TE PUEDES SALIR DEL MAPA\n";
          lives--;
        } else {
          heroPosRow++;
        }
      break;

      case 'l':
        if ((heroPosCol - 1) < 0) {
          std::cout << "\nNO TE PUEDES SALIR DEL MAPA\n";
          lives--;
        } else {
          heroPosCol--;
        }
      break;

      case 'r':
        if ((heroPosCol + 1) > 2) {
          std::cout << "\nNO TE PUEDES SALIR DEL MAPA\n";
          lives--;
        } else {
          heroPosCol++;
        }
      break;

      default: std::cout << "Vuelve a intentarlo.";
      break;
    }
  } while (lives > 0);

  std::cout << "\nGAME OVER!\n";
}

RETO CUMPLIDO 馃槃

#include <iostream>
#include <stdlib.h>

using namespace std;

//DIBUJAR MAPA
void DrawMap(int HeroPosX, int HeroPosY, char GameMap[5][5]){
    system("cls");
    for (int i = 0; i < 5; i++){
        for (int p = 0; p < 5; p++){
            if (i != HeroPosY){
                cout << GameMap[i][p];
                cout << ' ';
            } else {
                if (p != HeroPosX){
                    cout << GameMap[i][p];
                    cout << ' ';
                } else {
                    cout << 'H';
                    cout << ' ';
                }
            }
        }
        cout << endl;
    }
}

int main()
{
    //POSICIONES DEL HEROE
    int HeroPosX = 0;
    int HeroPosY = 0;

    char Input;
    bool isGameOver = false;

    char GameMap[5][5] =
    {
        {'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'}
    };

    DrawMap(HeroPosX, HeroPosY, GameMap);

    while (isGameOver == false){
        cin >> Input;

        if (Input == 'd'){
            HeroPosX++;
        } else if (Input == 'a'){
            HeroPosX--;
        } else if (Input == 'w'){
            HeroPosY--;
        } else if (Input == 's'){
            HeroPosY++;
        } else if (Input == 'p'){
            isGameOver = true;
        }

        DrawMap(HeroPosX, HeroPosY, GameMap);
    }



    return 0;
}

#include <iostream>

using namespace std;

void DrawMap(int HeroPosX, int HeroPosY, char GameMap[5][5]){

    for(int i = 0; i < 5 ; i++){
        for(int p = 0; p < 5 ; p++){
            if(p != HeroPosX){
                cout <<GameMap[p][i];
            }else{
                if(i != HeroPosY){
                    cout <<GameMap[p][i];
                }else{
                    cout <<'H';
                }
            }
        }
        cout <<endl;
    }
}
int main()
{
    int HeroPosX = 1;
    int HeroPosY = 1;
    bool isGameOver = false;
    char Input = ' ';

    char GameMap[5][5] = {
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'}
    };

    DrawMap(HeroPosX,HeroPosY,GameMap);
    while(isGameOver == false){
        cin>> Input;
        if(Input =='d'){
            HeroPosX = HeroPosX+1;
        }else if(Input == 'a'){
            HeroPosX = HeroPosX -1;
        }else if(Input == 'w'){
            HeroPosY = HeroPosY -1;
        }else if(Input == 's'){
            HeroPosY = HeroPosY +1;
        }else if(Input == 'p'){
            isGameOver = true;
        }

        DrawMap(HeroPosX,HeroPosY,GameMap);
    }
    return 0;
}

As铆 voy, me falta hacer que salga un error cuando se salga del l铆mite.

#include <conio.h>
#include <iostream>
using namespace std;

void mapa(char [][20], int, int, int);

int main() { 

	setlocale(LC_ALL,"");	
//Variables funcion mapa:	

	char map[20][20]={'_'};
//	int player_pos=1;
	int player_posX=1;
	int player_posY=1;
	int map_size = sizeof(map) / sizeof(map[0]);
//Variables movimiento de personaje	
	char input;	
	bool GameOver=false;	
	
	while(GameOver==false){	
	
	mapa(map, player_posX, player_posY, map_size);
	
	cout<<"\nHacia donde quiere mover a su personaje. 驴Derecha o Izquierda?\n";
	cout<<"S铆 es derecha escribir la letra 'D'\tS铆 es izquierda escribir la letra 'I'\t S铆 no quieres avanzar m谩s escribir letra 'P'\n\n";
	cout<<"Mover hacia la: ";cin>>input;
	switch(input){
		case 'W':
		case 'w':
			player_posY--;
			system("cls");
		break;
		case 'S':
		case 's':
			player_posY++;
			system("cls");
		break;
		case 'A':
		case 'a':
			player_posX--;
			system("cls");
		break;
		case 'D':
		case 'd':
			player_posX++;
			system("cls");
		break;
		case 'P':
		case 'p':
			GameOver=true;
		break;
		default:
			cout<<"\nDigit贸 incorrectamente.";
		break;	
	

  	
  	mapa(map, player_posX, player_posY, map_size);
  	
  	
  	}
}
	getch ();
    return 0;
}


//Elaboraci贸n del mapa:
void mapa(char map[][20], int player_posX, int player_posY, int map_size){
	
	
	for(int i=0;i<map_size;i++){
		for(int j=0;j<map_size;j++){
			if(i !=player_posY){
			cout<<map[0][0];
		}
		else{
			if(j !=player_posX){
				cout<<map[0][0];
			}
			else{
			cout<<"P";
		}
	
		}
	}
	cout<<endl;
}

//programa cuando el hero termina el camino , regresa
//al principio, no puede pasar del limite
#include <iostream>
using namespace std; //para evitar poner std::cout

void drawmap(int heroposx, int heroposy, char map[5][5]){

for(int i =0;i<5;i++){
for(int j=0;j<5;j++){
if(i != heroposy){
cout<< map[j][i] ;
}
else{ //si heroposx == i
if(j != heroposx){
cout<< map[j][i] ;
}
else {
cout<< 鈥楬鈥;}
}
}
cout<< endl;
}

} //fin drawmap

int main()
{ int heroposx=1;
int heroposy=1;
//char map[5] = {鈥1鈥,鈥1鈥,鈥1鈥,鈥1鈥,鈥1鈥檥;
char input = 鈥 ';
bool gameover = false;
char map[5][5] = {{鈥1鈥,鈥1鈥,鈥1鈥,鈥1鈥,鈥1鈥檥,
{鈥1鈥,鈥1鈥,鈥1鈥,鈥1鈥,鈥1鈥檥,
{鈥1鈥,鈥1鈥,鈥1鈥,鈥1鈥,鈥1鈥檥,
{鈥1鈥,鈥1鈥,鈥1鈥,鈥1鈥,鈥1鈥檥,
{鈥1鈥,鈥1鈥,鈥1鈥,鈥1鈥,鈥1鈥檥};

drawmap(heroposx,heroposy,map);

while(gameover ==false){

cin>> input;
if(input == 'd'){
    heroposx ++;
}else if(input=='a'){
    heroposx--;
} else if(input=='p'){
    gameover=true;
} else if(input=='w'){
    heroposy--;
} else if(input=='s'){
    heroposy++;
}



if ( heroposx ==5 ){
    heroposx=0;
    heroposy++;
} else if(heroposx ==-1){
    heroposx = 5;
    heroposy--;
} else if(heroposy ==5){
    heroposx=0;
    heroposy=0;
}  else if(heroposy ==-1){
    heroposx=0;
    heroposy=0;
}

if(heroposy ==5){
    heroposx=0;
    heroposy=0;
}  else if(heroposy ==-1){
    heroposx=0;
    heroposy=0;
}


drawmap(heroposx,heroposy,map);
}

return 0;
}

mi juego

// practica de c++.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
using namespace std;

void DrawMap(int posX,int posY) {

	char map[5][5] = {
	{ '1','1','1','1','1' },
	{ '1','1','1','1','1' },
	{ '1','1','1','1','1' },
	{ '1','1','1','1','1' },
	{ '1','1','1','1','1' }
	};
	for (size_t i = 0; i < 5; i++)
	{
		for (size_t O = 0; O < 5; O++)
		{
			if ((posY != i)||(posX != O)) {
				cout << map[O][i];
			}
			else {
				cout << "H";		
			}
			
		}
		cout << endl;
	
	}

}
int clamp(int num, int min, int max) {
	if (num <= min) {
		return min;
	}
	else if (num >= max){
		return max;
	}
	else {
		return num;
	}

	}

int main()
{
	char mover;
	int HeroPosX = 0;
	int HeroPosY = 0;
	bool isGameOver = false;
	DrawMap(HeroPosX, HeroPosY);


	while (!isGameOver) {
		cin >> mover;

		//mueve en el eje X
		if (mover == 'a') {
			HeroPosX--;
		}
		else if (mover == 'd') {
			HeroPosX++;
			//mueve en el eje Y
		}else if (mover == 's') {
			HeroPosY++;
		}
		else if (mover == 'w') {
			HeroPosY--;
		}
		else if (mover == 'p') {
			isGameOver = true;
		}

	    HeroPosX = clamp(HeroPosX, 0, 4);
		HeroPosY = clamp(HeroPosY, 0, 4);
		DrawMap(HeroPosX,HeroPosY);
			
	}
}




Soluci贸n al reto, con reinicio de la consola para mantener el mapa en su lugar, y con los limites del array para que nunca se salga la 鈥楬鈥 del mapa

#include <iostream>
#include <cstdlib>

using namespace std;

void DrawMap(int HeroPosX, int HeroPosY, char GameMap[5][5])
{
    system("cls");
    for (int i = 0; i < 5; i++)
    {
        for (int p = 0; p < 5; p++)
        {
            if (i != HeroPosY)
            {
                cout << GameMap[p][i];
            }
            else
            {
                if (p != HeroPosX)
                {
                    cout << GameMap[p][i];
                }
                else
                {
                    cout << 'H';
                }
            }
        }
        cout << endl;
    }
}

int main()
{
    int HeroPosX = 1;
    int HeroPosY = 1;
    bool isGameOver = false;
    char Input = ' ';
    char GameMap[5][5] =
        {
            {'1', '1', '1', '1', '1'},
            {'1', '1', '1', '1', '1'},
            {'1', '1', '1', '1', '1'},
            {'1', '1', '1', '1', '1'},
            {'1', '1', '1', '1', '1'}};
    int rows = sizeof(GameMap) / sizeof(GameMap[0]);
    int columns = sizeof(GameMap[0]) / sizeof(GameMap[0][0]);

    DrawMap(HeroPosX, HeroPosY, GameMap);

    while (isGameOver == false)
    {
        cin >> Input;

        if (Input == 'd')
        {
            HeroPosX++;
        }
        else if (Input == 'a')
        {
            HeroPosX--;
        }
        else if (Input == 'w')
        {
            HeroPosY--;
        }
        else if (Input == 's')
        {
            HeroPosY++;
        }
        else if (Input == 'p')
        {
            isGameOver = true;
        }

        if (HeroPosX > columns - 1)
        {
            HeroPosX = 0;
        }
        else if (HeroPosX < 0)
        {
            HeroPosX = columns - 1;
        }

        if (HeroPosY > rows - 1)
        {
            HeroPosY = 0;
        }
        else if (HeroPosY < 0)
        {
            HeroPosY = rows - 1;
        }
        DrawMap(HeroPosX, HeroPosY, GameMap);
    }

    return 0;
}

Reto completado , movimientos a la derecha, izquierda, arriba y abajo.

馃槃

#include<iostream>
#include<conio.h>

using namespace std;

void PaintMap(char vec[5][5], int,int); //firma o prototipo del procedimiento

int main(){

int		GameOver=1;
char	move='f'; // la f, no significa nada, solo es que no me deja dejar el campo vacio :0
char	map[5][5]={
					{'X','X','X','X','X'},
					{'X','X','X','X','X'},
					{'X','X','X','X','X'},
					{'X','X','X','X','X'},
					{'X','X','X','X','X'}
				   };
				   
int posPJX=0;
int posPJY=0;	



while(GameOver){ 
	
	
	PaintMap(map,posPJY,posPJX);
		cin>>move;
		
		if(move=='a')posPJX=posPJX-1;		
		if(move=='d') posPJX=posPJX+1;
		if(move=='s')posPJY=posPJY+1;
		if(move=='w')posPJY=posPJY-1;
		if(move=='p')GameOver=0;	
}

return 0;
}

//Estructura del procedimiento
void PaintMap(char map[5][5], int posi,int posj){  
	
		for(int i=0; i<5;i++){
			for(int j=0;j<5;j++){
			
				if((posi==i)&&(posj==j)){			
					cout<<"PJ"<<"  ";
				}else{
					cout<<map[i][j]<<"   ";
				}
			}
			cout<<endl;
		}
}
#include <iostream>

using namespace std;

void DrawMap( int HeroPosX, int HeroPosY, char GameMap [5][5])
{
    for (int i = 0; i < 5; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            if (i != HeroPosY)
            {
                cout << GameMap[j][i];
            }
            else
            {
                if (j != HeroPosX)
                {
                    cout << GameMap[j][i];
                }
                else
                {
                    cout << 'H';
                }
            }
        }
        cout << endl;
    }
}

int main()
{
    int HeroPosX = 2, HeroPosY = 1, anteriorY = 0, anteriorX = 0;
    bool isGameOver = false;
    char input = ' ';
    char GameMap [5][5] =
    {
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'}
    };

    DrawMap (HeroPosX, HeroPosY, GameMap);

    while (isGameOver == false)
    {

        cin >> input;

        if (input == 'd')
        {
            HeroPosX ++;
        }
        else if(input == 'a')
        {
            HeroPosX --;
        }
        else if (input == 'w')
        {
            HeroPosY --;
        }
        else if (input == 's')
        {
            HeroPosY ++;
        }
        else if (input == 'p')
        {
            isGameOver = true;
        }

        if (HeroPosX > 4 || HeroPosY > 4)
        {
            cout << "Comando fuera del limite" << endl;
            DrawMap (anteriorX, anteriorY, GameMap);
        }
        else
        {
            DrawMap (HeroPosX, HeroPosY, GameMap);
            anteriorX = HeroPosX;
            anteriorY = HeroPosY;
        }
    }
    return 0;
}
#include <iostream>

using namespace std;

void DrawMap(int HeroPosX, int HeroPosY, char GameMap[5][5]) {
  for(int i = 0; i < 5; i++)
    {
     for(int p = 0; p < 5; p++)
      {
      if (i != HeroPosY)
      {
        cout << GameMap[p][i];
      }
      else
      {
        if (p != HeroPosX)
        {
          cout << GameMap[p][i];
        }
        else
        {
          cout << 'H';
        }
      }
    }

    // Necesitamos un salto de l铆nea para diferenciar
    // las filas de las columnas:
    cout << endl;
  }

}

int main()
{

  char Input = ' ';
  bool isGameOver = false;
  int HeroPosX = 1;
  int HeroPosY = 1;

  char GameMap[5][5] =
  {
    {'1','1','1','1','1'},
    {'1','1','1','1','1'},
    {'1','1','1','1','1'},
    {'1','1','1','1','1'},
    {'1','1','1','1','1'},
  };

  DrawMap(HeroPosX,HeroPosY,GameMap);

  while(isGameOver == false)
    {
    cin>> Input;
    if (Input == 'd'){
      if(HeroPosX>=4){
        HeroPosX=4;
      }
    else{
      HeroPosX++;

      }
    }
    else if(Input =='a'){
      if(HeroPosX<=0){
      HeroPosX=0;}
      else{
      HeroPosX--;
      }
      }
    else if (Input == 'w'){
        if(HeroPosY<=0){
        HeroPosY=0;}
        else{
        HeroPosY--;
        }

      }
    else if (Input =='s'){
        if(HeroPosY>=4){
        HeroPosY=4;}
        else{
        HeroPosY++;
        }

        }
    else if (Input== 'p'){
        isGameOver = true;}
    DrawMap(HeroPosX,HeroPosY,GameMap);
    }

      return 0;
}

Codigo de reto

#include <iostream>

using namespace std;

void DrawMap(int HeroPosX, int HeroPosY, char GameMap[5][5])
{
    for(int i = 0; i < 5; i++)
    {
        for(int p = 0; p < 5; p++)
        {
            if(i != HeroPosY)
            {
                cout << GameMap[p][i];
            } else
            {
                if(p != HeroPosX)
                {
                    cout << GameMap[p][i];
                } else
                {
                    cout << 'H';
                }
            }
        }
        cout << endl;
    }
}

int main()
{
    int HeroPosX = 1;
    int HeroPosY = 1;
    bool IsGameOver = false;
    char Input = ' ';
    char GameMap[5][5] =
    {
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'}
    };


    DrawMap(HeroPosX, HeroPosY, GameMap);
    while(IsGameOver == false)
    {
        cin >> Input;
        switch (Input)
        {
            case 'a':
                HeroPosX -= 1;
                break;
            case 'd':
                HeroPosX += 1;
                break;
            case 'w':
                HeroPosY -= 1;
                break;
            case 's':
                HeroPosY += 1;
                break;
            case 'p':
                 IsGameOver = true;
                 break;
            default:
                  break;
        }
        DrawMap(HeroPosX, HeroPosY, GameMap);
    }


    return 0;
}
#include <iostream>

using namespace std;

void DrawMap(int HeroPosX, int HeroPosY, char GameMap[5][5])
{
    for(int i = 0; i < 5; i = i + 1)
    {
        for(int p = 0; p < 5; p++)
            if(i != HeroPosY)
            {
                cout << GameMap[p][i];
            }
            else
            {
                if(p != HeroPosX)
                {
                    cout << GameMap[p][i];
                }
                else
                {
                    cout<< 'H';
                }
            }
        cout << endl;
    }
}


int main()
{
    int HeroPosX = 1;
    int HeroPosY = 1;
    bool isGameOver = false;
    char Input = ' d';
    char GameMap[5][5] =
    {
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'}
    };




    DrawMap(HeroPosX, HeroPosY,GameMap);

    while(isGameOver == false)
    {
        cin >> Input;

        if(Input == 'd')
        {
            HeroPosX = HeroPosX + 1;
        }
        else if (Input == 'a')
        {
            HeroPosX = HeroPosX - 1;
        }
        else if (Input == 's')
        {
            HeroPosY = HeroPosY + 1;
        }
        else if (Input == 'w')
        {
            HeroPosY = HeroPosY - 1;
        }
        else if (Input == 'p')
        {
            isGameOver = true;
        }
        DrawMap(HeroPosX, HeroPosY, GameMap);
        }
    return 0;
}

Ya va quedando!

Haber que tal me va 馃槂

#include <iostream>

using namespace std;

void dibujaMapa(int heroPosX, int heroPosY, char mapa[5][5])
{
    for(int i = 0; i < 5; i++)
    {
     for(int p = 0; p < 5; p++)
     {
      if (i != heroPosY)
      {
        cout << mapa[p][i];
      }
      else
      {
        if (p != heroPosX)
        {
          cout << mapa[p][i];
        }
        else
        {
          cout << 'H';
        }
      }
     }
     cout << endl;
    }
}

int main() {

    bool gameOver = false;
    char mov = ' ';
    int heroPosX = 1;
    int heroPosY = 1;
    char cont = ' ';
    char mapa[5][5] =
    {
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'}
    };

    dibujaMapa(heroPosX, heroPosY, mapa);
    cout << "Elige movimiento (l, r, u, d, g): ";

    while(gameOver == false)
    {
        cin >> mov;
        if(mov == 'r' && heroPosX < 4)
        {
            heroPosX = heroPosX + 1;
        }
        else if(mov == 'l' && heroPosX > 0)
        {
            heroPosX = heroPosX - 1;
        }
        else if(mov == 'd' && heroPosY < 4)
        {
            heroPosY = heroPosY + 1;
        }
        else if(mov == 'u' && heroPosY > 0)
        {
            heroPosY = heroPosY - 1;
        }
        else if(mov == 'g')
        {
            gameOver = true;
            cout << "Game Over :(!";
            break;
        }
        else
        {
            cout << "Movimiento erroneo estas en el limite del mapa" << endl;
        }
        dibujaMapa(heroPosX, heroPosY, mapa);
    }
    return 0;
}
<#include <iostream>

using namespace std;

void DrawMap(int HeroPosX, int HeroPosY, char GameMap[5][5])
{
 for(int i = 0; i < 5; i++)
   {for (int p = 0; p < 5; p++)
        if (i != HeroPosY)
        cout << DrawMap[p][i];
        else
          if (p != HeroPosX)
          cout << DrawMap[p][i];
          else
            cout << 'H';
            cout << endl;
   }

}
int main()
{
    int HeroPosY = 1;
    int HeroPosX = 1;
    char Input = ' ';
    bool IsGameOver = false;
    char GameMap[5][5] =
    {
    {1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1},
    {1, 1, 1, 1, 1}
    };

    DrawMap(HeroPosX, HeroPosY, GameMap);

    while(IsGameOver == false)
    {
    cin >> Input;
    if(Input == 'd' && HeroPosX <=3)
        HeroPosX++;
    else if(Input == 'a' && HeroPosX >= 1)
        HeroPosX = HeroPosX - 1;
    else if(Input == 'w' && HeroPosY >= 1)
        HeroPosY = HeroPosY -1;
        else if(Input == 's' && HeroPosY<=3)
        HeroPosY++;
    else
        IsGameOver = true;
    DrawMap(HeroPosX, HeroPosY, GameMap);
    }
    return 0;
}
>

Todo esta ok, solo cambie a switch el detalle de ingreso de char鈥 y puse condicionales como limites

while(IsGameOver == false)
    {
        cin >> Input;

        switch(Input)
        {
            case 'd':
                if(HeroPosX != 4)
                {
                    HeroPosX++;
                } else {
                    HeroPosX;
                }
                break;
            case 'a':
                if(HeroPosX != 0)
                {
                    HeroPosX--;
                } else {
                    HeroPosX;
                }
                break;
            case 's':
                if(HeroPosY != 4)
                {
                    HeroPosY++;
                } else {
                    HeroPosY;
                }
                break;
            case 'w':
                if(HeroPosY != 0)
                {
                    HeroPosY--;
                } else {
                    HeroPosY;
                }
                break;
            default:
                IsGameOver = true;
                break;
        }

Aqui esta mi codigo!

#include <iostream>

using namespace std;

void printMap (int heroPosX, int heroPosY, char gameMap[5][5]) {

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

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

            if (i != heroPosX) {

                cout << gameMap[j][i];

            } else if (j != heroPosY) {

                cout << gameMap[j][i];

            } else {

                cout << 'H';

            } // fin if

        } // fin for j

        cout << endl;

    } // fin for i



} // funcion


int main()
{
    int heroPosX = 1;
    int heroPosY = 1;

    bool isGameOver = false;
    char Input = ' ';

    char GameMap[5][5] = {

        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'}

    };


    printMap(heroPosX, heroPosY, GameMap);

    while (isGameOver == false){

        cin >> Input;

        if (Input == 'd') {

            if (heroPosX != 4) {

                heroPosX++;

            }

        } else if (Input == 'a') {

            if (heroPosX != 0) {

                heroPosX--;

            }

        } else if (Input == 'p') {

            isGameOver = true;

        }

        printMap(heroPosX, heroPosY, GameMap);

        cout << "HeroPosX: " << heroPosX << endl;

    }

    return 0;
}
#include <iostream>

using namespace std;

void DrawMap(int HeroPosX, int HeroPosY, char GameMap[5][5])
{
    for (int i = 0; i < 5; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            if (i !=HeroPosY)
            {
                cout << GameMap[i][j];
            }else
            {
                if (j != HeroPosX)
                {
                    cout << GameMap[i][j];
                }else
                {
                    cout << 'H';
                }
                
            }
        }
        cout << endl;
    }
}



int main(int argc, char const *argv[])
{
    int HeroPosX = 2;
    int HeroPosY = 0;
    bool isGameOver = false;
    char input = ' ';
    char GameMap[5][5] = {
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'}
    };

    DrawMap(HeroPosX, HeroPosY, GameMap);

   

    while (isGameOver == false)
    {

        cin >> input;
        if (input == 'd')
        {
            HeroPosX++;
        }
        else if (input == 'a')
        {
            HeroPosX--;
        }
        else if (input == 'w')
        {
            HeroPosY--;
        }
        else if (input == 's')
        {
            HeroPosY++;
        }
        else
        {
            isGameOver = true;
        }
        
        DrawMap(HeroPosX, HeroPosY, GameMap);
    }
    

    cout << endl;
    return 0;
}

hice este codigo antes de ver el video, es un poco diferente, pero igual funciona

#include <iostream>
#include <windows.h>

using namespace std;

void drawMap(char gameZone[5][5],int x,int y){
	system("cls");
	for(int i = 0; i < 5; i++){
		for(int j = 0; j < 5; j++){
			if(y == i && x == j){
				gameZone[i][j] = 'h';
				cout << gameZone[i][j];
			}
			else{
				gameZone[i][j] = '.';
				cout << gameZone[i][j];
			}
		}
		cout << endl;
	}
}

int main()
{
	char gameZone[5][5];
	int x = 1,y = 1;
	bool isGameOver = false;
	char movement = ' ';
	
	while(!isGameOver)
	{
		cin >> movement;
		switch(movement){
			case 'a': 
				x--;
				drawMap(gameZone,x,y);
			break;
			case 'd': 
				x++;
				drawMap(gameZone,x,y);
			break;
			case 'w': 
				y--;
				drawMap(gameZone,x,y);
			break;
			case 's': 
				y++;
				drawMap(gameZone,x,y);
			break;
			case 'p': isGameOver = true;
			break;
			default: cout << "Opcion Invalida" << endl;
			break;
		}
	}
	
	return 0;
	
}```

Hecho! 馃槂

#include <iostream>

using namespace std;

void DrawMap(int, int, char map[5][5]);

int main()
{
    int heroPosX = 2;
    int heroPosY = 2;
    char Input;
    bool isGameOver = false;
    char map[5][5] =
    {
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'}
    };

    cout << endl << "Mueve el jugador a la derecha (d), izquierda (a), arriba (w) y abajo (s
    )" << endl;

    DrawMap(heroPosX, heroPosY, map);

    do
    {
        cin >> Input;
        if(Input == 'd')
        {
            heroPosX++;
        }else if(Input == 'a')
        {
            heroPosX--;
        }else if(Input == 'w')
        {
            heroPosY--;
        }else if(Input == 's')
        {
            heroPosY++;
        }
        else if(Input == 'e')
        {
            isGameOver = true;
        }

        DrawMap(heroPosX,  heroPosY, map);
    }while(isGameOver == false);


    return 0;
}

void DrawMap(int heroPosX, int heroPosY, char map[5][5])
{
    for(int i = 0; i < 5; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            if(j == heroPosX && i == heroPosY)
            {
                cout << 'H';
            }else
            {
                cout << map[j][i];
            }
        }
        cout << endl;
    }
    cout << endl;
}

Comparto mi c贸digo, decid铆 usar un switch para el input y cambiar un poco la funci贸n que dibuja el mapa.

#include <iostream>

using namespace std;

void drawMap(int heroPosX, int heroPosY, char gameMap[5][5] ) {
  for (int i = 0; i < 5; i++)
  {
    for(int j=0; j < 5; j++){
      if (i == heroPosY && j == heroPosX)
      {
        cout << 'H' << " ";
      }
      else
      {
        cout << gameMap[i][j] << " ";
      }
    }
    cout << endl;
  }
}

int main() {

  int heroPosX = 0;
  int heroPosY = 0;
  bool gameOver = false;
  char Inpt = ' ';
  char gameMap[5][5] = 
  {
      {'1', '1', '1', '1', '1'},
      {'1', '1', '1', '1', '1'},
      {'1', '1', '1', '1', '1'},
      {'1', '1', '1', '1', '1'},
      {'1', '1', '1', '1', '1'},
  };

  drawMap(heroPosX, heroPosY, gameMap);

  while(gameOver == false) {
    cout << endl;
    cin >> Inpt;


    switch (Inpt)
    {
    case 'd':
      heroPosX++;
      break;
    case 'a':
      heroPosX--;
      break;
    case 'w':
      heroPosY--;
      break;
    case 's':
      heroPosY++;
      break;
    case 'p':
      gameOver = true;
      break;
    default:
      gameOver = true;
      break;
    }

    drawMap(heroPosX, heroPosY, gameMap);
  }
  

  return 0;
}

Reto cumplido

#include <iostream>

using namespace std;

void DrawMap(int HeroPosX, int HeroPosY, char GameMap[5][5])
{
    for(int i = 0; i < 5; i++)
    {
        for(int j = 0; j < 5; j++)
        {
            if(i != HeroPosY)
            {
                cout << GameMap[i][j];
            }
            else if (j != HeroPosX)
            {
                cout << GameMap[i][j];
            }
            else
            {
                cout << 'H';
            }
        }
        cout << endl;
    }
}

int main()
{
    int HeroPosX = 1;
    int HeroPosY = 1;
    bool GameOver = false;
    char Input = ' ';
    char GameMap[5][5] =
    {
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'}
    };

    DrawMap(HeroPosX, HeroPosY, GameMap);

    while(GameOver == false)
    {
        cin >> Input;

        if(Input == 'd')
        {
            HeroPosX = HeroPosX + 1;
        }else if(Input == 'a')
        {
            HeroPosX = HeroPosX - 1;
        }else if(Input == 'w')
        {
            HeroPosY = HeroPosY - 1;
        }else if(Input == 's')
        {
            HeroPosY = HeroPosY + 1;
        }
        else if(Input == 'p')
        {
            GameOver = true;
        }
        DrawMap(HeroPosX, HeroPosY, GameMap);
    }

    return 0;
}

alguien sabe sobe grafos, arboles binarios etc.

#include<iostream>
using namespace std;
char Mapa[5][5]{
{鈥1鈥,鈥1鈥,鈥1鈥,鈥1鈥,鈥1鈥檥,
{鈥1鈥,鈥1鈥,鈥1鈥,鈥1鈥,鈥1鈥檥,
{鈥1鈥,鈥1鈥,鈥1鈥,鈥1鈥,鈥1鈥檥,
{鈥1鈥,鈥1鈥,鈥1鈥,鈥1鈥,鈥1鈥檥,
{鈥1鈥,鈥1鈥,鈥1鈥,鈥1鈥,鈥1鈥檥,
};
void generarMostrar(int *HeroeX,int *HeroeY ,char **mapa) {

for (int i = 0; i < 5; i++) {
	for (int j = 0; j < 5; j++) {
		mapa[i][j] = Mapa[i][j];
	}

}

for (int i = 0; i < 5; i++) {
	for (int j = 0; j < 5; j++) {
		if (i != (*HeroeY)) {
			cout << mapa[i][j];
		}
		else {
			if (j != (*HeroeX))
				cout << mapa[i][j];
			else {
				cout << "*";
			}
		}		
	}
	cout << endl;
}

}
void MoverPersonaje() {
char *mapa = new char[5];
for (int i = 0; i < 5; i++) {
mapa[i] = new char[5];
}
int *HeroeX = new int;
int *HeroeY = new int;
*HeroeY = 3;
*HeroeX = 3;
char *input = new char;
generarMostrar(HeroeX, HeroeY, mapa);
do {
cin >> *input;
if (*input == 鈥楢鈥)
(*HeroeX) -= 1;
else {
if (*input == 鈥楧鈥)
(*HeroeX) += 1;
else {
if (*input == 鈥榃鈥)
(*HeroeY) -= 1;

			else {
				if (*input == 'S')
					(*HeroeY) += 1;
			}
		}

	}
	generarMostrar(HeroeX, HeroeY, mapa);
} while (*input = 'P');

}
int main() {
MoverPersonaje();
system(鈥減ause鈥);
return(0);
}

#include <iostream>
#include <stdlib.h>

using namespace std;

void DrawMap(int HeroPos[2], char map[5][5])
{
    for(int i = 0; i < 5; i++)
    {
        for(int j = 0; j < 5; j++)
        {
            if(i == HeroPos[0] & j == HeroPos[1])
            {
                cout << 'H';
            }
            else
            {
                cout << map[i][j];
            }
        }
        cout << "\n";
    }
}

int main()
{
    int HeroPos[2] = {2, 2};
    char input = ' ';
    char map[5][5] = 
    {
    {'_', '_', '_', '_', '_'},
    {'_', '_', '_', '_', '_'},
    {'_', '_', '_', '_', '_'},
    {'_', '_', '_', '_', '_'},
    {'_', '_', '_', '_', '_'}
    };
    bool IsGameOver = false;

    while(!IsGameOver)
    {
        DrawMap(HeroPos, map);
        cout << "\n";
        cin >> input;

        if(input == 'd'  )
        {
            if(HeroPos[1] < 4)
            {
                HeroPos[1]++;
            }
        }
        else if(input == 'a')
        {
            if(HeroPos[1] > 0)
            {
                HeroPos[1]--;
            }
        }
        else if(input == 'w')
        {
            if(HeroPos[0] > 0)
            {
                HeroPos[0]--;
            }
        }
        else if(input == 's')
        {
            if(HeroPos[0] < 4)
            {
                HeroPos[0]++;
            }
        }
        else
        {
            IsGameOver = true;
        }
        system("cls");
    }

    return 0;
}```
#include <iostream>

using namespace std;
//Funcion para dibujar el mapa
void drawMap(int hero_posx, int hero_posy, char game_map[5][5])
{
     for (int i = 0; i < 5; i++)
    {
        for (int c = 0; c < 5; c++)
        {
            if (i != hero_posy)
            {
                cout << game_map[c][i];
            }else
            {
                if(c != hero_posx)
                {
                    cout << game_map[c][i];
                }else
                {
                    cout << 'H';
                }
                
                
            }
        }
        cout <<endl;
    }
}

int main()
{
    //variables
    int hero_posx = 1;
    int hero_posy = 1;
    bool game_over = false;
    char input;
    char game_map[5][5] = 
    {
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'}
    };
    drawMap(hero_posx, hero_posy, game_map);
    //controles para movimiento
    while (!game_over)
    {
        cin >> input;
        if (input == 'd')
        {
            hero_posx++;
        }else if (input == 'a')
        {
            hero_posx = hero_posx -1;
        }else if(input == 'w')
        {
           hero_posy = hero_posy - 1; 
        }else if(input == 's')
        {
            hero_posy++;
        }else if (input == 'p')
        {
            game_over = true;
        }
        
        drawMap(hero_posx, hero_posy, game_map);
    }
    
    

   return 0;
}```
#include <iostream>

using namespace std;

void DrawMap (int HeroPosX, int HeroPosY, char GameMap [5][5]){
    for (int i=0; i< 5; i++){
            for (int j = 0; j<5; j++){
                if (i !=HeroPosY)
                {
                    cout << GameMap[i][j];
                }else
                {
                    if (j !=HeroPosX)
                    {
                        cout << GameMap[i][j];
                    }
                    else
                    {
                        cout << 'H';
                    }
                }
            }
            cout << endl;
    }
}

int main()
{
    int HeroPosX= 1;
    int HeroPosY=1;
    char Input = ' ';
    bool isGameOver = false;
    char GameMap [5][5] =
    {
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'}

    };
        DrawMap(HeroPosX,HeroPosY, GameMap);

        while (!isGameOver)
        {
            cin >> Input;

            if (Input == 'd')
            {
                HeroPosX = HeroPosX + 1;
            }
            else if (Input == 'a')
            {
                HeroPosX = HeroPosX - 1;
            }
            else if (Input == 'w')
            {
                HeroPosY = HeroPosY - 1;
            }
            else if (Input == 's')
            {
                HeroPosY = HeroPosY + 1;
            }
            else if (Input == 'p')
            {
                isGameOver = true;
            }
            DrawMap(HeroPosX, HeroPosY, GameMap);
        }
    return 0;
}```
#include <iostream>


using namespace std;


void DrawMap(int HeroPosY,int HeroPosX,char GameMap[5][5])
{
    for (int i = 0;  i < 5; i++) //0
    {

        for (int p = 0; p < 5; p++) // 0
        {
            if ( i != HeroPosY)
            {
                cout << GameMap[i][p];
            }
            else
            {
                if (p != HeroPosX)
                {
                    cout << GameMap[i][p];
                }
                else
                {
                    cout << 'H';
                }

            }


        }
        cout << endl;
    }

};





int main()
{

    //HeroPos

    int HeroPosY =0;
    int HeroPosX =0;
    char GameMap[5][5] =
    {
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
    };

    char Input = ' ';
    bool IsGameOver = false;
    DrawMap(HeroPosY,HeroPosX,GameMap);

    while (IsGameOver == false)

    {
        cin >> Input;
        if (Input == 'w')
        {
            HeroPosY = HeroPosY-1;
        }
        else if (Input == 's')
        {
            HeroPosY = HeroPosY +1;

        }
        else if (Input == 'd')
        {
            HeroPosX = HeroPosX +1;

        }
        else if (Input == 'a')
        {
            HeroPosX = HeroPosX -1;

        }
        else if (Input == 'p')
        {

            IsGameOver = true;
        }

        DrawMap(HeroPosY,HeroPosX,GameMap);



    }

    return 0;
}

Ejercicio realizado, trate de limitar el recorrido para que no se salga el jugador

#include <iostream>

using namespace std;

void DrawMap(int HeroPosX, int HeroPosY, char GameMap[5][5])
{
    for(int i=0; i<5; i++)
    {
        for(int j=0; j<5; j++)
        {
            if(i != HeroPosY )
            {
                cout<<GameMap[j][i];
            }
            else
            {
                if(j != HeroPosX)
                {
                    cout<<GameMap[j][i];
                }
                else
                {
                    cout<<'H';
                    cout<<GameMap[j][i];
                }
            }
        }

        if(HeroPosX <=0 )
        {
            HeroPosX = 0;
        }
        else if(HeroPosX >=5)
        {
            HeroPosX =4;
        }
        else if(HeroPosY <=0)
        {
            HeroPosY = 0;
        }
        else if(HeroPosY >=5)
        {
            HeroPosY =4;
        }


        //Nesecitamos un salto de linea para diferenciar las filas de las columnas
        cout<<endl;
    }
    cout<<"Posicion X = "<<HeroPosX <<endl;
    cout<<"Posicion Y = "<<HeroPosY <<endl;
}


int main()
{
    int HeroPosX =1;
    int HeroPosY = 1;
    char Input = 'x';
    bool isGameOver = false;
    char GameMap[5][5] =
    {
        {'-', '-', '-', '-', '-'},
        {'-', '-', '-', '-', '-'},
        {'-', '-', '-', '-', '-'},
        {'-', '-', '-', '-', '-'},
        {'-', '-', '-', '-', '-'}

    };

    DrawMap(HeroPosX, HeroPosY, GameMap);

    while(isGameOver == false)
    {
        cin>> Input;



        if(Input == 'd')
        {
            HeroPosX = HeroPosX+1;
        }
        else if(Input == 'a')
        {
            HeroPosX = HeroPosX-1;
        }
        else if(Input == 'w')
        {
            HeroPosY = HeroPosY-1;
        }
        else if(Input == 's')
        {
            HeroPosY = HeroPosY+1;
        }
        else if(Input == 'p')
        {
            isGameOver = true;
        }



        DrawMap(HeroPosX, HeroPosY, GameMap);

    }

    return 0;
}```

Lo que llevo de momento

#include <iostream>
#include <string>
using namespace std;

void drawMap (int playerPosX, int playerPosY, char gameMap[10][10]) {

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

		for (int f = 0; f < 10; f++){

			if (i != playerPosY) {

				cout << gameMap[f][i];
			}
			else if (f != playerPosX) {

					cout << gameMap[f][i];
			}
			else {
				cout << 'M';
			}
		}
		cout << endl;
	}
}

int main() {	
	char input = ' ';
	bool isGameOver = false;
	int playerPosX = 0;
	int playerPosY = 0;
	char gameMap[10][10] = {
		{ '|','|','|','|','|','|','|','|','|','|'},
		{ '|','|','|','|','|','|','|','|','|','|'},
		{ '|','|','|','|','|','|','|','|','|','|'},
		{ '|','|','|','|','|','|','|','|','|','|'},
		{ '|','|','|','|','|','|','|','|','|','|'},
		{ '|','|','|','|','|','|','|','|','|','|'},
		{ '|','|','|','|','|','|','|','|','|','|'},
		{ '|','|','|','|','|','|','|','|','|','|'},
		{ '|','|','|','|','|','|','|','|','|','|'},
		{ '|','|','|','|','|','|','|','|','|','|'},
	};

	while (isGameOver == false) {

		drawMap(playerPosX, playerPosY, gameMap);

		cin >> input;

		if (input == 'd') {
			playerPosX = playerPosX + 1;
		}
		else if (input == 'a') {
			playerPosX = playerPosX - 1;
		}
		else if (input == 's') {
			playerPosY = playerPosY + 1;
		}
		else if (input == 'w') {
			playerPosY = playerPosY - 1;
		}
		else if (input == 'q') {
			isGameOver = true;
		}
	}
	return 0;
}

Reto superado

#include <iostream>

using namespace std;

void drawmap(int hposx, int hposy, char gmap [5][5])
{
    //system(cls); junto a libreria stdlib
    for(int i = 0; i < 5; i++)
    {
        for(int j = 0; j < 5; j++)
        {
            if (i != hposy)
            {
                    cout << gmap[i][j];
            }
            else
            {
                if (j!= hposx)
                {
                    cout << gmap[i][j];
                }
                else
                {
                    cout << 'H';
                }
            }
        }
        cout<<endl;
    }
}
int main()
{
    int hposx = 1, hposy = 1;
    char input = ' ';
    bool gameover = false;
    char gmap[5][5] =
    {
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'}
    };

    drawmap(hposx, hposy, gmap);

    while(gameover == false)
    {
        cin >> input;

        if ((input == 'a') || (input == 'd') || (input == 'w') || (input == 's'))
        {
            if(input == 'd')
            {
                hposx ++;
            }
            else if(input == 'a')
            {
                hposx --;
            }
            else if(input == 'w')
            {
                hposy --;
            }
            else if(input == 's')
            {
                hposy ++;
            }
            else if (input == 'p')
            {
                gameover = true;
            }
        }
        else
        {
           cout << "Direccion incorrecta" << endl;
        }

        if(hposx < 0 || hposx > 4 || hposy < 0 || hposy > 4)
        {
            if(hposx < 0)
            {
                hposx = 0;
            }
            else if(hposx > 4)
            {
                hposx = 4;
            }
            else if(hposy < 0)
            {
                hposy = 0;
            }
            else if(hposy > 4)
            {
                hposy = 4;
            }
        }
        drawmap(hposx, hposy, gmap);
    }

    return 0;
}

隆Punto Extra!
Logr茅 que mi programa impidiera que el h茅roe se saliera del mapa 馃槃

HECHO 馃槂

#include <iostream>
using namespace std;
/*HeroPosX y HeroPosY no existen dentro de la funcion drawmap
por lo tanto se tiene que pasar como parametro al igual que map
*/
void drawmap(int HeroPosX, int HeroPosY, char map[5][5])
{
  for(int i = 0; i < 5; i++)
    { for (int p = 0; p < 5; p++)
        {if(i != HeroPosY)
        {
         cout<<map[p][i];
        }
            else
           {
            if(p != HeroPosX)
            {cout<<map[p][i];}

            else{cout<<'H';}
            }
        }cout<<endl;
    }
}
int main()
{
    char HeroPosX = 1;
    char HeroPosY = 1;
    char Input = ' ';
    bool GameOver= false;
    char map[5][5]=
    {
      {'1','1','1','1','1'},
      {'1','1','1','1','1'},
      {'1','1','1','1','1'},
      {'1','1','1','1','1'},
      {'1','1','1','1','1'}
    };


    drawmap(HeroPosX,HeroPosY,map);
/*mientras no sea GameOver el juego sigue,
en caso de ingresar la letra p, el juego termina
*/
while(GameOver==false)
    {
       cin>>Input;

    if(Input=='d')
    {HeroPosX=HeroPosX+ 1;}

    else if(Input=='a')
    {HeroPosX=HeroPosX - 1;}

    else if(Input=='p')
    {GameOver=true;}

    drawmap(HeroPosX,HeroPosY,map);
  }
    return 0;
}

logrado!!!

#include<iostream>

using namespace std;


void Game (char Map[5][5],int HeroPosX, int HeroPosY)
{
    for(int columna=0; columna<5; columna++)
    {
        cout<<" "<<endl;

        for (int fila =0; fila<5; fila ++)
        {
            if (columna!=HeroPosY)
            {
                cout<<Map[columna][fila];
            }
            else
            {
                if(fila!=HeroPosX)
                {
                    cout<<Map[columna][fila];
                }
                else
                {
                    cout<<'H';
                }
            }
        }
    }
}


int main()
{

    char Map [5][5]= {
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'}
    };
    char Input= ' ';
    int HeroPosX=1,HeroPosY=3;
    bool GameOver=false;

    Game(Map,HeroPosX,HeroPosY);
while(GameOver==false){


    cin>>Input;
    if (Input=='a')
    {
        HeroPosX=HeroPosX-1;

    }
    else if(Input=='d')
    {
        HeroPosX=HeroPosX+1;

    }
    else if(Input=='w')
    {
        HeroPosY=HeroPosY-1;

    }
    else if(Input=='s')
    {
        HeroPosY=HeroPosY+1;

    }
    else if (Input=='p')
    {
        GameOver=true;
    }

    Game(Map,HeroPosX, HeroPosY);

}

    return 0;

}
#include <iostream>
#include <array>

using namespace std;

// Recorriendo un arreglo y dibujandolo
void drawMap(char gameMap[][5], int mapSize, int x, int y) {

    for ( int i = 0; i < mapSize; i++ ) {
        cout << endl;
        for ( int j = 0; j < mapSize; j++ ) {
            if ( ( i == y ) && ( x == j ) ){
                cout << 'H';
            }
            else {
                cout << gameMap[i][j];
            }

        }
    }
}


// Rellenando un arreglo
void fillMap( char gameMap[][5], int mapSize ) {
    const char EMPTY = '1'; // constante de lugar vacio

    // Recorriendo el arreglo y rellenando dependiendo si es
    // Lugar   vacio, o el jugador
    for ( int i = 0; i < mapSize; i++ ) {
        for ( int j = 0; j < mapSize; j++ ) {
            gameMap[i][j] = EMPTY;
        }
    }
}

int main() {
    // Constant
    const int mapSize = 5;

    // Variables
    char gameMap[mapSize][mapSize];
    int heroPosX = 1;
    int heroPosY = 1;
    bool keepPlaying = true;

    char input = ' ';

    while ( keepPlaying ) {
        // Volviendo a rellenar y a dibujar
        fillMap( gameMap, mapSize );
        drawMap( gameMap, mapSize, heroPosX, heroPosY );

        // Tomando input del usuario
        cin >> input;

        // Cambiando la posicion del jugador dependiendo del input
        if ( input == 'd' ) {
            heroPosX++;
        }
        else if ( input == 'a' ) {
            heroPosX--;
        }
        else if ( input == 'p' ) {
            keepPlaying = false;
        }
    }

    return 0;
}

#include <iostream>

using namespace std;
void DraMap (int HeroPostH, int HeroPostV, char GameMaps[5][5])
{
    for (int i = 0; i <5; i++)
    {
        for (int f = 0; f < 5; f++)
        {
            if (i != HeroPostV || f != HeroPostH)
            {
                cout << GameMaps[i][f];
            }
            else
            {
                cout << 'H';
            }

        }
       cout << endl;

    }
}

int main()
{   int HeroPostH = 0;
    int HeroPostV = 0;
    char Imput = 0;
    bool IsGameOver = false;
    char GameMaps[5][5] =
    {
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'}
    };



    do
    {
        DraMap(HeroPostH,HeroPostV,GameMaps);
        cout <<endl;
        cin >> Imput;


        switch (Imput)

        {
            case 'd' : HeroPostH = HeroPostH + 1;
                break;

            case 'a' : HeroPostH = HeroPostH - 1;
                break;

            case 'w' : HeroPostV = HeroPostV - 1;
                break;

            case 's' : HeroPostV = HeroPostV + 1;
                break;

            case 'p' : IsGameOver = true;
            break;

        }


        



    } while (IsGameOver == false);




    return 0;
}```
#include<iostream>

using namespace std;


void Game (char Map[5][5],int HeroPosX, int HeroPosY)
{
    for(int columna=0; columna<5; columna++)
    {
        cout<<" "<<endl;

        for (int fila =0; fila<5; fila ++)
        {
            if (columna!=HeroPosY)
            {
                cout<<Map[columna][fila];
            }
            else
            {
                if(fila!=HeroPosX)
                {
                    cout<<Map[columna][fila];
                }
                else
                {
                    cout<<'H';
                }
            }
        }
    }
}


int main()
{

    char Map [5][5]= {
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'}
    };
    char Input= ' ';
    int HeroPosX=1,HeroPosY=3;
    bool GameOver=false;

    Game(Map,HeroPosX,HeroPosY);
while(GameOver==false){


    cin>>Input;
    if (Input=='a')
    {
        HeroPosX=HeroPosX-1;

    }
    elseif(Input=='d')
    {
        HeroPosX=HeroPosX+1;

    }
    elseif(Input=='w')
    {
        HeroPosY=HeroPosY-1;

    }
    elseif(Input=='s')
    {
        HeroPosY=HeroPosY+1;

    }
    elseif (Input=='p')
    {
        GameOver=true;
    }

    Game(Map,HeroPosX, HeroPosY);

}

    return0;

}```
#include <iostream>
using namespace std;
void DibujarMapa(int PosX,int PosY,char Mapa[5][5]){
    for(int x=0;x<5;x++){
        for(int y=0;y<5;y++){
            if(x!=PosY || y!=PosX){
                cout<<Mapa[x][y];
            }else{
                cout<<'*';
            }
        }
        cout<<endl;
    }
}
int main(){
    bool IsGameOver=false;
    int CharPosX=2;
    int CharPosY=0;
    char Input=' ';
    char map[5][5]={
        {'a','1','2','3','4'},
        {'b','1','2','3','4'},
        {'c','1','2','3','4'},
        {'d','1','2','3','4'},
        {'e','1','2','3','4'}
        };

    cout<<"n para salir"<<endl;

    while(IsGameOver==false){
        DibujarMapa(CharPosX,CharPosY,map);
        cin>>Input;

        if(Input=='d'){
            if(CharPosX==4){
                cout<<"no se puede ir mas hacia la derecha"<<endl;
            }else{
                CharPosX=CharPosX+1;
            }
        }
        if(Input=='a'){
            if(CharPosX==0){
                cout<<"no se puede ir mas hacia la izquierda"<<endl;
            }else{
                CharPosX=CharPosX-1;
            }
        }
        if(Input=='w'){
            if(CharPosY==0){
                cout<<"no se puede avanzar mas"<<endl;
            }else{
                CharPosY=CharPosY-1;
            }
        }
        if(Input=='s'){
            if(CharPosY==4){
                cout<<"no se puede retroceder mas"<<endl;
            }else{
                CharPosY=CharPosY+1;
            }
        }
        if(Input=='n'){
            IsGameOver=true;
            cout<<"Juego terminado"<<endl;
        }
    }
    return 0;
}


esta muy bueno 馃槈

Me perd铆 tanto en el c贸digo que tuve que rehacerlo a uno un poco m谩s simple XD Pienso que quedar铆a m谩s bonito y ordenado as铆:

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

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

               if (HeroPosX == i && HeroPosY == j) {
               cout << 'H';

               } else {

               cout << GameMap[j][i];

               }

            }
        cout<<endl;
    }

}```



#include <iostream>

using namespace std;

void DrawMap(int HeroPosX, int HeroPosY, char GameMap[5][5])
{
    for(int i = 0; i < 5; i++)
    {
        for(int j = 0; j < 5; j++)
        {
            if(i != HeroPosY)
            {
                cout << GameMap[j][i];
            }
            else if(j != HeroPosX)
            {
                cout << GameMap[j][i];
            }
            else if(j != HeroPosX)
            {
                cout << GameMap[j][i];
            }
            else if(i != HeroPosY)
            {
                cout << GameMap[j][i];
            }
            else
            {
                cout << 'H';
            }
        }
        cout << endl;
    }
}

int main()
{
    int HeroPosX = 0;
    int HeroPosY = 0;
    char Input = ' ';
    bool isGameOver = false;
    char GameMap[5][5] =
    {
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'}
    };

    DrawMap(HeroPosX, HeroPosY, GameMap);
    while(isGameOver == false)
    {
        cin >> Input;

        if(Input == 'd')
        {
            HeroPosX++;
        }
        else if(Input == 'a')
        {
            HeroPosX--;
        }
        else if(Input == 'w')
        {
            HeroPosY--;
        }
        else if(Input == 's')
        {
            HeroPosY++;
        }
        else if(Input == 'p')
        {
            isGameOver = true;
        }
        DrawMap(HeroPosX, HeroPosY, GameMap);
    }

    return 0;
}
#include <iostream>

using namespace std;

void DrawMap(int HeroPosX, int HeroPosY, char GameMap[5][5])
{
    for(int fila = 0; fila < 5; fila++)
    {
        for(int columna = 0; columna<5; columna++)
        {
            if(fila != HeroPosY)
            {
            cout << GameMap[columna][fila] << " ,";
            }else
            {
                if(columna != HeroPosX)
            {
                cout << GameMap[columna][fila] << " ,";
            }else
            {
                cout << "HeroIsHere" << " ,";
            }
            }
        }
        cout << endl;
    }
}

int main()
{
    int HeroPosX = 1;
    int HeroPosY = 1;
    bool isGameOver = false;
    char Input = ' ';
    char GameMap[5][5] =
    {
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'}
    };

    DrawMap(HeroPosX, HeroPosY, GameMap);

    while(isGameOver == false)
    {
          cin >> Input;

    if(Input == 'd')
    {
        HeroPosX += 1;
    }else if(Input == 'a')
    {
        HeroPosX -= 1;
    }else if(Input == 'w')
    {
        HeroPosY -= 1;
    }else if(Input == 'z')
    {
        HeroPosY += 1;
    }else if(Input == 'p')
    {
        isGameOver = true;
    }

    DrawMap(HeroPosX, HeroPosY, GameMap);
    }

    return 0;
}```

Atascado en estas clases 鈥 nivel Dios!

No es mucho codigo pero es codigo propio.

if (HeroPosX == 4)
{
HeroPosX = HeroPosX - 1;
}else if (HeroPosX == HeroPosX -1)
{
HeroPosX = HeroPosX + 1;
}else if (HeroPosY == 6)
{
HeroPosY = HeroPosY - 1;

    }else if (HeroPosY == 0)
    {

        HeroPosY = HeroPosY + 1;
    }else

#include <iostream>

using namespace std;

void DrawMap(int HeroPosX, int HeroPosY, char GameMap[5][5])
{
for (int i = 0; i<5;i++)
{
for (int p = 0; p<5;p++)
{
if(i !=HeroPosY)
{
cout << GameMap[p][i];
}else
{
if(p !=HeroPosX)
{
cout << GameMap[p][i];
}else
{
cout << 鈥楬鈥;
}
}
}
cout << endl;

}

}

int main()
{
int HeroPosX =0;
int HeroPosY =0;
bool isGameOver = false;
char Input = 鈥 ';

char GameMap[5][5] =
{
    {'1','1','1','1','1'},
    {'1','1','1','1','1'},
    {'1','1','1','1','1'},
    {'1','1','1','1','1'},
    {'1','1','1','1','1'}
};


DrawMap(HeroPosX, HeroPosY,GameMap);
while (isGameOver == false)
{
    cin >> Input;

    if(Input =='d')
    {
        HeroPosX = HeroPosX + 1;
    }else if( Input == 'a')
    {
        HeroPosX = HeroPosX -1;
    }

    if(Input =='s')
    {
        HeroPosY = HeroPosY + 1;
    }else if( Input == 'w')
    {
        HeroPosY = HeroPosY -1;
    }

    if(Input =='p')
    {
        isGameOver = true;
    }
    DrawMap(HeroPosX, HeroPosY,GameMap);

}


return 0;

}

#include <iostream>

using namespace std;

void dibujaMapa(int posHeroeX, int posHeroeY, char mapa[5][5]){
  for(int i = 0; i < 5; i++){ // Columnas
    for(int j = 0; j < 5; j++){ // Filas
      if(j != posHeroeX){
        cout << mapa[j][i];
      }else{
        if(i != posHeroeY){
          cout << mapa[j][i];
        }else{
        cout << 'H';
        }
      }
    }
    cout << endl;
  }
}

int main(){

  int posHeroeX = 0;
  int posHeroeY = 0;
  bool juegoTerminado = false;
  char entrada = ' ';
  char mapa[5][5] =
  {
    { '_', '_', '_', '_', '_' },
    { '_', '_', '_', '_', '_' },
    { '_', '_', '_', '_', '_' },
    { '_', '_', '_', '_', '_' },
    { '_', '_', '_', '_', '_' }
  };

  dibujaMapa(posHeroeX, posHeroeY, mapa);
  while(juegoTerminado == false){
    cin >> entrada;

    if(entrada == 'd'){
      posHeroeX = posHeroeX + 1;
    }else if(entrada == 'a'){
      posHeroeX = posHeroeX - 1;
    }else if(entrada == 's'){
      posHeroeY = posHeroeY + 1;
    }else if(entrada == 'w'){
      posHeroeY = posHeroeY - 1;
    }else if(entrada == 'p'){
      juegoTerminado = true;
    }
    dibujaMapa(posHeroeX, posHeroeY, mapa);
  }

  return 0;
}
#include <iostream>

using namespace std;


void drawMap(char map[6][7], int herokaY, int herokaX)
{
    for(int y = 0; y < 6; y++)
    {
        for(int x = 0; x < 7; x++)
        {
            if (y != herokaY)
            {
                cout << map[y][x];
            }else if (x != herokaX)
            {
                cout << map[y][x];
            }

            else
            {
                cout << 'H';
            }

        }
        cout << endl;



    }
}

int main()
{

    int herokaX = 3;
    int herokaY = 3;
    bool status = false;
    char inputDir;

    char map[6][7] =
    {
        {'1','1','1','1','1','1','1'},
        {'1','1','1','1','1','1','1'},
        {'1','1','1','1','1','1','1'},
        {'1','1','1','1','1','1','1'},
        {'1','1','1','1','1','1','1'},
        {'1','1','1','1','1','1','1'}
    };

    drawMap(map, herokaY, herokaX);


    while(status == false)
    {
        cin >> inputDir;
        if ( inputDir == 'd' )
            herokaX++;
        else if (inputDir == 'a')
            herokaX--;
        else if (inputDir == 's' )
            herokaY++;
        else if (inputDir == 'w')
            herokaY--;
        else if (inputDir == 'p')
        {
                status = true;
        }

        drawMap(map, herokaY, herokaX);
    }

    return 0;

}

Maldita dislexia, batalle para configurar los controles XD

#include <iostream>

using namespace std;

void DrawMap(int HeroPosX, int HeroPosY, char GameMap[5][5]){

    for(int i = 0; i < 5; i++){
        for(int p = 0; p < 5; p++){
            if (i == HeroPosY && p == HeroPosX){
               cout << 'H';
            }
            else{
                cout << GameMap[i][p];
            }
        }
        cout << endl;
    }
}

int main(){

    bool isGameOver = false;
    char input = ' ';
    int HeroPosX = 1;
    int HeroPosY = 1;
    char GameMap[5][5] =
  {
    {'1','1','1','1','1'},
    {'1','1','1','1','1'},
    {'1','1','1','1','1'},
    {'1','1','1','1','1'},
    {'1','1','1','1','1'}
  };

    while(isGameOver == false){

        DrawMap(HeroPosX, HeroPosY, GameMap);
        cin >> input;

        switch(input){
            case 'a':
                HeroPosX = HeroPosX - 1;
                break;
            case 's':
                HeroPosY = HeroPosY + 1;
                break;
            case 'd':
                HeroPosX = HeroPosX + 1;
                break;
            case 'w':
                HeroPosY = HeroPosY - 1;
                break;
            case 'p':
                isGameOver = true;
                break;
        }
    }
}```

mi solucion enfocada en practicar punteros

#include <iostream>

using namespace std;
#define __MAP_SIZE 15

typedef struct Pos {
    int y;
    int x;
} POS;

char *setMapRow(int columns);

char **setMap(int columns, int rows);

void printMap( char *map, int character_position);

void movePlayer(POS *position);

void clamp(int *value, int min, int max);

POS *newPosition(POS *position)
{
    position->x = 0;
    position->y = 0;
    return position;
}

char **setMap(int columns, int rows)
{
    char **map = new char*[rows];
    for(int h = 0; h < rows; h++)
    {
        *(map + h) = setMapRow(columns);
    }
    return map;
}

char *setMapRow(int columns)
{
    char *name = (char*)malloc(sizeof(char) * columns);
    int h;
    for(h = 0; h < columns; h++)
    {
        name[h] = '0';
    }
    *(name+h) = '\0';
    return name;
}

void printMap( char **map, POS *character_position)
{
    char character_to_print;
    for(int y = 0; y < __MAP_SIZE; y++)
    {
        for(int x = 0; x < __MAP_SIZE; x++)
        {
            character_to_print = !(character_position->x == x && character_position->y == y) ? *(*(map + y)+x) : 'H';
            cout << character_to_print;
        }
        cout << endl;
    }
}

string input(char const *msg, char const *end="\n")
{
    string user_input;
    cout << msg;
    cin >> user_input;
    return user_input;
}

void clamp(int *value, int min, int max)
{
    *value = (*value) < min ? min : *value;
    *value = (*value) > max ? max : *value;
}

void movePlayer(POS *position)
{
    char key_entered = input("Pick a direction to go(w\\a\\s\\d)")[0];
    if( key_entered == 'w' || key_entered == 's')
    {
        position->y += key_entered == 'w' ? -1 : 1;
        clamp(&(position->y), 0, (__MAP_SIZE - 1));
    }
    else if(key_entered == 'd' || key_entered == 'a')
    {
        position->x += key_entered == 'a' ? -1 : 1;
        clamp(&(position->x), 0, (__MAP_SIZE - 1));
    }

}

int main(int argc, char const *argv[])
{
    POS *position; 
    newPosition(position);
    char **map = setMap(__MAP_SIZE, __MAP_SIZE);
    while(true)
    {
        printMap(map, position);
        movePlayer(position);
    }
    return 0;
}

Creo que a muchos nos gust贸 m谩s usar switch en este caso馃槄

#include <iostream>

using namespace std;

void DrawMap(int heroPosX, int heroPosY, char map[20][20]){
      for(int i = 0; i < 20; i++){
            for(int j = 0; j < 20; j++){
                if(heroPosX == i && heroPosY == j){
                    cout << 'H' << " ";
                }else{
                   cout << map[i][j] << " ";
                }
            }
            cout << endl;
        }
}

int main()
{
    int heroPosX = 0;
    int heroPosY = 0;
    char key = ' ';
    bool isGameOver = false;
    char map[20][20];

    for(int i = 0; i < 20; i++){
        for(int j = 0; j < 20; j++){
            map[i][j] = '1';
        }
    }

    DrawMap(heroPosX, heroPosY, map);

    while(isGameOver == false){
        cin >> key;
        switch(key){
    case 'd':
        heroPosY++;
        break;
    case 'a':
        heroPosY--;
        break;
    case 'w':
        heroPosX--;
        break;
    case 's':
        heroPosX++;
    }
    DrawMap(heroPosX, heroPosY, map);
  }
}
#include <iostream>
#include <array>
#define MAXSIZEMAP 5

using namespace std;

void drawMap(int heroPosX, int heroPosY, const array<array<char,MAXSIZEMAP>,MAXSIZEMAP>&gameMap);

int main (){
	array<array<char,MAXSIZEMAP>,MAXSIZEMAP> gameMap = 
	{{
	{'1', '1', '1', '1', '1'},
	{'1', '1', '1', '1', '1'},
	{'1', '1', '1', '1', '1'},
	{'1', '1', '1', '1', '1'},
	{'1', '1', '1', '1', '1'}
	}};

	char input = 0;
	bool isGameOver = false;
	int heroPosX = 0, heroPosY = 0;
	
	do
	{
	drawMap(heroPosX,heroPosY,gameMap);

	cin >> input;

	switch (input)
	{
	case 'a':
		heroPosX--;
		break;
	case 'd':
		heroPosX++;
		break;
	case 'w':
		heroPosY--;
		break;
	case 's':
		heroPosY++;
		break;
	case 'p':
		isGameOver = true;
		break;
	
	default:
		cout << "Please type a right command" << endl;
		cout << "a-> move left, d-> move right, p-> exit" << endl;
		break;
	}

	} while (!isGameOver);
	


	return 0;

}

void drawMap(int heroPosX, int heroPosY, const array<array<char,MAXSIZEMAP>,MAXSIZEMAP>&gameMap){

		for(int y=0; y<gameMap.size();y++){
			for (int x = 0; x < gameMap[y].size(); x++)
			{
				if (heroPosX==x && heroPosY == y)
				{
					cout << "H";
				} else
				{
					cout<<gameMap[x][y];
				}
			}
			cout << endl;
	}
}

Reto Completado 馃槂

#include <iostream>

using namespace std;

void DrawMap(int HeroPosX, int HeroPosY, char GameMap[5][5])
{
    for(int i = 0; i < 5; i++)
    {
        for(int j = 0; j < 5; j++)
        {
            if(i != HeroPosY)
            {
                cout << GameMap[j][i];
            }
            else
            {
                if(j != HeroPosX)
                {
                    cout << GameMap[j][i];
                }
                else
                {
                    cout << 'H';
                }

            }
        }

        cout << endl;

    }
}

int main()
{
    int HeroPosX = 2;
    int HeroPosY = 2;
    bool isGameOver = false;
    char Input = ' ';
    char GameMap[5][5] =
    {
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
    };

    DrawMap(HeroPosX, HeroPosY, GameMap);

    while(isGameOver == false)
    {
        cin >> Input;

        if(Input == 'D')
        {
            HeroPosX = HeroPosX + 1;
        }
        else if(Input == 'A')
        {
            HeroPosX = HeroPosX - 1;
        }
        else if(Input == 'W')
        {
            HeroPosY = HeroPosY - 1;
        }
        else if(Input == 'S')
        {
            HeroPosY = HeroPosY + 1;
        }
        else
        {
            isGameOver = true;
        }

        DrawMap(HeroPosX, HeroPosY, GameMap);
    }

    return 0;
}

#include <iostream>

using namespace std;

void drawMap(int heroX, int heroY, char map[5][5]) {
	for (int i = 0; i < 5; i++) {
		for (int j = 0; j < 5; j++) {
			if (j != heroX)
			{
				cout << map[i][j] << ", ";
			}
			else {
				if (i != heroY) {
					cout << map[i][j] << ", ";
				}
				else {
					cout << 'H';
				}
				
			}
		}
		cout << endl;

	}
}

int main()
{
	char input = ' ';
	bool isGameOver = false;
	int heroPosX = 1;
	int heroPosY = 1;
	char gameMap[5][5] = 
	{ 
		{ '1', '1', '1', '1', '1' },
		{ '1', '1', '1', '1', '1' },
		{ '1', '1', '1', '1', '1' },
		{ '1', '1', '1', '1', '1' },
		{ '1', '1', '1', '1', '1' }
	};

	cout << "Mueve al heroe sin salirte del mapa (SI SALES DEL MAPA PIERDES)" << endl;
	cout << ":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::" << endl;
	cout << endl;

	do {
		drawMap(heroPosX, heroPosY, gameMap);
		
		cin >> input;

		if (input == 'd' || input == 'D') {
			heroPosX++;
		}
		else if (input == 'a' || input == 'A') {
			heroPosX--;
		}
		else if (input == 'w' || input == 'W') {
			heroPosY--;
		}
		else if (input == 's' || input == 'S') {
			heroPosY++;
		}

		if (heroPosX > 4 || heroPosX < 0) {
			cout << "GAME OVER";
			isGameOver = true;
		}
		if (heroPosY > 4 || heroPosY < 0) {
			cout << "GAME OVER";
			isGameOver = true;
		}
	} while (isGameOver == false); 

	
	
}

#include <iostream>

using namespace std;

void drawMap(int heroPosX, int heroPosY, char gameMap[5][5]){
	system("cls");
	for(int i = 0; i < 5; i++){
		for(int j = 0; j < 5; j++){
			if(i != heroPosY){
				cout << gameMap[j][i];
			}else{
				if(j != heroPosX){
					cout << gameMap[j][i];	
				}else{
					cout << 'H';
				}
			}
		}
		cout << endl;
	}
}

int main(){
	int heroPosX = 1;
	int heroPosY = 1;
	bool isGameOver = false;
	char input = ' ';
	
	char gameMap[5][5] = {
		{'1', '1', '1', '1', '1'},
		{'1', '1', '1', '1', '1'},
		{'1', '1', '1', '1', '1'},
		{'1', '1', '1', '1', '1'},
		{'1', '1', '1', '1', '1'}
	};
	
	drawMap(heroPosX, heroPosY, gameMap);
	
	while(isGameOver == false){
		cin >> input;
		if(input == 'd'){
			heroPosX = heroPosX + 1;
		}else if(input == 'a'){
			heroPosX = heroPosX - 1;
		}else if(input == 'w'){
			heroPosY = heroPosY - 1;
		}else if(input == 's'){
			heroPosY = heroPosY + 1;
		}else if(input == 'p'){
			isGameOver = true;
		}
		drawMap(heroPosX, heroPosY, gameMap);
	}
		
	return 0;
}

Listo. Inclu铆 los casos de WASD en may煤scula tambi茅n por si el blocmayus est谩 activado.

#include <iostream>

using namespace std;

void drawMap(int heroPosX, int heroPosY, char gameMap[5][5])
{
    for (int i = 0; i < 5; i++)
    {
        for(int j = 0; j < 5; j++)
        {
            cout << "[";

            if (i != heroPosY || j != heroPosX)
                cout << gameMap[i][j];
            else
                cout << 'H';

            cout << "]";
        }

        cout << endl;
    }
}

int main()
{
    int heroPosX = 1, heroPosY = 1;
    bool isGameOver = false;
    char input = ' ';
    char gameMap[5][5] =
    {
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'}
    };


    drawMap(heroPosX, heroPosY, gameMap);

    while (!isGameOver)
    {
        cout << "Movimiento (WASD): ";
        cin >> input;

        if(input == 'd' || input == 'D')
            heroPosX += 1;
        else if(input == 'a' || input == 'A')
            heroPosX -= 1;
        else if (input == 'w' || input == 'W')
            heroPosY -= 1;
        else if (input == 's' || input == 'S')
            heroPosY += 1;
        else if(input == 'p' || input == 'P')
            isGameOver = true;

        drawMap(heroPosX, heroPosY, gameMap);
    }

    return 0;
}

Recibo todo su feedback para poder hacerlo mucho mejor! 馃槂 Gracias de antemano

#include <iostream>

using namespace std;

void DrawMap(int HeroPosX, int HeroPosY, char GameMap[5][5])
{
  for(int i = 0; i < 5; i++)
    {

        for(int j = 0; j < 5; j++)
        {
            if (i != HeroPosY)
            {
                cout << GameMap[j][i];
            }
            else
            {
                if (j != HeroPosX)
                {
                cout << GameMap[j][i];
                }
                else
                {
                    cout << 'H';
                }
            }
        }

    // Necesitamos un salto de l铆nea para diferenciar
    // las filas de las columnas:
    cout << endl;
  }
}

int main()
{
  // ...

  int HeroPosX = 0;
  int HeroPosY = 0;
  char GameMap[5][5] =
  {
    {'1','1','1','1','1'},
    {'1','1','1','1','1'},
    {'1','1','1','1','1'},
    {'1','1','1','1','1'},
    {'1','1','1','1','1'},
  };
    char input = ' ';
    char isGameOver = false;

    DrawMap(HeroPosX, HeroPosY, GameMap);

    while (isGameOver != true)
    {
        cin >> input;
        switch(input)
        {
            case 'd':
                if (HeroPosX < 4 && HeroPosX >= 1)
                {
                    HeroPosX++;
                }else{
                    cout << "Game over"  << endl;
                    isGameOver = true;
                }
            break;

            case 'a':
                if (HeroPosX < 4 && HeroPosX >= 1)
                {
                    HeroPosX--;
                }else{
                    cout << "Game over"  << endl;
                    isGameOver = true;
                }
            break;

            case 'w':
                if (HeroPosY < 4 && HeroPosY >= 1)
                {
                    HeroPosY--;
                }else{
                    cout << "Game over"  << endl;
                    isGameOver = true;
                }

            break;

            case 's':
                if(HeroPosY < 4 && HeroPosY >= 1)
                {
                    HeroPosY++;
                }else{
                    cout << "Game over"  << endl;
                    isGameOver = true;
                }
            break;
            case 'p':
                {
                    isGameOver = true;
                }
            break;
            default:
                cout << "W -> arriba S -> abajo D -> derecha A-> izquierda" << endl;
            break;
        }

        DrawMap(HeroPosX, HeroPosY, GameMap);
    }



    return 0;
  // ...
}```
#include <iostream>

using namespace std;

  int HeroPosX = 1;
  int HeroPosy = 1;
  char GameMap[5][5] =
  {
    {'1','1','1','1','1'},
    {'1','1','1','1','1'},
    {'1','1','1','1','1'},
    {'1','1','1','1','1'},
    {'1','1','1','1','1'},
  };

void DrawMap(int HeroPosX, int HeroPosY, char GameMap[5][5]) {
  for(int i = 0; i < 5; i++) {
     for(int p = 0; p < 5; p++) {
      if(i==HeroPosX && p==HeroPosY)
      {
            cout<<'H';
      }else{
          cout<<GameMap[i][p];
      }
    }
    cout << endl;
  }
}

bool mover(bool flag)
{
  char mov;
  cout<<"Izquierda(i), Derecha(d),Arriba(a),Abajo(b) y Salir(s)"<<endl;
  cin>>mov;
  switch(mov)
  {
    case 'd':
        HeroPosy++;

        break;
    case 'i':
        HeroPosy--;
        break;
    case 'a':
        HeroPosX--;
        break;
    case 'b':
        HeroPosX++;
        break;
    case 's':
        return false;
        break;

  }
  return true;
}

int main()
{


  DrawMap(HeroPosX,HeroPosy,GameMap);

  bool flag=true;

  while(flag)
  {
          flag=mover(flag);
          if(HeroPosX==5)HeroPosX--;
          if(HeroPosX==-1)HeroPosX++;
          if(HeroPosy==5)HeroPosy--;
          if(HeroPosy==-1)HeroPosy++;
          DrawMap(HeroPosX,HeroPosy,GameMap);




  }

  }

Divertido 鈽

#include <iostream>

using namespace std;


void DrawMap(int HeroPosX, int HeroPosY, char GameMap[5][5])
{
	for (int j = 0; j < 5; j++)
	{
		for (int i = 0; i < 5; i++)
		{
			if (HeroPosX == i and HeroPosY == j)
				cout<<'O';
			else
				cout<<GameMap[i][j];
		}
		cout<<endl;
	}
}



int main()
{
	int HeroPosX = 1;
	int HeroPosY = 1;
	bool isGameOver = false;
	char Input = ' ';
	
	char GameMap[5][5] = 
	{
		{'1','1','1','1','1'},
		{'1','1','1','1','1'},
		{'1','1','1','1','1'},
		{'1','1','1','1','1'},
		{'1','1','1','1','1'}
	};
	
	DrawMap(HeroPosX, HeroPosY, GameMap);
	
	while(isGameOver == false)
	{
		cin>> Input;
		
		if (Input == 'r')
			HeroPosX += 1;
		else if (Input == 'l')
			HeroPosX -= 1;
		else if (Input == 'u')
			HeroPosY -= 1; 
		else if (Input == 'd')
			HeroPosY += 1;
		else if (Input == 'k')
			isGameOver = true;
			
		DrawMap(HeroPosX, HeroPosY, GameMap);
	}
	
	return 0;
}

Hice el reto de la clase y aqu铆 les dejo mi codigo espero que les sirva!

#include <iostream>

void printMap(int Map[5][7], int HeroX, int HeroY) {
    char Hero = 'H';
    for (int i = 0; i < 5; i++)
    {
        for (int y = 0; y < 7; y++)
        {
            if (HeroX == i && HeroY == y)
            {
                std::cout << Hero;
                continue;
            }
            
            std::cout << Map[i][y];
        }
        std::cout << std::endl;  
    }
    
}

int main() 
{
    int Map[5][7] = {
        {1, 1, 1, 1, 1, 1, 1},
        {1, 1, 1, 1, 1, 1, 1},
        {1, 1, 1, 1, 1, 1, 1},
        {1, 1, 1, 1, 1, 1, 1},
        {1, 1, 1, 1, 1, 1, 1},
    };
    
    int limitX = 4;
    int limitY = 6;
    int heroX = 0;
    int heroY = 0;
    bool isPlayerAlive = true;
    char movement;

    while (isPlayerAlive)
    {
        if (heroX > limitX || heroY > limitY || heroX < 0 || heroY < 0)
        {
            
            isPlayerAlive = false;
        }

        printMap(Map, heroX, heroY);

        std::cin >> movement;
        if (movement == 'd')
        {
            heroY++;

        }else if(movement == 'a') {
            heroY--;

        }else if (movement == 'w')
        {
            heroX--;
        }else if (movement == 's')
        {
            heroX++;
        }

        system("cls");
        
    }
    


}

![](

Aqui el reto:

#include <iostream>

using namespace std;


struct Map{
    char wall = '-';
    int Xsize;
    int Ysize;
};

struct Hero{
    char mark = 'H';
    int heroX;
    int heroY;
};

void keyPicker(int, int, char);
void mapOne(int mapX, int mapY, char wall, int heroX, int heroY, char heromark);
void mapOneInit();


int main(){
    mapOneInit();


    return 0;
}

void keyPicker(int* currentX, int* currentY, char letter){
    switch (letter){
    case 'a': *currentX-=1;
        break;
    case 'w': *currentY-=1;
        break;
    case 's': *currentY+=1;
        break;
    case 'd': *currentX+=1;
        break;
    default:
        cout << "Invalid Key." << endl;
        break;
    }
}

void mapOne(int mapX, int mapY, char wall, int heroX, int heroY, char heromark){
    while (true){
        cout << "Hero position X: " << heroX << " Hero position Y: "<< heroX << endl;
        for (int i = 0; i < mapY; i++){
            for (int j = 0; j < mapX; j++){
                if (j == heroX && i == heroY){
                    cout << heromark;
                }else{
                    cout << wall;
                }
            }
            cout << endl;
        }

        char input;
        cout << "letter: "; cin >> input;
        keyPicker(&heroX, &heroY, input);
        system("cls");
    }
}

void mapOneInit(){
    Map map;
    Hero hero;

    map.Xsize = 100;
    map.Ysize = 15;
    
    hero.heroX = 1;
    hero.heroY = 2;

    mapOne(map.Xsize, map.Ysize, map.wall, hero.heroX, hero.heroY, hero.mark);
}

As铆 lo resolv铆 yo

#include <iostream>

using namespace std;

void DrawMap(int HeroPosX,int HeroPosY,char game_map[5][5]){

    for (int i = 0 ; i<5 ; i = i + 1)
    {
        for(int p = 0 ;p<5;p=p+1)
        {
            if (i != HeroPosY  )
            {
                cout << game_map[p][i];
            }
            else
            {
                if(p != HeroPosX)
                {
                    cout<< game_map[p][i];
                }
                else
                {
                    cout<<'H';
                }

            }
        }
        cout << endl;


    }
}

int main()
{
    int HeroPosX = 0 ;
    int HeroPosY = 0 ;
    bool isGameOver = false ;
    char Input = 'd';
    char game_map[5][5] =
    {
    {'1','1','1','1','1'},
    {'1','1','1','1','1'},
    {'1','1','1','1','1'},
    {'1','1','1','1','1'},
    {'1','1','1','1','1'}
    };

    while(isGameOver == false){


    if(Input == 'd')
    {
        HeroPosX = HeroPosX + 1;
    }
    else if(Input == 'a')
    {
        HeroPosX = HeroPosX - 1;
    }
    else if(Input == 's')
    {
        HeroPosY = HeroPosY + 1;
    }
    else if(Input == 'w')
    {
        HeroPosY = HeroPosY - 1;
    }
    else if(Input=='p')
    {
        isGameOver = true;
    }


    DrawMap(HeroPosX,HeroPosY,game_map);

    cin >> Input;
    }


    return 0;

}
#include <iostream>

using namespace std;

void DrawMap(int heroPositionX, int heroPositionY, char gameMap[5][5])
{  for(int i = 0; i < 5; i++)
  {
    for (int p = 0; p < 5; p++)
    {
      if(i != heroPositionY)
      {
        cout << gameMap [p][i];
      } else {
        if (p != heroPositionX) {
        cout << gameMap [p][i];
      }else
      {
        cout << 'O';
      }
      }
    }
    cout << endl;

  }
}


int main()
{
    int heroPositionX = 0;
    int heroPositionY = 0;

    bool gameOver = false;

    char input = ' ';

    char gameMap[5][5] =
    {
      {'X', 'X', 'X', 'X', 'X'},
      {'X', 'X', 'X', 'X', 'X'},
      {'X', 'X', 'X', 'X', 'X'},
      {'X', 'X', 'X', 'X', 'X'},
      {'X', 'X', 'X', 'X', 'X'},
    };

    while (gameOver == false)
    {
      cin >> input;

      if(input == 'd')
      {
        heroPositionX = heroPositionX + 1;
        heroPositionY = heroPositionY + 1;
      } else if( input == 'a')
      {
        heroPositionX = heroPositionX - 1;
        heroPositionY = heroPositionY - 1;
      } else if ( input == 'p')
      {
        gameOver = true;
      }

      DrawMap(heroPositionX, heroPositionY, gameMap);
    }



    return 0;
}

馃槃

using namespace std;

void drawMap(int heroPosX, int heroPosY,char gameMap[5][5])
{
    for(int i = 0; i < 5; i++)
    {
       for(int p = 0; p < 5; p++)
       {
         if(i != heroPosY)
         {
          cout << gameMap[i][p];
         }
         else if(p != heroPosX)
         {
          cout << gameMap[i][p];
         }
         else
         {
          cout << 'H';
         }
       }
       cout << endl;
    }
}

int main()
{
   int heroPosX = 1;
   int heroPosY = 1;
   char input = ' ';
   bool isGameOver = false;
   char gameMap [5][5] =
   {
     {'1','1','1','1','1'},
     {'1','1','1','1','1'},
     {'1','1','1','1','1'},
     {'1','1','1','1','1'},
     {'1','1','1','1','1'}
   };

   while(isGameOver  == false)
   {
       drawMap(heroPosX, heroPosY, gameMap);
       cin >> input;

       if(input == 'd')
       {
        heroPosX = heroPosX + 1;
       }
       else if(input == 'a')
       {
        heroPosX = heroPosX - 1;
       }
       else if(input == 'w')
       {
        heroPosY = heroPosY - 1;
       }
       else if(input == 's')
       {
        heroPosY = heroPosY + 1;
       }
       else
       {
        isGameOver = true;
        cout << "GAME OVER";
       }
   }
  return 0;
}```
#include<iostream>
#include<conio.h>
using namespace std;

void drawmap(int heropos[2], char map[5][5])
{
    for(int i = 0; i < 5; i++)
    {
        for(int j = 0; j < 5; j++)
            if(i == heropos[0] && j == heropos[1]) cout << 'h';
            else cout << map[i][j];
        cout << endl;
    }
}

int main()
{
    bool gameover = false;
    char input = ' ';
    char map[5][5] = {{'1','1','1','1','1'},
    {'1','1','1','1','1'},
    {'1','1','1','1','1'},
    {'1','1','1','1','1'},
    {'1','1','1','1','1'}};
    int heropos[2] = {1,1};
    while (gameover == false)
    {
        drawmap(heropos,map);
        cin >> input;

        if (input == 'd') heropos[1]++;
        else if (input == 'a') heropos[1]--;
        else if (input == 'w') heropos[0]--;
        else if (input == 's') heropos[0]++;
        system("cls");
    }
    return 0;
}

Ya le puse las colisiones de arriba y abajo

#include <iostream>
using namespace std;

void drawMap (int heroPosX, int heroPosY, char gameMap[11][11]){
    for (int i=0; i<11; i++){

        for (int p=0; p<11; p++){

        if( i != heroPosX){
            cout << gameMap[i][p];
        }
        else{

        if(p != heroPosY){
            cout << gameMap[i][p];
        }
        else{
            cout << "H";
        }

        }
        cout << " ";
        }
        cout << "" << endl;
    }

    cout << "   ";
}

int main(){

    /* Vamos a hacer el mapa del juego
    con un arreglo bidimensional */

    int heroPosX = 5;
    int heroPosY = 5;
    char gameMap[11][11] = {
        {'1','1','1','1','1','1','1','1','1','1','1'},
        {'1','1','1','1','1','1','1','1','1','1','1'},
        {'1','1','1','1','1','1','1','1','1','1','1'},
        {'1','1','1','1','1','1','1','1','1','1','1'},
        {'1','1','1','1','1','1','1','1','1','1','1'},
        {'1','1','1','1','1','1','1','1','1','1','1'},
        {'1','1','1','1','1','1','1','1','1','1','1'},
        {'1','1','1','1','1','1','1','1','1','1','1'},
        {'1','1','1','1','1','1','1','1','1','1','1'},
        {'1','1','1','1','1','1','1','1','1','1','1'},
        {'1','1','1','1','1','1','1','1','1','1','1'},
    };

    bool gameOver = false;
    char input;

    cout << "WASD para moverte. Escribe 0 para salir" << endl; cout << "" << endl;

    while(gameOver == false){

        drawMap(heroPosY, heroPosX, gameMap);
        cin >> input;

            //Switch para el Movimiento
            switch(input){
                case 'a': heroPosX -= 1;
                break;
                case 'd': heroPosX += 1;
                break;
                case 'w': heroPosY -= 1;
                break;
                case 's': heroPosY += 1;
                break;
                case '0': gameOver = true;
                break;
            }

            //Switch para las colisiones X
            switch(heroPosX){
                case -1: heroPosX += 1;
                break;
                case 11: heroPosX -= 1;
                break;
            }

            //Switch para las colisiones Y
            switch(heroPosY){
                case -1: heroPosY += 1;
                break;
                case 11: heroPosY -= 1;
                break;
            }

    }

    return 0;
}

*Mis apuntes sobre 鈥淎rreglos bidimensionales鈥:

Les comparto el c贸digo que hice, cambi茅 al uso del switch para usar las teclas: w,s,a,d y puse un peque帽o instructivo para el uso del juego, adem谩s de no permitir salir de los l铆mites del arreglo:

#include <iostream>

using namespace std;

void drawMap(int heroPosX, int heroPosY, char gameMap[5][5])
{
    for(int i=0;i<5;i++)
    {
        for(int j=0;j<5;j++)
        {
        if(i!=heroPosX)
        {
        cout<<gameMap[j][i];
        }else
        {
            if(j!=heroPosY)
            {
                cout<<gameMap[j][i];
            }else
            {
            cout<<'H';
            }
        }
        }
    cout<<endl;
    }
}

int main()
{
    int heroPosX=0;
    int heroPosY=0;
    bool isGameOver=false;
    char gameMap[5][5]=
    {
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
        {'1','1','1','1','1'},
    };
    cout<<"Welcome to your map, you can move with the following keys:"<<endl;
    cout<<"-Press 'w' to go up"<<endl;
    cout<<"-Press 's' to go down"<<endl;
    cout<<"-Press 'a' to go left"<<endl;
    cout<<"-Press 'd' to go right"<<endl;
    cout<<"-Press 'q' to exit the game"<<endl<<endl<<endl;

    drawMap(heroPosX,heroPosY,gameMap);
    char input=' ';
    while(isGameOver==false)
    {
        cout<<endl;
        cin>>input;
    switch(input)
    {
    case 's':
        heroPosX+=1;
        break;

    case 'w':
        heroPosX-=1;
        break;

    case 'd':
         heroPosY+=1;
         break;

    case 'a':
        heroPosY-=1;
        break;

    case 'q':
        isGameOver=true;
        break;

    default:
        cout<<"*Wrong input"<<endl<<endl;
    }
    if(heroPosX==5)
    {
        heroPosX-=1;
    }
    else if(heroPosX==-1)
    {
        heroPosX+=1;
    }
    else if(heroPosY==5)
    {
        heroPosY-=1;
    }
    else if(heroPosY==-1)
    {
        heroPosY+=1;
    }
    cout<<endl<<"Welcome to your map, you can move with the following keys:"<<endl;
    cout<<"-Press 'w' to go up"<<endl;
    cout<<"-Press 's' to go down"<<endl;
    cout<<"-Press 'a' to go left"<<endl;
    cout<<"-Press 'd' to go right"<<endl;
    cout<<"-Press 'q' to exit the game"<<endl<<endl<<endl;
    drawMap(heroPosX,heroPosY,gameMap);
    }
    return 0;
}
# include <iostream>

using namespace std; // Esto sirve para utilizar cout y cin

void DrawMap(int HeroPosX, int HeroPosY, char GameMap[5][5])
{
    for (int i = 0; i < 5; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            if (i != HeroPosY)
            {
                cout << GameMap[j][i];
            }
            else
            {
                if(j != HeroPosX)
                {
                    cout << GameMap[j][i];
                }
                else
                {
                    cout << 'H';
                }
                
            }
        }
        cout << endl;
    }
}

int main()
{
    int HeroPosX = 0; // Posicion actual de mi personaje
    int HeroPosY = 0;
    bool isGameOver = false;
    char input = ' ';
    char GameMap[5][5] = 
    {
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'},
        {'1', '1', '1', '1', '1'}
    };

    DrawMap(HeroPosX, HeroPosY, GameMap);

    while (isGameOver == false)
    {
        cin >> input;

        if (input == 'd' && HeroPosX < 4)
        {
            HeroPosX = HeroPosX + 1;
        }
        else if (input == 'a' && HeroPosX > 0)
        {
            HeroPosX = HeroPosX - 1;
        }
        else if (input == 'w' && HeroPosY > 0)
        {
            HeroPosY = HeroPosY - 1;
        }
        else if (input == 's' && HeroPosY < 4)
        {
            HeroPosY = HeroPosY + 1;
        }
        else if (input == 'p') 
        {
            isGameOver = true;
        }

        DrawMap(HeroPosX, HeroPosY, GameMap);
    }

    return 0;
}
<code>
//Cortesia de Juan Calderon
#include <iostream>
#include<time.h>

using namespace std;

//Me di cuenta que no necesitamos el susodicho mapa =D
//Con la posicion del heroe basta y sobra.
void DrawMap(int Xpos, int Ypos)
{
    for(int j=0; j<6;j++){
        for(int i=0; i<6;i++){
            if(i!=Xpos)
                cout<<"-";
            else if(j!=Ypos)
                cout<<"-";
            else
                cout<<"H";
        }
        cout<<endl;
    }
}

int main()
{
//La posicion inicial la defini de forma aleatoria
    srand(time(0));
    int Xpos = rand()%6;
    int Ypos = rand()%6;

    cout<<"La posicion del heroe es ("<<Xpos<<" , "<<Ypos<<")"<<endl;

    DrawMap(Xpos, Ypos);

    cout<<endl<<"Quieres moverte a la izquierda o a la derecha? (a/d) "<<endl;
    cout<<"Arriba o abajo? (p/l) "<<endl<<endl;
    //Me parecio mas comodo usar p y l para arriba y abajo, pruebenlo!!
    //Parte Principal: Cambiamos la posicion del heroe al gusto del usuario
    bool IsGameOver=false;
    while(IsGameOver==false)
    {
        char mov;
        cin>>mov;
        switch(mov)
        {
            case 'a': Xpos=Xpos-1;
                if(Xpos<0)
                    Xpos=Xpos+6;
            break;
            case 'd': Xpos=Xpos+1;
                if(Xpos>5)
                    Xpos=Xpos-6;
            break;
            case 'p': Ypos=Ypos-1;
                if(Ypos<0)
                    Ypos=Ypos+6;
            break;
            case 'l': Ypos=Ypos+1;
                if(Ypos>5)
                    Ypos=Ypos-6;
            break;
            default: cout<<"Rompiste el programa!!"<<endl;
                IsGameOver=true;
                cout<<"GAME OVER";
            break;
        }
        //Se imprime la nueva configuracion
        if(IsGameOver==false)
        {
         DrawMap(Xpos, Ypos);
        }
    }
    return 0;
}