Ejemplo n.º 1
0
 public void CannotCreateWithInvalidValues()
 {
     console.WriteLine("0");
     Assert.Throws <ArgumentOutOfRangeException> (() => RobotFactory.CreateRobot(console));
     console.WriteLine("10001");
     Assert.Throws <ArgumentOutOfRangeException> (() => RobotFactory.CreateRobot(console));
 }
 public Controller()
 {
     this.robotFactory = new RobotFactory();
     this.garage       = new Garage();
     this.procedures   = new Dictionary <string, IProcedure>();
     this.InitializeProcedures();
 }
Ejemplo n.º 3
0
        void StartRobot(string robotname)
        {
            btnDFFB.Enabled = false;
            btnJJC.Enabled  = false;
            btnMY.Enabled   = false;
            new Thread(() =>
            {
                Robot rbt = RobotFactory.GetRobot(robotname);
                currRot   = rbt;

                websocket.MessageReceived += new EventHandler <MessageReceivedEventArgs>(rbt.websocket_MessageReceived);
                rbt.SendMessageEvent      += Robot_SendMessageEvent;
                rbt.SendQuickMessageEvent += Robot_SendQuickMessageEvent;
                rbt.SendWaitMessageEvent  += Robot_SendWaitMessageEvent;
                rbt.IsContinue             = true;
                while (rbt.IsContinue)
                {
                    rbt.Run();
                }
                rbt.Run();
                websocket.MessageReceived -= new EventHandler <MessageReceivedEventArgs>(rbt.websocket_MessageReceived);
                this.Invoke(new Action(() =>
                {
                    btnDFFB.Enabled = true;
                    btnJJC.Enabled  = true;
                    btnMY.Enabled   = true;
                }));
            }).Start();
        }
Ejemplo n.º 4
0
    private void Awake()
    {
        levelGenerator          = GetComponent <LevelGenerator>();
        levelGeometry           = levelGenerator.Generate();
        levelGeometry.parent    = transform;
        levelGeometry.position -= Vector3.forward * levelGenerator.LaneSize;
        initialPosition         = levelGeometry.position;

        var robot = RobotFactory.GetRobot(RobotChangeManager.CurrentType);

        robotMov = robot.GetComponent <RobotMovement> ();
        Debug.Assert(robotMov != null, "Robot Prefab has no Robot Movement Component");
        robotMov.Init(this);

        var spawners = GetComponentsInChildren <Spawner> ();

        foreach (var s in spawners)
        {
            s.Init(this);
        }

        var hudController = GetComponentInChildren <HUDController> ();

        if (hudController != null)
        {
            hudController.Init(robot);
        }

        FillAvailableLastLanes();
    }
Ejemplo n.º 5
0
        public void TestCorrectSpinningOfRobot()
        {
            Arena.Instance.Init(5, 5);;
            int robotId = RobotFactory.CreateRobot(2, 2, RobotOrientation.N);

            Arena.Instance.Move(robotId, RobotCommandType.L);
            Assert.AreEqual(Arena.Instance.GetRobot(robotId).Orientation, RobotOrientation.W);

            Arena.Instance.Move(robotId, RobotCommandType.L);
            Assert.AreEqual(Arena.Instance.GetRobot(robotId).Orientation, RobotOrientation.S);

            Arena.Instance.Move(robotId, RobotCommandType.L);
            Assert.AreEqual(Arena.Instance.GetRobot(robotId).Orientation, RobotOrientation.E);

            Arena.Instance.Move(robotId, RobotCommandType.L);
            Assert.AreEqual(Arena.Instance.GetRobot(robotId).Orientation, RobotOrientation.N);

            Arena.Instance.Move(robotId, RobotCommandType.R);
            Assert.AreEqual(Arena.Instance.GetRobot(robotId).Orientation, RobotOrientation.E);

            Arena.Instance.Move(robotId, RobotCommandType.R);
            Assert.AreEqual(Arena.Instance.GetRobot(robotId).Orientation, RobotOrientation.S);

            Arena.Instance.Move(robotId, RobotCommandType.R);
            Assert.AreEqual(Arena.Instance.GetRobot(robotId).Orientation, RobotOrientation.W);

            Arena.Instance.Move(robotId, RobotCommandType.R);
            Assert.AreEqual(Arena.Instance.GetRobot(robotId).Orientation, RobotOrientation.N);
        }
Ejemplo n.º 6
0
        public static void Main(string[] args)
        {
            string response;
            var    jsonParameters      = LoadRobotParameters(args[0]);
            var    robotCreationResult = RobotFactory.GetRobot(jsonParameters);

            if (robotCreationResult.Item1.Equals(RobotConstructionStatus.Error))
            {
                response = "Parameters are not valid";
            }
            else
            {
                try
                {
                    response = JsonConvert.SerializeObject(robotCreationResult.Item2.Clean());
                }
                catch (RobotCleanerException e)
                {
                    Console.WriteLine(e.Message);
                    response = e.Response;
                }
            }

            WriteResponse(response);
        }
Ejemplo n.º 7
0
        public void test05_Checks_That_Adds_Robor_In_The_List()
        {
            #region Arrange

            pieces = new List <RobotPiece>();
            aRobot = new Robot(EOrigin.Earth, EModelName.WallE, pieces);

            #endregion

            #region Act

            int  listSizeBefore = RobotFactory.Robots.Count;
            bool addToWarehouse = RobotFactory.AddRobotToWarehouse(aRobot);
            int  listSizeAfter  = RobotFactory.Robots.Count;

            #endregion

            #region Assert

            Assert.AreEqual(0, listSizeBefore);
            Assert.IsTrue(addToWarehouse);
            Assert.AreEqual(1, listSizeAfter);

            #endregion
        }
Ejemplo n.º 8
0
        private static void StartTheRobot()
        {
            var minCoordinate = Coordinate.CreateInstance(-100_000, -100_000);
            var maxCoordinate = Coordinate.CreateInstance(100_000, 100_000);

            var commandsCount    = PrintOutInput("Please enter the number of robot commands:");
            var startingPosition = PrintOutInput("Please enter the starting position coordinates {x y}:");
            var commands         = new List <string>();

            for (var i = 1; i <= int.Parse(commandsCount); i++)
            {
                var cmd = PrintOutInput($"Please enter the command number ({i}):");
                commands.Add(cmd);
            }

            var inputs = new InputsModel
            {
                StartingPosition = startingPosition,
                Commands         = commands
            };

            _robot = RobotFactory.CreateRobot(inputs, minCoordinate, maxCoordinate);

            _robot.StartCleaning();
        }
Ejemplo n.º 9
0
 public Engine(IReader reader, IWriter writer)
 {
     this.reader    = reader;
     this.writer    = writer;
     citizenFactory = new CitizenFactory();
     robotFactory   = new RobotFactory();
     list           = new List <string>();
 }
Ejemplo n.º 10
0
        public void TestNotCorrectCreationOutOfBounderies()
        {
            Arena.Instance.Init(10, 10);

            Assert.ThrowsException <Exception>(() => RobotFactory.CreateRobot(2, 14, RobotOrientation.E), "Robot Y position cannot be greater than 10");
            Assert.ThrowsException <Exception>(() => RobotFactory.CreateRobot(10, 1, RobotOrientation.E), "Robot X position cannot be greater than 10");
            Assert.ThrowsException <Exception>(() => RobotFactory.CreateRobot(-1, 1, RobotOrientation.E), "Robot X position cannot be lower than 0");
            Assert.ThrowsException <Exception>(() => RobotFactory.CreateRobot(5, -2, RobotOrientation.E), "Robot Y position cannot be lower than 0");
        }
Ejemplo n.º 11
0
        public void TestOutOfTopRightBounderiesException()
        {
            Arena.Instance.Init(5, 5);;
            int robotId = RobotFactory.CreateRobot(4, 4, RobotOrientation.E);

            Assert.ThrowsException <Exception>(() => Arena.Instance.Move(robotId, RobotCommandType.M), "Robot cannot move to East, it is already at the limit");

            Arena.Instance.Move(robotId, RobotCommandType.L);
            Assert.ThrowsException <Exception>(() => Arena.Instance.Move(robotId, RobotCommandType.M), "Robot cannot move to North, it is already at the limit");
        }
Ejemplo n.º 12
0
    public void StartLevel(PlayerManager playerManager, RobotFactory factory)
    {
        this.playerManager = playerManager;
        levelActive        = true;

        SpawnRobots(factory);
        playerManager.StartLevel();

        Debug.Log("Started level " + ToString());
    }
