Ejemplo n.º 1
0
        public void Describe(Room room)
        {
            CenterText centerText = new CenterText();

            centerText.WriteTextAndCenter($"Current room: {room.Name}\n");
            centerText.WriteTextAndCenter(room.Bio);
        }
Ejemplo n.º 2
0
        public void WriteitemsList(Player player)
        {
            CenterText centerText = new CenterText();

            for (int i = 0; i < player.itemList.Count; i++)
            {
                centerText.WriteTextAndCenter($"{i + 1}) {player.itemList[i].Name}");
            }
        }
Ejemplo n.º 3
0
        public void Playing(Player player)
        {
            //Startposition
            currentPosition = new Home(player.Character);

            // loopen fortsätter så länge du lever && du inte har nått endpoint (klassrummet)
            while (alive && currentPosition.endpoint == false)
            {
                WriteAndReadCommandos();

                while (true)
                {
                    Console.WriteLine("\n");

                    // Felhantering om användaren skriver in enbart "pick", "drop", "exit", "inspect"
                    if (commando == Commandos.Get.ToString().ToLower() ||
                        commando == Commandos.Exit.ToString().ToLower() ||
                        commando == Commandos.Drop.ToString().ToLower() ||
                        commando == Commandos.Inspect.ToString().ToLower()
                        )
                    {
                        Console.Clear();
                        centerText.WriteTextAndCenter($"{commando} what?\n");
                        break;
                    }
                    else if (commando == Commandos.Use.ToString().ToLower())
                    {
                        Console.Clear();
                        centerText.WriteTextAndCenter($"{commando} what on what?\n");
                        break;
                    }

                    // Dela upp commandot till en array
                    string[] wordSplit = commando.Split(' ');


                    // Fortsättning av att kolla commandot
                    if (wordSplit[0].ToLower() == "get")
                    {
                        Console.Clear();
                        Console.WriteLine("\n\n\n\n");
                        if (CheckIfItemsExist(currentPosition, wordSplit[1]))
                        {
                            // Ta upp något
                            player.Pick(player, wordSplit[1], currentPosition.itemsList);
                        }
                        else
                        {
                            centerText.WriteTextAndCenter("The item you are trying to get are missing in the room");
                        }

                        // Inspektera spelarens items
                        Console.WriteLine("\n");
                        centerText.WriteTextAndCenter("Items in your bag: ");
                        player.WriteitemsList(player);
                        break;
                    }
                    else if ((wordSplit[0].ToLower() == "drop"))
                    {
                        Console.Clear();
                        Console.WriteLine("\n\n\n\n");

                        if (CheckIfItemsExist(player, wordSplit[1]))
                        {
                            // Droppa något
                            player.Drop(player, wordSplit[1], currentPosition.itemsList);
                        }
                        else
                        {
                            centerText.WriteTextAndCenter(
                                "The item you are trying to drop are missing in the your bag");
                        }

                        // Inspektera spelarens items
                        Console.WriteLine("\n");
                        centerText.WriteTextAndCenter("Items in your bag: ");
                        player.WriteitemsList(player);
                        Console.WriteLine("\n");
                        break;
                    }
                    else if ((wordSplit[0].ToLower() == "exit"))
                    {
                        Console.Clear();
                        Console.WriteLine("\n\n\n\n");

                        // Kolla om exit finns på rummet och ifall enbart 2 ord skrivits in
                        if (CheckIfExitExists(currentPosition, wordSplit[1]) && wordSplit.Length == 2)
                        {
                            if (wordSplit[1].ToLower() == "bed")
                            {
                                centerText.WriteTextAndCenter("Bad choice....\n\n");
                                centerText.WriteTextAndCenter("GAME OVER\n\n");
                                alive = false;
                            }
                            else if (wordSplit[1].ToLower() == "home")
                            {
                                centerText.WriteTextAndCenter("You chose to go home... You will never make it to school today!" +
                                                              " You better call in sick today!\n");
                                centerText.WriteTextAndCenter("GAME OVER\n\n");
                                alive = false;
                            }
                            else
                            {
                                currentPosition.Position(ref currentPosition, player,
                                                         CheckIfItemsExist(player, "keys"), CheckIfItemsExist(player, "loaded buscard"),
                                                         CheckIfItemsExist(player, "smartphone"), CheckIfItemsExist(player, "coffe"), ref alive);

                                // Inspektera current position och dess items
                                if (currentPosition.endpoint == false && alive == true)
                                {
                                    Look();
                                }
                            }
                        }
                        // Felmeddelande om exit inte finns
                        else
                        {
                            centerText.WriteTextAndCenter("The exit you are trying to use doesn't exist");
                        }
                        break;
                    }
                    else if ((wordSplit[0].ToLower() == "look"))
                    {
                        Console.Clear();
                        Console.WriteLine("\n\n\n\n");

                        Look();
                        break;
                    }
                    else if ((wordSplit[0].ToLower() == "check"))
                    {
                        Console.Clear();
                        Console.WriteLine("\n\n\n\n");

                        // Inspektera spelarens items
                        centerText.WriteTextAndCenter("Items in your bag: ");
                        player.WriteitemsList(player);
                        break;
                    }
                    else if ((wordSplit[0].ToLower() == "quit"))
                    {
                        Console.Clear();
                        Console.WriteLine("\n\n\n\n");

                        centerText.WriteTextAndCenter("You gave up!");
                        alive = false;
                        break;
                    }
                    else if ((wordSplit[0].ToLower() == "use"))
                    {
                        Console.Clear();
                        Console.WriteLine("\n\n\n\n");

                        //Use item on item
                        if (wordSplit[0].ToLower() == "use" &&
                            CheckIfItemsExist(player, wordSplit[1]) == true &&
                            wordSplit[2].ToLower() == "on" &&
                            CheckIfItemsExist(player, wordSplit[3]) == true &&
                            wordSplit.Length == 4)
                        {
                            Items useItems = ConvertTextToitems(player, wordSplit[1]);
                            Items onItems  = ConvertTextToitems(player, wordSplit[3]);

                            // kolla money mot tomt busskort
                            if (useItems.Name == new Money().Name&& onItems.Name == new BusCardEmpty().Name)
                            {
                                player.Drop(player, wordSplit[1]);
                                player.Drop(player, wordSplit[3]);

                                Items busCardLoaded = new BusCardLoaded();
                                player.itemList.Add(busCardLoaded);

                                Console.ForegroundColor = ConsoleColor.Green;
                                centerText.WriteTextAndCenter($"Succesfully converted {wordSplit[1]} and " +
                                                              $"{wordSplit[3]} to {busCardLoaded.Name}");
                                Console.ForegroundColor = ConsoleColor.Cyan;

                                GetItemsFrom(currentPosition);
                                currentPosition.isLocked = false;
                            }
                            else
                            {
                                centerText.WriteTextAndCenter("Try another combo, but");
                                centerText.WriteTextAndCenter(
                                    "to be able to travel you need to convert money to another object");
                            }
                        }
                        //Use item on exit
                        else if (wordSplit[0].ToLower() == "use" &&
                                 CheckIfItemsExist(player, wordSplit[1]) == true &&
                                 wordSplit[2].ToLower() == "on" &&
                                 CheckIfExitExists(currentPosition, wordSplit[3]) == true &&
                                 wordSplit.Length == 4)
                        {
                            // Ifall items används på exit
                            Items useItems = ConvertTextToitems(player, wordSplit[1]);

                            // Kolla smartphone och cab
                            if (useItems.Name.ToLower() == new SmartPhone().Name.ToLower() &&
                                wordSplit[3].ToLower() == new Cab().Name.ToLower())
                            {
                                SuccesfullyOpenedExit(player);
                                Look();
                            }
                            //kolla keys mot door
                            else if (useItems.Name.ToLower() == "keys" &&
                                     wordSplit[3].ToLower() == "door" && currentPosition.Name ==
                                     new ToSchool().Name)
                            {
                                SuccesfullyOpenedExit(player);
                                Look();
                            }
                            // kolla laddat busskort mot bussen
                            else if (useItems.Name.ToLower() == new BusCardLoaded().Name.ToLower() &&
                                     wordSplit[3].ToLower() == "bus" && currentPosition.Name ==
                                     new ToBus(player.Character).Name)
                            {
                                SuccesfullyOpenedExit(player);
                                Look();
                            }
                            else
                            {
                                centerText.WriteTextAndCenter("The item you are trying to use on the exit doesn't work.");
                            }
                        }
                        else
                        {
                            // Skriv ut ifall orden som använder försöker använda inte fungerar
                            centerText.WriteTextAndCenter("You need to have items in your " +
                                                          "bag to be able to use item on an item or exit");
                        }
                        break;
                    }
                    else if (commando.Contains(Commandos.Inspect.ToString().ToLower()))
                    {
                        Console.Clear();
                        Console.WriteLine("\n\n\n\n");
                        Items checkItems;

                        // Visa bio för föremål
                        if (CheckIfItemsExist(player, wordSplit[1]) == true)
                        {
                            // Kollar commando mot items i rummet
                            checkItems = ConvertTextToitems(player, wordSplit[1]);
                            player.Inspect(checkItems);
                        }
                        else if (CheckIfItemsExist(currentPosition, wordSplit[1]) == true)
                        {
                            // Kollar commando mot items i rummet
                            checkItems = ConvertTextToitems(currentPosition, wordSplit[1]);
                            player.Inspect(checkItems);
                        }
                        else if (CheckIfExitExists(currentPosition, wordSplit[1]) == true)
                        {
                            centerText.WriteTextAndCenter(currentPosition.ExitWithDescription[wordSplit[1]]);
                            Console.WriteLine();
                        }

                        break;
                    }
                    else
                    {
                        centerText.WriteTextAndCenter("Try again");
                        commando = centerText.ReadTextAndCenter(5).ToLower();
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public void Inspect(Items items)
        {
            CenterText centerText = new CenterText();

            centerText.WriteTextAndCenter(items.Bio);
        }
Ejemplo n.º 5
0
        //Metod som tar in första position (Home) och ändrar värdet för varje exit-commando
        public void Position(ref Room room, Player player,
                             bool controlKeys, bool controlBusCard, bool controlSmartPhone,
                             bool controlCoffe, ref bool alive)
        {
            CenterText centerText = new CenterText();

            if (room.isLocked == true)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                centerText.WriteTextAndCenter($"To be able to enter " +
                                              $"you need to unlock the exit with an item.\n\n");
                Console.ForegroundColor = ConsoleColor.Cyan;
            }
            else
            {
                if (room.Name == new Home(player.Character).Name)
                {
                    room = new ToBus(player.Character);
                }
                else if (room.Name == new ToBus(player.Character).Name&& controlBusCard)
                {
                    room = new Bus();
                }
                else if (room.Name == new Bus().Name)
                {
                    room = new ToSchool();
                }
                else if (room.Name == new ToBus(player.Character).Name&& controlSmartPhone)
                {
                    room = new Cab();
                }
                else if (room.Name == new Cab().Name)
                {
                    room = new ToSchool();
                }
                else if (room.Name == new ToSchool().Name&& controlKeys)
                {
                    room = new School();
                }
                else if (room.Name == new School().Name)
                {
                    if (controlCoffe)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        centerText.WriteTextAndCenter("You made it in time for Fredriks lecture " +
                                                      "and you have brought the most important item. COFFE! \n\n");
                        centerText.WriteTextAndCenter("YOU WIN!");
                        Console.ForegroundColor = ConsoleColor.Cyan;

                        // Sätt endpoint på rummet så att spelet avslutas
                        room.endpoint = true;
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        centerText.WriteTextAndCenter("Did you forget to bring COFFE?? " +
                                                      "You will die a slowly death...");
                        Console.ForegroundColor = ConsoleColor.Cyan;
                        alive = false;
                    }
                }
            }
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            bool gameOver = false;

            while (gameOver == false)
            {
                //Declaration
                var        charMimmi       = new CharMimmi();
                var        charMarkus      = new CharMarkus();
                var        charAhmad       = new CharAhmad();
                Player     chosenCharacter = null;
                Play       game            = new Play();
                CenterText centerText      = new CenterText();


                //Title Screen
                Console.WriteLine("\n\n\n\n");
                Console.ForegroundColor = ConsoleColor.Cyan;
                centerText.WriteTextAndCenter("Welcome to Travel Adventure\n");
                Console.ForegroundColor = ConsoleColor.Green;
                centerText.WriteTextAndCenter("Your mission is to get to school!\n");
                Console.ForegroundColor = ConsoleColor.Cyan;
                centerText.WriteTextAndCenter("But first, choose your character bio\n\n");
                centerText.WriteTextAndCenter("Character (1)");
                centerText.WriteTextAndCenter(charMimmi.Bio + "\n");
                centerText.WriteTextAndCenter("Character (2)");
                centerText.WriteTextAndCenter(charMarkus.Bio + "\n");
                centerText.WriteTextAndCenter("Character (3)");
                centerText.WriteTextAndCenter(charAhmad.Bio + "\n");


                //Väljer story att gå efter
                int charChoice;
                while (true)
                {
                    if (int.TryParse(centerText.ReadTextAndCenter(), out charChoice))
                    {
                        if (charChoice == 1)
                        {
                            chosenCharacter = charMimmi;
                        }
                        if (charChoice == 2)
                        {
                            chosenCharacter = charMarkus;
                        }
                        if (charChoice == 3)
                        {
                            chosenCharacter = charAhmad;
                        }
                        if (charChoice != 1 && charChoice != 2 && charChoice != 3)
                        {
                            centerText.WriteTextAndCenter("Try a number between 1-3!");
                            continue;
                        }
                        break;
                    }
                    else
                    {
                        centerText.WriteTextAndCenter("Try with numbers instead");
                    }
                }

                Console.Clear();
                Console.WriteLine("\n\n\n");
                centerText.WriteTextAndCenter("Name your character");
                string name = centerText.ReadTextAndCenter(5);
                chosenCharacter.Name = name;

                Console.Clear();
                Console.WriteLine("\n\n\n\n");

                centerText.WriteTextAndCenter("Welcome " + chosenCharacter.Name + "!");

                game.Playing(chosenCharacter);

                centerText.WriteTextAndCenter("Play again?(Y/N)");
                string answer = centerText.ReadTextAndCenter().ToUpper();
                Console.Clear();

                if (answer == "N")
                {
                    gameOver = true;
                    Console.WriteLine("\n\n\n\n\n\n\n\n");
                    centerText.WriteTextAndCenter("GAME OVER!");
                }

                Console.ReadLine();
            }
        }