Advertisement
saluxx

Fixed uppgift 2

Oct 8th, 2015
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.03 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 ConsoleApplication12
  8. {
  9. class Program
  10. {
  11. public static int x = 2; //Vi kommer använda de här variablerna för att uppdatera spelarens verision
  12. public static int y = 2;
  13.  
  14. //När man gör något public static gör man så att man kan komma åt och ändra värdena på dessa variabler ifrån andra ställen.
  15.  
  16.  
  17. public static string player = ("☺");
  18.  
  19.  
  20. public static ConsoleKeyInfo tangent;
  21.  
  22. static void Main(string[] args)
  23. {
  24. Console.ForegroundColor = ConsoleColor.Yellow;
  25. Ritautspelaren();
  26. Map();
  27. while (0 < 100)
  28. {
  29. Flyttaspelaren(); // här skriver jag en funktion för att flytta min spelare
  30. Ritautspelaren(); // här gör jag en funktion som ritar ut spelaren efter den har flyttats
  31. Map();
  32. }
  33. }
  34. public static void Flyttaspelaren()
  35. {
  36. tangent = Console.ReadKey();
  37.  
  38. // Här inne kommer jag ha koden för att flytta min spelare
  39. //För att kunna komma åt min position alltså mitt X och Y måste jag göra dessa public static
  40. if (x >= 0)
  41. {
  42. if (tangent.Key == ConsoleKey.A)
  43. {
  44. x--;
  45. }
  46. else if (tangent.Key == ConsoleKey.D)
  47. {
  48. x++;
  49. }
  50. else if (tangent.Key == ConsoleKey.W)
  51. {
  52. y--;
  53. }
  54. else if (tangent.Key == ConsoleKey.S)
  55. {
  56. y++;
  57. }
  58. }
  59. else
  60. {
  61. }
  62.  
  63. if (x == 0)
  64. {
  65. x = 1;
  66. }
  67. else if (y == 0)
  68. {
  69. y = 1;
  70. }
  71. else if (x == 79)
  72. {
  73. x = 78;
  74. }
  75. else if (y == 24)
  76. {
  77. y = 23;
  78. }
  79. }
  80.  
  81. public static void Map()
  82. {
  83. Console.SetCursorPosition(0, 0);
  84. for (int i = 0; i < 80; i++)
  85. {
  86. Console.Write("█");
  87. }
  88. Console.SetCursorPosition(0, 1);
  89. for (int i = 0; i < 23; i++)
  90. {
  91. Console.WriteLine("█");
  92. }
  93. Console.SetCursorPosition(0, 24);
  94. for (int i = 0; i < 79; i++)
  95. {
  96. Console.Write("█");
  97. }
  98. Console.SetCursorPosition(79, 1);
  99. Console.WriteLine("█");
  100. Console.SetCursorPosition(79, 2);
  101. Console.WriteLine("█");
  102. Console.SetCursorPosition(79, 3);
  103. Console.WriteLine("█");
  104. Console.SetCursorPosition(79, 4);
  105. Console.WriteLine("█");
  106. Console.SetCursorPosition(79, 5);
  107. Console.WriteLine("█");
  108. Console.SetCursorPosition(79, 6);
  109. Console.WriteLine("█");
  110. Console.SetCursorPosition(79, 7);
  111. Console.WriteLine("█");
  112. Console.SetCursorPosition(79, 8);
  113. Console.WriteLine("█");
  114. Console.SetCursorPosition(79, 9);
  115. Console.WriteLine("█");
  116. Console.SetCursorPosition(79, 10);
  117. Console.WriteLine("█");
  118. Console.SetCursorPosition(79, 11);
  119. Console.WriteLine("█");
  120. Console.SetCursorPosition(79, 12);
  121. Console.WriteLine("█");
  122. Console.SetCursorPosition(79, 13);
  123. Console.WriteLine("█");
  124. Console.SetCursorPosition(79, 14);
  125. Console.WriteLine("█");
  126. Console.SetCursorPosition(79, 15);
  127. Console.WriteLine("█");
  128. Console.SetCursorPosition(79, 16);
  129. Console.WriteLine("█");
  130. Console.SetCursorPosition(79, 17);
  131. Console.WriteLine("█");
  132. Console.SetCursorPosition(79, 18);
  133. Console.WriteLine("█");
  134. Console.SetCursorPosition(79, 19);
  135. Console.WriteLine("█");
  136. Console.SetCursorPosition(79, 20);
  137. Console.WriteLine("█");
  138. Console.SetCursorPosition(79, 21);
  139. Console.WriteLine("█");
  140. Console.SetCursorPosition(79, 22);
  141. Console.WriteLine("█");
  142. Console.SetCursorPosition(79, 23);
  143. Console.Write("█");
  144.  
  145. }
  146.  
  147. private static void Ritautspelaren()
  148. {
  149. Console.Clear();
  150. Console.SetCursorPosition(x, y);
  151. Console.Write(player);
  152. Console.SetCursorPosition(0, 0);
  153. }
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178. }
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement