Advertisement
saluxx

Untitled

Sep 16th, 2015
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 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. public static void Flyttaspelaren()
  30. {
  31. tangent = Console.ReadKey();
  32.  
  33. // Här inne kommer jag ha koden för att flytta min spelare
  34. //För att kunna komma åt min position alltså mitt X och Y måste jag göra dessa public static
  35. if (x >= 0)
  36. {
  37. if (tangent.Key == ConsoleKey.A)
  38. {
  39. x--;
  40. }
  41. else if (tangent.Key == ConsoleKey.D)
  42. {
  43. x++;
  44. }
  45. else if (tangent.Key == ConsoleKey.W)
  46. {
  47. y--;
  48. }
  49. else if (tangent.Key == ConsoleKey.S)
  50. {
  51. y++;
  52. }
  53. else if (tangent.Key == ConsoleKey.R)
  54. {
  55. Console.ForegroundColor = ConsoleColor.Red;
  56. }
  57.  
  58. }
  59. else
  60. {
  61.  
  62. }
  63.  
  64. }
  65.  
  66. private static void Ritautspelaren()
  67. {
  68. Console.Clear();
  69. Console.SetCursorPosition(x, y);
  70. Console.Write(player);
  71. }
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement