Advertisement
saluxx

Untitled

Sep 23rd, 2015
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 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. public static ConsoleKeyInfo tangent;
  18.  
  19. static void Main(string[] args)
  20. {
  21. Random r = new Random();
  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. Console.WriteLine(r.Next(1, 5));
  28. Console.WriteLine(r.Next(1, 5));
  29. Console.WriteLine(r.Next(1, 5));
  30. string number = Random;
  31. int move = Convert.ToInt32(number);
  32.  
  33.  
  34. }
  35. }
  36. public static void Flyttaspelaren()
  37. {
  38. tangent = Console.ReadKey();
  39.  
  40. // Här inne kommer jag ha koden för att flytta min spelare
  41. //För att kunna komma åt min position alltså mitt X och Y måste jag göra dessa public static
  42. if (x >= 0)
  43. {
  44. if (tangent.Key == ConsoleKey.D)
  45. {
  46. x--;
  47. }
  48. else if (tangent.Key == ConsoleKey.D)
  49. {
  50. x++;
  51. }
  52. else if (tangent.Key == ConsoleKey.W)
  53. {
  54. y--;
  55. }
  56. else if (tangent.Key == ConsoleKey.S)
  57. {
  58. y++;
  59. }
  60. }
  61. else
  62. {
  63. }
  64.  
  65. if (x == -1)
  66. {
  67. x = 1;
  68. }
  69. else if (y == -1)
  70. {
  71. y = 1;
  72. }
  73. else if (x == 80)
  74. {
  75. x = 79;
  76. }
  77. else if (y == 300)
  78. {
  79. y = 299;
  80. }
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87. }
  88.  
  89. private static void Ritautspelaren()
  90. {
  91. Console.Clear();
  92. Console.SetCursorPosition(x, y);
  93. Console.Write(player);
  94. Console.SetCursorPosition(0, 0);
  95. }
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120. }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement