Advertisement
saluxx

Fixat Spel

Oct 7th, 2015
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.25 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 = 76; //Vi kommer använda de här variablerna för att uppdatera spelarens verision
  12. public static int y = 21;
  13. public static int x1 = 3;
  14. public static int y1 = 3;
  15. public static int P = 0;
  16. public static int P1 = 0;
  17. public static int point = 0;
  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. public static string player = ("☺");
  22. public static string enemy = ("☺");
  23.  
  24. public static ConsoleKeyInfo tangent;
  25. static void Main(string[] args)
  26. {
  27. Meny();
  28. while (0 < 100)
  29. {
  30. Flyttaspelaren(); // här skriver jag en funktion för att flytta min spelare
  31. Attack();
  32. Points();
  33. Ritautspelaren();
  34. Ritautenemy();
  35. Map();
  36. Victory();
  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.LeftArrow)
  49. {
  50. x--;
  51. }
  52. else if (tangent.Key == ConsoleKey.RightArrow)
  53. {
  54. x++;
  55. }
  56. else if (tangent.Key == ConsoleKey.UpArrow)
  57. {
  58. y--;
  59. }
  60. else if (tangent.Key == ConsoleKey.DownArrow)
  61. {
  62. y++;
  63. }
  64. else if (tangent.Key == ConsoleKey.W)
  65. {
  66. y1--;
  67. }
  68. else if (tangent.Key == ConsoleKey.S)
  69. {
  70. y1++;
  71. }
  72. else if (tangent.Key == ConsoleKey.A)
  73. {
  74. x1--;
  75. }
  76. else if (tangent.Key == ConsoleKey.D)
  77. {
  78. x1++;
  79. }
  80. }
  81. else
  82. {
  83. }
  84. if (x == 1)
  85. {
  86. x = 2;
  87. }
  88. else if (y == 1)
  89. {
  90. y = 2;
  91. }
  92. else if (x == 78)
  93. {
  94. x = 77;
  95. }
  96. else if (y == 23)
  97. {
  98. y = 22;
  99. }
  100. else if (x1 == 1)
  101. {
  102. x1 = 2;
  103. }
  104. else if (y1 == 1)
  105. {
  106. y1 = 2;
  107. }
  108. else if (x1 == 78)
  109. {
  110. x1 = 77;
  111. }
  112. else if (y1 == 23)
  113. {
  114. y1 = 22;
  115. }
  116.  
  117. }
  118.  
  119. public static void Meny()
  120. {
  121. Console.ForegroundColor = ConsoleColor.Yellow;
  122. Console.SetCursorPosition(36, 8);
  123. Console.WriteLine("Welcome");
  124. Console.SetCursorPosition(31, 10);
  125. Console.ForegroundColor = ConsoleColor.Red;
  126. Console.WriteLine("Player 1: W,A,S,D");
  127. Console.SetCursorPosition(31, 11);
  128. Console.ForegroundColor = ConsoleColor.Green;
  129. Console.WriteLine("Player 2: Arrows");
  130. Console.ResetColor();
  131. Console.ForegroundColor = ConsoleColor.White;
  132. Console.SetCursorPosition(20, 13);
  133. Console.WriteLine("Get into the enemies base to get 1 point");
  134. Console.SetCursorPosition(29, 14);
  135. Console.WriteLine("First to 3 points win");
  136. Console.ResetColor();
  137. Console.SetCursorPosition(23, 17);
  138. Console.WriteLine("Press any button to start the game");
  139. }
  140.  
  141. public static void Map()
  142. {
  143. Console.ForegroundColor = ConsoleColor.Red;
  144. Console.SetCursorPosition(2, 2);
  145. Console.WriteLine("⌂");
  146. Console.ForegroundColor = ConsoleColor.Green;
  147. Console.SetCursorPosition(77, 22);
  148. Console.WriteLine("⌂");
  149. Console.SetCursorPosition(78, 24);
  150. Console.WriteLine(P);
  151. Console.SetCursorPosition(0, 0);
  152. Console.ForegroundColor = ConsoleColor.Red;
  153. Console.WriteLine(P1);
  154. Console.ResetColor();
  155. }
  156.  
  157. public static void Attack()
  158. {
  159. if (x == x1 && y == y1)
  160. {
  161.  
  162. x = 76;
  163. y = 21;
  164. x1 = 2;
  165. y1 = 2;
  166. point = 1;
  167. Console.WriteLine(point);
  168. }
  169.  
  170. }
  171.  
  172. public static void Points()
  173. {
  174. if (x == 2 && y == 2)
  175. {
  176. P++;
  177. x = 76;
  178. y = 21;
  179. x1 = 3;
  180. y1 = 3;
  181. }
  182. else if (x1 == 77 && y1 == 22)
  183. {
  184. P1++;
  185. x1 = 3;
  186. y1 = 3;
  187. x = 76;
  188. y = 21;
  189. }
  190. else if (x1 == 2 && y1 == 2)
  191. {
  192. x1 = 3;
  193. y1 = 3;
  194. }
  195. else if (x == 77 && y == 22)
  196. {
  197. x = 76;
  198. y = 21;
  199. }
  200.  
  201. }
  202.  
  203. public static void Victory()
  204. {
  205. if (P1 == 3)
  206. {
  207. Console.Clear();
  208. Console.SetCursorPosition(33, 10);
  209. Console.ForegroundColor = ConsoleColor.Red;
  210. Console.WriteLine("Red Player Won");
  211. Console.ResetColor();
  212. Console.SetCursorPosition(19, 14);
  213. System.Environment.Exit(1);
  214. }
  215. if (P == 3)
  216. {
  217. Console.Clear();
  218. Console.SetCursorPosition(32, 10);
  219. Console.ForegroundColor = ConsoleColor.Green;
  220. Console.WriteLine("Green Player Won");
  221. Console.ResetColor();
  222. Console.SetCursorPosition(19, 14);
  223. System.Environment.Exit(1);
  224. }
  225. }
  226.  
  227. private static void Ritautspelaren()
  228. {
  229. Console.Clear();
  230. Console.SetCursorPosition(x, y);
  231. Console.ForegroundColor = ConsoleColor.Green;
  232. Console.Write(player);
  233. Console.ResetColor();
  234. }
  235.  
  236. private static void Ritautenemy()
  237. {
  238. Console.SetCursorPosition(x1, y1);
  239. Console.ForegroundColor = ConsoleColor.Red;
  240. Console.WriteLine(enemy);
  241. Console.ResetColor();
  242. }
  243. }
  244. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement