Advertisement
TargeTPoweR

Brave new world

Apr 1st, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Tasks
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. char[,] map = { { '*', '*', '*', '*', '*','*', '*', '*', '*', '*', '*' },
  14. { '*', ' ', ' ', ' ', '*',' ', ' ', ' ', ' ', ' ', '*' },
  15. { '*', ' ', ' ', ' ', '*',' ', ' ', ' ', ' ', ' ', '*' },
  16. { '*', ' ', ' ', ' ', '*',' ', ' ', ' ', ' ', ' ', '*' },
  17. { '*', ' ', ' ', ' ', ' ',' ', ' ', ' ', ' ', ' ', '*' },
  18. { '*', ' ', ' ', ' ', ' ',' ', ' ', ' ', ' ', ' ', '*' },
  19. { '*', ' ', ' ', ' ', ' ',' ', ' ', ' ', ' ', ' ', '*' },
  20. { '*', ' ', ' ', ' ', ' ',' ', ' ', ' ', ' ', ' ', '*' },
  21. { '*', ' ', '*', ' ', ' ',' ', ' ', ' ', ' ', ' ', '*' },
  22. { '*', ' ', '*', ' ', ' ',' ', ' ', ' ', '*', ' ', '*' },
  23. { '*', ' ', '*', ' ', ' ',' ', ' ', ' ', '*', ' ', '*' },
  24. { '*', '*', '*', '*', '*','*', '*', '*', '*', '*', '*' }};
  25.  
  26. Console.CursorVisible = false;
  27. int userX = 6, userY = 6;
  28. while (true)
  29. {
  30. DrawMap(ref map);
  31.  
  32. Console.SetCursorPosition(userY, userX);
  33. Console.Write("$");
  34. ConsoleKeyInfo playerKey = Console.ReadKey();
  35.  
  36. MovePlayer(playerKey, ref map,ref userX, ref userY);
  37.  
  38. Console.Clear();
  39. }
  40. }
  41.  
  42. static void DrawMap(ref char[,] array)
  43. {
  44. for (int i = 0; i < array.GetLength(0); i++)
  45. {
  46. for (int j = 0; j < array.GetLength(1); j++)
  47. {
  48. Console.Write(array[i, j]);
  49. }
  50. Console.WriteLine();
  51. }
  52. }
  53.  
  54. static void MovePlayer (ConsoleKeyInfo playerInput, ref char [,] playGround, ref int xposition, ref int yPosition)
  55. {
  56. switch (playerInput.Key)
  57. {
  58. case ConsoleKey.UpArrow:
  59. if (playGround[xposition - 1, yPosition] != '*')
  60. {
  61. xposition--;
  62. }
  63. break;
  64. case ConsoleKey.DownArrow:
  65. if (playGround[xposition + 1, yPosition] != '*')
  66. {
  67. xposition++;
  68. }
  69. break;
  70. case ConsoleKey.LeftArrow:
  71. if (playGround[xposition, yPosition - 1] != '*')
  72. {
  73. yPosition--;
  74. }
  75. break;
  76. case ConsoleKey.RightArrow:
  77. if (playGround[xposition, yPosition + 1] != '*')
  78. {
  79. yPosition++;
  80. }
  81. break;
  82. }
  83. }
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement