Пример #1
0
        private static string ParseCommand(Command command, string[] arguments)
        {
            switch (command)
            {
            case Command.JoinParty:
                return(master.JoinParty(arguments));

            case Command.AddItemToPool:
                return(master.AddItemToPool(arguments));

            case Command.PickUpItem:
                return(master.PickUpItem(arguments));

            case Command.UseItem:
                return(master.UseItem(arguments));

            case Command.UseItemOn:
                return(master.UseItemOn(arguments));

            case Command.GiveCharacterItem:
                return(master.GiveCharacterItem(arguments));

            case Command.GetStats:
                return(master.GetStats());

            case Command.Attack:
                return(master.Attack(arguments));

            case Command.Heal:
                return(master.Heal(arguments));

            case Command.EndTurn:
                return(master.EndTurn(arguments));

            case Command.IsGameOver:
                master.IsGameOver();
                return("");

            default:
                return("");
            }
        }
Пример #2
0
        public static void Main(string[] args)
        {
            var           input         = Console.ReadLine();
            DungeonMaster dungeonMaster = new DungeonMaster();

            while (!string.IsNullOrEmpty(input))
            {
                var separaedInput = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                var command       = separaedInput[0];
                var arguments     = separaedInput.Skip(1).ToArray();

                try
                {
                    switch (command)
                    {
                    case "JoinParty":
                        Console.WriteLine(dungeonMaster.JoinParty(arguments));
                        break;

                    case "AddItemToPool":
                        Console.WriteLine(dungeonMaster.AddItemToPool(arguments));
                        break;

                    case "PickUpItem":
                        Console.WriteLine(dungeonMaster.PickUpItem(arguments));
                        break;

                    case "UseItem":
                        Console.WriteLine(dungeonMaster.UseItem(arguments));
                        break;

                    case "UseItemOn":
                        Console.WriteLine(dungeonMaster.UseItemOn(arguments));
                        break;

                    case "GiveCharacterItem":
                        Console.WriteLine(dungeonMaster.GiveCharacterItem(arguments));
                        break;

                    case "GetStats":
                        Console.WriteLine(dungeonMaster.GetStats());
                        break;

                    case "Attack":
                        Console.WriteLine(dungeonMaster.Attack(arguments));
                        break;

                    case "Heal":
                        Console.WriteLine(dungeonMaster.Heal(arguments));
                        break;

                    case "EndTurn":
                        Console.WriteLine(dungeonMaster.EndTurn());
                        break;
                    }
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine($"Parameter Error: {ae.Message}");
                }
                catch (InvalidOperationException oe)
                {
                    Console.WriteLine($"Invalid Operation: {oe.Message}");
                }

                input = Console.ReadLine();
            }
            Console.WriteLine("Final stats:");
            Console.WriteLine(dungeonMaster.GetStats());
        }
Пример #3
0
        public static void Main(string[] args)
        {
            var    dungeonMaster = new DungeonMaster();
            string input;

            while (!string.IsNullOrEmpty(input = Console.ReadLine()))
            {
                var tokens        = input.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToList();
                var command       = tokens[0];
                var commandTokens = tokens.Skip(1).ToArray();
                var result        = string.Empty;
                var isEnd         = false;
                try
                {
                    switch (command)
                    {
                    case "JoinParty":
                        result = dungeonMaster.JoinParty(commandTokens);
                        break;

                    case "AddItemToPool":
                        result = dungeonMaster.AddItemToPool(commandTokens);
                        break;

                    case "PickUpItem":
                        result = dungeonMaster.PickUpItem(commandTokens);
                        break;

                    case "UseItem":
                        result = dungeonMaster.UseItem(commandTokens);
                        break;

                    case "UseItemOn":
                        result = dungeonMaster.UseItemOn(commandTokens);
                        break;

                    case "GiveCharacterItem":
                        result = dungeonMaster.GiveCharacterItem(commandTokens);
                        break;

                    case "GetStats":
                        result = dungeonMaster.GetStats();
                        break;

                    case "Attack":
                        result = dungeonMaster.Attack(commandTokens);
                        break;

                    case "Heal":
                        result = dungeonMaster.Heal(commandTokens);
                        break;

                    case "EndTurn":
                        result = dungeonMaster.EndTurn(commandTokens);
                        break;

                    case "IsGameOver":
                        isEnd = dungeonMaster.IsGameOver();
                        break;
                    }

                    if (!string.IsNullOrWhiteSpace(result))
                    {
                        Console.WriteLine(result);
                    }
                    if (isEnd || dungeonMaster.IsGameOver())
                    {
                        break;
                    }
                }
                catch (ArgumentException err)
                {
                    Console.WriteLine($"Parameter Error: " + err.Message);
                }
                catch (InvalidOperationException err)
                {
                    Console.WriteLine($"Invalid Operation: " + err.Message);
                }
            }

            Console.WriteLine($"Final stats:");
            Console.WriteLine(dungeonMaster.GetStats());
        }
Пример #4
0
        public static void Main(string[] args)
        {
            DungeonMaster dungeonMaster = new DungeonMaster();

            while (true)
            {
                string inputCommand = Console.ReadLine();
                if (string.IsNullOrEmpty(inputCommand))
                {
                    break;
                }

                if (dungeonMaster.IsGameOver())
                {
                    break;
                }

                var input = inputCommand
                            .Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)
                            .ToList();

                string command = input[0];

                string[] inputToPass = input.Skip(1).ToArray();

                try
                {
                    if (command == "JoinParty")
                    {
                        Console.WriteLine(dungeonMaster.JoinParty(inputToPass));
                    }
                    else if (command == "AddItemToPool")
                    {
                        Console.WriteLine(dungeonMaster.AddItemToPool(inputToPass));
                    }
                    else if (command == "PickUpItem")
                    {
                        Console.WriteLine(dungeonMaster.PickUpItem(inputToPass));
                    }
                    else if (command == "UseItem")
                    {
                        Console.WriteLine(dungeonMaster.UseItem(inputToPass));
                    }
                    else if (command == "UseItemOn")
                    {
                        Console.WriteLine(dungeonMaster.UseItemOn(inputToPass));
                    }
                    else if (command == "GiveCharacterItem")
                    {
                        Console.WriteLine(dungeonMaster.GiveCharacterItem(inputToPass));
                    }
                    else if (command == "GetStats")
                    {
                        Console.WriteLine(dungeonMaster.GetStats());
                    }
                    else if (command == "Attack")
                    {
                        Console.WriteLine(dungeonMaster.Attack(inputToPass));
                    }
                    else if (command == "Heal")
                    {
                        Console.WriteLine(dungeonMaster.Heal(inputToPass));
                    }
                    else if (command == "EndTurn")
                    {
                        Console.WriteLine(dungeonMaster.EndTurn(inputToPass));
                    }
                    else if (command == "GameOver")
                    {
                        Console.WriteLine(dungeonMaster.IsGameOver());
                    }
                }
                catch (Exception e)
                {
                    if (e.GetType().Name == "ArgumentException")
                    {
                        Console.WriteLine("Parameter Error: " + e.Message);
                    }
                    else
                    {
                        Console.WriteLine("Invalid Operation: " + e.Message);
                    }
                }
            }

            Console.WriteLine($"Final stats:");
            Console.WriteLine(dungeonMaster.GetStats());
        }
Пример #5
0
        // DO NOT rename this file's namespace or class name.
        // However, you ARE allowed to use your own namespaces (or no namespaces at all if you prefer) in other classes.
        public static void Main(string[] args)
        {
            string        input;
            DungeonMaster dungeonMaster = new DungeonMaster();

            do
            {
                input = Console.ReadLine();
                string[] arguments = input.Split(' ');

                try
                {
                    try
                    {
                        if (arguments[0] == "JoinParty")
                        {
                            Console.WriteLine(dungeonMaster.JoinParty(arguments.Skip(1).ToArray()));
                        }
                        else if (arguments[0] == "AddItemToPool")
                        {
                            Console.WriteLine(dungeonMaster.AddItemToPool(arguments.Skip(1).ToArray()));
                        }
                        else if (arguments[0] == "PickUpItem")
                        {
                            Console.WriteLine(dungeonMaster.PickUpItem(arguments.Skip(1).ToArray()));
                        }
                        else if (arguments[0] == "UseItem")
                        {
                            Console.WriteLine(dungeonMaster.UseItem(arguments.Skip(1).ToArray()));
                        }
                        else if (arguments[0] == "UseItemOn")
                        {
                            Console.WriteLine(dungeonMaster.UseItemOn(arguments.Skip(1).ToArray()));
                        }
                        else if (arguments[0] == "GiveCharacterItem")
                        {
                            Console.WriteLine(dungeonMaster.GiveCharacterItem(arguments.Skip(1).ToArray()));
                        }
                        else if (arguments[0] == "GetStats")
                        {
                            Console.WriteLine(dungeonMaster.GetStats());
                        }
                        else if (arguments[0] == "Attack")
                        {
                            Console.WriteLine(dungeonMaster.Attack(arguments.Skip(1).ToArray()));
                        }
                        else if (arguments[0] == "Heal")
                        {
                            Console.WriteLine(dungeonMaster.Heal(arguments.Skip(1).ToArray()));
                        }
                        else if (arguments[0] == "EndTurn")
                        {
                            Console.WriteLine(dungeonMaster.EndTurn());

                            if (dungeonMaster.LastSurvivorRounds > 1)
                            {
                                Console.WriteLine("Final stats:");
                                Console.WriteLine(dungeonMaster.GetStats());

                                break;
                            }
                        }
                        else if (arguments[0] == "IsGameOver")
                        {
                            if (dungeonMaster.IsGameOver())
                            {
                                break;
                            }
                        }
                    }
                    catch (ArgumentException e)
                    {
                        Console.WriteLine("Parameter Error: " + e.Message);
                    }
                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine("Invalid Operation: " + ex.Message);
                }
            } while (!String.IsNullOrEmpty(input));
        }
Пример #6
0
        public void Run()
        {
            string input = Console.ReadLine();

            while (!string.IsNullOrEmpty(input))
            {
                string[] commandArgs = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                string   commandName = commandArgs[0];
                commandArgs = commandArgs.Skip(1).ToArray();
                string output     = string.Empty;
                bool   isGameOver = false;

                try
                {
                    switch (commandName)
                    {
                    case "JoinParty":
                        output = dungeonMaster.JoinParty(commandArgs);
                        break;

                    case "AddItemToPool":
                        output = dungeonMaster.AddItemToPool(commandArgs);
                        break;

                    case "PickUpItem":
                        output = dungeonMaster.PickUpItem(commandArgs);
                        break;

                    case "UseItem":
                        output = dungeonMaster.UseItem(commandArgs);
                        break;

                    case "UseItemOn":
                        output = dungeonMaster.UseItemOn(commandArgs);
                        break;

                    case "GiveCharacterItem":
                        output = dungeonMaster.GiveCharacterItem(commandArgs);
                        break;

                    case "GetStats":
                        output = dungeonMaster.GetStats();
                        break;

                    case "Attack":
                        output = dungeonMaster.Attack(commandArgs);
                        break;

                    case "Heal":
                        output = dungeonMaster.Heal(commandArgs);
                        break;

                    case "EndTurn":
                        output     = dungeonMaster.EndTurn(commandArgs);
                        isGameOver = dungeonMaster.isGameOver;
                        break;

                    case "IsGameOver":
                        isGameOver = dungeonMaster.IsGameOver();
                        break;

                    default:
                        break;
                    }
                    Console.WriteLine(output);
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine("Parameter Error: " + ae.Message);
                }
                catch (InvalidOperationException ioe)
                {
                    Console.WriteLine("Invalid Operation: " + ioe.Message);
                }

                if (isGameOver)
                {
                    break;
                }

                input = Console.ReadLine();
            }

            PrintFinalStats();
        }
Пример #7
0
        // DO NOT rename this file's namespace or class name.
        // However, you ARE allowed to use your own namespaces (or no namespaces at all if you prefer) in other classes.
        public static void Main()
        {
            var dm = new DungeonMaster();

            while (true)
            {
                try
                {
                    if (dm.IsGameOver())
                    {
                        break;
                    }
                    string line = Console.ReadLine();
                    if (string.IsNullOrEmpty(line))
                    {
                        break;
                    }
                    var command = line.Split()[0];

                    var tokens = line.Split().Skip(1).ToArray();

                    switch (command)
                    {
                    case "JoinParty":
                        Console.WriteLine(dm.JoinParty(tokens));
                        break;

                    case "AddItemToPool":
                        Console.WriteLine(dm.AddItemToPool(tokens));
                        break;

                    case "PickUpItem":
                        Console.WriteLine(dm.PickUpItem(tokens));
                        break;

                    case "UseItem":
                        Console.WriteLine(dm.UseItem(tokens));
                        break;

                    case "UseItemOn":
                        Console.WriteLine(dm.UseItemOn(tokens));
                        break;

                    case "GiveCharacterItem":
                        Console.WriteLine(dm.GiveCharacterItem(tokens));
                        break;

                    case "GetStats":
                        Console.WriteLine(dm.GetStats());
                        break;

                    case "Attack":
                        Console.WriteLine(dm.Attack(tokens));
                        break;

                    case "Heal":
                        Console.WriteLine(dm.Heal(tokens));
                        break;

                    case "EndTurn":
                        Console.WriteLine(dm.EndTurn(tokens));
                        if (dm.IsGameOver())
                        {
                            break;
                        }
                        break;
                    }
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine("Parameter Error: " + e.Message);
                }
                catch (InvalidOperationException e)
                {
                    Console.WriteLine("Invalid Operation: " + e.Message);
                }
            }
            Console.WriteLine("Final stats:");
            Console.WriteLine(dm.GetStats());
        }
Пример #8
0
        // DO NOT rename this file's namespace or class name.
        // However, you ARE allowed to use your own namespaces (or no namespaces at all if you prefer) in other classes.
        public static void Main(string[] args)
        {
            DungeonMaster game = new DungeonMaster();
            string        inputLine;

            while ((inputLine = Console.ReadLine()) != null && inputLine != string.Empty && game.IsOver == false)
            {
                try
                {
                    string[] arguments   = inputLine.Split();
                    string   commandType = arguments[0];

                    arguments = arguments.Skip(1).ToArray();
                    switch (commandType)
                    {
                    case "JoinParty":
                        Console.WriteLine(game.JoinParty(arguments));
                        break;

                    case "AddItemToPool":
                        Console.WriteLine(game.AddItemToPool(arguments));
                        break;

                    case "PickUpItem":
                        Console.WriteLine(game.PickUpItem(arguments));
                        break;

                    case "UseItem":
                        Console.WriteLine(game.UseItem(arguments));
                        break;

                    case "UseItemOn":
                        Console.WriteLine(game.UseItemOn(arguments));
                        break;

                    case "GiveCharacterItem":
                        Console.WriteLine(game.GiveCharacterItem(arguments));
                        break;

                    case "GetStats":
                        Console.Write(game.GetStats());
                        break;

                    case "Attack":
                        Console.WriteLine(game.Attack(arguments));
                        break;

                    case "Heal":
                        Console.WriteLine(game.Heal(arguments));
                        break;

                    case "EndTurn":
                        Console.Write(game.EndTurn(arguments));
                        break;

                    case "IsGameOver":
                        Console.WriteLine(game.IsGameOver());
                        break;
                    }
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine("Parameter Error: " + ex.Message);
                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine("Invalid Operation: " + ex.Message);
                }

                if (game.IsOver)
                {
                    break;
                }
            }

            Console.WriteLine("Final stats:");
            Console.Write(game.GetStats());
        }
        public void Run()
        {
            while (true)
            {
                string input = Console.ReadLine();

                if (string.IsNullOrEmpty(input) || dungeonMaster.IsGameOver())
                {
                    Console.WriteLine("Final stats:");
                    Console.WriteLine(dungeonMaster.GetStats());
                    break;
                }

                var inputArgs = input.Split();

                var commandName = inputArgs[0];
                var commandArgs = inputArgs.Skip(1).ToArray();

                try
                {
                    switch (commandName)
                    {
                    case "JoinParty":
                        Console.WriteLine(dungeonMaster.JoinParty(commandArgs));
                        break;

                    case "AddItemToPool":
                        Console.WriteLine(dungeonMaster.AddItemToPool(commandArgs));
                        break;

                    case "PickUpItem":
                        Console.WriteLine(dungeonMaster.PickUpItem(commandArgs));
                        break;

                    case "UseItem":
                        Console.WriteLine(dungeonMaster.UseItem(commandArgs));
                        break;

                    case "UseItemOn":
                        Console.WriteLine(dungeonMaster.UseItemOn(commandArgs));
                        break;

                    case "GiveCharacterItem":
                        Console.WriteLine(dungeonMaster.GiveCharacterItem(commandArgs));
                        break;

                    case "GetStats":
                        Console.WriteLine(dungeonMaster.GetStats());
                        break;

                    case "Attack":
                        Console.WriteLine(dungeonMaster.Attack(commandArgs));
                        break;

                    case "Heal":
                        Console.WriteLine(dungeonMaster.Heal(commandArgs));
                        break;

                    case "EndTurn":
                        Console.WriteLine(dungeonMaster.EndTurn(commandArgs));
                        break;

                    case "IsGameOver":
                        Console.WriteLine(dungeonMaster.IsGameOver());
                        break;
                    }
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine($"Parameter Error: {e.Message}");
                }
                catch (InvalidOperationException e)
                {
                    Console.WriteLine($"Invalid Operation: {e.Message}");
                }
            }
        }
Пример #10
0
        // DO NOT rename this file's namespace or class name.
        // However, you ARE allowed to use your own namespaces (or no namespaces at all if you prefer) in other classes.
        public static void Main(string[] args)
        {
            DungeonMaster dungeonMaster = new DungeonMaster();
            bool          isGameOver    = false;

            while (true)
            {
                try
                {
                    string input = Console.ReadLine();

                    if (string.IsNullOrEmpty(input) || isGameOver)
                    {
                        break;
                    }

                    string[] arguments = input.Split();
                    string   command   = arguments[0];
                    arguments = arguments.Skip(1).ToArray();

                    switch (command)
                    {
                    case "JoinParty":
                        Console.WriteLine(dungeonMaster.JoinParty(arguments));
                        break;

                    case "AddItemToPool":
                        Console.WriteLine(dungeonMaster.AddItemToPool(arguments));
                        break;

                    case "PickUpItem":
                        Console.WriteLine(dungeonMaster.PickUpItem(arguments));
                        break;

                    case "UseItem":
                        Console.WriteLine(dungeonMaster.UseItem(arguments));
                        break;

                    case "UseItemOn":
                        Console.WriteLine(dungeonMaster.UseItemOn(arguments));
                        break;

                    case "GiveCharacterItem":
                        Console.WriteLine(dungeonMaster.GiveCharacterItem(arguments));
                        break;

                    case "GetStats":
                        Console.WriteLine(dungeonMaster.GetStats());
                        break;

                    case "Attack":
                        Console.WriteLine(dungeonMaster.Attack(arguments));
                        break;

                    case "Heal":
                        Console.WriteLine(dungeonMaster.Heal(arguments));
                        break;

                    case "EndTurn":
                        Console.WriteLine(dungeonMaster.EndTurn(arguments));
                        break;

                    case "IsGameOver":
                        if (dungeonMaster.IsGameOver())
                        {
                            isGameOver = true;
                            Console.WriteLine(true);
                        }
                        else
                        {
                            Console.WriteLine(false);
                        }
                        break;
                    }
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine("Parameter Error: " + ae.Message);
                }
                catch (InvalidOperationException ioe)
                {
                    Console.WriteLine("Invalid Operation: " + ioe.Message);
                }
            }

            Console.WriteLine("Final stats:");
            Console.WriteLine(dungeonMaster.GetStats());
        }
Пример #11
0
        // DO NOT rename this file's namespace or class name.
        // However, you ARE allowed to use your own namespaces (or no namespaces at all if you prefer) in other classes.
        public static void Main(string[] args)
        {
            var dungeonMaster = new DungeonMaster();
            var input         = "";
            var output        = new StringBuilder();

            while (!string.IsNullOrEmpty(input = Console.ReadLine()))
            {
                try
                {
                    var arguments = input.Split();
                    var command   = arguments[0];
                    arguments = arguments.Skip(1).ToArray();

                    switch (command)
                    {
                    case "JoinParty":
                        output.AppendLine(dungeonMaster.JoinParty(arguments));
                        break;

                    case "AddItemToPool":
                        output.AppendLine(dungeonMaster.AddItemToPool(arguments));
                        break;

                    case "PickUpItem":
                        output.AppendLine(dungeonMaster.PickUpItem(arguments));
                        break;

                    case "UseItem":
                        output.AppendLine(dungeonMaster.UseItem(arguments));
                        break;

                    case "UseItemOn":
                        output.AppendLine(dungeonMaster.UseItemOn(arguments));
                        break;

                    case "GiveCharacterItem":
                        output.AppendLine(dungeonMaster.GiveCharacterItem(arguments));
                        break;

                    case "GetStats":
                        output.AppendLine(dungeonMaster.GetStats());
                        break;

                    case "Attack":
                        output.AppendLine(dungeonMaster.Attack(arguments));
                        break;

                    case "Heal":
                        output.AppendLine(dungeonMaster.Heal(arguments));
                        break;

                    case "EndTurn":
                        output.AppendLine(dungeonMaster.EndTurn(null));
                        break;

                    case "IsGameOver":
                        output.AppendLine(dungeonMaster.IsGameOver().ToString());
                        break;
                    }
                }
                catch (ArgumentException e)
                {
                    output.AppendLine($"Parameter Error: {e.Message}");
                }
                catch (InvalidOperationException e)
                {
                    output.AppendLine($"Invalid Operation: {e.Message}");
                }

                if (dungeonMaster.IsGameOver())
                {
                    break;
                }
            }

            output.AppendLine($"Final stats:{Environment.NewLine}{dungeonMaster.GetStats()}");

            Console.Write(output.ToString());
        }
Пример #12
0
        // DO NOT rename this file's namespace or class name.
        // However, you ARE allowed to use your own namespaces (or no namespaces at all if you prefer) in other classes.
        public static void Main(string[] args)
        {
            var master = new DungeonMaster();

            while (true)
            {
                var input = Console.ReadLine();
                if (String.IsNullOrEmpty(input))
                {
                    var builder = new StringBuilder();
                    builder.AppendLine("Final stats:");
                    builder.Append(master.GetStats());
                    Console.WriteLine(builder.ToString().Trim());
                    return;
                }

                string[] command   = input.Split();
                var      arguments = command.Skip(1).ToArray();

                try
                {
                    switch (command[0])
                    {
                    case "JoinParty":
                        Console.WriteLine(master.JoinParty(arguments));
                        break;

                    case "AddItemToPool":
                        Console.WriteLine(master.AddItemToPool(arguments));
                        break;

                    case "PickUpItem":
                        Console.WriteLine(master.PickUpItem(arguments));
                        break;

                    case "UseItem":
                        Console.WriteLine(master.UseItem(arguments));
                        break;

                    case "UseItemOn":
                        Console.WriteLine(master.UseItemOn(arguments));
                        break;

                    case "GiveCharacterItem":
                        Console.WriteLine(master.GiveCharacterItem(arguments));
                        break;

                    case "GetStats":
                        Console.WriteLine(master.GetStats());
                        break;

                    case "Attack":
                        Console.WriteLine(master.Attack(arguments));
                        break;

                    case "Heal":
                        Console.WriteLine(master.Heal(arguments));
                        break;

                    case "EndTurn":
                        Console.WriteLine(master.EndTurn(arguments));
                        if (master.IsGameOver())
                        {
                            var builder = new StringBuilder();
                            builder.AppendLine("Final stats:");
                            builder.Append((master.GetStats()));
                            Console.WriteLine(builder.ToString().Trim());
                            return;
                        }
                        break;

                    case "IsGameOver":
                        Console.WriteLine(master.IsGameOver());
                        break;
                    }
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine($"Parameter Error: {ae.Message}");
                }
                catch (InvalidOperationException ioe)
                {
                    Console.WriteLine($"Invalid Operation: {ioe.Message}");
                }
            }
        }
Пример #13
0
        static void Main(string[] args)
        {
            var engine = new DungeonMaster();

            string line = Console.ReadLine();

            while (!string.IsNullOrEmpty(line))
            {
                var array = line.Split(' ');

                if (array[0] == "IsGameOver")
                {
                    break;
                }
                try
                {
                    switch (array[0])
                    {
                    case "JoinParty":
                        Console.WriteLine(engine.JoinParty(array.Skip(1).ToArray()));
                        break;

                    case "AddItemToPool":
                        Console.WriteLine(engine.AddItemToPool(array.Skip(1).ToArray()));
                        break;

                    case "PickUpItem":
                        Console.WriteLine(engine.PickUpItem(array.Skip(1).ToArray()));
                        break;

                    case "UseItem":
                        Console.WriteLine(engine.UseItem(array.Skip(1).ToArray()));
                        break;

                    case "UseItemOn":
                        Console.WriteLine(engine.UseItemOn(array.Skip(1).ToArray()));
                        break;

                    case "GiveCharacterItem":
                        Console.WriteLine(engine.GiveCharacterItem(array.Skip(1).ToArray()));
                        break;

                    case "GetStats":
                        Console.WriteLine(engine.GetStats());
                        break;

                    case "Attack":
                        Console.WriteLine(engine.Attack(array.Skip(1).ToArray()));
                        break;

                    case "Heal":
                        Console.WriteLine(engine.Heal(array.Skip(1).ToArray()));
                        break;

                    case "EndTurn":
                        Console.WriteLine(engine.EndTurn());
                        break;
                    }
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine("Parameter Error: " + ex.Message);
                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine("Invalid Operation: " + ex.Message);
                }

                line = Console.ReadLine();
            }

            Console.WriteLine("Final stats:");
            Console.WriteLine(engine.GetStats());
        }
        // DO NOT rename this file's namespace or class name.
        // However, you ARE allowed to use your own namespaces (or no namespaces at all if you prefer) in other classes.
        public static void Main(string[] args)
        {
            DungeonMaster dungeonMaster = new DungeonMaster();
            string        input         = Console.ReadLine();

            while (!string.IsNullOrWhiteSpace(input))
            {
                string[] splitInput = input.Split();
                string   command    = splitInput[0];

                if (string.IsNullOrWhiteSpace(command))
                {
                    break;
                }

                string[] arguments = splitInput.Skip(1).ToArray();

                string output = string.Empty;

                try
                {
                    switch (command)
                    {
                    case "JoinParty":
                        output = dungeonMaster.JoinParty(arguments);
                        break;

                    case "AddItemToPool":
                        output = dungeonMaster.AddItemToPool(arguments);
                        break;

                    case "PickUpItem":
                        output = dungeonMaster.PickUpItem(arguments);
                        break;

                    case "UseItem":
                        output = dungeonMaster.UseItem(arguments);
                        break;

                    case "UseItemOn":
                        output = dungeonMaster.UseItemOn(arguments);
                        break;

                    case "GiveCharacterItem":
                        output = dungeonMaster.GiveCharacterItem(arguments);
                        break;

                    case "GetStats":
                        output = dungeonMaster.GetStats();
                        break;

                    case "Attack":
                        output = dungeonMaster.Attack(arguments);
                        break;

                    case "Heal":
                        output = dungeonMaster.Heal(arguments);
                        break;

                    case "EndTurn":
                        output = dungeonMaster.EndTurn(arguments);
                        break;

                    case "IsGameOver":
                        output = dungeonMaster.IsGameOver().ToString();
                        break;
                    }
                }
                catch (InvalidOperationException ex)
                {
                    output = $"Invalid Operation: {ex.Message}";
                }
                catch (ArgumentException ex)
                {
                    output = $"Parameter Error: {ex.Message}";
                }
                catch (Exception ex)
                {
                    output = ex.Message;
                }

                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(output);
                Console.ForegroundColor = ConsoleColor.White;

                if (dungeonMaster.IsGameOver())
                {
                    break;
                }

                input = Console.ReadLine();
            }

            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Final stats:");
            Console.WriteLine(dungeonMaster.GetStats());
        }
