Advertisement
saluxx

FIxed walls

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