Advertisement
saluxx

Fungerande spel

Sep 30th, 2015
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 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.  
  7. namespace ConsoleApplication12
  8. {
  9. class Program
  10. {
  11. public static int x = 10; //Vi kommer använda de här variablerna för att uppdatera spelarens verision
  12. public static int y = 10;
  13. public static int x1 = 0;
  14. public static int y1 = 0;
  15. public static Random rnd = new Random();
  16. public static int position = rnd.Next(1, 4);
  17.  
  18. //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.
  19.  
  20.  
  21. public static string player = ("☺");
  22. public static string enemy = ("E");
  23.  
  24.  
  25. public static ConsoleKeyInfo tangent;
  26.  
  27. static void Main(string[] args)
  28. {
  29. Console.ForegroundColor = ConsoleColor.Yellow;
  30. Ritautspelaren();
  31. Ritautenemy();
  32. while (0 < 100)
  33. {
  34. Flyttaspelaren(); // här skriver jag en funktion för att flytta min spelare
  35. Ritautspelaren(); // här gör jag en funktion som ritar ut spelaren efter den har flyttats
  36. Ritautenemy();
  37.  
  38. }
  39. }
  40. public static void Flyttaspelaren()
  41. {
  42. tangent = Console.ReadKey();
  43.  
  44. // Här inne kommer jag ha koden för att flytta min spelare
  45. //För att kunna komma åt min position alltså mitt X och Y måste jag göra dessa public static
  46. if (100 > 0)
  47. {
  48. if (tangent.Key == ConsoleKey.A)
  49. {
  50. x--;
  51. }
  52. else if (tangent.Key == ConsoleKey.D)
  53. {
  54. x++;
  55. }
  56. else if (tangent.Key == ConsoleKey.W)
  57. {
  58. y--;
  59. }
  60. else if (tangent.Key == ConsoleKey.S)
  61. {
  62. y++;
  63. }
  64. else if (tangent.Key == ConsoleKey.UpArrow)
  65. {
  66. y1--;
  67. }
  68. else if (tangent.Key == ConsoleKey.DownArrow)
  69. {
  70. y1++;
  71. }
  72. else if (tangent.Key == ConsoleKey.LeftArrow)
  73. {
  74. x1--;
  75. }
  76. else if (tangent.Key == ConsoleKey.RightArrow)
  77. {
  78. x1++;
  79. }
  80.  
  81. }
  82. else
  83. {
  84. }
  85. if (x == -1)
  86. {
  87. x = 79;
  88. }
  89. else if (y == -1)
  90. {
  91. y = 24;
  92. }
  93. else if (x == 80)
  94. {
  95. x = 0;
  96. }
  97. else if (y == 25)
  98. {
  99. y = 0;
  100. }
  101. else if (x1 == -1)
  102. {
  103. x1 = 79;
  104. }
  105. else if (y1 == -1)
  106. {
  107. y1 = 24;
  108. }
  109. else if (x1 == 80)
  110. {
  111. x1 = 0;
  112. }
  113. else if (y1 == 25)
  114. {
  115. y1 = 0;
  116. }
  117.  
  118. }
  119. private static void Ritautspelaren()
  120. {
  121. Console.Clear();
  122. Console.SetCursorPosition(x, y);
  123. Console.Write(player);
  124. }
  125.  
  126.  
  127. private static void Ritautenemy()
  128. {
  129. Console.SetCursorPosition(x1, y1);
  130. Console.WriteLine(enemy);
  131. }
  132. }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement