Advertisement
saluxx

hmm

Sep 30th, 2015
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 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. public static int position = rnd.Next(1, 4);
  17.  
  18. //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.
  19.  
  20.  
  21. public static string player = ("☺");
  22. public static string enemy = ("E");
  23.  
  24.  
  25. public static ConsoleKeyInfo tangent;
  26.  
  27. static void Main(string[] args)
  28. {
  29. Console.ForegroundColor = ConsoleColor.Yellow;
  30. Ritautspelaren();
  31. Ritautenemy();
  32. while (0 < 100)
  33. {
  34. Flyttaspelaren(); // här skriver jag en funktion för att flytta min spelare
  35. Ritautspelaren(); // här gör jag en funktion som ritar ut spelaren efter den har flyttats
  36. Ritautenemy();
  37.  
  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. private static void Ritautspelaren()
  121. {
  122. Console.Clear();
  123. Console.SetCursorPosition(x, y);
  124. Console.Write(player);
  125. }
  126.  
  127.  
  128. private static void flyttaenemy()
  129. {
  130. if (position == 1)
  131. {
  132. x1--;
  133. }
  134. else if (position == 2)
  135. {
  136. y1++;
  137. }
  138. else if (position == 3)
  139. {
  140. x1++;
  141. }
  142. else if (position == 4)
  143. {
  144. y1--;
  145. }
  146.  
  147. }
  148.  
  149. private static void Ritautenemy()
  150. {
  151. Console.SetCursorPosition(x1, y1);
  152. Console.WriteLine(enemy);
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement