Advertisement
saluxx

idk

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