private void MovePlayer(PlayerMoveModel result) { //Logger.DebugHighlight("[RecevieNtotication.MovePlayer] = " + result.playerNum + " / movePosition X : {0} Y : {1} : Z : {2}" , result.playerPosX, result.playerPosY, result.playerPosZ); PlayerManager.inst.UpdatePosition(result.playerNum, new Vector3(result.playerPosX , result.playerPosY , result.playerPosZ) , result.playerYaw); }
// undo the lastMove // entry into this method comes as a result of two things; 1) a player has clicked on the // undo button and, 2) the .Update() method of this class has picked up the truthy value of // undoLastMoveButtonControllerScript.shouldUndoLastMove. private void revertLastMove() { undoLastMoveButtonControllerScript.disable(); inturruptUndoLastMoveCoroutine(); PlayerMoveModel lastMove = GameBoardHistory.findLastPlayerMove(); if (GameBoardHistory.removeLastMoveFromHistory() && GameBoardController.removePlayerAtPoint(lastMove)) { removePlayerPieceFromPost(lastMove); finalizePlayerChange(); } }
// at a specific point on the gameBoard, change the value from -1 to the number representing the // player making the move. public static bool addPlayerAtPoint(PlayerMoveModel moveToMake) { if (!isValidMove(moveToMake.point)) { return false; } int level = moveToMake.point.level; int row = moveToMake.point.row; int column = moveToMake.point.column; gameBoard[level][row][column] = moveToMake.player; return true; }
// revert a specific point to INVALID_PLAYER // used during the undo process to remove a player piece from the gameBoard public static bool removePlayerAtPoint(PlayerMoveModel moveToRemove) { if (findPlayerAtPoint(moveToRemove.point) == moveToRemove.player) { int level = moveToRemove.point.level; int row = moveToRemove.point.row; int column = moveToRemove.point.column; gameBoard[level][row][column] = INVALID_PLAYER; return(true); } return(false); }
// at a specific point on the gameBoard, change the value from -1 to the number representing the // player making the move. public static bool addPlayerAtPoint(PlayerMoveModel moveToMake) { if (!isValidMove(moveToMake.point)) { return(false); } int level = moveToMake.point.level; int row = moveToMake.point.row; int column = moveToMake.point.column; gameBoard[level][row][column] = moveToMake.player; return(true); }
// given an array of formations, find one that is a winner public static FormationModel findWinningFormation(PlayerMoveModel moveToMake) { if (GameBoardHistory.isWinPossible()) { List <FormationModel> formations = FormationCollection.filterFormationsForPoint(moveToMake.point); List <FormationModel> formation = formations.Where(f => isWinningFormation(moveToMake.player, f.points)).ToList(); if (formation.Count != 0) { return(formation[0]); } } return(null); }
////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// // entry into this method comes from InteractWithGameBoardPost.OnMouseDown // this method kicks off all operations that need to happen when a player clicks a game post. public void willExecutePlayerMove(Vector3 postPosition, string postName) { if (!didStart || isComplete) { return; } if (undoLastMoveCoroutine != null) { inturruptUndoLastMoveCoroutine(); } PlayerMoveModel playerMove = new PlayerMoveModel(postName); executePlayerMove(playerMove, postPosition, postName); didExecutePlayerMove(postName, playerMove); finalizePlayerChange(); }
public ActionResult Move([FromBody] PlayerMoveModel playerMoveModel) { try { Guid playerId = playerMoveModel.PlayerId; int x = playerMoveModel.X; int y = playerMoveModel.Y; Game.Move(playerId, x, y); GameStateModel gameStateModel = new GameStateModel(Game); return(Json(gameStateModel)); } catch (Exception ex) { return(StatusCode(500, ex)); } }
// perform system cleanups and updates after a move has been made successfully // check for a win and stop the game if one is found. private void didExecutePlayerMove(string postName, PlayerMoveModel playerMove) { FormationModel winningFormation = GameBoardController.findWinningFormation(playerMove); if (winningFormation != null) { inturruptUndoLastMoveCoroutine(); isComplete = true; // show winning formation PlayerScoreController.declareWinner(playerMove.player); buildWinnerText(); return; } undoLastMoveCoroutine = enableUndoLastMove(); StartCoroutine(undoLastMoveCoroutine); }
// add a PlayerMoveModel to history List public static void addMoveToHistory(PlayerMoveModel moveToAdd) { history.Add(moveToAdd); length = history.Count; }
// remove a player piece from the view private void removePlayerPieceFromPost(PlayerMoveModel playerPiece) { GameObject pieceToRemove = GameObject.Find(playerPiece.translateBoardPositionToPieceName()); Destroy(pieceToRemove); }
// given an array of formations, find one that is a winner public static FormationModel findWinningFormation(PlayerMoveModel moveToMake) { if (GameBoardHistory.isWinPossible()) { List<FormationModel> formations = FormationCollection.filterFormationsForPoint(moveToMake.point); List<FormationModel> formation = formations.Where(f => isWinningFormation(moveToMake.player, f.points)).ToList(); if (formation.Count != 0) { return formation[0]; } } return null; }
////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// // place player piece in the view on the selected post private void executePlayerMove(PlayerMoveModel playerMove, Vector3 postPosition, string postName) { GameBoardController.addPlayerAtPoint(playerMove); GameBoardHistory.addMoveToHistory(playerMove); placePlayerPieceOnPost(postPosition, postName, playerMove.player); }
// revert a specific point to INVALID_PLAYER // used during the undo process to remove a player piece from the gameBoard public static bool removePlayerAtPoint(PlayerMoveModel moveToRemove) { if (findPlayerAtPoint(moveToRemove.point) == moveToRemove.player) { int level = moveToRemove.point.level; int row = moveToRemove.point.row; int column = moveToRemove.point.column; gameBoard[level][row][column] = INVALID_PLAYER; return true; } return false; }