// checks for the winner by checking the pieces left on the game board public Guid?GetWinner(BoardGameState <Checkers> state, Guid white, Guid black) { Guid?winner = null; foreach (var c in state.Board) { if (c == Checkers.White || c == Checkers.WhiteKing) { whiteCheckers += 1; } if (c == Checkers.Black || c == Checkers.BlackKing) { blackCheckers += 1; } } if (whiteCheckers <= 1 && BoardGameMoveResult <Checkers> .ok == false) { winner = black; } if (blackCheckers <= 1 && BoardGameMoveResult <Checkers> .ok == false) { winner = white; } return(winner); }
public void OnActionMoveFinished() { //User has decided to confirm the movement. We must check if the tile he is selecting is valid for movement or not if(selectedTile.GetPermanentMarkType() == BoardMark.MarkType.Good) //We can check if the mark is Good or not :) { currentGameState = BoardGameState.Pointing; //Move the bug! BoardTile fromTile = board.GetBugTile( actionBug ); //Get the tile where the bug is before moving fromTile.SetBug(null); //There isnt a bug anymore in you Vector3 worldPos = board.GetWorldPos( selectedTile.GetTilePos() ); actionBug.MoveTo(worldPos); //Move the bug itself selectedTile.SetBug( actionBug ); //You have a new bug on you yay actionBug = null; //The action finished, so we don't need to track the action with the actionBug anymore //Unselect the tile and all stuff ResetEverything(); } else //Trying to move to a tile where another bug is in { //Warn the user somehow, ftm a log Debug.Log("Moving to a bad tile, try to move to a different location"); } }
protected virtual void AnnounceWinner() { _State = BoardGameState.GameOver; if (_WinnerTimer == null) { _WinnerTimer = new WinnerTimer(this, WinDelay); _WinnerTimer.Start(); } }
public BoardGameMoveResult <Checkers> MakeMove(BoardGameState <Checkers> state, string from, string to) { var xs = "ABCDE"; var ys = "12345"; int fromX = xs.IndexOf(from[0]); int fromY = ys.IndexOf(from[1]); int toX = xs.IndexOf(to[0]); int toY = ys.IndexOf(to[1]); // check if checker is in "from" position, return error result if not var dx = toX - fromX; var dy = toY - fromY; // check if move is in list of all valid moves var isValidMove = GetPossibleMoves(state, fromX, fromY) .Where(x => x.Item1 == dx && x.Item2 == dy) .Count() != 0; // if not, do not change state and return current state if (!isValidMove) { return(new BoardGameMoveResult <Checkers> { Ok = false, State = state }); } // update state by current move // move checker var checker = state.Board[fromY, fromX]; state.Board[fromY, fromX] = Checkers.Empty; state.Board[toY, toX] = checker; // capture if needed if (dx == 2 || dx == -2) { state.Board[fromY + dy / 2, fromX + dx / 2] = Checkers.Empty; } // promote to king if (checker == Checkers.White && toY == 0) { state.Board[toY, toX] = Checkers.WhiteKing; } if (checker == Checkers.Black && toY == 4) { state.Board[toY, toX] = Checkers.BlackKing; } return(new BoardGameMoveResult <Checkers> { Ok = true, State = state }); }
public override void Deserialize(GenericReader reader) { base.Deserialize(reader); int version = reader.ReadInt(); _BoardMap = version >= 2 ? reader.ReadMap() : Map; _AllowPlayerConfiguration = version < 1 || reader.ReadBool(); State = (BoardGameState) reader.ReadInt(); _CostToPlay = reader.ReadInt(); CurrentMaxPlayers = reader.ReadInt(); _BoardWidth = reader.ReadInt(); _BoardHeight = reader.ReadInt(); GameZone = new Rectangle3D(new Point3D(reader.ReadInt(), reader.ReadInt(), reader.ReadInt()), new Point3D(reader.ReadInt(), reader.ReadInt(), reader.ReadInt())); _BoardOffset = new Point3D(reader.ReadInt(), reader.ReadInt(), reader.ReadInt()); int count = reader.ReadInt(); for (int i = 0; i < count; i++) { Players.Add(reader.ReadMobile()); } count = reader.ReadInt(); for (int i = 0; i < count; i++) { BackgroundItems.Add((GamePiece) reader.ReadItem()); } if (_State == BoardGameState.Pending || _State == BoardGameState.Recruiting) { _State = BoardGameState.Inactive; _Players = null; } _BoardGameRegion = new BoardGameRegion(this); _BoardGameRegion.Register(); _SettingsReady = !_AllowPlayerConfiguration; }
List <Tuple <int, int> > GetPossibleMoves(BoardGameState <Checkers> state, int x, int y) { var moves = new List <Tuple <int, int> >() { GetValidMove(state, x, y, 1, 1), GetValidMove(state, x, y, 1, -1), GetValidMove(state, x, y, -1, -1), GetValidMove(state, x, y, -1, 1), GetValidMove(state, x, y, 2, 2), GetValidMove(state, x, y, 2, -2), GetValidMove(state, x, y, -2, -2), GetValidMove(state, x, y, -2, 2), }; moves = moves.Where(m => m != null).ToList(); return(moves); }
// GET: BoardGame public ActionResult Details(int id) { BoardGame boardGame = boardGameRepository.FindById(id); BoardGamePublisher publisher = boardGamePublisherRepository.FindById(boardGame.BoardGamePublisherId); BoardGameState state = boardGameStateRepository.FindById(boardGame.BoardGameStateId); return(View(new Models.BoardGame { BoardGameId = boardGame.BoardGameId, Name = boardGame.Name, Content = boardGame.Content, Description = boardGame.Description, MinimumAge = boardGame.MinimumAge, GameTimeInMinutes = boardGame.GameTimeInMinutes, MinPlayerCount = boardGame.MinPlayerCount, MaxPlayerCount = boardGame.MaxPlayerCount, BoardGamePublisherName = publisher.Name, BoardGameStateName = state.Name, Image = boardGame.Image })); }
public override void Deserialize( GenericReader reader ) { base.Deserialize( reader ); int version = reader.ReadInt(); if( version >= 2 ) { _BoardMap = reader.ReadMap(); } else { _BoardMap = Map; } if( version >= 1 ) { _AllowPlayerConfiguration = reader.ReadBool(); } else { _AllowPlayerConfiguration = true; } State = (BoardGameState)reader.ReadInt(); _CostToPlay = reader.ReadInt(); CurrentMaxPlayers = reader.ReadInt(); _BoardWidth = reader.ReadInt(); _BoardHeight = reader.ReadInt(); GameZone = new Rectangle3D( new Point3D( reader.ReadInt(), reader.ReadInt(), reader.ReadInt() ), new Point3D( reader.ReadInt(), reader.ReadInt(), reader.ReadInt() ) ); _BoardOffset = new Point3D( reader.ReadInt(), reader.ReadInt(), reader.ReadInt() ); int count = reader.ReadInt(); for( int i = 0; i < count; i++ ) { Players.Add( reader.ReadMobile() ); } count = reader.ReadInt(); for( int i = 0; i < count; i++ ) { BackgroundItems.Add( (GamePiece)reader.ReadItem() ); } if( _State == BoardGameState.Pending || _State == BoardGameState.Recruiting ) { _State = BoardGameState.Inactive; _Players = null; } _BoardGameRegion = new BoardGameRegion( this ); _BoardGameRegion.Register(); _SettingsReady = !_AllowPlayerConfiguration; }
protected virtual void AnnounceWinner() { _State = BoardGameState.GameOver; _WinnerTimer = new WinnerTimer( this, WinDelay ); _WinnerTimer.Start(); }
public override void Deserialize( GenericReader reader ) { base.Deserialize( reader ); int version = reader.ReadInt(); switch( version ) { case 3: { _AllowBaddaBoomUpgrade = reader.ReadBool(); _AllowSpeedUpgrade = reader.ReadBool(); _AllowBlastStrengthUpgrade = reader.ReadBool(); _AllowDetonatorUpgrade = reader.ReadBool(); goto case 2; } case 2: { _BoardMap = reader.ReadMap(); goto case 1; } case 1: { _AllowPlayerConfiguration = reader.ReadBool(); goto case 0; } case 0: { State = (BoardGameState)reader.ReadInt(); _CostToPlay = reader.ReadInt(); CurrentMaxPlayers = reader.ReadInt(); _BoardWidth = reader.ReadInt(); _BoardHeight = reader.ReadInt(); GameZone = new Rectangle3D( new Point3D( reader.ReadInt(), reader.ReadInt(), reader.ReadInt() ), new Point3D( reader.ReadInt(), reader.ReadInt(), reader.ReadInt() ) ); _BoardOffset = new Point3D( reader.ReadInt(), reader.ReadInt(), reader.ReadInt() ); int count = reader.ReadInt(); for( int i = 0; i < count; i++ ) { Players.Add( reader.ReadMobile() ); } count = reader.ReadInt(); for( int i = 0; i < count; i++ ) { BackgroundItems.Add( (GamePiece)reader.ReadItem() ); } if( _State == BoardGameState.Pending || _State == BoardGameState.Recruiting ) { _State = BoardGameState.Inactive; _Players = null; } _BoardGameRegion = new BoardGameRegion( this ); _BoardGameRegion.Register(); _SettingsReady = !_AllowPlayerConfiguration; break; } } }
public void OnActionDefense() { currentGameState = BoardGameState.Pointing; }
public void OnActionAttackStarted() { currentGameState = BoardGameState.AttackingWithBug; }
public void Start() { currentGameState = BoardGameState.Pointing; }
///////////////////////////////////////////////////////////////////////////////////////////////// // UTILS //////////////////////////////////////////////////////////// public void ResetEverything() { if (selectedTile != null) selectedTile.OnUnSelected(); if (selectedBug != null) selectedBug.OnUnSelected(); selectedBug = null; selectedTile = null; actionBug = null; board.GetMarkManager().ClearBoardMarks(); currentGameState = BoardGameState.Pointing; }
//ACTION EVENT LISTENERS //////////////////////////////////////////////////////////////////////////////// public void OnActionMoveStarted() { //Mark the board with the tiles the selected bug can move(travel) to currentGameState = BoardGameState.MovingBug; actionBug = selectedBug; int movementRange = actionBug.GetMovementRange(); Vector2 selectedTilePos = selectedTile.GetTilePos(); List<Vector2> bugPossibleMoves = actionBug.GetPossibleMoves(); //Get the possible moves of the bug board.GetMarkManager().MarkMovementRangeOnTheBoard(selectedTilePos, bugPossibleMoves); //Mark where the bug can go }
// returns null if move is invalid, otherwise (dx, dy) of checker Tuple <int, int> GetValidMove(BoardGameState <Checkers> state, int x, int y, int dx, int dy) { var checker = state.Board[y, x]; // if no checker at position if (checker == Checkers.Empty) { return(null); } //check that is moving player's own figure if (state.CurrentPlayer == state.WhitePlayerId && (checker == Checkers.Black || checker == Checkers.BlackKing)) { return(null); } if (state.CurrentPlayer != state.WhitePlayerId && (checker == Checkers.White || checker == Checkers.WhiteKing)) { return(null); } // if move is outside of board var newX = x + dx; if (newX > 4 || newX < 0) { return(null); } var newY = y + dy; if (newY > 4 || newY < 0) { return(null); } // black can't move up if (checker == Checkers.Black && dy < 0) { return(null); } // white can't move down if (checker == Checkers.White && dy > 0) { return(null); } if (state.Board[y + dy, x + dx] != Checkers.Empty) { return(null); } if (dx == 2) { var mX = x + dx / 2; var mY = y + dy / 2; var otherChecker = state.Board[mY, mX]; if (otherChecker == Checkers.Empty) { return(null); } // can't capture own checkers if (checker == Checkers.Black || checker == Checkers.BlackKing) { if (otherChecker == Checkers.Black || otherChecker == Checkers.BlackKing) { return(null); } } if (checker == Checkers.White || checker == Checkers.WhiteKing) { if (otherChecker == Checkers.White || otherChecker == Checkers.WhiteKing) { return(null); } } } return(Tuple.Create(dx, dy)); }