コード例 #1
0
        private Coordinates GenerateMinePosition()
        {
            Coordinates position;

            do
            {
                position = new Coordinates(random.Next(this.field.Rows), random.Next(this.field.Cols));
            } while (this.field[position] != Field.Empty);

            return position;
        }
コード例 #2
0
 public static bool TryParse(string input, out Coordinates result)
 {
     try
     {
         result = Coordinates.Parse(input);
         return true;
     }
     catch
     {
         result = new Coordinates(0, 0);
         return false;
     }
 }
コード例 #3
0
        public static Coordinates Parse(string input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input", "Value can not be null.");
            }

            Match match = Regex.Match(input, @"^\s*(\d+)\s+(\d+)\s*$");

            if (!match.Success)
            {
                throw new FormatException("Input string was not in a correct format.");
            }

            int row = int.Parse(match.Groups[1].Value);
            int col = int.Parse(match.Groups[2].Value);

            Coordinates result = new Coordinates(row, col);
            return result;
        }
コード例 #4
0
        public void DetonateMine(Coordinates position)
        {
            Mine mine = this.field.GetMine(position);
            string[] area = detonationAreaOfMine[mine];

            Coordinates center = new Coordinates(area.GetLength(0) / 2, area[0].Length / 2);

            Coordinates topLeft = position - center;
            Coordinates bottomRight = position + center;

            this.field.ForEach(
                topLeft,
                bottomRight,
                currentPosition =>
                {
                    Coordinates areaPosition = currentPosition - topLeft;

                    if (area[areaPosition.Row][areaPosition.Col] != Detonator.Empty)
                    {
                        this.field.Destroy(currentPosition);
                    }
                });
        }
コード例 #5
0
ファイル: Field.cs プロジェクト: TeamPotassium/BattleField
        public void ForEach(Coordinates topLeft, Coordinates bottomRight, Action<Coordinates> action)
        {
            Coordinates innerTopLeft = new Coordinates(
                Math.Max(topLeft.Row, 0),
                Math.Max(topLeft.Col, 0));

            Coordinates innerBottomRight = new Coordinates(
                Math.Min(bottomRight.Row, this.Rows - 1),
                Math.Min(bottomRight.Col, this.Cols - 1));

            for (int row = innerTopLeft.Row; row <= innerBottomRight.Row; row++)
            {
                for (int col = innerTopLeft.Col; col <= innerBottomRight.Col; col++)
                {
                    action(new Coordinates(row, col));
                }
            }
        }
コード例 #6
0
ファイル: Field.cs プロジェクト: TeamPotassium/BattleField
 public void Destroy(Coordinates coordinates)
 {
     this[coordinates] = Field.Detonated;
 }
コード例 #7
0
ファイル: Field.cs プロジェクト: TeamPotassium/BattleField
 public string this[Coordinates coordinates]
 {
     get { return this[coordinates.Row, coordinates.Col]; }
     set { this[coordinates.Row, coordinates.Col] = value; }
 }
コード例 #8
0
ファイル: Field.cs プロジェクト: TeamPotassium/BattleField
        public bool IsMine(Coordinates coordinates)
        {
            bool result = true;

            result = result && this[coordinates] != Field.Empty;
            result = result && this[coordinates] != Field.Detonated;

            return result;
        }
コード例 #9
0
ファイル: Field.cs プロジェクト: TeamPotassium/BattleField
        public Mine GetMine(Coordinates position)
        {
            if (!IsMine(position))
            {
                throw new ArgumentException("There is no mine at this position.");
            }

            Mine mine = (Mine)int.Parse(this[position]);
            return mine;
        }