public void PlaceRandomTest() { int rows = 2, cols = 2; int colors = 1; int cells = rows * cols; Board b = new Board(rows, cols, colors); Tuple<Point, ushort>[] pieces = new Tuple<Point, ushort>[cells]; int i, j; for (i = 0; i < cells; i++) { pieces[i] = b.PlaceRandom(); } Assert.AreEqual(b.NumEmpty, 0); for (i = 0; i < cells; i++) { for (j = i + 1; j < cells; j++) { if (pieces[i].Item1.Equals(pieces[j].Item1)) Assert.Fail("duplicate empty points"); } } PrivateObject b_private = new PrivateObject(b); ushort[,] b_m_board = (ushort[,])b_private.GetField("m_board"); for (i = 0; i < rows; i++) { for (j = 0; j < cols; j++) { if (b_m_board[i, j] == 0) Assert.Fail("not all cells on the board filled"); } } bool threwException = false; try { b.PlaceRandom(); } catch (Exception) { threwException = true; } Assert.IsTrue(threwException, "did not throw exception on extra place"); }
public Game(ushort rows, ushort cols, ushort colors) { m_board = new Board(rows, cols, colors); m_view = new View(rows, cols, colors); m_view.OnClick += ClickHandler; m_view.OnMoveCompleted += MoveCompletedHandler; m_view.Show(); // place first 5 Tuple<Point, ushort>[] pieces = new Tuple<Point, ushort>[5]; do { for (int i = 0; i < 5; i++) pieces[i] = m_board.PlaceRandom(); // if we get a completed line, try again if (m_board.CheckLines(pieces[0].Item1).Count > 0) m_board.Clear(); else break; } while (true); for (int i = 0; i < 5; i++) m_view.Place(pieces[i].Item1, pieces[i].Item2); m_state = GameState.On; }