コード例 #1
0
ファイル: CLI.cs プロジェクト: muratsplat/HBFooCli
        public void Start()
        {
            var lineNumber = 0;
            var rovers     = new List <IRover>();

            while (In.Peek() >= 0)
            {
                lineNumber++;
                var line = In.ReadLine();
                // end of it
                if (line == null)
                {
                    break;
                }
                if (plateue.Match(line).Success || mars == null)
                {
                    var segment = line.Split(" ");
                    var x       = Int32.Parse(segment[0]);
                    var y       = Int32.Parse(segment[1]);
                    mars = new Plateue(new Point(x, y), new Point(0, 0));
                    continue;
                }

                if (roverInit.Match(line).Success)
                {
                    // 1 2 N
                    var segment = line.Split(" ");
                    var x       = Int32.Parse(segment[0]);
                    var y       = Int32.Parse(segment[1]);
                    var d       = segment[2];

                    if (mars != null)
                    {
                        var rover = new Rover(new Point(x, y), Compass.FromChar(d));
                        rovers.Add(mars.AddRover(rover));
                    }
                    continue;
                }
                if (commands.Match(line).Success)
                {
                    if (rovers.Count == 0)
                    {
                        throw new Exception("There is not rover which landed on mars!");
                    }
                    mars.Move(rovers[0], line);

                    Out.WriteLine(rovers[0].GetPosition());
                    mars.CallStation(rovers[0]);
                    rovers.Remove(rovers[0]);
                }
            }

            Out.Close();
        }
コード例 #2
0
ファイル: Rover.cs プロジェクト: muratsplat/HBFooCli
        public void Move()
        {
            if (Direction.Equals(Compass.FromChar("N")))
            {
                if (UpperRight == null)
                {
                    Point.Y++;
                }
                else if (Point.Y < UpperRight.Y)
                {
                    Point.Y++;
                }
                return;
            }

            if (Direction.Equals(Compass.FromChar("S")))
            {
                if (LowerLeft == null)
                {
                    Point.Y--;
                }
                else if (Point.Y > LowerLeft.Y)
                {
                    Point.Y--;
                }
                return;
            }
            if (Direction.Equals(Compass.FromChar("W")))
            {
                if (LowerLeft == null)
                {
                    Point.X--;
                }
                else if (Point.X > LowerLeft.X)
                {
                    Point.X--;
                }
                return;
            }

            if (UpperRight == null)
            {
                Point.X++;
                return;
            }
            else if (Point.X < UpperRight.X)
            {
                Point.X++;
            }
        }