Advertisement
allerost

Veri bad snake 2.0

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