Advertisement
saluxx

maybe

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