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;
- using System.Threading;
- namespace MovePlayer
- {
- class Program
- {
- //Två int variabler som kan innehålla heltal.
- //Vi kommer att använda dessa för att uppdatera vår spelares position
- public static int x = 10;
- public static int y = 10;
- public static int x2 = 20;
- public static int y2 = 20;
- //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 = '☺';
- public static char enemy = 'E';
- public static ConsoleKeyInfo tangent;
- static void Main(string[] args)
- {
- Intro();
- Thread.Sleep(6000);
- RitaUtSpelaren();
- RitaUtFienden();
- while (0 < 100)
- {
- //Här väljer jag att skriva en funktion för att flytta min spelar.
- FlyttaSpelaren();
- //Här väljer jag att göra en funktion som ritar ut spelaren efter att den har flyttats.
- RitaUtSpelaren();
- RitaUtFienden();
- }
- }
- 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 (tangent.Key == ConsoleKey.LeftArrow && x > 0)
- {
- x--;
- }
- else if (tangent.Key == ConsoleKey.RightArrow && x < 79)
- {
- x++;
- }
- else if (tangent.Key == ConsoleKey.UpArrow && y > 0)
- {
- y--;
- }
- else if (tangent.Key == ConsoleKey.DownArrow && y < 24)
- {
- y++;
- }
- if (x == x2 && y == y2)
- {
- Console.Clear();
- Console.ReadKey();
- }
- }
- private static void RitaUtSpelaren()
- {
- Console.Clear();
- Console.SetCursorPosition(x, y);
- Console.Write(player);
- Console.SetCursorPosition(0, 0);
- }
- private static void RitaUtFienden()
- {
- Console.SetCursorPosition(x2, y2);
- Console.Write(enemy);
- Console.SetCursorPosition(0, 0);
- }
- public static void Intro()
- {
- Console.WriteLine(" Hello And Welcome To My Simple Game!");
- Thread.Sleep(2000);
- Console.WriteLine("");
- Console.WriteLine("");
- Console.WriteLine("The Game Is Easy To manouver.");
- Thread.Sleep(1500);
- Console.WriteLine("You move the character using the following!");
- Thread.Sleep(2500);
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Go left by using the left arrow key! <--");
- Console.WriteLine("");
- Console.WriteLine("Go right by using the riht arrow key! -->");
- Console.WriteLine("");
- Console.WriteLine("Go down by using the down arrow key!");
- Console.WriteLine("");
- Console.WriteLine("Go up by using the up arrow key!");
- Console.WriteLine("");
- Console.ForegroundColor = ConsoleColor.White;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement