Пример #1
0
        public bool Execute(Command command)
        {
            if (!command.hasSecondWord())
            {
                // if there is no second word
                Console.WriteLine("Save what story?");
                return false;
            }
            string fileName = command.SecondWord + ".txt";
            writer = new StreamWriter(fileName);
            writer.AutoFlush = true;

            var startTime = DateTime.Now;

            foreach (Player p in _game.getPlayerArr()) //writes info in plain text for each character
            {
                writer.WriteLine("{0}-{1}-{2}-{3}-{4}-{5}-{6}-{7}-{8}-{9}-{10}-{11}-{12}-{13}-{14}-{15}-{16}-{17}-{18}-{19}-{20}",
                    p.getName(), p.getClass(), p.getLevel(), p.getHP(), p.getMP(), p.getGold(),
                    p.getGear().getHeadgear(), p.getGear().getArmor(), p.getGear().getShoes(), p.getGear().getGloves(), p.getGear().getAccessory(), p.getGear().getJewlery(), p.getGear().getLeftHand(), p.getGear().getRightHand(), p.getGear().getEtc(),
                    p.getStats().getSTR(), p.getStats().getDEX(), p.getStats().getCON(), p.getStats().getINT(), p.getStats().getWIS(), p.getStats().getCHA());
            }

            var totalSeconds = (DateTime.Now - startTime).TotalSeconds;
            Console.WriteLine("Character data saved in {0} seconds as {1}.", totalSeconds, fileName);
            writer.Close();
            return false;
        }
Пример #2
0
        public bool Execute(Command command)
        {
            Console.Clear();
            Game game = new Game(); //creates and plays new game
            game.play();

            return false;
        }
Пример #3
0
 /// "Quit" was entered. Check the rest of the command to see
 /// whether we really quit the game.
 /// Return true, if this command quits the game, false otherwise.
 public bool Execute(Command command)
 {
     if(command.hasSecondWord()) {
     Console.WriteLine("Quit what?");
     return false;
      }
      else {
     return UI.Agree("Do you really want to quit?");
      }
 }
Пример #4
0
        public bool Execute(Command command)
        {
            //string charName = command.SecondWord;
            int diceNumber = int.Parse(UI.PromptLine("How many dice do you want to roll?\n"));

            if (diceNumber > 3) { Console.WriteLine("Why do you want to roll so many?\n"); }

            for (int i = 0; i < diceNumber; i++)
            {
                int die = int.Parse(UI.PromptLine("How many sides for the die?\n"));
                _dice.roll(die);
                Console.WriteLine();
            }
            return false;
        }
Пример #5
0
        public bool Execute(Command command)
        {
            if (!command.hasSecondWord())
            {
                // if there is no second word
                Console.WriteLine("Stats for who?");
                return false;
            }
            string charName = command.SecondWord;

            foreach (Player p in _game.getPlayerArr())
            {
                if (p.getName() == charName)
                {
                    p.getStats().display(); //print out stats of player
                }
            }

            return false;
        }
Пример #6
0
        public bool Execute(Command command)
        {
            if (!command.hasSecondWord())
            {
                // if there is no second word
                foreach (Player p in _game.getPlayerArr())
                {
                    Console.Write(String.Format("{0,-10}", p.getName()));
                }
                Console.WriteLine();
                return false;
            }
            string charName = command.SecondWord;

            foreach (Player p in _game.getPlayerArr())
            {
                if (p.getName() == charName)
                {
                    p.display(); //displays player's basic info
                }
            }

            return false;
        }
Пример #7
0
        public bool Execute(Command command)
        {
            if (!command.hasSecondWord())
            {
                // if there is no second word
                foreach (Player p in _game.getPlayerArr())
                {
                    p.displayAll();
                    Console.WriteLine();
                }
                return false;
            }
            string charName = command.SecondWord;

            foreach (Player p in _game.getPlayerArr())
            {
                if (p.getName() == charName)
                {
                    p.displayAll(); //displays all info of a player
                }
            }

            return false;
        }
Пример #8
0
        public bool Execute(Command command)
        {
            Console.Clear();

            return false;
        }
Пример #9
0
        public bool Execute(Command command)
        {
            if (!command.hasSecondWord())
            {
                // if there is no second word
                Console.WriteLine("Change who?");
                return false;
            }
            string charName = command.SecondWord;

            foreach (Player p in _game.getPlayerArr())
            {
                if (p.getName() == charName) //matches player
                {
                    Console.WriteLine("What would you like to change for " + p.getName() + "?\n");
                    string response = UI.PromptLine("stats, gear, or player\n");

                    Console.ForegroundColor = ConsoleColor.Red;

                    if (response == "stats")
                    {
                        string response2 = UI.PromptLine(" STR DEX CON INT WIS CHA ?\n");
                        int amount = UI.PromptInt("How much would you like to change " + response2 + " by?\n");
                        //STRENGTH
                        if (response2 == "STR")
                        {
                            p.getStats().setSTR(p.getStats().getSTR() + amount);
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("{0} has been changed to {1}", response2, p.getStats().getSTR());

                        }
                        //DEXTERITY
                        if (response2 == "DEX")
                        {
                            p.getStats().setDEX(p.getStats().getDEX() + amount);
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("{0} has been changed to {1}", response2, p.getStats().getDEX());
                        }
                        //CONSTITUTION
                        if (response2 == "CON")
                        {
                            p.getStats().setCON(p.getStats().getCON() + amount);
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("{0} has been changed to {1}", response2, p.getStats().getDEX());
                        }
                        // INTELLIGENCE
                        if (response2 == "INT")
                        {
                            p.getStats().setINT(p.getStats().getINT() + amount);
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("{0} has been changed to {1}", response2, p.getStats().getINT());
                        }
                        //WISDOM
                        if (response2 == "WIS")
                        {
                            p.getStats().setWIS(p.getStats().getWIS() + amount);
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("{0} has been changed to {1}", response2, p.getStats().getWIS());
                        }
                        //CHARISMA
                        if (response2 == "CHA")
                        {
                            p.getStats().setCHA(p.getStats().getCHA() + amount);
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("{0} has been changed to {1}", response2, p.getStats().getCHA());
                        }
                    }
                    if (response == "gear")
                    {
                        string response2 = UI.PromptLine("Headgear Armor Shoes Gloves Accessory Jewlery ?\n");
                        string item = UI.PromptLine("What would you like to change " + response2 + " to?\n");
                        //Headgear;
                        if (response2 == "Headgear")
                        {
                            p.getGear().setHeadgear(item);
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("{0} has been changed to {1}", response2, p.getGear().getHeadgear());
                        }
                        //Armor;
                        if (response2 == "Armor")
                        {
                            p.getGear().setArmor(item);
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("{0} has been changed to {1}", response2, p.getGear().getArmor());
                        }
                        //Shoes;
                        if (response2 == "Shoes")
                        {
                            p.getGear().setShoes(item);
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("{0} has been changed to {1}", response2, p.getGear().getShoes());
                        }
                        //Gloves;
                        if (response2 == "Gloves")
                        {
                            p.getGear().setGloves(item);
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("{0} has been changed to {1}", response2, p.getGear().getGloves());
                        }
                        //Accessory;
                        if (response2 == "Accessory")
                        {
                            p.getGear().setAccessory(item);
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("{0} has been changed to {1}", response2, p.getGear().getAccessory());
                        }
                        //Jewlery;
                        if (response2 == "Jewlery")
                        {
                            p.getGear().setJewlery(item);
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("{0} has been changed to {1}", response2, p.getGear().getJewlery());
                        }
                    }
                    if (response == "player")
                    {
                        string response2 = UI.PromptLine("Name Class Level HP MP Gold ?\n");
                        var item = UI.PromptLine("What would you like to change " + response2 + " to?\n");
                        // _name;
                        if (response2 == "Name")
                        {
                            p.setName(item);
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("{0} has been changed to {1}", response2, p.getName());
                        }
                        //_class;
                        if (response2 == "Class")
                        {
                            p.setClass(item);
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("{0} has been changed to {1}", response2, p.getClass());
                        }
                        //_level;
                        if (response2 == "Level")
                        {
                            p.setLevel(p.getLevel() + int.Parse(item));
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("{0} has been changed to {1}", response2, p.getLevel());
                        }
                        // _HP;
                        if (response2 == "HP")
                        {
                            p.setHP(p.getHP() + int.Parse(item));
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("{0} has been changed to {1}", response2, p.getHP());
                        }
                        // _MP;
                        if (response2 == "MP")
                        {
                            p.setMP(p.getMP() + int.Parse(item));
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("{0} has been changed to {1}", response2, p.getMP());
                        }
                        // _Gold;
                        if (response2 == "Gold")
                        {
                            p.setGold(p.getGold() + int.Parse(item));
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("{0} has been changed to {1}", response2, p.getGold());
                        }
                    }
                    Console.ForegroundColor = ConsoleColor.Yellow;
                }
            }
            return false;
        }
Пример #10
0
        /// Print out some Help information.
        /// Here we print some stupid, cryptic message and a list of the 
        /// command words.
        public bool Execute(Command cmd)
        {
            if (!cmd.hasSecondWord())
            {
                Console.WriteLine("Are you confused?\n ");
                Console.Write("Type '");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("help");
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.Write("' for help. \n");
                Console.Write("Type '");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("player");
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.Write("' for specific player info. \n");
                Console.Write("Type '");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("gear");
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.Write("' for viewing gear. \n");
                Console.Write("Type '");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("stats");
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.Write("' for viewing stats. \n");
                Console.Write("Type '");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("dice");
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.Write("' To roll dice. \n");
                Console.Write("Type '");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("display");
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.Write("' to view all of the info of a character at once. \n");
                Console.Write("Type '");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("change");
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.Write("' for changing a character. \n");
                Console.Write("Type '");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("clear");
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.Write("' to clear the screen of text. \n");
                Console.Write("Type '");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("save");
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.Write("' to save characters data in a file. \n");
                Console.Write("Type '");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("reset");
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.Write("' to reset the game. \n");
                Console.Write("Type '");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("quit");
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.Write("' to quit. \n");

            }
            else if (_responses.ContainsKey(cmd.SecondWord))
            {
                Console.WriteLine(_responses[cmd.SecondWord].Help());
            }
            else
            {
                Console.WriteLine(
            @"Unknown command {0}!  Command words are
            {1}", cmd.SecondWord, _commandMapper.AllCommands);
            }
            return false;
        }
Пример #11
0
 /// Given a command: process (that is: Execute) the command.
 /// Return true If the command ends the game, false otherwise.
 private bool processCommand(Command command)
 {
     if (!_commandMapper.isCommand(command.CommandWord))
     {
         Console.WriteLine("Try something different.");
         return false;
     }
     Response response = _commandMapper.getResponse(command.CommandWord);
     return response.Execute(command);
 }