Advertisement
allerost

Hero Tale 2.0

Sep 19th, 2015
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.35 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 x2 = 20;
  21. //public static int y2 = 20;
  22. //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.
  23. public static char player = '☺';
  24. public static Random random = new Random();
  25.  
  26. public static ConsoleKeyInfo tangent;
  27.  
  28. static void Main(string[] args)
  29. {
  30. Enemy bob = new Enemy(20, 20);
  31.  
  32. do
  33. {
  34. points++;
  35. } while (bob.alive == false);
  36.  
  37. Intro();
  38. Thread.Sleep(5000);
  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. FlyttaSpelaren();
  47. Points(bob);
  48.  
  49. CheckCollision(bob);
  50.  
  51. //om bob är död
  52. if (!bob.alive)
  53. {
  54. //pausa spelet och informera spelarn
  55. Console.ForegroundColor = ConsoleColor.Green;
  56. Console.WriteLine(" You've killed Bob!");
  57. Console.ForegroundColor = ConsoleColor.White;
  58. Thread.Sleep(500);
  59. Console.Clear();
  60.  
  61. bob = new Enemy(random.Next(0, 78), random.Next(0, 24));
  62. }
  63.  
  64. //rita
  65. RitaUtSpelaren();
  66. bob.RitaUtFienden();
  67. }
  68. }
  69. public static void FlyttaSpelaren()
  70. {
  71. tangent = Console.ReadKey();
  72. //Här inne kommer jag ha koden för att flytta min spelare
  73. //För att kunna komma åt min position alltså mitt X och Y måste jag göra dessa public static
  74. if (tangent.Key == ConsoleKey.LeftArrow && x > 0)
  75. {
  76. x--;
  77. }
  78. else if (tangent.Key == ConsoleKey.RightArrow && x < 79)
  79. {
  80. x++;
  81. }
  82. else if (tangent.Key == ConsoleKey.UpArrow && y > 0)
  83. {
  84. y--;
  85. }
  86. else if (tangent.Key == ConsoleKey.DownArrow && y < 24)
  87. {
  88. y++;
  89. }
  90. }
  91. public static void CheckCollision(Enemy e)
  92. {
  93. if (x == e.x && y == e.y)
  94. e.alive = false;
  95. }
  96. private static void RitaUtSpelaren()
  97. {
  98. Console.Clear();
  99. Console.SetCursorPosition(5, 5);
  100. Console.Write(points);
  101. Console.SetCursorPosition(x, y);
  102. Console.Write(player);
  103. Console.SetCursorPosition(0, 0);
  104. }
  105. public static void Points(Enemy e)
  106. {
  107. points++;
  108. }
  109. public static void Intro()
  110. {
  111. Console.WriteLine(" Hello And Welcome To My Simple Game!");
  112. Thread.Sleep(introSpeed);
  113. Console.WriteLine("");
  114. Console.WriteLine("");
  115. Console.WriteLine("The Game Is Easy To manouver.");
  116. Thread.Sleep(introSpeed);
  117. Console.WriteLine("You move the character using the following!");
  118. Thread.Sleep(introSpeed);
  119. Console.ForegroundColor = ConsoleColor.Green;
  120. Console.WriteLine("Go left by using the left arrow key! <--");
  121. Console.WriteLine("");
  122. Console.WriteLine("Go right by using the riht arrow key! -->");
  123. Console.WriteLine("");
  124. Console.WriteLine("Go down by using the down arrow key!");
  125. Console.WriteLine("");
  126. Console.WriteLine("Go up by using the up arrow key!");
  127. Console.WriteLine("");
  128. Console.ForegroundColor = ConsoleColor.White;
  129. }
  130. }
  131. }
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140. using System;
  141. using System.Collections.Generic;
  142. using System.Linq;
  143. using System.Text;
  144. using System.Threading.Tasks;
  145.  
  146. namespace HeroGames
  147. {
  148. class Enemy
  149. {
  150. char picture = 'E';
  151. int health;
  152. public int x;
  153. public int y;
  154. public bool alive = true;
  155.  
  156.  
  157. public Enemy(int X, int Y)
  158. {
  159. x = X;
  160. y = Y;
  161. }
  162. public Enemy(int X, int Y, int Health)
  163. {
  164. x = X;
  165. y = Y;
  166. health = Health;
  167. }
  168.  
  169. public void Walk()
  170. {
  171.  
  172. }
  173. public void Attack()
  174. {
  175.  
  176. }
  177. public void Die()
  178. {
  179.  
  180. }
  181. public void RitaUtFienden()
  182. {
  183. if (alive)
  184. {
  185. Console.SetCursorPosition(x, y);
  186. Console.Write(picture);
  187. Console.SetCursorPosition(0, 0);
  188. }
  189. }
  190. }
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement