Exemplo n.º 1
0
        private static void Execute(string inputLine)
        {
            var input   = inputLine.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var command = input[0];
            var args    = input.Skip(1).ToArray();

            var result = string.Empty;

            switch (command)
            {
            case "JoinParty":
                result = dm.JoinParty(args);
                break;

            case "AddItemToPool":
                result = dm.AddItemToPool(args);
                break;

            case "PickUpItem":
                result = dm.PickUpItem(args);
                break;

            case "UseItem":
                result = dm.UseItem(args);
                break;

            case "UseItemOn":
                result = dm.UseItemOn(args);
                break;

            case "GiveCharacterItem":
                result = dm.GiveCharacterItem(args);
                break;

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

            case "Attack":
                result = dm.Attack(args);
                break;

            case "Heal":
                result = dm.Heal(args);
                break;

            case "EndTurn":
                result = dm.EndTurn(args);
                break;

            case "IsGameOver":
                dm.IsGameOver();
                break;

            default:
                break;
            }

            output.AppendLine(result);
        }
Exemplo n.º 2
0
        private string ParseCommand(string[] args)
        {
            string commandType = args[0];
            string output      = "";

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

            switch (commandType)
            {
            case "JoinParty":
                output = dungeonMaster.JoinParty(data);
                break;

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

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

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

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

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

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

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

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

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

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

            default:
                throw new InvalidOperationException("Invalid command");
            }

            return(output);
        }
Exemplo n.º 3
0
        private void ReadCommand(string input)
        {
            if (string.IsNullOrEmpty(input))
            {
                this.isRunning = false;
                return;
            }

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

            var command = inputArgs[0];
            var args    = inputArgs.Skip(1).ToArray();

            switch (command)
            {
            case "JoinParty":
                this.writer.WriteLine(dungeonMaster.JoinParty(args));
                break;

            case "AddItemToPool":
                this.writer.WriteLine(dungeonMaster.AddItemToPool(args));
                break;

            case "PickUpItem":
                this.writer.WriteLine(dungeonMaster.PickUpItem(args));
                break;

            case "UseItem":
                this.writer.WriteLine(dungeonMaster.UseItem(args));
                break;

            case "UseItemOn":
                this.writer.WriteLine(dungeonMaster.UseItemOn(args));
                break;

            case "GiveCharacterItem":
                this.writer.WriteLine(dungeonMaster.GiveCharacterItem(args));
                break;

            case "GetStats":
                this.writer.WriteLine(dungeonMaster.GetStats());
                break;

            case "Attack":
                this.writer.WriteLine(dungeonMaster.Attack(args));
                break;

            case "Heal":
                this.writer.WriteLine(dungeonMaster.Heal(args));
                break;

            case "EndTurn":
                this.writer.WriteLine(dungeonMaster.EndTurn(args));
                break;
            }
        }
Exemplo n.º 4
0
        public void Run()
        {
            while (true)
            {
                try
                {
                    string inputLine = Console.ReadLine();
                    if (string.IsNullOrEmpty(inputLine))
                    {
                        Console.WriteLine("Final stats:");
                        Console.Write(dg.GetStats());
                        break;
                    }
                    string[] input   = inputLine.Split(' ', StringSplitOptions.RemoveEmptyEntries);
                    string   command = input[0].ToLower();

                    input = input.Skip(1).ToArray();
                    switch (command)
                    {
                    case "joinparty": Console.WriteLine(dg.JoinParty(input)); break;

                    case "additemtopool": Console.WriteLine(dg.AddItemToPool(input)); break;

                    case "pickupitem": Console.WriteLine(dg.PickUpItem(input)); break;

                    case "useitem": Console.WriteLine(dg.UseItem(input)); break;

                    case "useitemon": Console.WriteLine(dg.UseItemOn(input)); break;

                    case "givecharacteritem": Console.WriteLine(dg.GiveCharacterItem(input)); break;

                    case "getstats": Console.WriteLine(dg.GetStats()); break;

                    case "heal": Console.WriteLine(dg.Heal(input)); break;

                    case "attack": Console.WriteLine(dg.Attack(input)); break;

                    case "endturn": Console.WriteLine(dg.EndTurn(input)); break;
                    }
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine($"Parameter Error: {ae.Message}");
                }
                catch (InvalidOperationException ioe)
                {
                    Console.WriteLine($"Invalid Operation: {ioe.Message}");
                }
                if (dg.IsGameOver())
                {
                    Console.WriteLine("Final stats:");
                    Console.Write(dg.GetStats());
                    break;
                }
            }
        }
