예제 #1
0
        /// <summary>
        /// Le Main
        /// </summary>
        /// <param name="args">
        /// Program arguments
        /// </param>
        public static void Main(string[] args)
        {
            var counter = 1;

            // repeat until "0 0" is entered for dimension size input
            while (true)
            {
                // read dimension
                Console.Write("Field dimension (format 'n m'): ");
                string dimensionInput = Console.ReadLine();
                if (String.IsNullOrEmpty(dimensionInput))
                {
                    Console.WriteLine("Expecting dimension input");
                    break;
                }

                string[] dimensionParts = dimensionInput.Trim().Split(new[] { ' ' }, 2);
                if (dimensionParts.Length != 2)
                {
                    Console.WriteLine("Invalid input given, expecting dimension in format \"Width Height\" (e.g. \"4 3\"");
                    break;
                }

                int width, height;
                if (!ParseDimension(dimensionParts[0], "Width", out width))
                {
                    break;
                }

                if (!ParseDimension(dimensionParts[1], "Height", out height))
                {
                    break;
                }

                // validate input
                if (width == 0 && height == 0)
                {
                    break;
                }

                string fieldString = ReadField(width, height);

                // init
                var fieldParser = new FieldParser(MaxSize);
                var mineCounter = new MineCounter();
                var fieldSolver = new FieldSolver(mineCounter);

                Field field = fieldParser.ParseAsync(width, height, fieldString).Result;
                char[,] result = fieldSolver.GetTextualRepresentation(field);

                // output
                Console.WriteLine();
                Console.WriteLine("Field #{0}: ", counter);

                WriteResult(result);
                Console.WriteLine();

                ++counter;
            }
        }
예제 #2
0
 // Use this for initialization
 void Start()
 {
     number      = GetComponentInChildren <Text>();
     number.text = "";
     manager     = FindObjectOfType <GameManager>();
     counter     = FindObjectOfType <MineCounter>();
     condition   = FindObjectOfType <Conditions>();
 }
예제 #3
0
        public ControlPanel()
        {
            this.SuspendLayout();
            _newgame = new NewGameButton();
            this.Controls.Add(_newgame);

            _mineCtr = new MineCounter();
            this.Controls.Add(_mineCtr);

            _time = new TimeLabel();
            this.Controls.Add(_time);
            this.ResumeLayout();

            InitializeComponent();
            this.BackColor = Color.FromArgb(0, Color.White);
        }
예제 #4
0
        public void CalculateWhenFieldPassedThenAppropriateResultExpected()
        {
            // .***.
            // .*.*.
            // .***.
            // .....
            // ....*
            var field = new Field(
                5,
                5,
                new List <MinePoint>
            {
                new MinePoint(0, 1),
                new MinePoint(0, 2),
                new MinePoint(0, 3),
                new MinePoint(1, 1),
                new MinePoint(1, 3),
                new MinePoint(2, 1),
                new MinePoint(2, 2),
                new MinePoint(2, 3),
                new MinePoint(4, 4)
            });

            var expected = new[, ]
            {
                { 2, 3, 2, 1, 0 },
                { -1, -1, -1, 2, 0 },
                { -1, 8, -1, 3, 0 },
                { -1, -1, -1, 3, 1 },
                { 2, 3, 2, 2, -1 }
            };

            var counter = new MineCounter();
            var result  = counter.Calculate(field);

            result.Should().Equal(expected);
        }