Advertisement
saluxx

FInt

Oct 1st, 2015
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 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 = 79; //Vi kommer använda de här variablerna för att uppdatera spelarens verision
  12. public static int y = 23;
  13. public static int x1 = 0;
  14. public static int y1 = 0;
  15. public static int point = 0;
  16. public static Random rnd = new Random();
  17. public static int position = rnd.Next(1, 4);
  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 = ("☺");
  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. Points();
  37. Ritautspelaren(); // här gör jag en funktion som ritar ut spelaren efter den har flyttats
  38. Ritautenemy();
  39.  
  40.  
  41. }
  42. }
  43. public static void Flyttaspelaren()
  44. {
  45. tangent = Console.ReadKey();
  46.  
  47. // Här inne kommer jag ha koden för att flytta min spelare
  48. //För att kunna komma åt min position alltså mitt X och Y måste jag göra dessa public static
  49. if (100 > 0)
  50. {
  51. if (tangent.Key == ConsoleKey.A)
  52. {
  53. x--;
  54. }
  55. else if (tangent.Key == ConsoleKey.D)
  56. {
  57. x++;
  58. }
  59. else if (tangent.Key == ConsoleKey.W)
  60. {
  61. y--;
  62. }
  63. else if (tangent.Key == ConsoleKey.S)
  64. {
  65. y++;
  66. }
  67. else if (tangent.Key == ConsoleKey.UpArrow)
  68. {
  69. y1--;
  70. }
  71. else if (tangent.Key == ConsoleKey.DownArrow)
  72. {
  73. y1++;
  74. }
  75. else if (tangent.Key == ConsoleKey.LeftArrow)
  76. {
  77. x1--;
  78. }
  79. else if (tangent.Key == ConsoleKey.RightArrow)
  80. {
  81. x1++;
  82. }
  83.  
  84. }
  85. else
  86. {
  87. }
  88. if (x == -1)
  89. {
  90. x = 0;
  91. }
  92. else if (y == -1)
  93. {
  94. y = 0;
  95. }
  96. else if (x == 80)
  97. {
  98. x = 79;
  99. }
  100. else if (y == 24)
  101. {
  102. y = 23;
  103. }
  104. else if (x1 == -1)
  105. {
  106. x1 = 0;
  107. }
  108. else if (y1 == -1)
  109. {
  110. y1 = 0;
  111. }
  112. else if (x1 == 80)
  113. {
  114. x1 = 79;
  115. }
  116. else if (y1 == 24)
  117. {
  118. y1 = 23;
  119. }
  120.  
  121. }
  122.  
  123. public static void Points()
  124. {
  125.  
  126. if (x == x1 && y == y1)
  127. {
  128.  
  129. x = 79;
  130. y = 23;
  131. x1 = 0;
  132. y1 = 0;
  133. point = 1;
  134. Console.WriteLine(point);
  135. }
  136.  
  137. }
  138.  
  139.  
  140.  
  141.  
  142. private static void Ritautspelaren()
  143. {
  144. Console.Clear();
  145. Console.SetCursorPosition(x, y);
  146. Console.ForegroundColor = ConsoleColor.Green;
  147. Console.Write(player);
  148. Console.ResetColor();
  149. }
  150.  
  151.  
  152. private static void Ritautenemy()
  153. {
  154. Console.SetCursorPosition(x1, y1);
  155. Console.ForegroundColor = ConsoleColor.Red;
  156. Console.WriteLine(enemy);
  157. Console.ResetColor();
  158. }
  159. }
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement