Advertisement
Guest User

ablero - No pasa las paredes

a guest
Jun 28th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. #pragma once
  2. void LLenar_Matriz(int** m, int*f, int *c)
  3. { for (int i = 0;i < *f;i++)
  4. for (int j = 0;j < *c;j++)
  5. m[i][j] = 0;
  6. for (int j = 0;j < *c;j++)
  7. m[0][j] = m[*f-1][j] = 1;
  8. for (int i = 0;i < *f;i++)
  9. m[i][0] = m[i][*c-1] = 1;
  10. }
  11. void Mostrar_Matriz(int** m, int*f, int *c)
  12. { Console::Clear();
  13. Console::ForegroundColor = ConsoleColor::Red;
  14. for (int i = 0;i < *f;i++)
  15. { for (int j = 0;j < *c;j++)
  16. { Console::SetCursorPosition(j, i);
  17. if (m[i][j]==1)
  18. cout << (char)219;
  19. else
  20. cout << " ";
  21. }
  22. }
  23. }
  24. void Mostrar(int *xj, int *yj)
  25. {
  26. Console::SetCursorPosition(*xj, *yj);
  27. Console::ForegroundColor = ConsoleColor::Blue;
  28. cout << (char)219;
  29. }
  30. void Borrar(int *xj, int *yj)
  31. {
  32. Console::SetCursorPosition(*xj, *yj);
  33. Console::ForegroundColor = ConsoleColor::Blue;
  34. cout << " ";
  35. }
  36. void Izq(int **m, int *f, int*c, int *xj, int *yj)
  37. {
  38. if (*xj - 1 >= 0)
  39. { if (m[*yj][*xj - 1] == 0)
  40. { Borrar(xj, yj);
  41. *xj = *xj - 1;
  42. Mostrar(xj, yj);
  43. }
  44. }
  45. }
  46. void Der(int **m, int *f, int*c, int *xj, int *yj)
  47. {
  48. if (*xj + 1 <= 79)
  49. {
  50. if (m[*yj][*xj + 1] == 0)
  51. {
  52. Borrar(xj, yj);
  53. *xj = *xj + 1;
  54. Mostrar(xj, yj);
  55. }
  56. }
  57. }
  58. void Up(int **m, int *f, int*c, int *xj, int *yj)
  59. {
  60. if (*yj - 1 >= 0)
  61. { if (m[*yj - 1][*xj] == 0)
  62. { Borrar(xj, yj);
  63. *yj = *yj - 1;
  64. Mostrar(xj, yj);
  65. }
  66. }
  67. }
  68. void Dw(int **m, int *f, int*c, int *xj, int *yj)
  69. { if (*yj + 1 <= 24)
  70. {if (m[*yj + 1][*xj] == 0)
  71. { Borrar(xj, yj);
  72. *yj = *yj + 1;
  73. Mostrar(xj, yj);
  74. }
  75. }
  76. }
  77.  
  78.  
  79. Source:
  80. #include <iostream>
  81. #include <conio.h>
  82. #include <stdio.h>
  83. using namespace std;
  84. using namespace System;
  85. #include "Header.h"
  86. int main()
  87. { int **matriz, *filas, *columnas;
  88. int *xjugador,*yjugador;
  89. filas = new int; columnas = new int;
  90. *filas = 25; *columnas = 80;
  91. xjugador = new int; yjugador = new int;
  92. *xjugador = 10; *yjugador = 10;
  93. matriz = new int*[*filas];
  94. for (int i = 0;i < *filas;i++)
  95. matriz[i] = new int[*columnas];
  96. LLenar_Matriz(matriz, filas, columnas);
  97. Mostrar_Matriz(matriz, filas, columnas);
  98. while (true)
  99. {
  100. if (_kbhit())
  101. { char t = getch();
  102. if (t == 'a')
  103. Izq(matriz, filas, columnas,xjugador,yjugador);
  104. if (t == 'd')
  105. Der(matriz, filas, columnas, xjugador, yjugador);
  106. if (t == 'w')
  107. Up(matriz, filas, columnas, xjugador, yjugador);
  108. if (t == 's')
  109. Dw(matriz, filas, columnas, xjugador, yjugador);
  110. }
  111.  
  112. }
  113. getch();
  114. return 0;
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement