예제 #1
0
 public GameBoardCellViewModel
 (
     GameBoardCoordinate gameBoardCoordinate,
     T content
 )
 {
     _gameBoardCoordinate = gameBoardCoordinate;
     Content = content;
 }
예제 #2
0
 public SnakeMasterViewModel
 (
     IGameBoardFactory gameBoardFactory
 )
 {
     _gameBoardFactory  = gameBoardFactory;
     _initialCoordinate = new GameBoardCoordinate(1, 11);
     _random            = new Random();
 }
예제 #3
0
        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));
            }
        }
예제 #4
0
 public IGameBoardCellViewModel <T> this[GameBoardCoordinate index]
 {
     get
     {
         IGameBoardCellViewModel <T> cell;
         if (_gameBoard.TryGetValue(index, out cell))
         {
             return(cell);
         }
         else
         {
             throw new OutOfGameBoardException(index);
         }
     }
 }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
 public GameBoardCellViewModel(GameBoardCoordinate gameBoardCoordinate) : this(gameBoardCoordinate, default(T))
 {
 }
예제 #8
0
 private SnakeCellViewModel GenerateCell(GameBoardCoordinate coordinate)
 {
     return(new SnakeCellViewModel());
 }