Exemplo n.º 5
0
        public void MoveCommand(string inputLine, DungeonMaster dm)
        {
            string[] input   = inputLine.Split();
            string   command = input[0];

            string[] args = new string[input.Length - 1];
            for (int i = 0; i < args.Length; i++)
            {
                args[i] = input[i + 1];
            }

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

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

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

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

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

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

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

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

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

            case "EndTurn":
                Console.WriteLine(dm.EndTurn(args));
                this.gameOver = dm.IsGameOver(); break;

            default: break;
            }
        }
Exemplo n.º 6
0
        public string ProcesCommand(string[] arr)
        {
            switch (arr[0])
            {
            case "JoinParty":
                return(cm.JoinParty(arr));

            case "AddItemToPool":
                return(cm.AddItemToPool(arr));

            case "PickUpItem":
                return(cm.PickUpItem(arr));

            case "UseItem":
                return(cm.UseItem(arr));

            case "UseItemOn":
                return(cm.UseItemOn(arr));

            case "GiveCharacterItem":
                return(cm.GiveCharacterItem(arr));

            case "GetStats":
                return(cm.GetStats());

            case "Attack":
                return(cm.Attack(arr));

            case "Heal":
                return(cm.Heal(arr));

            case "EndTurn":
                return(cm.EndTurn(arr));

            default:
                throw new ArgumentNullException("NE VLEZE");
            }
        }
Exemplo n.º 7
0
        public void Run()
        {
            string command    = Console.ReadLine();
            bool   isGameOver = false;

            while (!string.IsNullOrEmpty(command))
            {
                string[] args = command.Split();

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

                    case "AddItemToPool":
                        Console.WriteLine(master.AddItemToPool(args.Skip(1).ToArray()));
                        break;

                    case "PickUpItem":
                        Console.WriteLine(master.PickUpItem(args.Skip(1).ToArray()));
                        break;

                    case "UseItem":
                        Console.WriteLine(master.UseItem(args.Skip(1).ToArray()));
                        break;

                    case "UseItemOn":
                        Console.WriteLine(master.UseItemOn(args.Skip(1).ToArray()));
                        break;

                    case "GiveCharacterItem":
                        Console.WriteLine(master.GiveCharacterItem(args.Skip(1).ToArray()));
                        break;

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

                    case "Attack":
                        Console.WriteLine(master.Attack(args.Skip(1).ToArray()));
                        break;

                    case "Heal":
                        Console.WriteLine(master.Heal(args.Skip(1).ToArray()));
                        break;

                    case "EndTurn":
                        Console.WriteLine(master.EndTurn(args.Skip(1).ToArray()));
                        break;

                    case "IsGameOver":
                        isGameOver = master.IsGameOver();
                        break;
                    }
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine($"Parameter Error: {ex.Message}");
                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine($"Invalid Operation: {ex.Message}");
                }
                if (master.IsGameOver() || isGameOver)
                {
                    break;
                }
                command = Console.ReadLine();
            }
            Console.WriteLine("Final stats:");
            Console.WriteLine(master.GetStats());
        }
Exemplo n.º 8
0
        private void DistrubuteCommand(string[] inputParams)
        {
            var result  = "";
            var command = inputParams[0];

            inputParams = inputParams.Skip(1).ToArray();
            bool invalidCommand = false;

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

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

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

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

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

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

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

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

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

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

                case "IsGameOver":
                    result = $"Final stats:" + Environment.NewLine + $"{dungeonMaster.GetStats()}";
                    isRun  = dungeonMaster.IsGameOver();
                    break;

                default:
                    invalidCommand = true;
                    break;
                }
            }
            catch (Exception e)
            {
                if (e is ArgumentException)
                {
                    result = $"Parameter Error: {e.Message}";
                }
                else
                {
                    result = $"Invalid Operation: {e.Message}";
                }
            }
            if (string.IsNullOrWhiteSpace(command))
            {
                Console.WriteLine("Final stats:");
                Console.WriteLine($"{dungeonMaster.GetStats()}");
                isRun = false;
            }
            else if (!invalidCommand)
            {
                Console.WriteLine(result.TrimEnd());
                invalidCommand = false;
            }
            if (dungeonMaster.LastSurvivorsRounds > 1)
            {
                isRun = false;
                Console.WriteLine("Final stats:");
                Console.WriteLine($"{dungeonMaster.GetStats()}");
            }
        }
Exemplo n.º 9
0
        public void Run()
        {
            string input = Console.ReadLine();

            while (!string.IsNullOrEmpty(input))
            {
                string[] inputArgs = input.Split();

                string   command = inputArgs[0];
                string[] args    = inputArgs.Skip(1).ToArray();

                string result = string.Empty;

                try
                {
                    switch (command)
                    {
                    case "JoinParty":
                        result = dungeonMaster.JoinParty(args);
                        break;

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

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

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

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

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

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

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

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

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

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

                    default:
                        break;
                    }

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

                if (dungeonMaster.IsGameOver())
                {
                    break;
                }
                input = Console.ReadLine();
            }

            Console.WriteLine("Final stats:");
            Console.WriteLine(dungeonMaster.GetStats());
        }
        public void Run()
        {
            DungeonMaster dungeonMaster = new DungeonMaster();

            string command;

            while (this.IsRunning && !dungeonMaster.IsGameOver())
            {
                try
                {
                    command = Console.ReadLine();

                    if (string.IsNullOrEmpty(command))
                    {
                        this.IsRunning = false;
                        continue;
                    }
                    string   commandArg    = command.Split()[0];
                    string[] remainingArgs = command.Split().Skip(1).ToArray();

                    string result;
                    switch (commandArg)
                    {
                    case "JoinParty":
                        result = dungeonMaster.JoinParty(remainingArgs);
                        break;

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

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

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

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

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

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

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

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

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

                    case "IsGameOver":
                        result = dungeonMaster.IsGameOver().ToString();
                        break;

                    default:
                        result = "";
                        break;
                    }

                    Console.WriteLine(result);
                }
                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());
        }
Exemplo n.º 11
0
        public void ExecuteCommand(string[] inputArgs)
        {
            var command = inputArgs[0];

            var cmdArgs = inputArgs.Skip(1).ToArray();

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

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

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

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

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

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

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

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

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

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

                case "IsGameOver":
                    this.GameIsOver = dungeonMaster.IsGameOver();
                    break;
                }
            }
            catch (ArgumentException ae)
            {
                Console.WriteLine($"Parameter Error: {ae.Message}");
            }
            catch (InvalidOperationException io)
            {
                Console.WriteLine($"Invalid Operation: {io.Message}");
            }
        }
Exemplo n.º 12
0
        public void Run()
        {
            DungeonMaster dm = new DungeonMaster();
            string        input;

            while (!string.IsNullOrEmpty((input = Console.ReadLine())))
            {
                StringBuilder result  = new StringBuilder();
                string[]      args    = input.Split();
                string        command = args[0];
                args = args.Skip(1).ToArray();
                bool gameOver = false;

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

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

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

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

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

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

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

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

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

                    case "EndTurn":
                        Console.WriteLine(dm.EndTurn(args));
                        if (dm.IsGameOver())
                        {
                            gameOver = true;
                        }
                        break;

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

                if (gameOver)
                {
                    break;
                }
            }

            Console.WriteLine(dm.GameOver());
        }
Exemplo n.º 13
0
        public void Run()
        {
            string[] args = Console.ReadLine()
                            .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                            .ToArray();

            DungeonMaster dungeonMaster = new DungeonMaster();

            while (!string.IsNullOrEmpty(args[0]) || !dungeonMaster.IsGameOver())
            {
                string output = string.Empty;
                try
                {
                    switch (args[0].ToLower())
                    {
                    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":
                        if (dungeonMaster.IsGameOver())
                        {
                            output = $"\nFinal stats:\n{dungeonMaster.GetStats()}";
                        }
                        break;

                    default:
                        break;
                    }
                    if (dungeonMaster.IsGameOver())
                    {
                        output += $"\nFinal stats:\n{dungeonMaster.GetStats()}";
                        Console.WriteLine(output);
                        return;
                    }
                    Console.WriteLine(output);
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine($"Parameter Error: {ae.Message}");
                }
                catch (InvalidOperationException ioe)
                {
                    Console.WriteLine($"Invalid Operation: {ioe.Message}");
                }

                args = Console.ReadLine()
                       .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                       .ToArray();
            }
        }