Ejemplo n.º 13
0
        public void TestOutOfLeftBottomBounderiesException()
        {
            Arena.Instance.Init(5, 5);;
            int robotId = RobotFactory.CreateRobot(0, 0, RobotOrientation.W);

            Assert.ThrowsException <Exception>(() => Arena.Instance.Move(robotId, RobotCommandType.M), "Robot cannot move to West, it is already at the limit");

            Arena.Instance.Move(robotId, RobotCommandType.L);
            Assert.ThrowsException <Exception>(() => Arena.Instance.Move(robotId, RobotCommandType.M), "Robot cannot move to South, it is already at the limit");
        }
Ejemplo n.º 14
0
        public void GivenValidInstructions()
        {
            var instructions = new List<Instruction>()
            {
                new ForwardInstruction(),
                new LeftInstruction(),
                new RightInstruction()
            };

            this.robotFactory = new RobotFactory(instructions);
        }
Ejemplo n.º 15
0
        public void TestCorrectCreation()
        {
            Arena.Instance.Init(10, 10);

            int robotId = RobotFactory.CreateRobot(2, 4, RobotOrientation.E);

            Assert.AreNotEqual(robotId, 0);
            Assert.AreEqual(Arena.Instance.GetRobot(robotId).X, 2);
            Assert.AreEqual(Arena.Instance.GetRobot(robotId).Y, 4);
            Assert.AreEqual(Arena.Instance.GetRobot(robotId).Orientation, RobotOrientation.E);
        }
Ejemplo n.º 16
0
        public void ShouldCreateRobotSuccessfully()
        {
            console.WriteLine("2");
            console.WriteLine("10 22");
            console.WriteLine("N 2");
            console.WriteLine("E 1");

            var robot = RobotFactory.CreateRobot(console);

            Assert.That(robot, Is.Not.Null);
        }
Ejemplo n.º 17
0
        public IChallenge InitializeChallenge(ChallengeConfiguration configuration)
        {
            IChallenge challenge = ChallengeFactory.CreateChallenge(configuration.ChallengeGuid);

            if (challenge != null)
            {
                List <IRobot> robots = RobotFactory.CreateRobots(configuration.Robots);
                challenge.Initialize(robots, configuration.ChallengeMatDetails, configuration.IsSinglePlayer);
            }

            return(challenge);
        }
Ejemplo n.º 18
0
        static void Main(string[] args)
        {
            DisplayIntroductoryText();

            IRobot robot = RobotFactory.Create(TABLE_LENGTH, TABLE_WIDTH);

            while (true)
            {
                string command = Console.ReadLine();
                robot.ExecuteCommand(command);
            }
        }
Ejemplo n.º 19
0
 /// <summary>
 /// EventHandler of the button 'btnInitializeFactory'.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnInitializeFactory_Click(object sender, EventArgs e)
 {
     if (!isEnabled && RobotFactory.InitFactoryAndStock())
     {
         isEnabled = !isEnabled;
         this.GetMaterialStock();
         LockButtons(isEnabled);
     }
     else
     {
         MessageBox.Show("The factory has been already initialized");
     }
 }
Ejemplo n.º 20
0
        public void TestRobotFactories()
        {
            rf = new CyborgRobotFactory();

            Assert.IsInstanceOfType(rf.Generate(""), typeof(CyborgRobot));

            rf = new ScienceRobotFactory();

            Assert.IsInstanceOfType(rf.Generate(""), typeof(ScienceRobot));

            rf = new WorkerRobotFactory();

            Assert.IsInstanceOfType(rf.Generate(""), typeof(WorkerRobot));
        }
Ejemplo n.º 21
0
        static void Main(string[] args)
        {
            var robotFactory = new RobotFactory(new JsonDataSource());

            var robot = robotFactory.CreateRobot();

            Console.WriteLine(robot);

            robotFactory.ResetId(robot);

            Console.WriteLine(robot);

            ConsoleTools.CloseProgram();
        }
Ejemplo n.º 22
0
 /// <summary>
 /// EventHandler of the formClosing.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void frmLobby_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (MessageBox.Show("Are you sure to quit?", "Leaving", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
     {
         RobotFactory.SaveDataOfFactory();
         formShut = new frmShutdown();
         formShut.ShowDialog();
         MyPlayer.Stop();
         this.Dispose();
     }
     else
     {
         e.Cancel = true;
     }
 }
Ejemplo n.º 23
0
        static void Main(string[] args)
        {
            var consoleReader = new ConsoleInputReader()
                                .ReadNumberOfCommands()
                                .ReadStartPosition()
                                .ReadCommands();
            var robot         = RobotFactory.CreateCleaningRobotAt(consoleReader.StartPosition);
            var textCommander = new TextCommander(robot);

            foreach (var command in consoleReader.Commands)
            {
                textCommander.Execute(command);
            }

            Console.WriteLine("=> Cleaned: " + robot.GetLog().CleanedStations);
        }
Ejemplo n.º 24
0
        public void Test03_Check_Not_Enough_Material_To_Manufacture()
        {
            #region Arrange

            #endregion

            #region Act

            bool enoughMaterials = RobotFactory.CheckAmountOfMaterialsInBuckets((int)EModelName.DragonZord);

            #endregion

            #region Assert

            Assert.IsFalse(enoughMaterials);

            #endregion
        }
Ejemplo n.º 25
0
        private void StartRobots()
        {
            if (bool.Parse(ConfigurationManager.AppSettings["EnableRobots"]))
            {
                WriteLog("Start Robots", EventLogEntryType.Information);

                var factory = RobotFactory.CreateFactory();

                _robots = factory.CreateRobots();

                foreach (var robot in _robots)
                {
                    robot.Start(_fts);
                }

                WriteLog("Robots Started.", EventLogEntryType.Information);
            }
        }
Ejemplo n.º 26
0
        public void OnBuildingSelection(string building)
        {
            Building b = this.Buildings.FirstOrDefault(keyValPair => keyValPair.Key == this.ActConsBlockPos).Value;
            Dictionary <byte, int> actualRessources = null;

            if (b != null)
            {
                if (b.Built)
                {
                    return;
                }
                actualRessources = b.ActualRessources;
            }

            switch (building)
            {
            case "HQ":
                b = new HeadQuarter(this.mStateMgr, this.mIsland, this.mRTSManager.PlayerRTS);
                break;

            case "CD":
                b = new CrystalDrill(this.mStateMgr, this.mIsland, this.mRTSManager.PlayerRTS);
                break;

            case "RF":
                b = new RobotFactory(this.mStateMgr, this.mIsland, this.mRTSManager.PlayerRTS);
                break;

            case "G":
                b = new Generator(this.mStateMgr, this.mIsland, this.mRTSManager.PlayerRTS);
                break;
            }

            if (actualRessources == null)
            {
                actualRessources = b.NeededRessources.Keys.ToDictionary(key => key, key => 0);
            }
            b.ActualRessources = actualRessources;
            if (!this.Buildings.ContainsKey(this.ActConsBlockPos))
            {
                this.Buildings.Add(this.ActConsBlockPos, b);
            }
            b.DrawRemainingRessource();
        }
Ejemplo n.º 27
0
    public void cheer()
    {
        Console.WriteLine("cheer");

        Robot [] factory = new Robot[10];
        RobotFactory factory2 = new RobotFactory();

        Robot target2 = factory2[10];
        if (target2 != null)
        {
            target2.hp = 100;
        }

        Robot target1 = factory[10];
        if (target1 != null)
        {
            target1.hp = 100;
        }
    }
Ejemplo n.º 28
0
        /// <summary>
        /// Load Event Handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmLobby_Load(object sender, EventArgs e)
        {
            frmOpening opening = new frmOpening();

            opening.ShowDialog();
            try {
                MyPlayer.Play("MainTheme", true);
                if (File.Exists(fullMpersistencePath))
                {
                    RobotFactory.Buckets = smb.Read(fullMpersistencePath);
                }
                if (File.Exists(fullRpersistencePath))
                {
                    RobotFactory.Robots = smr.Read(fullRpersistencePath);
                    RobotFactory.ChargeBiography(biographyPath);
                }
            } catch (Exception ex) {
                frmLobby.FormExceptionHandler(ex);
            }
        }
Ejemplo n.º 29
0
            public static void Demo()
            {
                ManFactory   manFactory   = new ManFactory();
                WomanFactory womanFactory = new WomanFactory();
                RobotFactory robotFactory = new RobotFactory();

                List <Person> people = new List <Person>
                {
                    manFactory.CreatePerson(),
                              womanFactory.CreatePerson(),
                              robotFactory.CreatePerson(),
                              robotFactory.CreatePerson(),
                              manFactory.CreatePerson(),
                };

                foreach (Person item in people)
                {
                    item.doSomethins();
                }
            }
