Esempio n. 1
0
        // Make the mechanic and the robots move
        public void Move()
        {
            Mechanic.FactoryWidth  = Width;
            Mechanic.FactoryHeight = Height;
            foreach (var movement in Mechanic.Movements)
            {
                Mechanic.Move(movement);
                // If the mechanic bumps into a robot, the robot will be oiled
                foreach (var robot in RobotList)
                {
                    if (robot.XPosition == Mechanic.XPosition & robot.YPosition == Mechanic.YPosition & robot.Alive)
                    {
                        robot.Oil();
                        Robots--;
                    }
                }

                if (RobotsMove)
                {
                    foreach (Robot robot in RobotList)
                    {
                        // Check the surrounding positions
                        robot.PositionCheckUp    = CheckPositions(robot.XPosition, robot.YPosition - 1);
                        robot.PositionCheckDown  = CheckPositions(robot.XPosition, robot.YPosition + 1);
                        robot.PositionCheckLeft  = CheckPositions(robot.XPosition - 1, robot.YPosition);
                        robot.PositionCheckRight = CheckPositions(robot.XPosition + 1, robot.YPosition);
                        // Move the robot in a random direction
                        robot.Move(Rnd.Next(1, 5));
                    }
                }
            }
        }
Esempio n. 2
0
        // Move the mechanic and the robots
        public void Move(string moves)
        {
            Hans.Move(moves);
            if (Hans.xCor < 1)
            {
                Hans.xCor = 1;
            }
            else if (Hans.yCor < 1)
            {
                Hans.yCor = 1;
            }
            else if (Hans.xCor > width)
            {
                Hans.xCor = width;
            }
            else if (Hans.yCor > height)
            {
                Hans.yCor = height;
            }

            if (robotsMove)
            {
                foreach (Robot robot in AllRobots)
                {
                    robot.Move(moves);
                    while (robot.xCor <1 | robot.xCor> width | robot.yCor <1 | robot.yCor> height)
                    {
                        robot.Move(moves);
                    }
                }
            }

            for (int i = 0; i < AllRobots.Count; i++)
            {
                if (AllRobots[i].xCor == Hans.xCor & AllRobots[i].yCor == Hans.yCor)
                {
                    OilRobot();
                }
            }
        }
Esempio n. 3
0
        public void MoveMechanic(string moves)
        {
            Bob.Move(moves);

            // Don't let Bob go out of bounds
            if (Bob.yPos < 1)
            {
                Bob.yPos = 1;
            }
            else if (Bob.xPos < 1)
            {
                Bob.xPos = 1;
            }
            else if (Bob.yPos > Height)
            {
                Bob.yPos = Height;
            }
            else if (Bob.xPos > Width)
            {
                Bob.xPos = Width;
            }
        }
Esempio n. 4
0
        // 1 ronde en verloren spel afsluiten
        public void Ronde(int turns, bool win)
        {
            PrintFactory();
            Console.Write("Geef de stappen: ");
            string input = Console.ReadLine();

            //Ga iedere zet af of er robots op een mechanic staan, of een robot op een robot staat, mechanic
            //in de fabriek houden en checken op dode robots
            foreach (char direction in input)
            {
                List <Robot> toRemove = new List <Robot>();
                foreach (Robot robot in robots)
                {
                    List <int> newPosition         = robot.Robotmoves(Width, Height);
                    GameObject objectOnNewPosition = GetObjectByPosition(newPosition[0], newPosition[1]);
                    if (objectOnNewPosition is Mechanic)
                    {
                        // robot verwijderen
                        toRemove.Add(robot);
                    }
                    else if (!(objectOnNewPosition is Robot))
                    {
                        robot.xpositie = newPosition[0];
                        robot.ypositie = newPosition[1];
                    }
                }
                foreach (Robot robot in toRemove)
                {
                    robots.Remove(robot);
                }
                Simone.Move(direction);
                // Zorgen dat Mechanic in de fabriek blijft
                //Als mechanic uit de fabriek loopt, blijft die op dezelfde plek staan.
                if (Simone.ypositie < 1)
                {
                    Simone.ypositie = 1;
                }
                else if (Simone.xpositie < 1)
                {
                    Simone.xpositie = 1;
                }
                else if (Simone.ypositie > Height)
                {
                    Simone.ypositie = Height;
                }
                else if (Simone.xpositie > Width)
                {
                    Simone.xpositie = Width;
                }
                // checken op dode robots
                for (int ii = robots.Count - 1; ii >= 0; ii--)
                {
                    if (Simone.xpositie == robots[ii].xpositie & Simone.ypositie == robots[ii].ypositie)
                    {
                        robots.RemoveAt(ii);
                    }
                }
            }

            Console.WriteLine(String.Format("You've got {0} turns left.", turns));
            //als je geen rondes meer over hebt, heb je verloren
            if (turns == 0)
            {
                Console.Clear();
                Console.WriteLine("Verloren");
            }

            win = win_je(win, turns);
        }