Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication12
- {
- class Program
- {
- public static int x = 0; //Vi kommer använda de här variablerna för att uppdatera spelarens verision
- public static int y = 0;
- public static int x1 = 10;
- public static int y1 = 10;
- //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.
- public static char player = 'A';
- public static char enemy = 'E';
- public static ConsoleKeyInfo tangent;
- static void Main(string[] args)
- {
- Ritautspelaren();
- while (0 < 100)
- {
- Flyttaspelaren(); // här skriver jag en funktion för att flytta min spelare
- Ritautspelaren(); // här gör jag en funktion som ritar ut spelaren efter den har flyttats
- }
- }
- public static void Flyttaspelaren()
- {
- tangent = Console.ReadKey();
- // Här inne kommer jag ha koden för att flytta min spelare
- //För att kunna komma åt min position alltså mitt X och Y måste jag göra dessa public static
- if (x >= 0)
- {
- if (tangent.Key == ConsoleKey.A)
- {
- x--;
- }
- else if (tangent.Key == ConsoleKey.D)
- {
- x++;
- }
- else if (tangent.Key == ConsoleKey.W)
- {
- y--;
- }
- else if (tangent.Key == ConsoleKey.S)
- {
- y++;
- }
- }
- else
- {
- }
- if (x == -1)
- {
- x = 1;
- }
- else if (y == -1)
- {
- y = 1;
- }
- else if (x == 80)
- {
- x = 79;
- }
- else if (y == 300)
- {
- y = 299;
- }
- }
- private static void Ritautspelaren()
- {
- Console.Clear();
- Console.SetCursorPosition(x, y);
- Console.Write(player);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement