Пример #1
0
        public void ToggleOutofRangeColumnLow()
        {
            var g = new Grid(5, 5, 5);

            Assert.IsNotNull(g);

            Assert.Throws <ArgumentOutOfRangeException>(() => g.ActivatePosition(-1, 2));
        }
Пример #2
0
        public void ToggleOutofRangeRowHigh()
        {
            var g = new Grid(5, 5, 5);

            Assert.IsNotNull(g);

            Assert.Throws <ArgumentOutOfRangeException>(() => g.ActivatePosition(2, 10));
        }
Пример #3
0
        public void ToggleRight()

        /* create a grid of 5,5 dimensions with no initial random population and activate a position in the
         * rightmost column of the grid.
         * Test that
         * 1) The state of the activated position is true
         * 2) The state of the three adjacent positions is true
         * 3) That all other positions are false
         * 4) That the count of set positions is 4
         * */
        {
            var expectedPositions = new int[, ] {
                { 2, 4 }, { 1, 4 }, { 3, 4 }, { 2, 3 }
            };

            var g = new Grid(5, 5);

            Assert.IsNotNull(g, "grid object has not been instantiated");

            g.ActivatePosition(2, 4);
            Assert.AreEqual(g.CountLit, expectedPositions.GetLength(0), "Unexpected value of CountSet property");

            for (int r = 0; r < 5; r++)
            {
                for (int c = 0; c < 5; c++)
                {
                    if (isInSet(expectedPositions, r, c))
                    {
                        Assert.AreEqual(g[r, c], true, String.Format("Position {0},{1} is expected to be true", r, c));
                    }
                    else
                    {
                        Assert.AreEqual(g[r, c], false, String.Format("Position {0},{1} is expected to be false", r, c));
                    }
                }
            }
        }
Пример #4
0
        private void checkBox_Click(object sender, EventArgs e)
        {
            /* a checkbox has been clicked....extract the row/column position from the
             * Tag object and call the method to update the Grid object state.
             * Refresh the visual grid and check to see if the last move completed the game */

            var pos = ((Position)((CheckBox)sender).Tag);

            _Grid.ActivatePosition(pos.Row, pos.Column);
            RefreshDisplayedGrid();
            if (_Grid.Complete)
            {
                foreach (var cb in _Checkboxes)
                {
                    cb.Enabled = false;
                }

                var dlgRes = MessageBox.Show(
                    "You have completed the game. Click Menu->New Game to play again",
                    "Game over",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
            }
        }