Created
October 4, 2020 17:00
-
-
Save hafsasheik/c496d9678021f28b706631bef32e2bae to your computer and use it in GitHub Desktop.
kaoz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| using System.Media; | |
| using System.Security.Cryptography; | |
| using System.Net; | |
| namespace speltest | |
| { | |
| class Program | |
| { | |
| public static Player2 currentPlayer = new Player2(); | |
| static void Main(string[] args) | |
| { | |
| Game currentGame = new Game(); | |
| currentGame.Start(); | |
| } | |
| } | |
| class Player2 | |
| { | |
| public string name; | |
| public int coins = 0; | |
| public int health = 10; | |
| public int damage = 1; | |
| public int armorValue = 0; | |
| public int potion = 5; | |
| public int wepValue = 1; | |
| } | |
| class Healingpotion // // // // // // // hej | |
| { | |
| private World MyWorld; | |
| private Player CurrentPlayer; | |
| public int HealingX { get; set; } | |
| public int HealingY { get; set; } | |
| public string HealingPotion; | |
| public ConsoleColor PotionColor; | |
| public int Healing = 10; | |
| public Healingpotion(int x, int y) // konstruktor | |
| { | |
| HealingX = x; | |
| HealingY = y; | |
| HealingPotion = "@ "; | |
| PotionColor = ConsoleColor.Red; | |
| } | |
| public void SetHealingPotiononScreen(Random random, out int HealingX, out int HealingY) // metod 1 | |
| { | |
| HealingX = random.Next(1, 20); | |
| HealingY = random.Next(1, 20); | |
| Console.SetCursorPosition(HealingX, HealingY); | |
| Console.ForegroundColor = PotionColor; | |
| Console.Write(HealingPotion); | |
| Console.ResetColor(); | |
| } | |
| } | |
| class Player | |
| { | |
| public int X { get; set; } | |
| public int Y { get; set; } | |
| private string PlayerMarker; | |
| private ConsoleColor PlayerColor; | |
| public Player(int initialX, int initialY) | |
| { | |
| X = initialX; | |
| Y = initialY; | |
| PlayerMarker = "0"; | |
| PlayerColor = ConsoleColor.Green; | |
| } | |
| public void Draw() | |
| { | |
| Console.ForegroundColor = PlayerColor; | |
| Console.SetCursorPosition(X, Y); | |
| Console.Write(PlayerMarker); | |
| Console.ResetColor(); | |
| } | |
| } | |
| class World | |
| { | |
| private string[,] Grid; | |
| private int Rows; | |
| private int Cols; | |
| public World(string[,] grid) | |
| { | |
| Grid = grid; | |
| Rows = Grid.GetLength(0); | |
| Cols = Grid.GetLength(1); | |
| } | |
| public void Draw() | |
| { | |
| for (int y = 0; y < Rows; y++) | |
| { | |
| for (int x = 0; x < Cols; x++) | |
| { | |
| string element = Grid[y, x]; | |
| Console.SetCursorPosition(x, y); | |
| Console.Write(element); | |
| } | |
| } | |
| } | |
| public string GetElementAt(int x, int y) | |
| { | |
| return Grid[y, x]; | |
| } | |
| public bool IsPositionWalkable(int x, int y) | |
| { | |
| if (x < 0 || y < 0 || x >= Cols || y >= Rows) | |
| { | |
| return false; | |
| } | |
| return Grid[y, x] == " " || Grid[y, x] == "X" || Grid[y, x] == "Y" || Grid[y, x] == "@"; | |
| } | |
| } | |
| class Game | |
| { | |
| private World MyWorld; | |
| private Player CurrentPlayer; | |
| private Healingpotion Potion; /// Hej | |
| bool IsHealingTaken = true; /// Hej | |
| public void Start() | |
| { | |
| Console.Title = "The Game"; | |
| Console.CursorVisible = false; | |
| string[,] grid = | |
| { | |
| { "╔", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═","═", "═","╗" }, | |
| { "║", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "," ", " ","║" }, | |
| { "║", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "Y", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "," ", " ","║" }, | |
| { "║", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "," ", " ","║" }, | |
| { "║", " ", " ", " ", " ", "X", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "," ", " ","║" }, | |
| { "║", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "X", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "," ", " ","║" }, | |
| { "║", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "," ", " ","║" }, | |
| { "║", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "," ", " ","║" }, | |
| { "║", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "," ", " ","║" }, | |
| { "║", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "," ", " ","║" }, | |
| { "║", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "," ", " ","║" }, | |
| { "║", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "," ", " ","║" }, | |
| { "║", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "," ", " ","║" }, | |
| { "║", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "@ ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "," ", " ","║" }, | |
| { "║", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "," ", " ","║" }, | |
| { "║", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "," ", " ","║" }, | |
| { "║", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "," ", " ","║" }, | |
| { "║", " ", " ", " ", " ", " ", " ", " ", " ", "@ ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "," ", " ","║" }, | |
| { "║", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "," ", " ","║" }, | |
| { "║", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "," ", " ","║" }, | |
| { "║", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "," ", " ","║" }, | |
| { "║", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "," ", " ","║" }, | |
| { "║", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "," ", " ","║" }, | |
| { "╚", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═", "═","═", "═","╝" }, | |
| }; | |
| MyWorld = new World(grid); | |
| CurrentPlayer = new Player(6, 3); | |
| Potion = new Healingpotion(10, 10); | |
| RunGameLoop(); | |
| } | |
| private void DisplayIntro() | |
| { | |
| Console.WriteLine("Welcome to the game!"); | |
| Console.WriteLine("\nInstructions"); | |
| Console.WriteLine("> Use arrow keys to move"); | |
| Console.ResetColor(); | |
| Console.WriteLine("> Press any key to start"); | |
| Console.ReadKey(true); | |
| } | |
| private void DisplayOutro() | |
| { | |
| Console.Clear(); | |
| Console.WriteLine("You died!"); | |
| Console.WriteLine("Thanks for playing"); | |
| Console.WriteLine("Press enter to exit..."); | |
| Console.ReadKey(true); | |
| } | |
| static Random rng = new Random(); | |
| public static void FörstaMötet() | |
| { | |
| Console.WriteLine("Du tar dig försiktigt fram till dörren och öppnar den, där ser du din förmodliga kidnappare"); | |
| Console.WriteLine("Han vänder sig om.."); | |
| Console.ReadKey(); | |
| Battle("Raider", 1, 8); | |
| } | |
| public static void Battle(string name, int power, int health) | |
| { | |
| string n = ""; | |
| int p = 0; | |
| int h = 0; | |
| n = name; | |
| p = power; | |
| h = health; | |
| while (h > 0) | |
| { | |
| Console.Clear(); | |
| Console.WriteLine(n); | |
| Console.WriteLine("Enemy power:" + p + " Enemy HP: " + h); | |
| Console.WriteLine("====================="); | |
| Console.WriteLine("|====================|"); | |
| Console.WriteLine("|=======(A)ttack=====|"); | |
| Console.WriteLine("|===(R)un (H)eal===|"); | |
| Console.WriteLine("|====================|"); | |
| Console.WriteLine("====================="); | |
| Console.WriteLine(" Potions: " + Program.currentPlayer.potion + " Health: " + Program.currentPlayer.health); | |
| string input = Console.ReadLine(); | |
| if (input.ToLower() == "a") | |
| { | |
| Console.WriteLine("Han upptäcker att du försöker attackera och går till attack samtidigt som dig.."); | |
| int damage = p - Program.currentPlayer.armorValue; | |
| int attack = rng.Next(0, Program.currentPlayer.wepValue) + rng.Next(1, 4); | |
| if (damage < 0) | |
| damage = 0; | |
| Console.WriteLine("Du förlorar " + damage + " HP och ger: " + attack + " i skada"); | |
| Program.currentPlayer.health -= damage; | |
| h -= attack; | |
| Console.WriteLine("Tryck på en knapp för att fortsätta."); | |
| } | |
| else if (input.ToLower() == "r") | |
| { | |
| if (rng.Next(0, 2) == 0) | |
| { | |
| Console.WriteLine("Du försöker fly från " + n + ", han kastar sitt vapen mot dig och träffar dig i ryggen.. du faller ner på marken och träffar huvudet illa"); | |
| int damage = p - Program.currentPlayer.armorValue; | |
| if (damage < 0) | |
| damage = 0; | |
| Console.WriteLine("Du förlorar " + damage + " HP och blöder ut.."); | |
| Console.ReadKey(); | |
| } | |
| else | |
| { | |
| Console.WriteLine("Du använder dina sjuka skills och lyckas fly från " + n + " med livet fortfarande i behåll!"); | |
| Console.ReadKey(); | |
| // go to store | |
| } | |
| } | |
| else if (input.ToLower() == "h") | |
| { | |
| if (Program.currentPlayer.potion == 0) | |
| { | |
| Console.WriteLine("Du börjar gräva i din väska efter en potion, men förgäves.. Det enda du hittar är en tom burk NOCCO."); | |
| int damage = p - Program.currentPlayer.armorValue; | |
| if (damage < 0) | |
| damage = 0; | |
| Console.WriteLine(n + " träffar dig med att starkt slag och du förlorar " + damage + " health"); | |
| } | |
| else | |
| { | |
| Console.WriteLine("Du börjar ivrigt leta i din väska efter en HP-Potion.."); | |
| int potionValue = 5; | |
| Console.WriteLine("Du får " + potionValue + " HP"); | |
| Program.currentPlayer.health += potionValue; | |
| Program.currentPlayer.potion -= 1; | |
| Console.WriteLine("Samtidigt som du grävde i väskan så skadade " + n + " dig"); | |
| int damage = (p / 2) - Program.currentPlayer.armorValue; | |
| if (damage < 0) | |
| damage = 0; | |
| Console.WriteLine("Du förlorade " + damage + " hp"); | |
| } | |
| Console.ReadKey(); | |
| } | |
| Console.ReadKey(); | |
| } | |
| } | |
| public bool DetermineIfHealingIsTaken() //metod2 | |
| { | |
| if (CurrentPlayer.X == Potion.HealingX && CurrentPlayer.Y == Potion.HealingY) | |
| { | |
| return true; | |
| } | |
| else | |
| { | |
| return false; | |
| } | |
| } | |
| public void SetHealingPotiononScreen(Random random, out int HealingX, out int HealingY) /// // // | |
| { | |
| HealingX = random.Next(1, 20); | |
| HealingY = random.Next(1, 20); | |
| Console.SetCursorPosition(HealingX, HealingY); | |
| Console.ForegroundColor = Potion.PotionColor; | |
| Console.Write(Potion.HealingPotion); | |
| Console.ResetColor(); | |
| } | |
| private void DrawFrame() | |
| { | |
| Console.Clear(); | |
| MyWorld.Draw(); | |
| CurrentPlayer.Draw(); | |
| } | |
| private void HandlePlayerInput() | |
| { | |
| ConsoleKeyInfo keyInfo = Console.ReadKey(true); | |
| ConsoleKey key = keyInfo.Key; | |
| switch (key) | |
| { | |
| case ConsoleKey.UpArrow: | |
| if (MyWorld.IsPositionWalkable(CurrentPlayer.X, CurrentPlayer.Y - 1)) | |
| { | |
| CurrentPlayer.Y -= 1; | |
| } | |
| break; | |
| case ConsoleKey.DownArrow: | |
| if (MyWorld.IsPositionWalkable(CurrentPlayer.X, CurrentPlayer.Y + 1)) | |
| { | |
| CurrentPlayer.Y += 1; | |
| } | |
| break; | |
| case ConsoleKey.LeftArrow: | |
| if (MyWorld.IsPositionWalkable(CurrentPlayer.X - 1, CurrentPlayer.Y)) | |
| { | |
| CurrentPlayer.X -= 1; | |
| } | |
| break; | |
| case ConsoleKey.RightArrow: | |
| if (MyWorld.IsPositionWalkable(CurrentPlayer.X + 1, CurrentPlayer.Y)) | |
| { | |
| CurrentPlayer.X += 1; | |
| } | |
| break; | |
| default: | |
| break; | |
| } | |
| } | |
| private void RunGameLoop() | |
| { | |
| DisplayIntro(); | |
| while (true) | |
| { | |
| DrawFrame(); | |
| HandlePlayerInput(); | |
| IsHealingTaken = DetermineIfHealingIsTaken(); | |
| Random random = new Random(); | |
| //if (IsHealingTaken) | |
| //{ | |
| // SetHealingPotiononScreen(random, out int HealingX, out int HealingY); ///// // /// | |
| //} | |
| string elementAtPlayerPos = MyWorld.GetElementAt(CurrentPlayer.X, CurrentPlayer.Y); | |
| if (elementAtPlayerPos == "Y") | |
| { | |
| FörstaMötet(); | |
| continue; | |
| } | |
| if ( elementAtPlayerPos == "@ ") | |
| { | |
| Console.Clear(); | |
| Console.WriteLine("You have increased in 10 life"); | |
| } | |
| if (elementAtPlayerPos == "X") | |
| { | |
| break; | |
| } | |
| System.Threading.Thread.Sleep(20); | |
| } | |
| DisplayOutro(); | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment