Advertisement
allerost

Hero Tale 2.1

Sep 22nd, 2015
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.73 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. using System.Threading;
  7.  
  8. namespace HeroGames
  9. {
  10. class Program
  11. {
  12. public static int introSpeed = 0;
  13. public static int points = 0;
  14. //Två int variabler som kan innehålla heltal.
  15. //Vi kommer att använda dessa för att uppdatera vår spelares position
  16. public static int x = 10;
  17. public static int y = 10;
  18. public static int x2 = 38;
  19. public static int y2 = 15;
  20. public static int kills = 0;
  21. //public static int x2 = 20;
  22. //public static int y2 = 20;
  23. //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.
  24. public static char player = '☺';
  25. public static Random random = new Random();
  26.  
  27. public static ConsoleKeyInfo tangent;
  28.  
  29. static void Main(string[] args)
  30. {
  31. Enemy bob = new Enemy(20, 20);
  32.  
  33.  
  34. do
  35. {
  36. points++;
  37. } while (bob.alive == false);
  38.  
  39.  
  40. Intro();
  41. Thread.Sleep(5000);
  42.  
  43.  
  44. RitaUtSpelaren();
  45. bob.RitaUtFienden();
  46.  
  47. while (true)
  48. {
  49. //Här väljer jag att skriva en funktion för att flytta min spelar.
  50.  
  51.  
  52. if (10 == 10)
  53. {
  54. if (points >= 400)
  55. {
  56. Console.ForegroundColor = ConsoleColor.Red;
  57. }
  58.  
  59. Console.SetCursorPosition(55, 0);
  60.  
  61. Console.Write("Steps taken : {0}" , points);
  62. Console.SetCursorPosition(0, 0);
  63.  
  64. }
  65. Console.ForegroundColor = ConsoleColor.White;
  66. FlyttaSpelaren();
  67. Points(bob);
  68. if (points == 500)
  69. {
  70. Console.ForegroundColor = ConsoleColor.Red;
  71. Console.WriteLine(" GAME OVER!");
  72. Console.WriteLine(" You have done your 500 moves.");
  73. Console.ForegroundColor = ConsoleColor.Green;
  74. Console.WriteLine(" Total amout of bob's killed are: {0}!",kills);
  75. Thread.Sleep(5000);
  76.  
  77.  
  78. break;
  79. }
  80. //kollar om bob är död
  81. CheckCollision(bob);
  82.  
  83. //om bob är död
  84. if (!bob.alive)
  85. {
  86. //pausa spelet och informera spelarn
  87. Console.ForegroundColor = ConsoleColor.Green;
  88. Console.WriteLine(" You've killed Bob!");
  89. Console.ForegroundColor = ConsoleColor.White;
  90. Thread.Sleep(500);
  91. Console.Clear();
  92. kills++;
  93. bob = new Enemy(random.Next(0, 78), random.Next(0, 24));
  94.  
  95.  
  96.  
  97. }
  98. //om bob inte är död
  99. //rita ut dom igen
  100. RitaUtSpelaren();
  101. bob.RitaUtFienden();
  102. }
  103. }
  104. public static void FlyttaSpelaren()
  105. {
  106. tangent = Console.ReadKey();
  107. //Här inne kommer jag ha koden för att flytta min spelare
  108. //För att kunna komma åt min position alltså mitt X och Y måste jag göra dessa public static
  109. if (tangent.Key == ConsoleKey.LeftArrow && x > 0)
  110. {
  111. x--;
  112. }
  113. else if (tangent.Key == ConsoleKey.RightArrow && x < 79)
  114. {
  115. x++;
  116. }
  117. else if (tangent.Key == ConsoleKey.UpArrow && y > 0)
  118. {
  119. y--;
  120. }
  121. else if (tangent.Key == ConsoleKey.DownArrow && y < 24)
  122. {
  123. y++;
  124. }
  125. }
  126. public static void CheckCollision(Enemy e)
  127. {
  128. if (x == e.x && y == e.y)
  129. e.alive = false;
  130. }
  131. private static void RitaUtSpelaren()
  132. {
  133. Console.Clear();
  134. Console.SetCursorPosition(5, 5);
  135. Console.SetCursorPosition(x, y);
  136. Console.Write(player);
  137. Console.SetCursorPosition(0, 0);
  138. }
  139. public static void Points(Enemy e)
  140. {
  141. points++;
  142. }
  143.  
  144. public static void Intro()
  145. {
  146. Console.WriteLine(" Hello And Welcome To My Simple Game!");
  147. Thread.Sleep(introSpeed);
  148. Console.WriteLine("");
  149. Console.WriteLine("");
  150. Console.WriteLine("The Game Is Easy To manouver.");
  151. Thread.Sleep(introSpeed);
  152. Console.WriteLine("You move the character using the following!");
  153. Thread.Sleep(introSpeed);
  154. Console.ForegroundColor = ConsoleColor.Green;
  155. Console.WriteLine("Go left by using the left arrow key! <--");
  156. Console.WriteLine("");
  157. Console.WriteLine("Go right by using the riht arrow key! -->");
  158. Console.WriteLine("");
  159. Console.WriteLine("Go down by using the down arrow key!");
  160. Console.WriteLine("");
  161. Console.WriteLine("Go up by using the up arrow key!");
  162. Console.WriteLine("");
  163. Console.ForegroundColor = ConsoleColor.White;
  164. Console.WriteLine(" You have 500 moves to kills as many bobs as you can!");
  165. Console.WriteLine(" Best Of Luck!");
  166. }
  167. }
  168. }
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188. using System;
  189. using System.Collections.Generic;
  190. using System.Linq;
  191. using System.Text;
  192. using System.Threading.Tasks;
  193.  
  194. namespace HeroGames
  195. {
  196. class Enemy
  197. {
  198. char picture = 'E';
  199. int health;
  200. public int x;
  201. public int y;
  202. public bool alive = true;
  203.  
  204.  
  205. public Enemy(int X, int Y)
  206. {
  207. x = X;
  208. y = Y;
  209. }
  210. public Enemy(int X, int Y, int Health)
  211. {
  212. x = X;
  213. y = Y;
  214. health = Health;
  215. }
  216.  
  217. public void Walk()
  218. {
  219.  
  220. }
  221. public void Attack()
  222. {
  223.  
  224. }
  225. public void Die()
  226. {
  227.  
  228. }
  229. public void RitaUtFienden()
  230. {
  231. if (alive)
  232. {
  233. Console.SetCursorPosition(x, y);
  234. Console.Write(picture);
  235. Console.SetCursorPosition(0, 0);
  236. }
  237. }
  238. }
  239. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement