public Board(int rows, int cols, int tileScale) { Rows = rows; Cols = cols; TileScale = tileScale; TileBoard = new CheckerTile[rows, cols]; bool black = true; for (var row = 0; row < rows; row++) //top to down { for (int col = cols - 1; col >= 0; col--) // right to left { TileBoard[row, col] = new CheckerTile(row, col, (black)?1:0); if (col != 0 || Cols % 2 != 0) black = !black; } } }
public void DrawCheckerBoard(CheckerTile[,] tileBoard, List<CheckerPiece> allPieces, CheckerPiece selectedPiece, List<CheckerPiece>[] movablePieces, Dictionary<CheckerPiece, List<MoveSet>> MoveDict, int TILE_SCALE, SpriteBatch spriteBatch, Camera cam) { if (!_contentLoaded) return; spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, cam.get_transformation(_device)); //Checker Tiles for (var row = 0; row < tileBoard.GetLength(0); row++) { for (int col = 0; col < tileBoard.GetLength(1); col++) { spriteBatch.Draw(_blankTexture, new Rectangle(col * TILE_SCALE, row * TILE_SCALE, TILE_SCALE, TILE_SCALE), null, (tileBoard[row, col].Color == 1)?Color.Gray:Color.White, 0, Vector2.Zero, SpriteEffects.None, 1); } } //Lines for (var row = 0; row <= tileBoard.GetLength(0); row++) { spriteBatch.Draw(_blankTexture, new Rectangle(0, row * TILE_SCALE, tileBoard.GetLength(1) * TILE_SCALE, 1), null, Color.Black, 0, Vector2.Zero, SpriteEffects.None, 0); } for (var col = 0; col <= tileBoard.GetLength(1); col++) { spriteBatch.Draw(_blankTexture, new Rectangle(col * TILE_SCALE, 0, 1, tileBoard.GetLength(0) * TILE_SCALE), null, Color.Black, 0, Vector2.Zero, SpriteEffects.None, 0); } spriteBatch.End(); //Draw Pieces DrawPieces(spriteBatch, cam, allPieces, TILE_SCALE); //Draw the possible moves if (selectedPiece != null && movablePieces != null && movablePieces[selectedPiece.Color].Contains(selectedPiece) && MoveDict.ContainsKey(selectedPiece)) { DrawPossibleMoves(spriteBatch, cam, MoveDict[selectedPiece], TILE_SCALE, selectedPiece); } }
public Board(int rows, int cols, int tileScale) { Rows = rows; Cols = cols; TileScale = tileScale; TileBoard = new CheckerTile[rows, cols]; bool black = true; for (var row = 0; row < rows; row++) //top to down { for (int col = cols - 1; col >= 0; col--) // right to left { TileBoard[row, col] = new CheckerTile(row, col, (black)?1:0); if (col != 0 || Cols % 2 != 0) { black = !black; } } } }
public CheckerPiece GetCheckerPiece(CheckerTile tile) { return GetCheckerPiece(tile.Row, tile.Col); }
public void HandleInput(GameTime gameTime) { lastKeyboardState = currentKeyboardState; lastGamePadState = currentGamePadState; currentKeyboardState = Keyboard.GetState(); currentGamePadState = GamePad.GetState(PlayerIndex.One); // Check for exit. if (currentKeyboardState.IsKeyDown(Keys.Escape) || currentGamePadState.Buttons.Back == ButtonState.Pressed) { Exit(); } if (CurrentGameStatus == GameStatus.Setup) { } else if (CurrentGameStatus == GameStatus.InProgress) { if (Mouse.GetState().LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed) { if ((CurrentVsType == VsType.PlayerVsCpu && _currentTurn == PlayerColor) || CurrentVsType == VsType.PlayerVsPlayer) { Vector2 worldPosition = Vector2.Transform(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), Matrix.Invert(_cam.get_transformation(GraphicsDevice))); CheckerTile tile = _checkerBoard.Board.GetCheckerTile(worldPosition); //Handle mouse input for the game if it is player vs player or (player vs cpu if it is the player's turn) if (CurrentVsType == VsType.PlayerVsPlayer || CurrentVsType == VsType.PlayerVsCpu && _currentTurn == PlayerColor) { //Check that the user clicked on a tile if (tile != null) { //User clicked on his own piece var checkerPiece = _checkerBoard.GetCheckerPiece(tile); if ((checkerPiece) != null && checkerPiece.Color == _currentTurn) { _checkerBoard.SelectedPiece = checkerPiece; if (_selectedParticle != null) { _selectedParticle.status = ParticleStatus.Dead; _selectedParticle = null; } _selectedParticle = _particleManager.Spawn(_particleManager.particleSystemInfoDict["fireSmall"], _checkerBoard.GetCenterOfTile(checkerPiece.Row, checkerPiece.Col)); } //If a user has selected a piece and the piece is a movable piece if (_checkerBoard.SelectedPiece != null && _checkerBoard.MovablePieces[_currentTurn].Contains(_checkerBoard.SelectedPiece) && _checkerBoard.MoveDict.ContainsKey(_checkerBoard.SelectedPiece) && _checkerBoard.MoveDict[_checkerBoard.SelectedPiece].Any(moveSet => moveSet.MoveList.First().Row == tile.Row && moveSet.MoveList.First().Col == tile.Col)) { //Handle the move to that location _checkerBoard.HandleMove(tile.Row, tile.Col); if (_selectedParticle != null) { _selectedParticle.status = ParticleStatus.Dead; _selectedParticle = null; } //Move to the next turn _currentTurn = _checkerBoard.NextTurn(_currentTurn); } } } } } } }
public CheckerPiece GetCheckerPiece(CheckerTile tile) { return(GetCheckerPiece(tile.Row, tile.Col)); }