Ejemplo n.º 30
0
        /// <summary>
        /// Creates multiples pieces of the robot.
        /// </summary>
        /// <param name="metalType">Type Of metal of the robot.</param>
        /// <param name="origin">Origin of the robot.</param>
        /// <param name="modelName">Model name of the robot.</param>
        /// <param name="amountHead">Amount of heads of the robot.</param>
        /// <param name="amounTorso">Amount of torsos of the robot.</param>
        /// <param name="amountArms">Amount of arms of the robot.</param>
        /// <param name="amountLegs">Amount of legs of the robot.</param>
        /// <param name="amountTail">Amount of tails of the robot.</param>
        /// <param name="isRidable">boolean state that indicates if the robot is rideable or not.</param>
        private void ConfigureRobotForBuild(EMetalType metalType, EOrigin origin, EModelName modelName, int amountHead, int amounTorso, int amountArms, int amountLegs, int amountTail, bool isRidable)
        {
            amountOfMaterials = (int)modelName;
            int amountPieces = amountHead + amountArms + amountLegs + amounTorso + amountTail;
            int totalMaterialsForEachPiece = amountOfMaterials * amountPieces;

            if (RobotFactory.CheckAmountOfMaterialsInBuckets(totalMaterialsForEachPiece))
            {
                Robot prototype;
                prototype  = RobotFactory.CreateMultiplePiecesAndAddToStock(metalType, origin, modelName, amountOfMaterials, amountHead, amounTorso, amountArms, amountLegs, amountTail, isRidable);
                filename   = prototype.Model.ToString();
                absBioPath = $"{pathBiography}{filename}.bin";
                prototype.LoadBioFile(absBioPath);
                try {
                    if (RobotFactory.QualityControl(prototype, amountPieces))
                    {
                        if (RobotFactory.AddRobotToWarehouse(prototype))
                        {
                            ShowFormBuildingWithSound();
                            RobotFactory.SaveDataOfFactory();
                            prototype.SetSerialNumber();
                            DataAccessManager.InsertRobot(prototype);
                            ShowFormISOWithSound(prototype);
                        }
                    }
                    else
                    {
                        if (RobotFactory.DissasembleRobot(prototype))
                        {
                            throw new QualityControlFailedException("There have a difference in the amount of pieces, Quality control has failed!. For safety reasons, the robot was dismantled and its materials recycled.");
                        }
                    }
                } catch (Exception e) {
                    throw new Exception(e.Message, e);
                }
            }
            else
            {
                throw new InsufficientMaterialsException("Insufficients Materials to build this model of robot, you need to import more materials in the machine room or choose another model.");
            }
        }
Ejemplo n.º 31
0
        public void Test04_Robot_Fails_In_Quality()
        {
            #region Arrange

            pieces = new List <RobotPiece>();
            aRobot = new Robot(EOrigin.Earth, EModelName.WallE, pieces);

            #endregion

            #region Act

            bool failQualityControl = RobotFactory.QualityControl(aRobot, (int)aRobot.Model);

            #endregion

            #region Assert

            Assert.IsFalse(failQualityControl);

            #endregion
        }
Ejemplo n.º 32
0
        public void TestCorrectMovingOfRobot()
        {
            Arena.Instance.Init(5, 5);;
            int robotId = RobotFactory.CreateRobot(2, 2, RobotOrientation.N);

            Arena.Instance.Move(robotId, RobotCommandType.L);
            Arena.Instance.Move(robotId, RobotCommandType.M);
            Assert.AreEqual(Arena.Instance.GetRobot(robotId).X, 1);

            Arena.Instance.Move(robotId, RobotCommandType.L);
            Arena.Instance.Move(robotId, RobotCommandType.M);
            Assert.AreEqual(Arena.Instance.GetRobot(robotId).Y, 1);

            Arena.Instance.Move(robotId, RobotCommandType.L);
            Arena.Instance.Move(robotId, RobotCommandType.M);
            Assert.AreEqual(Arena.Instance.GetRobot(robotId).X, 2);

            Arena.Instance.Move(robotId, RobotCommandType.L);
            Arena.Instance.Move(robotId, RobotCommandType.M);
            Assert.AreEqual(Arena.Instance.GetRobot(robotId).Y, 2);
        }