Advertisement
saluxx

base

Oct 1st, 2015
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.51 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 x2 = 0;
  16. public static int y2 = 0;
  17. public static int point = 0;
  18. public static Random rnd = new Random();
  19. public static int position = rnd.Next(1, 4);
  20.  
  21. //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.
  22.  
  23.  
  24. public static string player = ("☺");
  25. public static string enemy = ("☺");
  26.  
  27.  
  28. public static ConsoleKeyInfo tangent;
  29.  
  30. static void Main(string[] args)
  31. {
  32. Meny();
  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. Ritautenvironment();
  40.  
  41.  
  42. }
  43. }
  44.  
  45. public static void Meny()
  46. {
  47. Console.SetCursorPosition(37, 7);
  48. Console.ForegroundColor = ConsoleColor.Green;
  49. Console.WriteLine("1 VS 1");
  50. Console.SetCursorPosition(30, 9);
  51. Console.WriteLine("Player one: W,S,A,D");
  52. Console.SetCursorPosition(30, 10);
  53. Console.WriteLine("Player two: Arrows");
  54. Console.ResetColor();
  55. Console.SetCursorPosition(23, 15);
  56. Console.WriteLine("Press any button to start the game");
  57.  
  58.  
  59.  
  60.  
  61. }
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. public static void Flyttaspelaren()
  71. {
  72. tangent = Console.ReadKey();
  73.  
  74. // Här inne kommer jag ha koden för att flytta min spelare
  75. //För att kunna komma åt min position alltså mitt X och Y måste jag göra dessa public static
  76. if (100 > 0)
  77. {
  78. if (tangent.Key == ConsoleKey.A)
  79. {
  80. x--;
  81. }
  82. else if (tangent.Key == ConsoleKey.D)
  83. {
  84. x++;
  85. }
  86. else if (tangent.Key == ConsoleKey.W)
  87. {
  88. y--;
  89. }
  90. else if (tangent.Key == ConsoleKey.S)
  91. {
  92. y++;
  93. }
  94. else if (tangent.Key == ConsoleKey.UpArrow)
  95. {
  96. y1--;
  97. }
  98. else if (tangent.Key == ConsoleKey.DownArrow)
  99. {
  100. y1++;
  101. }
  102. else if (tangent.Key == ConsoleKey.LeftArrow)
  103. {
  104. x1--;
  105. }
  106. else if (tangent.Key == ConsoleKey.RightArrow)
  107. {
  108. x1++;
  109. }
  110.  
  111. }
  112. else
  113. {
  114. }
  115. if (x == -1)
  116. {
  117. x = 0;
  118. }
  119. else if (y == -1)
  120. {
  121. y = 0;
  122. }
  123. else if (x == 80)
  124. {
  125. x = 79;
  126. }
  127. else if (y == 24)
  128. {
  129. y = 23;
  130. }
  131. else if (x1 == -1)
  132. {
  133. x1 = 0;
  134. }
  135. else if (y1 == -1)
  136. {
  137. y1 = 0;
  138. }
  139. else if (x1 == 80)
  140. {
  141. x1 = 79;
  142. }
  143. else if (y1 == 24)
  144. {
  145. y1 = 23;
  146. }
  147.  
  148. }
  149.  
  150. public static void Points()
  151. {
  152.  
  153. if (x == x1 && y == y1)
  154. {
  155.  
  156. x = 79;
  157. y = 23;
  158. x1 = 0;
  159. y1 = 0;
  160. point = 1;
  161. Console.WriteLine(point);
  162. }
  163.  
  164. }
  165.  
  166.  
  167.  
  168.  
  169. private static void Ritautspelaren()
  170. {
  171. Console.Clear();
  172. Console.SetCursorPosition(x, y);
  173. Console.ForegroundColor = ConsoleColor.Green;
  174. Console.Write(player);
  175. Console.ResetColor();
  176. }
  177.  
  178.  
  179. private static void Ritautenemy()
  180. {
  181. Console.SetCursorPosition(x1, y1);
  182. Console.ForegroundColor = ConsoleColor.Red;
  183. Console.WriteLine(enemy);
  184. Console.ResetColor();
  185.  
  186. }
  187.  
  188. private static void Ritautenvironment()
  189. {
  190. Console.ForegroundColor = ConsoleColor.Red;
  191. Console.SetCursorPosition(2, 0);
  192. Console.WriteLine("█");
  193. Console.SetCursorPosition(2, 1);
  194. Console.WriteLine("█");
  195. Console.SetCursorPosition(0, 2);
  196. Console.WriteLine("▀");
  197. Console.SetCursorPosition(1, 2);
  198. Console.WriteLine("▀");
  199. Console.SetCursorPosition(2, 2);
  200. Console.WriteLine("▀");
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213. }
  214. }
  215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement