Esempio n. 1
0
        public void Need_enough_tokens_to_repair()
        {
            gameState.Miner.InventoryItems.Add(new InventoryItem
            {
                Count = 10000,
                Item  = new GameItem
                {
                    Name = "Bolts"
                }
            });
            gameState.Miner.TaterTokens = 0;
            var command = new RepairCommand
            {
                GameState  = gameState,
                DiggerName = EXISTING_DIGGER_NAME,
            };

            repairCommandHandler.Handle(command);

            var output = ConsoleBufferHelper.GetLines(proc.Output);

            output[0].ShouldStartWith("Repairs will cost");
            output[1].ShouldBe("You don't have enough tokens.");
            output.Count().ShouldBe(2);
        }
Esempio n. 2
0
            public override bool IsTransferable(ACommand c)
            {
                RepairCommand command = c as RepairCommand;

                if (command != null)
                {
                    cache.Cached(command, new RepairCommandV1_0(command.MAX_DISTANCE));
                    return(true);
                }
                return(false);
            }
Esempio n. 3
0
        public void Digger_with_name_has_to_exist()
        {
            var command = new RepairCommand
            {
                GameState  = gameState,
                DiggerName = MISSING_DIGGER_NAME,
            };

            repairCommandHandler.Handle(command);

            var output = ConsoleBufferHelper.GetText(proc.Output);

            output.ShouldBe($"No digger named {MISSING_DIGGER_NAME} could be found.");
        }
Esempio n. 4
0
        public void Need_enough_bolts_to_repair()
        {
            var command = new RepairCommand
            {
                GameState  = gameState,
                DiggerName = EXISTING_DIGGER_NAME,
            };

            repairCommandHandler.Handle(command);

            var output = ConsoleBufferHelper.GetLines(proc.Output);

            output[0].ShouldStartWith("Repairs will cost");
            output[1].ShouldBe("You don't have enough bolts.");
            output.Count().ShouldBe(2);
        }
        private ACommand repairProcess(RepairCommand command, Battlefield.RobotAndBattlefield robotAndBattlefield)
        {
            Battlefield battlefield = robotAndBattlefield.BATTLEFIELD;
            Repairman   repairman   = robotAndBattlefield.ROBOT as Repairman;

            if (repairman == null)
            {
                return(new ErrorCommand(robotAndBattlefield.ROBOT.ROBOT_TYPE + " cannot use repair command."));
            }

            if (repairman.RepairToolUsed < repairman.RepairTool.MAX_USAGES && repairman.HitPoints > 0)
            {
                foreach (BattlefieldRobot robot in battlefield.robots)
                {
                    if (robot.HitPoints > 0)
                    {
                        double distance = EuclideanSpaceUtils.Distance(robot.Position,
                                                                       repairman.Position);
                        if (distance < command.MAX_DISTANCE)
                        {
                            Zone zone = Zone.GetZoneByDistance(repairman.RepairTool.ZONES, distance);
                            robot.HitPoints += zone.EFFECT;
                            robot.HitPoints  = Math.Min(robot.HitPoints, robot.Armor.MAX_HP);
                            if (repairman != robot)
                            {
                                repairman.Score += zone.EFFECT;
                            }
                        }

                        battlefield.battlefieldTurn.AddRepair(new ViewerLibrary.Repair(robot.X, robot.Y));
                    }
                }
                repairman.RepairToolUsed++;
                return(new RepairAnswerCommand(true));
            }
            else
            {
                return(new RepairAnswerCommand(false));
            }
        }