示例#1
0
        public void Run()
        {
            string command = Console.ReadLine();

            while (!String.IsNullOrWhiteSpace(command) && !dungeonMaster.IsGameOver())
            {
                var cmdArgs = command
                              .Split();

                var cmdType    = cmdArgs[0];
                var methodArgs = cmdArgs.Skip(1).ToArray();

                try
                {
                    ParseCommand(cmdType, methodArgs);
                }
                catch (ArgumentException ae)
                {
                    Console.WriteLine("Parameter Error: " + ae.Message);
                }
                catch (InvalidOperationException ioe)
                {
                    Console.WriteLine("Invalid Operation: " + ioe.Message);
                }

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

                command = Console.ReadLine();
            }

            Console.WriteLine("Final stats:");
            Console.WriteLine(dungeonMaster.GetStats());
        }
示例#2
0
        public void Run()
        {
            var master = new DungeonMaster();

            while (true)
            {
                try
                {
                    var commandArgs    = Console.ReadLine().Split(' ').ToList();
                    var currentCommand = commandArgs[0];
                    commandArgs.RemoveAt(0);

                    switch (currentCommand)
                    {
                    case "JoinParty":
                        Console.WriteLine(master.JoinParty(commandArgs.ToArray()));
                        break;

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

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

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

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

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

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

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

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

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

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

                    default:
                        break;
                    }

                    if (master.IsGameOver())
                    {
                        break;
                    }
                }
                catch (ArgumentException argEx)
                {
                    Console.WriteLine($"Parameter Error: {argEx.Message}");
                }
                catch (InvalidOperationException invOpEx)
                {
                    Console.WriteLine($"Invalid Operation: {invOpEx.Message}");
                }
                catch (Exception e)
                {
                    break;
                }
            }

            Console.WriteLine("Final stats:");
            Console.WriteLine(master.GetStats());
        }