public void RefreshFromModel(Latrunculi.Model.Board.T boardModel) { PiecesCount.Update(boardModel.WhitePiecesCount, boardModel.BlackPiecesCount); foreach (BoardRowViewModel rowVM in Rows) { foreach (BoardSquareViewModel sqVM in rowVM.Squares.OfType <BoardSquareViewModel>()) { Model.Square.T sq = boardModel.GetSquare(sqVM.Coord); sqVM.RefreshFromModel(sq); } } }
public void Init(Model.Board.T boardModel) { try { Clear(); History.Clear(); PiecesCount.Update(0, 0); Func <SquareColors, SquareColors> swapColor = new Func <SquareColors, SquareColors>(c => { return((c == SquareColors.scBlack) ? SquareColors.scWhite : SquareColors.scBlack); }); SquareColors color = SquareColors.scBlack; foreach (int rowNumber in boardModel.GetRowNumbers) { BoardRowViewModel row = new BoardRowViewModel(); Rows.Add(row); row.Squares.Add(new BoardSquareRowHeaderViewModel() { Content = string.Format("{0}", rowNumber) }); foreach (Tuple <Model.Coord.T, Model.Square.T> t in boardModel.GetCoordAndSquaresByRowNumber(rowNumber)) { BoardSquareViewModel sq = new BoardSquareViewModel(); sq.Init(t.Item1, color); row.Squares.Add(sq); color = swapColor(color); } color = swapColor(color); } BoardRowViewModel columnHeaders = new BoardRowViewModel(); columnHeaders.Squares.Add(new BoardSquareBottomLeftHeaderViewModel()); foreach (char col in Model.Coord.ColumnNumbers) { columnHeaders.Squares.Add(new BoardSquareColumnHeaderViewModel() { Content = string.Format("{0}", col) }); } Rows.Add(columnHeaders); } finally { OnNumberOfRowsOrColsChanged(); } }