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 = 10; //Vi kommer använda de här variablerna för att uppdatera spelarens verision
- public static int y = 10;
- public static int x1 = 0;
- public static int y1 = 0;
- public static Random rnd = new Random();
- //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 string enemy = ("E");
- public static ConsoleKeyInfo tangent;
- static void Main(string[] args)
- {
- Console.ForegroundColor = ConsoleColor.Yellow;
- Ritautspelaren();
- Ritautenemy();
- 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
- flyttaenemy();
- Ritautenemy();
- }
- }
- 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 (100 > 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 (tangent.Key == ConsoleKey.UpArrow)
- {
- y1--;
- }
- else if (tangent.Key == ConsoleKey.DownArrow)
- {
- y1++;
- }
- else if (tangent.Key == ConsoleKey.LeftArrow)
- {
- x1--;
- }
- else if (tangent.Key == ConsoleKey.RightArrow)
- {
- x1++;
- }
- }
- else
- {
- }
- if (x == -1)
- {
- x = 79;
- }
- else if (y == -1)
- {
- y = 24;
- }
- else if (x == 80)
- {
- x = 0;
- }
- else if (y == 25)
- {
- y = 0;
- }
- else if (x1 == -1)
- {
- x1 = 79;
- }
- else if (y1 == -1)
- {
- y1 = 24;
- }
- else if (x1 == 80)
- {
- x1 = 0;
- }
- else if (y1 == 25)
- {
- y1 = 0;
- }
- }
- private static void Ritautspelaren()
- {
- Console.Clear();
- Console.SetCursorPosition(x, y);
- Console.Write(player);
- }
- private static void flyttaenemy()
- {
- while (0 < 1)
- {
- int position = rnd.Next(1, 4);
- if (position == 1)
- {
- x1--;
- }
- else if (position == 2)
- {
- y1++;
- }
- else if (position == 3)
- {
- x1++;
- }
- else if (position == 4)
- {
- y1--;
- }
- }
- }
- private static void Ritautenemy()
- {
- Console.SetCursorPosition(x1, y1);
- Console.WriteLine(enemy);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement