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 = 2; //Vi kommer använda de här variablerna för att uppdatera spelarens verision
- public static int y = 2;
- //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 string player = ("☺");
- public static ConsoleKeyInfo tangent;
- static void Main(string[] args)
- {
- Console.ForegroundColor = ConsoleColor.Yellow;
- Ritautspelaren();
- Map();
- 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
- Map();
- }
- }
- 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 == 0)
- {
- x = 1;
- }
- else if (y == 0)
- {
- y = 1;
- }
- else if (x == 79)
- {
- x = 78;
- }
- else if (y == 24)
- {
- y = 23;
- }
- }
- public static void Map()
- {
- Console.SetCursorPosition(0, 0);
- for (int i = 0; i < 80; i++)
- {
- Console.Write("█");
- }
- Console.SetCursorPosition(0, 1);
- for (int i = 0; i < 23; i++)
- {
- Console.WriteLine("█");
- }
- Console.SetCursorPosition(0, 24);
- for (int i = 0; i < 79; i++)
- {
- Console.Write("█");
- }
- Console.SetCursorPosition(79, 1);
- Console.WriteLine("█");
- Console.SetCursorPosition(79, 2);
- Console.WriteLine("█");
- Console.SetCursorPosition(79, 3);
- Console.WriteLine("█");
- Console.SetCursorPosition(79, 4);
- Console.WriteLine("█");
- Console.SetCursorPosition(79, 5);
- Console.WriteLine("█");
- Console.SetCursorPosition(79, 6);
- Console.WriteLine("█");
- Console.SetCursorPosition(79, 7);
- Console.WriteLine("█");
- Console.SetCursorPosition(79, 8);
- Console.WriteLine("█");
- Console.SetCursorPosition(79, 9);
- Console.WriteLine("█");
- Console.SetCursorPosition(79, 10);
- Console.WriteLine("█");
- Console.SetCursorPosition(79, 11);
- Console.WriteLine("█");
- Console.SetCursorPosition(79, 12);
- Console.WriteLine("█");
- Console.SetCursorPosition(79, 13);
- Console.WriteLine("█");
- Console.SetCursorPosition(79, 14);
- Console.WriteLine("█");
- Console.SetCursorPosition(79, 15);
- Console.WriteLine("█");
- Console.SetCursorPosition(79, 16);
- Console.WriteLine("█");
- Console.SetCursorPosition(79, 17);
- Console.WriteLine("█");
- Console.SetCursorPosition(79, 18);
- Console.WriteLine("█");
- Console.SetCursorPosition(79, 19);
- Console.WriteLine("█");
- Console.SetCursorPosition(79, 20);
- Console.WriteLine("█");
- Console.SetCursorPosition(79, 21);
- Console.WriteLine("█");
- Console.SetCursorPosition(79, 22);
- Console.WriteLine("█");
- Console.SetCursorPosition(79, 23);
- Console.Write("█");
- }
- private static void Ritautspelaren()
- {
- Console.Clear();
- Console.SetCursorPosition(x, y);
- Console.Write(player);
- Console.SetCursorPosition(0, 0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement