Advertisement
allerost

Hero Tale 2.2

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