Advertisement
allerost

Accualy working programm

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