public GameBoardCellViewModel ( GameBoardCoordinate gameBoardCoordinate, T content ) { _gameBoardCoordinate = gameBoardCoordinate; Content = content; }
public SnakeMasterViewModel ( IGameBoardFactory gameBoardFactory ) { _gameBoardFactory = gameBoardFactory; _initialCoordinate = new GameBoardCoordinate(1, 11); _random = new Random(); }
private IEnumerable <IGameBoardCellViewModel <T> > GenerateRow <T>(int rowIndex, int columnCount, Func <GameBoardCoordinate, T> getCellContent) { for (int colIndex = 0; colIndex < columnCount; colIndex++) { var coordinate = new GameBoardCoordinate(colIndex, rowIndex); T content = getCellContent(coordinate); yield return(new GameBoardCellViewModel <T>(coordinate, content)); } }
public IGameBoardCellViewModel <T> this[GameBoardCoordinate index] { get { IGameBoardCellViewModel <T> cell; if (_gameBoard.TryGetValue(index, out cell)) { return(cell); } else { throw new OutOfGameBoardException(index); } } }
void LMUp(object sender, MouseButtonEventArgs e) { // Problem cases if (!(sender is SquareView)) { throw new ArgumentException(); } if (sender == null) { throw new ArgumentNullException(); } var square = ((SquareView)sender).GetValue(DataContextProperty); // Problem cases if (!(square is Square)) { throw new ArgumentException(); } // If nothing is selected, do nothing if (!dragSelection.selected) { return; } dragSelection.Deselect(); // Get which square did player drag the piece to GameBoardCoordinate coords = GridPositionToGridCoord(Mouse.GetPosition(GameBoardGrid)); // If piece is released outside the game board if (coords.R < 1 || coords.R > G.r || coords.C < 1 || coords.C > G.c) { return; } Square targetSquare = viewModel.table[coords.R, coords.C]; // If piece is released in the same square if (targetSquare == ((SquareView)sender).DataContext) { return; } // If a selected piece is released in a another square viewModel.Action(targetSquare); }
public SnakeyViewModel ( SnakeyToken snakeyToken, TimeSpan interval, bool doesSnakeySpeedUp, DirectionOfTravel initialDirectionOfTravel, GameBoardCoordinate initial ) { _snakeyToken = snakeyToken; _doesSnakeySpeedUp = doesSnakeySpeedUp; _interval = _initialInterval = interval; _directionOfTravel = initialDirectionOfTravel; _snakeBody = new Queue <GameBoardCoordinate>(); _snakeBody.Enqueue(initial); }
public GameBoardCellViewModel(GameBoardCoordinate gameBoardCoordinate) : this(gameBoardCoordinate, default(T)) { }
private SnakeCellViewModel GenerateCell(GameBoardCoordinate coordinate) { return(new SnakeCellViewModel()); }