Advertisement
saluxx

min kod

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