public void Run()
        {
            this.isRunning = true;

            while (this.isRunning)
            {
                string input = this.reader.ReadLine();
                try
                {
                    ReadCommand(input);
                }
                catch (ArgumentException ex)
                {
                    writer.WriteLine("Parameter Error: " + ex.Message);
                }
                catch (InvalidOperationException e)
                {
                    this.writer.WriteLine("Invalid Operation: " + e.Message);
                }

                if (this.dungeonMaster.IsGameOver() || this.isRunning == false)
                {
                    this.writer.WriteLine("Final stats:");
                    this.writer.WriteLine(dungeonMaster.GetStats());
                    this.isRunning = false;
                }
            }
        }
示例#2
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;
                }
            }
        }
示例#3
0
        public void Run()
        {
            string inputLine = Console.ReadLine();

            while (this.gameOver == false)
            {
                try
                {
                    MoveCommand(inputLine, dungeonMaster);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"{ex.GetBaseException().Message}");
                }

                if (this.gameOver == true)
                {
                    Console.WriteLine("Final stats:");
                    Console.WriteLine(dungeonMaster.GetStats());
                    return;
                }

                inputLine = Console.ReadLine();
            }
        }
示例#4
0
        public void Run()
        {
            while (GameIsOver == false)
            {
                var input = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(input))
                {
                    break;
                }
                var inputArgs = input.Split().ToArray();


                ExecuteCommand(inputArgs);
            }
            Console.WriteLine("Final stats:");
            Console.WriteLine(dungeonMaster.GetStats());
        }
示例#5
0
 public void Run()
 {
     while (this.isRun)
     {
         string input = Console.ReadLine();
         if (input == null)
         {
             Console.WriteLine("Final stats:");
             Console.WriteLine($"{dungeonMaster.GetStats()}");
             isRun = false;
         }
         else
         {
             var inputParams = input.Split().ToArray();
             DistrubuteCommand(inputParams);
         }
     }
 }
示例#6
0
        public void Run()
        {
            while (cm.IsGameOver() == false)
            {
                string[] line = Console.ReadLine().Split().ToArray();

                try
                {
                    Console.WriteLine(ProcesCommand(line));
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine($"ArgumentException: {ex.Message}");
                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine($"InvalidOperationException: {ex.Message}");
                }
            }
            Console.WriteLine(cm.GetStats());
        }
示例#7
0
        public void Run()
        {
            StringBuilder result = new StringBuilder();

            while (true)
            {
                try
                {
                    if (dungeonMaster.IsGameOver())
                    {
                        break;
                    }

                    string command = Console.ReadLine();

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

                    string[] args   = command.Split(' ');
                    string   output = ParseCommand(args);
                    result.AppendLine(output);
                }
                catch (ArgumentException ex)
                {
                    result.AppendLine("Parameter Error: " + ex.Message);
                }
                catch (InvalidOperationException ex)
                {
                    result.AppendLine("Invalid Operation: " + ex.Message);
                }
            }

            result.AppendLine("Final stats:");
            result.AppendLine(dungeonMaster.GetStats());

            Console.WriteLine(result.ToString().TrimEnd());
        }
示例#8
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;
            }
        }
示例#9
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());
        }
示例#10
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());
        }
示例#11
0
        public void Run()
        {
            string command = Console.ReadLine();

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

                string[] commandArgs = command.Split(' ');
                string   commandName = commandArgs[0];
                string[] args        = commandArgs.Skip(1).ToArray();
                string   output      = string.Empty;

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

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

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

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

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

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

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

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

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

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

                    if (output != string.Empty)
                    {
                        Console.WriteLine(output);
                    }
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine("Parameter Error: " + ae.Message);
                }
                catch (InvalidOperationException ioe)
                {
                    Console.WriteLine("Invalid Operation: " + ioe.Message);
                }

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

            Console.WriteLine("Final stats:");
            Console.WriteLine(dungeonMaster.GetStats());
        }
示例#12
0
        public void RunEngine()
        {
            string input = Console.ReadLine();

            while (!string.IsNullOrEmpty(input))
            {
                string[] args    = input.Split().ToArray();
                string   command = args[0];
                string[] tokkens = args.Skip(1).ToArray();
                string   result  = string.Empty;

                try
                {
                    if (command == "JoinParty")
                    {
                        result = this.DungeonMaster.JoinParty(tokkens);
                        Console.WriteLine(result);
                    }
                    else if (command == "AddItemToPool")
                    {
                        result = this.DungeonMaster.AddItemToPool(tokkens);
                        Console.WriteLine(result);
                    }
                    else if (command == "PickUpItem")
                    {
                        result = this.DungeonMaster.PickUpItem(tokkens);
                        Console.WriteLine(result);
                    }
                    else if (command == "UseItem")
                    {
                        result = this.DungeonMaster.UseItem(tokkens);
                        Console.WriteLine(result);
                    }
                    else if (command == "UseItemOn")
                    {
                        result = this.DungeonMaster.UseItemOn(tokkens);
                        Console.WriteLine(result);
                    }
                    else if (command == "GiveCharacterItem")
                    {
                        result = this.DungeonMaster.GiveCharacterItem(tokkens);
                        Console.WriteLine(result);
                    }
                    else if (command == "GetStats")
                    {
                        result = this.DungeonMaster.GetStats();
                        Console.WriteLine(result);
                    }
                    else if (command == "Attack")
                    {
                        result = this.DungeonMaster.Attack(tokkens);
                        Console.WriteLine(result);
                    }
                    else if (command == "Heal")
                    {
                        result = this.DungeonMaster.Heal(tokkens);
                        Console.WriteLine(result);
                    }
                    else if (command == "EndTurn")
                    {
                        result = this.DungeonMaster.EndTurn();
                        Console.WriteLine(result);
                    }
                    else if (command == "IsGameOver")
                    {
                        this.DungeonMaster.IsGameOver();
                    }
                }
                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: ");
            string finalStat = DungeonMaster.GetStats();

            Console.WriteLine(finalStat);
        }
        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());
        }
示例#14
0
 private void GetFinalStats()
 {
     output.AppendLine("Final stats:");
     output.AppendLine(dm.GetStats());
 }
        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());
        }
        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();
            }
        }