Exemplo n.º 1
0
        public void TestGetFirstEmptyTile()
        {
            var player = new Object();
            var col = new Column(0);

            Assert.AreEqual(col[0], col.GetFirstEmptyTile());

            col[0].OwningPlayer = player;
            Assert.AreEqual(col[1], col.GetFirstEmptyTile());

            col[1].OwningPlayer = player;
            Assert.AreEqual(col[2], col.GetFirstEmptyTile());

            col[2].OwningPlayer = player;
            Assert.AreEqual(col[3], col.GetFirstEmptyTile());

            col[3].OwningPlayer = player;
            Assert.AreEqual(col[4], col.GetFirstEmptyTile());

            col[4].OwningPlayer = player;
            Assert.AreEqual(col[5], col.GetFirstEmptyTile());

            col[5].OwningPlayer = player;
            Assert.AreEqual(null, col.GetFirstEmptyTile());
        }
Exemplo n.º 2
0
        public void TestIsFull()
        {
            var player = new Object();
            var col = new Column(0);

            Assert.AreEqual(false, col.IsFull);

            col[0].OwningPlayer = player;
            col[1].OwningPlayer = player;
            col[2].OwningPlayer = player;
            col[3].OwningPlayer = player;
            Assert.AreEqual(false, col.IsFull);

            col[4].OwningPlayer = player;
            col[5].OwningPlayer = player;
            Assert.AreEqual(true, col.IsFull);
        }
Exemplo n.º 3
0
 public Tile(Column column, int rowNo)
 {
     _column = column;
     _rowNo = rowNo;
 }
Exemplo n.º 4
0
 public Tile(Column column, int rowNo, Object owningPlayer)
     : this(column, rowNo)
 {
     OwningPlayer = owningPlayer;
 }
Exemplo n.º 5
0
        private void DropTokenOnColumn(Column column)
        {
            if (column.IsFull) {
                throw new ApplicationException(string.Format("Cannot drop token on column {0} because it is full!", column.ColumnNo));
            }

            Tile tokenTile = column.GetFirstEmptyTile();
            tokenTile.OwningPlayer = _currentPlayer;

            //To-Do: We should probably check for a win condition now
            List<List<Tile>> winningSets = CheckForWin(tokenTile);
            if (winningSets.Count != 0) {
                //We have a winner
                _winningTile = tokenTile;
                _winningSets = winningSets;
                _winningPlayer = _currentPlayer;
                _currentPlayer = null;

            } else if (this.Board.GetAllPlaceableTiles().Count == 0) {
                _isStalemate = true;

            } else {
                //after a token has been dropped we update the current player
                _currentPlayer = GetNonCurrentPlayer();
            }

            //and let any subscribers know that the game state has changed
            if (GameStateChanged != null) {GameStateChanged(this, new EventArgs());}
        }