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 = 76; //Vi kommer använda de här variablerna för att uppdatera spelarens verision
- public static int y = 21;
- public static int x1 = 3;
- public static int y1 = 3;
- public static int P = 0;
- public static int P1 = 0;
- public static int point = 0;
- //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
- Attack();
- Points();
- Ritautspelaren();
- Ritautenemy();
- Map();
- Victory();
- }
- }
- 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.LeftArrow)
- {
- x--;
- }
- else if (tangent.Key == ConsoleKey.RightArrow)
- {
- x++;
- }
- else if (tangent.Key == ConsoleKey.UpArrow)
- {
- y--;
- }
- else if (tangent.Key == ConsoleKey.DownArrow)
- {
- y++;
- }
- else if (tangent.Key == ConsoleKey.W)
- {
- y1--;
- }
- else if (tangent.Key == ConsoleKey.S)
- {
- y1++;
- }
- else if (tangent.Key == ConsoleKey.A)
- {
- x1--;
- }
- else if (tangent.Key == ConsoleKey.D)
- {
- x1++;
- }
- }
- else
- {
- }
- if (x == 1)
- {
- x = 2;
- }
- else if (y == 1)
- {
- y = 2;
- }
- else if (x == 78)
- {
- x = 77;
- }
- else if (y == 23)
- {
- y = 22;
- }
- else if (x1 == 1)
- {
- x1 = 2;
- }
- else if (y1 == 1)
- {
- y1 = 2;
- }
- else if (x1 == 78)
- {
- x1 = 77;
- }
- else if (y1 == 23)
- {
- y1 = 22;
- }
- }
- public static void Meny()
- {
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.SetCursorPosition(36, 8);
- Console.WriteLine("Welcome");
- Console.SetCursorPosition(31, 10);
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Player 1: W,A,S,D");
- Console.SetCursorPosition(31, 11);
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Player 2: Arrows");
- Console.ResetColor();
- Console.ForegroundColor = ConsoleColor.White;
- Console.SetCursorPosition(20, 13);
- Console.WriteLine("Get into the enemies base to get 1 point");
- Console.SetCursorPosition(29, 14);
- Console.WriteLine("First to 3 points win");
- Console.ResetColor();
- Console.SetCursorPosition(23, 17);
- Console.WriteLine("Press any button to start the game");
- }
- public static void Map()
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.SetCursorPosition(2, 2);
- Console.WriteLine("⌂");
- Console.ForegroundColor = ConsoleColor.Green;
- Console.SetCursorPosition(77, 22);
- Console.WriteLine("⌂");
- Console.SetCursorPosition(78, 24);
- Console.WriteLine(P);
- Console.SetCursorPosition(0, 0);
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine(P1);
- Console.ResetColor();
- }
- public static void Attack()
- {
- if (x == x1 && y == y1)
- {
- x = 76;
- y = 21;
- x1 = 2;
- y1 = 2;
- point = 1;
- Console.WriteLine(point);
- }
- }
- public static void Points()
- {
- if (x == 2 && y == 2)
- {
- P++;
- x = 76;
- y = 21;
- x1 = 3;
- y1 = 3;
- }
- else if (x1 == 77 && y1 == 22)
- {
- P1++;
- x1 = 3;
- y1 = 3;
- x = 76;
- y = 21;
- }
- else if (x1 == 2 && y1 == 2)
- {
- x1 = 3;
- y1 = 3;
- }
- else if (x == 77 && y == 22)
- {
- x = 76;
- y = 21;
- }
- }
- public static void Victory()
- {
- if (P1 == 3)
- {
- Console.Clear();
- Console.SetCursorPosition(33, 10);
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Red Player Won");
- Console.ResetColor();
- Console.SetCursorPosition(19, 14);
- System.Environment.Exit(1);
- }
- if (P == 3)
- {
- Console.Clear();
- Console.SetCursorPosition(32, 10);
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Green Player Won");
- Console.ResetColor();
- Console.SetCursorPosition(19, 14);
- System.Environment.Exit(1);
- }
- }
- 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();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement