Advertisement
saluxx

Fixat lite mer

Oct 6th, 2015
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 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 = 77; //Vi kommer använda de här variablerna för att uppdatera spelarens verision
  12. public static int y = 22;
  13. public static int x1 = 2;
  14. public static int y1 = 2;
  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. static void Main(string[] args)
  28. {
  29. Console.ForegroundColor = ConsoleColor.Yellow;
  30. Meny();
  31. while (0 < 100)
  32. {
  33. Map();
  34. Flyttaspelaren(); // här skriver jag en funktion för att flytta min spelare
  35. Attack();
  36. Ritautspelaren(); // här gör jag en funktion som ritar ut spelaren efter den har flyttats
  37. Ritautenemy();
  38.  
  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 = 2;
  91. }
  92. else if (y == 1)
  93. {
  94. y = 2;
  95. }
  96. else if (x == 78)
  97. {
  98. x = 77;
  99. }
  100. else if (y == 23)
  101. {
  102. y = 22;
  103. }
  104. else if (x1 == 1)
  105. {
  106. x1 = 2;
  107. }
  108. else if (y1 == 1)
  109. {
  110. y1 = 2;
  111. }
  112. else if (x1 == 78)
  113. {
  114. x1 = 77;
  115. }
  116. else if (y1 == 23)
  117. {
  118. y1 = 22;
  119. }
  120.  
  121. }
  122.  
  123. public static void Meny()
  124. {
  125. Console.ForegroundColor = ConsoleColor.Green;
  126. Console.SetCursorPosition(36, 8);
  127. Console.WriteLine("Welcome");
  128. Console.SetCursorPosition(31, 10);
  129. Console.WriteLine("Player 1: W,A,S,D");
  130. Console.SetCursorPosition(31, 11);
  131. Console.WriteLine("Player 2: Arrows");
  132. Console.ResetColor();
  133. Console.ForegroundColor = ConsoleColor.White;
  134. Console.SetCursorPosition(24, 14);
  135. Console.WriteLine("Press any button to start the game");
  136. Console.ReadKey();
  137. }
  138.  
  139. public static void Map()
  140. {
  141. Console.SetCursorPosition(2, 2);
  142. Console.WriteLine("A");
  143. }
  144.  
  145. public static void Attack()
  146. {
  147.  
  148. if (x == x1 && y == y1)
  149. {
  150.  
  151. x = 77;
  152. y = 22;
  153. x1 = 2;
  154. y1 = 2;
  155. point = 1;
  156. Console.WriteLine(point);
  157. }
  158.  
  159. }
  160. private static void Ritautspelaren()
  161. {
  162. Console.Clear();
  163. Console.SetCursorPosition(x, y);
  164. Console.ForegroundColor = ConsoleColor.Green;
  165. Console.Write(player);
  166. Console.ResetColor();
  167. }
  168.  
  169.  
  170. private static void Ritautenemy()
  171. {
  172. Console.SetCursorPosition(x1, y1);
  173. Console.ForegroundColor = ConsoleColor.Red;
  174. Console.WriteLine(enemy);
  175. Console.ResetColor();
  176.  
  177.  
  178. }
  179. }
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement