Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- void LLenar_Matriz(int** m, int*f, int *c)
- { for (int i = 0;i < *f;i++)
- for (int j = 0;j < *c;j++)
- m[i][j] = 0;
- for (int j = 0;j < *c;j++)
- m[0][j] = m[*f-1][j] = 1;
- for (int i = 0;i < *f;i++)
- m[i][0] = m[i][*c-1] = 1;
- }
- void Mostrar_Matriz(int** m, int*f, int *c)
- { Console::Clear();
- Console::ForegroundColor = ConsoleColor::Red;
- for (int i = 0;i < *f;i++)
- { for (int j = 0;j < *c;j++)
- { Console::SetCursorPosition(j, i);
- if (m[i][j]==1)
- cout << (char)219;
- else
- cout << " ";
- }
- }
- }
- void Mostrar(int *xj, int *yj)
- {
- Console::SetCursorPosition(*xj, *yj);
- Console::ForegroundColor = ConsoleColor::Blue;
- cout << (char)219;
- }
- void Borrar(int *xj, int *yj)
- {
- Console::SetCursorPosition(*xj, *yj);
- Console::ForegroundColor = ConsoleColor::Blue;
- cout << " ";
- }
- void Izq(int **m, int *f, int*c, int *xj, int *yj)
- {
- if (*xj - 1 >= 0)
- { if (m[*yj][*xj - 1] == 0)
- { Borrar(xj, yj);
- *xj = *xj - 1;
- Mostrar(xj, yj);
- }
- }
- }
- void Der(int **m, int *f, int*c, int *xj, int *yj)
- {
- if (*xj + 1 <= 79)
- {
- if (m[*yj][*xj + 1] == 0)
- {
- Borrar(xj, yj);
- *xj = *xj + 1;
- Mostrar(xj, yj);
- }
- }
- }
- void Up(int **m, int *f, int*c, int *xj, int *yj)
- {
- if (*yj - 1 >= 0)
- { if (m[*yj - 1][*xj] == 0)
- { Borrar(xj, yj);
- *yj = *yj - 1;
- Mostrar(xj, yj);
- }
- }
- }
- void Dw(int **m, int *f, int*c, int *xj, int *yj)
- { if (*yj + 1 <= 24)
- {if (m[*yj + 1][*xj] == 0)
- { Borrar(xj, yj);
- *yj = *yj + 1;
- Mostrar(xj, yj);
- }
- }
- }
- Source:
- #include <iostream>
- #include <conio.h>
- #include <stdio.h>
- using namespace std;
- using namespace System;
- #include "Header.h"
- int main()
- { int **matriz, *filas, *columnas;
- int *xjugador,*yjugador;
- filas = new int; columnas = new int;
- *filas = 25; *columnas = 80;
- xjugador = new int; yjugador = new int;
- *xjugador = 10; *yjugador = 10;
- matriz = new int*[*filas];
- for (int i = 0;i < *filas;i++)
- matriz[i] = new int[*columnas];
- LLenar_Matriz(matriz, filas, columnas);
- Mostrar_Matriz(matriz, filas, columnas);
- while (true)
- {
- if (_kbhit())
- { char t = getch();
- if (t == 'a')
- Izq(matriz, filas, columnas,xjugador,yjugador);
- if (t == 'd')
- Der(matriz, filas, columnas, xjugador, yjugador);
- if (t == 'w')
- Up(matriz, filas, columnas, xjugador, yjugador);
- if (t == 's')
- Dw(matriz, filas, columnas, xjugador, yjugador);
- }
- }
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement