Advertisement
saluxx

rad

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