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 = 77; //Vi kommer använda de här variablerna för att uppdatera spelarens verision
- public static int y = 22;
- public static int x1 = 2;
- public static int y1 = 2;
- 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)
- {
- Console.ForegroundColor = ConsoleColor.Yellow;
- Meny();
- while (0 < 100)
- {
- Map();
- Flyttaspelaren(); // här skriver jag en funktion för att flytta min spelare
- Attack();
- Ritautspelaren(); // här gör jag en funktion som ritar ut spelaren efter den har flyttats
- 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 = 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.Green;
- Console.SetCursorPosition(36, 8);
- Console.WriteLine("Welcome");
- Console.SetCursorPosition(31, 10);
- Console.WriteLine("Player 1: W,A,S,D");
- Console.SetCursorPosition(31, 11);
- Console.WriteLine("Player 2: Arrows");
- Console.ResetColor();
- Console.ForegroundColor = ConsoleColor.White;
- Console.SetCursorPosition(24, 14);
- Console.WriteLine("Press any button to start the game");
- Console.ReadKey();
- }
- public static void Map()
- {
- Console.SetCursorPosition(2, 2);
- Console.WriteLine("A");
- }
- public static void Attack()
- {
- if (x == x1 && y == y1)
- {
- x = 77;
- y = 22;
- x1 = 2;
- y1 = 2;
- 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();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement