Advertisement
saluxx

New gmae

Sep 16th, 2015
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 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. else if (x == -1)
  55. {
  56. x = 0;
  57. }
  58. else if (y == -1)
  59. {
  60. y = 0;
  61. }
  62.  
  63.  
  64.  
  65.  
  66. else if (tangent.Key == ConsoleKey.R)
  67. {
  68. Console.ForegroundColor = ConsoleColor.Red;
  69. }
  70.  
  71. }
  72. else
  73. {
  74.  
  75. }
  76.  
  77. }
  78.  
  79. private static void Ritautspelaren()
  80. {
  81. Console.Clear();
  82. Console.SetCursorPosition(x, y);
  83. Console.Write(player);
  84. }
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109. }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement