public void ConstructionTest()
        {
            List <string> candidates = new List <string> {
                "1", "2", "3", "4"
            };
            NumberSquare square = new NumberSquare('-', candidates);

            Assert.IsNotNull(square.candidates);
            Assert.AreEqual(square.number, '-');
            square = new NumberSquare('1', candidates);
            Assert.IsNull(square.candidates);
            Assert.AreEqual(square.number, '1');
            try
            {
                square = new NumberSquare('5', candidates);
                Assert.Fail();
            }
            catch (Exception)
            {
            }
        }
        public override void GenerateBoard(Panel panel)
        {
            GetBoard().SetPanel(panel);

            IGenerator gen  = _factory.CreateGenerator("NativeGenerator");
            int        size = 0;

            switch (GetDifficulty())
            {
            case Difficulty.Beginner:
                size      = 8;
                MineCount = 10;
                break;

            case Difficulty.Intermediate:
                size      = 16;
                MineCount = 40;
                break;

            case Difficulty.Expert:
                size      = 24;
                MineCount = 99;
                break;
            }

            // Create and filter the board
            GetBoard().MakeBoard(size);
            char[,] board = gen.GenerateBoard(size, MineCount);
            ICriteria boardFilter = new SizeChecker(board, GetDifficulty());

            boardFilter = new MinesChecker(boardFilter);
            boardFilter = new NumberChecker(boardFilter);
            board       = boardFilter.Verify();

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    Square square;
                    switch (board[i, j])
                    {
                    case 'X':
                        square = new Mine(i, j);
                        break;

                    case '0':
                        square = new EmptySquare(i, j);
                        break;

                    default:
                        square = new NumberSquare(i, j, board[i, j] - '0');
                        break;
                    }

                    GetBoard().AddSquare(square);
                    AddSquareToGame(square);
                    //square.Button.Top += panel.Top;
                    //square.Button.Left += panel.Left;
                    panel.Controls.Add(square.Button);

                    square.Subscribe(this);
                }
            }

            // Start the game
            FlagCount           = MineCount;
            MineCountField.Text = FlagCount.ToString();
            GameTimer           = new GameTimer(TimerField);
            GameTimer.Start();
        }
Exemple #3
0
        public static void Load(ref List <List <NumberSquare> > rowList, ref List <List <NumberSquare> > colList)
        {
            foreach (var r in rowList)
            {
                foreach (var s in r)
                {
                    asd.Engine.RemoveObject2D(s.getBackTexture());
                    asd.Engine.RemoveObject2D(s.getTextObject());
                }
            }
            foreach (var c in colList)
            {
                foreach (var s in c)
                {
                    asd.Engine.RemoveObject2D(s.getBackTexture());
                    asd.Engine.RemoveObject2D(s.getTextObject());
                }
            }

            string str = string.Empty;

            using (var stream = new StreamReader(_filename, true))
            {
                str = stream.ReadToEnd();
            }
            var data = JsonConvert.DeserializeObject <Data>(str);

            rowList = new List <List <NumberSquare> >();
            {
                int row = 0;
                foreach (var r in data.RowData)
                {
                    List <NumberSquare> list = new List <NumberSquare>();
                    int col = -1;
                    foreach (var v in r)
                    {
                        var s = new NumberSquare(row, col);
                        s.SetValue(v.ToString());
                        asd.Engine.AddObject2D(s.getBackTexture());
                        asd.Engine.AddObject2D(s.getTextObject());
                        list.Add(s);
                        col--;
                    }
                    {
                        var s = new NumberSquare(row, col);
                        s.SetValue("0");
                        asd.Engine.AddObject2D(s.getBackTexture());
                        asd.Engine.AddObject2D(s.getTextObject());
                        list.Add(s);
                    }
                    rowList.Add(list);
                    row++;
                }
            }
            colList = new List <List <NumberSquare> >();
            {
                int col = 0;
                foreach (var c in data.ColData)
                {
                    List <NumberSquare> list = new List <NumberSquare>();
                    int row = -1;
                    foreach (var v in c)
                    {
                        var s = new NumberSquare(row, col);
                        s.SetValue(v.ToString());
                        asd.Engine.AddObject2D(s.getBackTexture());
                        asd.Engine.AddObject2D(s.getTextObject());
                        list.Add(s);
                        row--;
                    }
                    {
                        var s = new NumberSquare(row, col);
                        s.SetValue("0");
                        asd.Engine.AddObject2D(s.getBackTexture());
                        asd.Engine.AddObject2D(s.getTextObject());
                        list.Add(s);
                    }
                    colList.Add(list);
                    col++;
                }
            }
        }