Пример #15
0
        public static void Main(string[] args)
        {
            var dungeonMaster = new DungeonMaster();

            while (dungeonMaster.IsGameOver() == false)
            {
                var input   = Console.ReadLine();
                var tokens  = input.Split(' ', StringSplitOptions.RemoveEmptyEntries).ToArray();
                var command = tokens[0];

                if (command == "JoinParty")
                {
                    try
                    {
                        Console.WriteLine(dungeonMaster.JoinParty(tokens.Skip(1).ToArray()));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
                else if (command == "AddItemToPool")
                {
                    try
                    {
                        Console.WriteLine(dungeonMaster.AddItemToPool(tokens.Skip(1).ToArray()));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
                else if (command == "PickUpItem")
                {
                    try
                    {
                        Console.WriteLine(dungeonMaster.PickUpItem(tokens.Skip(1).ToArray()));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
                else if (command == "UseItem")
                {
                    try
                    {
                        Console.WriteLine(dungeonMaster.UseItem(tokens.Skip(1).ToArray()));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }

                else if (command == "UseItemOn")
                {
                    try
                    {
                        Console.WriteLine(dungeonMaster.UseItemOn(tokens.Skip(1).ToArray()));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }

                else if (command == "GiveCharacterItem")
                {
                    try
                    {
                        Console.WriteLine(dungeonMaster.GiveCharacterItem(tokens.Skip(1).ToArray()));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }

                else if (command == "GetStats")
                {
                    try
                    {
                        Console.WriteLine(dungeonMaster.GetStats());
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }

                else if (command == "Attack")
                {
                    try
                    {
                        Console.WriteLine(dungeonMaster.Attack(tokens.Skip(1).ToArray()));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }


                else if (command == "Heal")
                {
                    try
                    {
                        Console.WriteLine(dungeonMaster.Heal(tokens.Skip(1).ToArray()));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }

                else if (command == "EndTurn")
                {
                    try
                    {
                        Console.WriteLine(dungeonMaster.EndTurn());
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
            }

            Console.WriteLine($"Final stats:");
            try
            {
                Console.WriteLine(dungeonMaster.GetStats());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Пример #16
0
        // DO NOT rename this file's namespace or class name.
        // However, you ARE allowed to use your own namespaces (or no namespaces at all if you prefer) in other classes.
        public static void Main()
        {
            DungeonMaster dungeonMaster = new DungeonMaster();

            var input = Console.ReadLine()?.Split();

            while (!string.IsNullOrEmpty(input[0]))
            {
                var command     = input[0];
                var commandArgs = input.Skip(1).ToArray();

                try
                {
                    switch (command)
                    {
                    case "JoinParty":
                        Console.WriteLine(dungeonMaster.JoinParty(commandArgs));
                        break;

                    case "AddItemToPool":
                        Console.WriteLine(dungeonMaster.AddItemToPool(commandArgs));
                        break;

                    case "PickUpItem":
                        Console.WriteLine(dungeonMaster.PickUpItem(commandArgs));
                        break;

                    case "UseItem":
                        Console.WriteLine(dungeonMaster.UseItem(commandArgs));
                        break;

                    case "UseItemOn":
                        Console.WriteLine(dungeonMaster.UseItemOn(commandArgs));
                        break;

                    case "GiveCharacterItem":
                        Console.WriteLine(dungeonMaster.GiveCharacterItem(commandArgs));
                        break;

                    case "GetStats":
                        Console.WriteLine(dungeonMaster.GetStats());
                        break;

                    case "Attack":
                        Console.WriteLine(dungeonMaster.Attack(commandArgs));
                        break;

                    case "Heal":
                        Console.WriteLine(dungeonMaster.Heal(commandArgs));
                        break;

                    case "EndTurn":
                        Console.WriteLine(dungeonMaster.EndTurn());
                        break;

                    case "IsGameOver":
                        Console.WriteLine(dungeonMaster.IsGameOver());
                        break;
                    }
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine($"Parameter Error: {ae.Message}");
                }
                catch (InvalidOperationException ioe)
                {
                    Console.WriteLine($"Invalid Operation: {ioe.Message}");
                }
                input = input = Console.ReadLine()?.Split();
            }
            Console.WriteLine("Final stats:");
            Console.WriteLine(dungeonMaster.GetStats());
        }
Пример #17
0
        public void Run()
        {
            DungeonMaster dm       = new DungeonMaster();
            bool          gameOver = false;

            while (true)
            {
                string input = Console.ReadLine();

                //if (string.IsNullOrEmpty(input))
                //{
                //    try set gameOver = true
                //    gameOver = true;
                //}

                if (string.IsNullOrEmpty(input))
                {
                    Console.Write(dm.GetStats());
                    return;
                }

                string[] command = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();

                try
                {
                    switch (command[0])
                    {
                    case "JoinParty":
                        Console.WriteLine(dm.JoinParty(command.Skip(1).ToArray()));
                        break;

                    case "AddItemToPool":
                        Console.WriteLine(dm.AddItemToPool(command.Skip(1).ToArray()));
                        break;

                    case "PickUpItem":
                        Console.WriteLine(dm.PickUpItem(command.Skip(1).ToArray()));
                        break;

                    case "UseItem":
                        Console.WriteLine(dm.UseItem(command.Skip(1).ToArray()));
                        break;

                    case "UseItemOn":
                        Console.WriteLine(dm.UseItemOn(command.Skip(1).ToArray()));
                        break;

                    case "GiveCharacterItem":
                        Console.WriteLine(dm.GiveCharacterItem(command.Skip(1).ToArray()));
                        break;

                    case "GetStats":
                        Console.WriteLine(dm.GetStats());
                        break;

                    case "Attack":
                        Console.Write(dm.Attack(command.Skip(1).ToArray()));
                        break;

                    case "Heal":
                        Console.WriteLine(dm.Heal(command.Skip(1).ToArray()));
                        break;

                    case "EndTurn":
                        Console.Write(dm.EndTurn(command.Skip(1).ToArray()));
                        gameOver = dm.IsGameOver();
                        //if (dm.IsGameOver())
                        //{
                        //    Console.Write(dm.GetStats());
                        //    return;
                        //}
                        break;

                    case "IsGameOver":
                        gameOver = dm.IsGameOver();
                        //if (dm.IsGameOver())
                        // {
                        //    Console.Write(dm.GetStats());
                        //    return;
                        //}
                        break;
                    }

                    if (gameOver)
                    {
                        Console.Write(dm.GetStats());
                        return;
                    }
                }
                catch (Exception exception)
                {
                    string exceptionDetails = string.Empty;

                    switch (exception.GetType().Name)
                    {
                    case "ArgumentException":
                        exceptionDetails = "Parameter Error:";
                        break;

                    case "InvalidOperationException":
                        exceptionDetails = "Invalid Operation:";
                        break;
                    }

                    Console.WriteLine($"{exceptionDetails} {exception.Message}");
                }
            }
        }
Пример #18
0
        // DO NOT rename this file's namespace or class name.
        // However, you ARE allowed to use your own namespaces (or no namespaces at all if you prefer) in other classes.
        public static void Main(string[] args)
        {
            DungeonMaster dungeonMaster = new DungeonMaster();

            while (!dungeonMaster.IsGameOver())
            {
                string first = Console.ReadLine();
                if (string.IsNullOrEmpty(first))
                {
                    Console.WriteLine("Final stats:");
                    Console.WriteLine(dungeonMaster.GetStats());
                    break;
                }
                string[] input = first.Split();

                try
                {
                    string[] arg = input.Skip(1).ToArray();

                    switch (input[0])
                    {
                    case "JoinParty":
                        Console.WriteLine(dungeonMaster.JoinParty(arg));
                        break;

                    case "AddItemToPool":
                        Console.WriteLine(dungeonMaster.AddItemToPool(arg));
                        break;

                    case "PickUpItem":
                        Console.WriteLine(dungeonMaster.PickUpItem(arg));
                        break;

                    case "UseItem":
                        Console.WriteLine(dungeonMaster.UseItem(arg));
                        break;

                    case "UseItemOn":
                        Console.WriteLine(dungeonMaster.UseItemOn(arg));
                        break;

                    case "GiveCharacterItem":
                        Console.WriteLine(dungeonMaster.GiveCharacterItem(arg));
                        break;

                    case "GetStats":
                        Console.WriteLine(dungeonMaster.GetStats());
                        break;

                    case "Attack":
                        Console.WriteLine(dungeonMaster.Attack(arg));
                        break;

                    case "Heal":
                        Console.WriteLine(dungeonMaster.Heal(arg));
                        break;

                    case "EndTurn":
                        Console.WriteLine(dungeonMaster.EndTurn(arg));
                        break;
                    }
                    if (dungeonMaster.IsGameOver())
                    {
                        Console.WriteLine("Final stats:");
                        Console.WriteLine(dungeonMaster.GetStats());
                    }
                }
                catch (Exception ex)
                {
                    if (ex is ArgumentException a)
                    {
                        Console.WriteLine($"Parameter Error: {a.Message}");
                    }
                    else if (ex is InvalidOperationException i)
                    {
                        Console.WriteLine($"Invalid Operation: {i.Message}");
                    }
                }
            }
        }
Пример #19
0
        // DO NOT rename this file's namespace or class name.
        // However, you ARE allowed to use your own namespaces (or no namespaces at all if you prefer) in other classes.
        public static void Main()
        {
            DungeonMaster master = new DungeonMaster();

            string command = Console.ReadLine();

            while (true)
            {
                if (string.IsNullOrEmpty(command))
                {
                    Console.WriteLine($"Final stats:");
                    Console.WriteLine(master.GetStats());
                    break;
                }

                string[] commandTokens = command.Split(' ');

                string[] methodArgs = commandTokens.Skip(1).ToArray();

                try
                {
                    switch (commandTokens[0])
                    {
                    case "JoinParty":
                        Console.WriteLine(master.JoinParty(methodArgs));
                        break;

                    case "AddItemToPool":
                        Console.WriteLine(master.AddItemToPool(methodArgs));
                        break;

                    case "PickUpItem":
                        Console.WriteLine(master.PickUpItem(methodArgs));
                        break;

                    case "UseItem":
                        Console.WriteLine(master.UseItem(methodArgs));
                        break;

                    case "UseItemOn":
                        Console.WriteLine(master.UseItemOn(methodArgs));
                        break;

                    case "GiveCharacterItem":
                        Console.WriteLine(master.GiveCharacterItem(methodArgs));
                        break;

                    case "GetStats":
                        Console.WriteLine(master.GetStats());
                        break;

                    case "Attack":
                        Console.WriteLine(master.Attack(methodArgs));
                        break;

                    case "Heal":
                        Console.WriteLine(master.Heal(methodArgs));
                        break;

                    case "EndTurn":
                        Console.WriteLine(master.EndTurn(methodArgs));
                        break;
                    }
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine("Parameter Error: " + ex.Message);
                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine("Invalid Operation: " + ex.Message);
                }

                if (master.IsGameOver())
                {
                    Console.WriteLine("Final stats:");
                    Console.WriteLine(master.GetStats());
                    break;
                }

                command = Console.ReadLine();
            }
        }
Пример #20
0
        // DO NOT rename this file's namespace or class name.
        // However, you ARE allowed to use your own namespaces (or no namespaces at all if you prefer) in other classes.
        public static void Main(string[] args)
        {
            DungeonMaster dungeonMaster = new DungeonMaster();

            string commnad = Console.ReadLine();

            while (true)
            {
                if (string.IsNullOrWhiteSpace(commnad))
                {
                    break;
                }

                if (dungeonMaster.IsGameOver())
                {
                    break;
                }
                string[] comandArgs = commnad.Split().ToArray();

                string commandName = comandArgs[0];

                switch (commandName)
                {
                case "JoinParty":

                    try
                    {
                        Console.WriteLine(dungeonMaster.JoinParty(comandArgs.Skip(1).ToArray()));
                    }
                    catch (ArgumentException argumentException)
                    {
                        Console.WriteLine(string.Format(ErrorMessages.ParametarError, argumentException.Message));
                    }
                    catch (InvalidOperationException invOpEx)
                    {
                        Console.WriteLine(string.Format(ErrorMessages.OperationError, invOpEx.Message));
                    }
                    break;

                case "AddItemToPool":
                    try
                    {
                        Console.WriteLine(dungeonMaster.AddItemToPool(comandArgs.Skip(1).ToArray()));
                    }
                    catch (ArgumentException argumentException)
                    {
                        Console.WriteLine(string.Format(ErrorMessages.ParametarError, argumentException.Message));
                    }
                    catch (InvalidOperationException invOpEx)
                    {
                        Console.WriteLine(string.Format(ErrorMessages.OperationError, invOpEx.Message));
                    }
                    break;

                case "PickUpItem":
                    try
                    {
                        Console.WriteLine(dungeonMaster.PickUpItem(comandArgs.Skip(1).ToArray()));
                    }
                    catch (ArgumentException argumentException)
                    {
                        Console.WriteLine(string.Format(ErrorMessages.ParametarError, argumentException.Message));
                    }
                    catch (InvalidOperationException invOpEx)
                    {
                        Console.WriteLine(string.Format(ErrorMessages.OperationError, invOpEx.Message));
                    }
                    break;

                case "UseItem":
                    try
                    {
                        Console.WriteLine(dungeonMaster.UseItem(comandArgs.Skip(1).ToArray()));
                    }

                    catch (ArgumentException argumentException)
                    {
                        Console.WriteLine(string.Format(ErrorMessages.ParametarError, argumentException.Message));
                    }
                    catch (InvalidOperationException invOpEx)
                    {
                        Console.WriteLine(string.Format(ErrorMessages.OperationError, invOpEx.Message));
                    }
                    break;

                case "UseItemOn":
                    try
                    {
                        Console.WriteLine(dungeonMaster.UseItemOn(comandArgs.Skip(1).ToArray()));
                    }
                    catch (ArgumentException argumentException)
                    {
                        Console.WriteLine(string.Format(ErrorMessages.ParametarError, argumentException.Message));
                    }
                    catch (InvalidOperationException invOpEx)
                    {
                        Console.WriteLine(string.Format(ErrorMessages.OperationError, invOpEx.Message));
                    }
                    break;

                case "GiveCharacterItem":
                    try
                    {
                        Console.WriteLine(dungeonMaster.GiveCharacterItem(comandArgs.Skip(1).ToArray()));
                    }
                    catch (ArgumentException argumentException)
                    {
                        Console.WriteLine(string.Format(ErrorMessages.ParametarError, argumentException.Message));
                    }
                    catch (InvalidOperationException invOpEx)
                    {
                        Console.WriteLine(string.Format(ErrorMessages.OperationError, invOpEx.Message));
                    }
                    break;

                case "GetStats":
                    try
                    {
                        Console.WriteLine(dungeonMaster.GetStats());
                    }
                    catch (ArgumentException argumentException)
                    {
                        Console.WriteLine(string.Format(ErrorMessages.ParametarError, argumentException.Message));
                    }
                    catch (InvalidOperationException invOpEx)
                    {
                        Console.WriteLine(string.Format(ErrorMessages.OperationError, invOpEx.Message));
                    }
                    break;

                case "Attack":
                    try
                    {
                        Console.WriteLine(dungeonMaster.Attack(comandArgs.Skip(1).ToArray()));
                    }
                    catch (ArgumentException argumentException)
                    {
                        Console.WriteLine(string.Format(ErrorMessages.ParametarError, argumentException.Message));
                    }
                    catch (InvalidOperationException invOpEx)
                    {
                        Console.WriteLine(string.Format(ErrorMessages.OperationError, invOpEx.Message));
                    }
                    break;

                case "Heal":
                    try
                    {
                        Console.WriteLine(dungeonMaster.Heal(comandArgs.Skip(1).ToArray()));
                    }
                    catch (ArgumentException argumentException)
                    {
                        Console.WriteLine(string.Format(ErrorMessages.ParametarError, argumentException.Message));
                    }
                    catch (InvalidOperationException invOpEx)
                    {
                        Console.WriteLine(string.Format(ErrorMessages.OperationError, invOpEx.Message));
                    }
                    break;

                case "EndTurn":
                    try
                    {
                        Console.WriteLine(dungeonMaster.EndTurn());
                        dungeonMaster.IsGameOver();
                    }
                    catch (ArgumentException argumentException)
                    {
                        Console.WriteLine(string.Format(ErrorMessages.ParametarError, argumentException.Message));
                    }
                    catch (InvalidOperationException invOpEx)
                    {
                        Console.WriteLine(string.Format(ErrorMessages.OperationError, invOpEx.Message));
                    }

                    break;
                }
                commnad = Console.ReadLine();
            }

            Console.WriteLine("Final stats:");
            Console.WriteLine(dungeonMaster.GetStats());
        }
Пример #21
0
        // DO NOT rename this file's namespace or class name.
        // However, you ARE allowed to use your own namespaces (or no namespaces at all if you prefer) in other classes.
        public static void Main(string[] args)
        {
            var dungeonMaster = new DungeonMaster();

            var input = "";

            while (!string.IsNullOrEmpty(input = Console.ReadLine()) && !dungeonMaster.IsGameOver())
            {
                try
                {
                    var command = input.Split()[0];

                    var details = input.Split().Skip(1).ToArray();

                    var output = "";

                    if (command == "JoinParty")
                    {
                        output = dungeonMaster.JoinParty(details);
                    }
                    else if (command == "AddItemToPool")
                    {
                        output = dungeonMaster.AddItemToPool(details);
                    }
                    else if (command == "PickUpItem")
                    {
                        output = dungeonMaster.PickUpItem(details);
                    }
                    else if (command == "UseItem")
                    {
                        output = dungeonMaster.UseItem(details);
                    }
                    else if (command == "UseItemOn")
                    {
                        output = dungeonMaster.UseItemOn(details);
                    }

                    else if (command == "GiveCharacterItem")
                    {
                        output = dungeonMaster.GiveCharacterItem(details);
                    }
                    else if (command == "GetStats")
                    {
                        output = dungeonMaster.GetStats();
                    }
                    else if (command == "Attack")
                    {
                        output = dungeonMaster.Attack(details);
                    }
                    else if (command == "Heal")
                    {
                        output = dungeonMaster.Heal(details);
                    }
                    else if (command == "EndTurn")
                    {
                        output = dungeonMaster.EndTurn(details);
                    }
                    else if (command == "IsGameOver")
                    {
                        output = dungeonMaster.IsGameOver().ToString();
                    }
                    if (!string.IsNullOrEmpty(output))
                    {
                        Console.WriteLine(output);
                    }
                }
                catch (Exception ex)
                {
                    if (ex is ArgumentException)
                    {
                        Console.WriteLine($"Parameter Error: {ex.Message}");
                    }
                    else
                    {
                        Console.WriteLine($"Invalid Operation: {ex.Message}");
                    }
                }
            }

            Console.WriteLine("Final stats:");
            Console.WriteLine(dungeonMaster.GetStats());
        }
Пример #22
0
        public string ProcessCommand(string[] splitCommand)
        {
            string cmd = splitCommand[0];

            string[] args = splitCommand.Skip(1).ToArray();

            string output = null;

            try
            {
                switch (cmd)
                {
                case "JoinParty":
                    output = dungeonMaster.JoinParty(args);
                    break;

                case "AddItemToPool":
                    output = dungeonMaster.AddItemToPool(args);
                    break;

                case "PickUpItem":
                    output = dungeonMaster.PickUpItem(args);
                    break;

                case "UseItem":
                    output = dungeonMaster.UseItem(args);
                    break;

                case "UseItemOn":
                    output = dungeonMaster.UseItemOn(args);
                    break;

                case "GiveCharacterItem":
                    output = dungeonMaster.GiveCharacterItem(args);
                    break;

                case "GetStats":
                    output = dungeonMaster.GetStats();
                    break;

                case "Attack":
                    output = dungeonMaster.Attack(args);
                    break;

                case "Heal":
                    output = dungeonMaster.Heal(args);
                    break;

                case "EndTurn":
                    output = dungeonMaster.EndTurn(args);
                    break;

                case "IsGameOver":
                    output = dungeonMaster.IsGameOver().ToString();
                    break;
                }
            }
            catch (ArgumentException ex)
            {
                output = "Parameter Error: " + ex.Message;
            }
            catch (InvalidOperationException ex)
            {
                output = "Invalid Operation: " + ex.Message;
            }

            return(output);
        }
Пример #23
0
        // DO NOT rename this file's namespace or class name.
        // However, you ARE allowed to use your own namespaces (or no namespaces at all if you prefer) in other classes.
        public static void Main(string[] args)
        {
            DungeonMaster dungeonMaster = new DungeonMaster();

            while (dungeonMaster.IsGameOver() == false)
            {
                string inputString = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(inputString))
                {
                    break;
                }
                var input = inputString.Split(' ');

                switch (input[0])
                {
                case "JoinParty":
                    try
                    {
                        Console.WriteLine(dungeonMaster.JoinParty(input.Skip(1).ToArray()));
                    }
                    catch (Exception exception)
                    {
                        HandleException(exception);
                        Console.WriteLine(exception.Message);
                    }
                    break;

                case "AddItemToPool":
                    try
                    {
                        Console.WriteLine(dungeonMaster.AddItemToPool(input.Skip(1).ToArray()));
                    }
                    catch (Exception exception)
                    {
                        HandleException(exception);
                    }
                    break;

                case "PickUpItem":
                    try
                    {
                        Console.WriteLine(dungeonMaster.PickUpItem(input.Skip(1).ToArray()));
                    }
                    catch (Exception exception)
                    {
                        HandleException(exception);
                    }
                    break;

                case "UseItem":
                    try
                    {
                        Console.WriteLine(dungeonMaster.UseItem(input.Skip(1).ToArray()));
                    }
                    catch (Exception exception)
                    {
                        HandleException(exception);
                    }
                    break;

                case "UseItemOn":
                    try
                    {
                        Console.WriteLine(dungeonMaster.UseItemOn(input.Skip(1).ToArray()));
                    }
                    catch (Exception exception)
                    {
                        HandleException(exception);
                    }
                    break;

                case "GiveCharacterItem":
                    try
                    {
                        Console.WriteLine(dungeonMaster.GiveCharacterItem(input.Skip(1).ToArray()));
                    }
                    catch (Exception exception)
                    {
                        HandleException(exception);
                    }
                    break;

                case "GetStats":
                    try
                    {
                        Console.WriteLine(dungeonMaster.GetStats());
                    }
                    catch (Exception exception)
                    {
                        HandleException(exception);
                    }
                    break;

                case "Attack":
                    try
                    {
                        Console.WriteLine(dungeonMaster.Attack(input.Skip(1).ToArray()));
                    }
                    catch (Exception exception)
                    {
                        HandleException(exception);
                    }
                    break;

                case "Heal":
                    try
                    {
                        Console.WriteLine(dungeonMaster.Heal(input.Skip(1).ToArray()));
                    }
                    catch (Exception exception)
                    {
                        HandleException(exception);
                    }
                    break;

                case "EndTurn":
                    try
                    {
                        Console.WriteLine(dungeonMaster.EndTurn(input));
                    }
                    catch (Exception exception)
                    {
                        HandleException(exception);
                    }
                    break;

                case "IsGameOver":
                    break;
                }
            }
            Console.WriteLine($"Final stats:\r\n{dungeonMaster.GetStats()}");
        }
Пример #24
0
        public void Start()
        {
            var  dungeon = new DungeonMaster();
            bool game    = false;

            while (!game)
            {
                try
                {
                    var inputLine = Console.ReadLine().Split();
                    var command   = inputLine[0];
                    var args      = inputLine.Skip(1).ToArray();
                    switch (command)
                    {
                    case "JoinParty": Console.WriteLine(dungeon.JoinParty(args));
                        break;

                    case "AddItemToPool": Console.WriteLine(dungeon.AddItemToPool(args));
                        break;

                    case "PickUpItem": Console.WriteLine(dungeon.PickUpItem(args));
                        break;

                    case "UseItem": Console.WriteLine(dungeon.UseItem(args));
                        break;

                    case "UseItemOn": Console.WriteLine(dungeon.UseItemOn(args));
                        break;

                    case "GiveCharacterItem": Console.WriteLine(dungeon.GiveCharacterItem(args));
                        break;

                    case "GetStats": Console.WriteLine(dungeon.GetStats());
                        break;

                    case "Attack": Console.WriteLine(dungeon.Attack(args));
                        break;

                    case "Heal": Console.WriteLine(dungeon.Heal(args));
                        break;

                    case "EndTurn": Console.WriteLine(dungeon.EndTurn(args));
                        game = dungeon.IsGameOver();
                        if (game)
                        {
                            Console.WriteLine($"Final stats:");
                            Console.WriteLine(dungeon.GetStats());
                        }
                        break;

                    case "IsGameOver": game = dungeon.IsGameOver();
                        Console.WriteLine($"Final stats:");
                        Console.WriteLine(dungeon.GetStats());
                        break;

                    default:
                        game = true;
                        Console.WriteLine($"Final stats:");
                        Console.WriteLine(dungeon.GetStats());
                        break;
                    }
                    //if (string.IsNullOrWhiteSpace(command))
                    //{
                    //    game = true;
                    //    Console.WriteLine($"Final stats:");
                    //    Console.WriteLine(dungeon.GetStats());
                    //}
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine("Parameter Error: " + e.Message);
                }
                catch (InvalidOperationException e)
                {
                    Console.WriteLine("Invalid Operation: " + e.Message);
                }
            }
        }
Пример #25
0
        // DO NOT rename this file's namespace or class name.
        // However, you ARE allowed to use your own namespaces (or no namespaces at all if you prefer) in other classes.
        public static void Main(string[] args)
        {
            DungeonMaster game = new DungeonMaster();

            while (true)
            {
                var input = Console.ReadLine();

                if (string.IsNullOrEmpty(input))
                {
                    GameStats(game);
                    GameOver();
                }

                var commands = input.Split(" ", StringSplitOptions.RemoveEmptyEntries);

                var command = commands[0];
                var tokens  = commands.Skip(1).ToArray();

                try
                {
                    switch (command)
                    {
                    case "JoinParty":
                        Print(game.JoinParty(tokens));
                        break;

                    case "AddItemToPool":
                        Print(game.AddItemToPool(tokens));
                        break;

                    case "PickUpItem":
                        Print(game.PickUpItem(tokens));
                        break;

                    case "UseItem":
                        Print(game.UseItem(tokens));
                        break;

                    case "UseItemOn":
                        Print(game.UseItemOn(tokens));
                        break;

                    case "GiveCharacterItem":
                        Print(game.GiveCharacterItem(tokens));
                        break;

                    case "GetStats":
                        Print(game.GetStats());
                        break;

                    case "Attack":
                        Print(game.Attack(tokens));
                        break;

                    case "Heal":
                        Print(game.Heal(tokens));
                        break;

                    case "EndTurn":
                        Print(game.EndTurn(tokens));
                        break;

                    case "IsGameOver":
                    {
                        if (game.IsGameOver())
                        {
                            GameStats(game);
                            GameOver();
                        }
                    }
                    break;
                    }
                }
                catch (ArgumentException e)
                {
                    Print($"Parameter Error: {e.Message}");
                }
                catch (InvalidOperationException e)
                {
                    Print($"Invalid Operation: {e.Message}");
                }
            }
        }
Пример #26
0
        // DO NOT rename this file's namespace or class name.
        // However, you ARE allowed to use your own namespaces (or no namespaces at all if you prefer) in other classes.
        public static void Main(string[] args)
        {
            DungeonMaster dungeon    = new DungeonMaster();
            bool          isGameOver = false;

            while (true)
            {
                string cmd = Console.ReadLine();
                if (cmd == null || cmd == string.Empty || String.IsNullOrWhiteSpace(cmd))
                {
                    break;
                }
                else
                {
                    string[] command = cmd.Split();
                    try
                    {
                        switch (command[0])
                        {
                        case "JoinParty":
                            string[] input = new string[command.Length - 1];
                            for (int i = 1; i < command.Length; i++)
                            {
                                input[i - 1] = command[i];
                            }
                            Console.WriteLine(dungeon.JoinParty(input));
                            break;

                        case "AddItemToPool":
                            string[] input1 = new string[1];
                            input1[0] = command[1];
                            Console.WriteLine(dungeon.AddItemToPool(input1));
                            break;

                        case "PickUpItem":
                            string[] input2 = new string[1];
                            input2[0] = command[1];
                            Console.WriteLine(dungeon.PickUpItem(input2));
                            break;

                        case "UseItem":
                            string[] input3 = new string[2];
                            input3[0] = command[1];
                            input3[1] = command[2];
                            Console.WriteLine(dungeon.UseItem(input3));
                            break;

                        case "UseItemOn":
                            string[] input4 = new string[3];
                            input4[0] = command[1];
                            input4[1] = command[2];
                            input4[2] = command[3];
                            Console.WriteLine(dungeon.UseItemOn(input4));
                            break;

                        case "GiveCharacterItem":
                            string[] input5 = new string[3];
                            input5[0] = command[1];
                            input5[1] = command[2];
                            input5[2] = command[3];
                            Console.WriteLine(dungeon.GiveCharacterItem(input5));
                            break;

                        case "GetStats":
                            Console.WriteLine(dungeon.GetStats());
                            break;

                        case "Attack":
                            string[] input6 = new string[2];
                            input6[0] = command[1];
                            input6[1] = command[2];
                            Console.WriteLine(dungeon.Attack(input6));
                            break;

                        case "Heal":
                            string[] input7 = new string[2];
                            input7[0] = command[1];
                            input7[1] = command[2];
                            Console.WriteLine(dungeon.Heal(input7));
                            break;

                        case "EndTurn":
                            Console.WriteLine(dungeon.EndTurn(new string[0]));
                            break;

                        case "IsGameOver":
                            isGameOver = dungeon.IsGameOver();
                            break;

                        default:
                            throw new NotImplementedException();
                        }
                        if (isGameOver)
                        {
                            break;
                        }
                    }
                    catch (ArgumentException ArgEx)
                    {
                        Console.WriteLine("Parameter Error: " + ArgEx.Message);
                    }
                    catch (InvalidOperationException OpEx)
                    {
                        Console.WriteLine("Invalid Operation: " + OpEx.Message);
                    }
                }
            }
            Console.WriteLine("Final stats:");
            Console.WriteLine(dungeon.GetStats());
        }
Пример #27
0
        static void Main(string[] args)
        {
            var master = new DungeonMaster();

            var input = Console.ReadLine();

            while (!String.IsNullOrEmpty(input))
            {
                try
                {
                    var arguments = input.Split(" ", StringSplitOptions.RemoveEmptyEntries);
                    var prefix    = arguments[0];
                    var info      = arguments.Skip(1).ToArray();
                    switch (prefix)
                    {
                    case "JoinParty":
                        Console.WriteLine(master.JoinParty(info));
                        break;

                    case "AddItemToPool":
                        Console.WriteLine(master.AddItemToPool(info));
                        break;

                    case "PickUpItem":
                        Console.WriteLine(master.PickUpItem(info));
                        break;

                    case "UseItem":
                        Console.WriteLine(master.UseItem(info));
                        break;

                    case "UseItemOn":
                        Console.WriteLine(master.UseItemOn(info));
                        break;

                    case "GiveCharacterItem":
                        Console.WriteLine(master.GiveCharacterItem(info));
                        break;

                    case "GetStats":
                        Console.WriteLine(master.GetStats());
                        break;

                    case "Attack":
                        Console.WriteLine(master.Attack(info));
                        break;

                    case "Heal":
                        Console.WriteLine(master.Heal(info));
                        break;

                    case "EndTurn":
                        Console.WriteLine(master.EndTurn(info));
                        break;

                    case "IsGameOver":
                        Console.WriteLine(master.IsGameOver());
                        break;
                    }
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine($"Parameter Error: {ae.Message}");
                }
                catch (InvalidOperationException ioe)
                {
                    Console.WriteLine($"Invalid Operation: {ioe.Message}");
                }

                if (master.IsGameOver())
                {
                    break;
                }

                input = Console.ReadLine();
            }

            Console.WriteLine($"Final stats:");
            Console.WriteLine(master.GetStats());
        }
Пример #28
0
        public static void Main()
        {
            var dungeon = new DungeonMaster();

            while (!dungeon.IsGameOver())
            {
                var inputLine = Console.ReadLine();

                if (string.IsNullOrEmpty(inputLine))
                {
                    break;
                }

                var    inputParams = inputLine.Split().ToList();
                string command     = inputParams[0];
                inputParams.RemoveAt(0);

                string result = null;

                try
                {
                    switch (command)
                    {
                    case "JoinParty":
                        result = dungeon.JoinParty(inputParams.ToArray());
                        break;

                    case "AddItemToPool":
                        result = dungeon.AddItemToPool(inputParams.ToArray());
                        break;

                    case "PickUpItem":
                        result = dungeon.PickUpItem(inputParams.ToArray());
                        break;

                    case "UseItem":
                        result = dungeon.UseItem(inputParams.ToArray());
                        break;

                    case "UseItemOn":
                        result = dungeon.UseItemOn(inputParams.ToArray());
                        break;

                    case "GiveCharacterItem":
                        result = dungeon.GiveCharacterItem(inputParams.ToArray());
                        break;

                    case "GetStats":
                        dungeon.GetStats();
                        break;

                    case "Attack":
                        result = dungeon.Attack(inputParams.ToArray());
                        break;

                    case "Heal":
                        result = dungeon.Heal(inputParams.ToArray());
                        break;

                    case "EndTurn":
                        result = dungeon.EndTurn(inputParams.ToArray());
                        break;

                    case "IsGameOver":
                        dungeon.IsGameOver();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    if (ex is ArgumentException)
                    {
                        Console.WriteLine("Parameter Error: " + ex.Message);
                    }

                    else if (ex is InvalidOperationException)
                    {
                        Console.WriteLine($"Invalid Operation: " + ex.Message);
                    }
                }

                Console.WriteLine(result);
            }

            Console.WriteLine("Final stats:");
            Console.Write(dungeon.GetStats());
        }
Пример #29
0
        // DO NOT rename this file's namespace or class name.
        // However, you ARE allowed to use your own namespaces (or no namespaces at all if you prefer) in other classes.
        public static void Main(string[] args)
        {
            DungeonMaster dungeonMaster = new DungeonMaster();
            string        input;

            while (string.IsNullOrEmpty(input = Console.ReadLine()) == false)
            {
                string[] split   = input.Split();
                string   command = split[0];
                try
                {
                    switch (command)
                    {
                    case "JoinParty":
                        Console.WriteLine(dungeonMaster.JoinParty(split.Skip(1).ToArray()));
                        break;

                    case "AddItemToPool":
                        Console.WriteLine(dungeonMaster.AddItemToPool(split.Skip(1).ToArray()));
                        break;

                    case "PickUpItem":
                        Console.WriteLine(dungeonMaster.PickUpItem(split.Skip(1).ToArray()));
                        break;

                    case "UseItem":
                        Console.WriteLine(dungeonMaster.UseItem(split.Skip(1).ToArray()));
                        break;

                    case "UseItemOn":
                        Console.WriteLine(dungeonMaster.UseItemOn(split.Skip(1).ToArray()));
                        break;

                    case "GiveCharacterItem":
                        Console.WriteLine(dungeonMaster.GiveCharacterItem(split.Skip(1).ToArray()));
                        break;

                    case "GetStats":
                        Console.WriteLine(dungeonMaster.GetStats());
                        break;

                    case "Attack":
                        Console.WriteLine(dungeonMaster.Attack(split.Skip(1).ToArray()));
                        break;

                    case "Heal":
                        Console.WriteLine(dungeonMaster.Heal(split.Skip(1).ToArray()));
                        break;

                    case "EndTurn":
                        Console.WriteLine(dungeonMaster.EndTurn(split.Skip(1).ToArray()));
                        if (dungeonMaster.IsGameOver())
                        {
                            Console.WriteLine("Final stats:");
                            Console.WriteLine(dungeonMaster.GetStats());
                            return;
                        }
                        break;

                    case "IsGameOver":
                        break;
                    }
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine("Parameter Error: " + ex.Message);
                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine("Invalid Operation: " + ex.Message);
                }
            }
            Console.WriteLine("Final stats:");
            Console.WriteLine(dungeonMaster.GetStats());
        }