Example #1
0
    public void Run()
    {
        IsRunning = true;

        while (IsRunning)
        {
            string input = reader.ReadLine();
            try
            {
                ProcessCommand(input);
            }
            catch (ArgumentException ae)
            {
                writer.WriteLine($"Parameter Error: {ae.Message}");
            }
            catch (InvalidOperationException ioe)
            {
                writer.WriteLine($"Invalid Operation: {ioe.Message}");
            }
            if (dungeonMaster.IsGameOver() || this.IsRunning == false)
            {
                writer.WriteLine("Final stats:");
                writer.WriteLine(this.dungeonMaster.GetStats());
                IsRunning = false;
            }
        }
    }
    public void Run()
    {
        while (!dungeonMaster.IsGameOver())
        {
            string input = Console.ReadLine();

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

            ExecuteCommand(input);
        }

        Console.WriteLine("Final stats:" + Environment.NewLine + dungeonMaster.GetStats());
    }
Example #3
0
    public void Run()
    {
        string input = Console.ReadLine();

        while (!string.IsNullOrEmpty(input))
        {
            string[] tokens  = input.Split(' ');
            string   command = tokens[0];

            tokens = tokens.Skip(1).ToArray();

            string result = string.Empty;

            try
            {
                result = ReadAndExecuteCommand(tokens, command, result);
                if (result != string.Empty)
                {
                    Console.WriteLine(result);
                }
            }
            catch (InvalidOperationException invalidOperation)
            {
                Console.WriteLine("Invalid Operation: " + invalidOperation.Message);
            }
            catch (ArgumentException argumentException)
            {
                Console.WriteLine("Parameter Error: " + argumentException.Message);
            }

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

            input = Console.ReadLine();
        }

        Console.WriteLine("Final stats:");
        Console.WriteLine(dungeonMaster.GetStats());
    }
Example #4
0
    public void Run()
    {
        var    operations = new List <string>();
        string input      = Console.ReadLine();

        while (true)
        {
            if (string.IsNullOrEmpty(input))
            {
                break;
            }

            operations.Add(input);
            input = Console.ReadLine();
        }

        var isItOver = true;

        foreach (var operation in operations)
        {
            if (dm.IsGameOver())
            {
                Console.WriteLine(OutputMessage.FinalStats);
                Console.WriteLine(dm.GetStats());
                isItOver = false;
                break;
            }

            var inputArgs = operation.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
            var command   = inputArgs[0];
            var args      = inputArgs.Skip(1).ToArray();

            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));
                    break;

                default:
                    throw new InvalidOperationException("Wrong command!");
                }
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine("Parameter Error: " + ex.Message);
            }
            catch (InvalidOperationException ex)
            {
                Console.WriteLine("Invalid Operation: " + ex.Message);
            }
        }

        if (isItOver)
        {
            Console.WriteLine(OutputMessage.FinalStats);
            Console.WriteLine(dm.GetStats());
        }
    }
Example #5
0
    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}");
            }
        }
    }
Example #6
0
    public void Run()
    {
        while (!dungeonMaster.IsGameOver())
        {
            string input = Console.ReadLine();
            if (string.IsNullOrEmpty(input))
            {
                break;
            }
            string[] tokens  = input.Split();
            string   command = tokens[0];
            tokens = tokens.Skip(1).ToArray();

            try
            {
                switch (command)
                {
                case "JoinParty":
                    sb.AppendLine(dungeonMaster.JoinParty(tokens));
                    break;

                case "AddItemToPool":
                    sb.AppendLine(dungeonMaster.AddItemToPool(tokens));
                    break;

                case "PickUpItem":
                    sb.AppendLine(dungeonMaster.PickUpItem(tokens));
                    break;

                case "UseItem":
                    sb.AppendLine(dungeonMaster.UseItem(tokens));
                    break;

                case "UseItemOn":
                    sb.AppendLine(dungeonMaster.UseItemOn(tokens));
                    break;

                case "GiveCharacterItem":
                    sb.AppendLine(dungeonMaster.GiveCharacterItem(tokens));
                    break;

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

                case "Attack":
                    sb.AppendLine(dungeonMaster.Attack(tokens));
                    break;

                case "Heal":
                    sb.AppendLine(dungeonMaster.Heal(tokens));
                    break;

                case "EndTurn":
                    sb.AppendLine(dungeonMaster.EndTurn(tokens));
                    break;

                default:
                    break;
                }
            }
            catch (ArgumentException ae)
            {
                sb.AppendLine($"Parameter Error: {ae.Message}");
            }
            catch (InvalidOperationException ioe)
            {
                sb.AppendLine($"Invalid Operation: {ioe.Message}");
            }
        }
        sb.AppendLine("Final stats:")
        .AppendLine(dungeonMaster.GetStats());
        Console.WriteLine(sb.ToString().Trim());
    }
Example #7
0
    public void Run()
    {
        while (!dungeonMaster.IsGameOver())
        {
            try
            {
                string command = Console.ReadLine();

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

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

                string currentCommand = commTokens[0];

                switch (currentCommand)
                {
                case "JoinParty":
                    Console.WriteLine(this.dungeonMaster.JoinParty(commTokens.Skip(1).ToArray()));
                    break;

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

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

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

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

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

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

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

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

                case "EndTurn":
                    Console.WriteLine(this.dungeonMaster.EndTurn(commTokens.Skip(1).ToArray()));
                    break;

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

                default:
                    break;
                }
            }
            catch (Exception e)
            {
                if (e is ArgumentException)
                {
                    Console.WriteLine($"Parameter Error: {e.Message}");
                }
                else if (e is InvalidOperationException)
                {
                    Console.WriteLine($"Invalid Operation: {e.Message}");
                }
            }
        }
        Console.WriteLine($"Final stats:");
        Console.WriteLine(dungeonMaster.GetStats());
    }