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 = 79; //Vi kommer använda de här variablerna för att uppdatera spelarens verision
- public static int y = 23;
- public static int x1 = 0;
- public static int y1 = 0;
- public static int x2 = 0;
- public static int y2 = 0;
- public static int point = 0;
- public static Random rnd = new Random();
- public static int position = rnd.Next(1, 4);
- //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 = ("☺");
- public static ConsoleKeyInfo tangent;
- static void Main(string[] args)
- {
- Meny();
- while (0 < 100)
- {
- Flyttaspelaren(); // här skriver jag en funktion för att flytta min spelare
- Points();
- Ritautspelaren(); // här gör jag en funktion som ritar ut spelaren efter den har flyttats
- Ritautenemy();
- Ritautenvironment();
- }
- }
- public static void Meny()
- {
- Console.SetCursorPosition(37, 7);
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("1 VS 1");
- Console.SetCursorPosition(30, 9);
- Console.WriteLine("Player one: W,S,A,D");
- Console.SetCursorPosition(30, 10);
- Console.WriteLine("Player two: Arrows");
- Console.ResetColor();
- Console.SetCursorPosition(23, 15);
- Console.WriteLine("Press any button to start the game");
- }
- 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 = 0;
- }
- else if (y == -1)
- {
- y = 0;
- }
- else if (x == 80)
- {
- x = 79;
- }
- else if (y == 24)
- {
- y = 23;
- }
- else if (x1 == -1)
- {
- x1 = 0;
- }
- else if (y1 == -1)
- {
- y1 = 0;
- }
- else if (x1 == 80)
- {
- x1 = 79;
- }
- else if (y1 == 24)
- {
- y1 = 23;
- }
- }
- public static void Points()
- {
- if (x == x1 && y == y1)
- {
- x = 79;
- y = 23;
- x1 = 0;
- y1 = 0;
- point = 1;
- Console.WriteLine(point);
- }
- }
- private static void Ritautspelaren()
- {
- Console.Clear();
- Console.SetCursorPosition(x, y);
- Console.ForegroundColor = ConsoleColor.Green;
- Console.Write(player);
- Console.ResetColor();
- }
- private static void Ritautenemy()
- {
- Console.SetCursorPosition(x1, y1);
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine(enemy);
- Console.ResetColor();
- }
- private static void Ritautenvironment()
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.SetCursorPosition(2, 0);
- Console.WriteLine("█");
- Console.SetCursorPosition(2, 1);
- Console.WriteLine("█");
- Console.SetCursorPosition(0, 2);
- Console.WriteLine("▀");
- Console.SetCursorPosition(1, 2);
- Console.WriteLine("▀");
- Console.SetCursorPosition(2, 2);
- Console.WriteLine("▀");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement