/// <summary> /// Helper function - Actually moves the player /// </summary> public void movePlayer() { FeedbackGUI.setText("Moving player."); if (gM.CurrentRoll == 1) //save to turn this card back over again { movedTo = tempCard; } //update the player's grid position Vector2 position = PositionToVector2(gM.players[gM.CurrentPlayerIndex].transform.position); gM.players[gM.CurrentPlayerIndex].Position = position; //set the player's current card gM.players[gM.CurrentPlayerIndex].CurrentCard = tempCard; gM.players[gM.CurrentPlayerIndex].CurrentCard = gM.board[(int)position.x, (int)position.y].GetComponent <Card>(); //send changes to server if (gM.isOnline) { gM.jsonFx.PerformUpdate("update_entity_pos/" + gM.players[gM.CurrentPlayerIndex].Position.x + "/" + gM.players[gM.CurrentPlayerIndex].Position.y + "/1"); gM.jsonFx.PerformUpdate("update_card_up/1/" + gM.players[gM.CurrentPlayerIndex].CurrentCard.data.serverID); //gM.jsonFx.PerformUpdate("update_card_up/" + gM.CurrentPlayerIndex + "/" + gM.players[gM.CurrentPlayerIndex].CurrentCard.data.serverID); } gM.clearHighlights(); //clear the board //prospect gM.CreateMaterial(gM.players[gM.CurrentPlayerIndex].CurrentCard.data.TexCoordinate, gM.board[(int)gM.players[gM.CurrentPlayerIndex].Position.x, (int)gM.players[gM.CurrentPlayerIndex].Position.y]); gM.players[gM.CurrentPlayerIndex].CurrentCard.data.isUp = true; gM.UpdateBars(); //clear moves gM.moves.Clear(); //if the card is staked by another player, the current player can bump it if (gM.gameState.CurrentGameState == GameStateManager.GameState.GAME_MINING_STATE && gM.players[gM.CurrentPlayerIndex].CurrentCard.data.staked) { FeedbackGUI.setText("This card has been staked out by somebody."); prepareBump(); } else //otherwise move on to staking { gM.calculateStakeableCards(); // based on where the player has moved to, find the adjacent positions he/she can stake a claim GameStateManager.Instance.CurrentTurnState = GameStateManager.TurnState.TURN_STAKE; //go to next turn state if (gM.isOnline) { gM.jsonFx.PerformUpdate("update_game_state/" + (int)gM.gameState.CurrentTurnState + "/" + gM.ID); } } }
private void moveOpponent(RaycastHit hit) { //current player position in unity coordinates Vector3 lastPos = gM.players[gM.CurrentPlayerIndex].transform.position; //loop through possible moves foreach (Vector2 pos in gM.moves) { if (pos.Equals(PositionToVector2(hit.transform.position))) //check if the card clicked is a valid move { Vector3 moveToLocation = new Vector3(hit.transform.position.x, hit.transform.position.y + 0.025f, tempCard.transform.position.z); //move the other player gM.players[indexToMove].transform.position = moveToLocation; //update the player's grid position gM.players[indexToMove].Position = PositionToVector2(gM.players[indexToMove].transform.position); //confirm move - double click if (lastPos == gM.players[indexToMove].transform.position) { FeedbackGUI.setText("Opponent was pushed away!"); if (gM.isOnline) { gM.jsonFx.PerformUpdate("update_entity_pos/" + gM.players[indexToMove].Position.x + "/" + gM.players[indexToMove].Position.y + "/" + gM.players[indexToMove].ID); } numToMove--; //one less that needs to be looked at //end the turn if all players are on valid spots now if (numToMove <= 0) { gM.endTurn(); } else { //someone isn't, find their index for (int index = 0; index < gM.players.Count; index++) { if (gM.players[index].Position == new Vector2(-1, -1)) { indexToMove = index; } } } } } } }
private void setupClick(RaycastHit hit) { Player holderPlayer = new Player(); // continue to add players while we are smaller than max players if (gM.players.Count < gM.maxPlayers) { Vector3 pos = new Vector3(gM.board[6, 0].transform.position.x, hit.transform.position.y + 0.025f, tempCard.transform.position.z); //first time was don't have to check is that space is avalible if (gM.players.Count <= 0) { holderPlayer = (Player)Instantiate(tempPlayer, pos, Quaternion.identity); } else {//have to check is that space is avalible for (int i = 0; i < gM.players.Count; i++) { if (pos == gM.players[i].transform.position) { return; } } holderPlayer = (Player)Instantiate(tempPlayer, pos, Quaternion.identity); } holderPlayer.Position = PositionToVector2(pos); FeedbackGUI.setText("Player avatar placed."); if (gM.isOnline) { gM.jsonFx.PerformUpdate("add_entity/" + holderPlayer.Position.x + "/" + holderPlayer.Position.y + "/1/" + gM.players.Count + "/1/" + gM.ID); } //set color & add to game manager holderPlayer.transform.renderer.material.color = bodyColor[gM.players.Count]; gM.players.Add(holderPlayer); if (gM.players.Count == gM.maxPlayers) { Debug.Log("MAX"); GameStateManager.Instance.CurrentGameState = GameStateManager.GameState.GAME_PROSPECTING_STATE; if (gM.isOnline) { gM.jsonFx.PerformUpdate("update_game_state/" + (int)gM.gameState.CurrentGameState + "/" + gM.ID); } } } }
private void stakeClickProspectingPhase(RaycastHit hit) { FeedbackGUI.setText("Staking a claim! Press the Action button to confirm."); foreach (Vector2 pos in gM.possibleStakes) // go through all possible stake locations (should be 5 at most) { if (pos.Equals(PositionToVector2(hit.transform.position)) && !tempCard.data.staked) //see if card is valid and not already staked { if (tempStake == null) //create a stake if they haven't placed it { tempStake = (GameObject)Instantiate(stakePrefab, hit.transform.position + new Vector3(0.0f, 0.01f, 0.0f), //create the stake Quaternion.identity); tempStake.transform.renderer.material.color = //set to current player's color gM.players[gM.CurrentPlayerIndex].transform.renderer.material.color; int id = gM.jsonFx.PerformUpdate("add_entity/" + pos.x + "/" + pos.y + "/0/" + gM.CurrentPlayerIndex + "/1/" + gM.ID); Debug.Log("JSON ID: " + id); if (id != -1) { tempStake.GetComponent <Stake>().ID = id; } else { Debug.Log("Something's wrong with the ID"); } } else //otherwise move it around { tempStake.transform.position = hit.transform.position + new Vector3(0.0f, 0.01f, 0.0f); // move the stake lastCard.data.staked = false; //mark the previously staked card as free gM.players[gM.CurrentPlayerIndex].stakedCards.Remove(lastCard); gM.players[gM.CurrentPlayerIndex].stakes.RemoveAt(gM.players[gM.CurrentPlayerIndex].stakes.Count - 1); Debug.Log("TEST ID: " + tempStake.GetComponent <Stake>().ID); if (gM.isOnline) { gM.jsonFx.PerformUpdate("update_entity_pos/" + pos.x + "/" + pos.y + tempStake.GetComponent <Stake>().ID); } } gM.sEnabled = true; //stake has been placed, action button should move on to the next turn phase tempCard.data.staked = true; // mark the currently staked card as staked //add stake gM.players[gM.CurrentPlayerIndex].stakes.Add(tempStake); gM.players[gM.CurrentPlayerIndex].stakedCards.Add(tempCard); lastCard = tempCard; //sets the last card equal to the current card } } }
public void prepareBump() { gM.possibleStakes.Clear(); gM.clearHighlights(); movedStake = false; //find necessary indicies for (int i = 0; i < gM.players.Count; i++) { if (gM.players[i].stakedCards.Contains(tempCard)) { stakeOwnerIndex = i; //leave if it's your own stake if (gM.CurrentPlayerIndex == i) { gM.clearHighlights(); gM.calculateStakeableCards(); gM.gameState.CurrentTurnState = GameStateManager.TurnState.TURN_STAKE; if (gM.isOnline) { gM.jsonFx.PerformUpdate("update_game_state/" + (int)gM.gameState.CurrentTurnState + "/" + gM.ID); } stakeOwnerIndex = stakeIndex = -1; movedStake = false; return; } for (int n = 0; n < gM.players[i].stakedCards.Count; n++) { if (tempCard == gM.players[i].stakedCards[n]) { stakeIndex = n; } } } } FeedbackGUI.setText("You have landed on an opponent's stake. You may move it if you so choose."); gM.calculateStakeableCards(new Vector2(gM.players[gM.CurrentPlayerIndex].CurrentCard.data.row, gM.players[gM.CurrentPlayerIndex].CurrentCard.data.col)); Debug.Log("Should see stakable cards"); }
/// <summary> /// Handles the results of a player clicking on the Skip button. /// </summary> public void handleSkip() { float width = 70; if (showSkipButton) //only show skip button if player can choose not to do this action { if (GUI.Button(new Rect(new Rect((actionRect.x + actionRect.width - width), (actionRect.y + actionRect.height), width, 20)), skipText)) { if (gM.gameState.CurrentGameState == GameStateManager.GameState.GAME_END) { return; } //don't do anythign after game ends //start the game if there are enough players and a button is hit if (gM.players.Count > 1 && gM.gameState.CurrentGameState == GameStateManager.GameState.GAME_SETUP) { gM.gameState.CurrentGameState = GameStateManager.GameState.GAME_PROSPECTING_STATE; if (gM.isOnline) { gM.jsonFx.PerformUpdate("update_game_state/" + (int)gM.gameState.CurrentGameState + "/" + gM.ID); } } switch (gM.gameState.CurrentTurnState) { case GameStateManager.TurnState.TURN_ROLL: // the player is choosing to stay where they are and not roll the dice this turn FeedbackGUI.setText("You must like your current location."); gM.pEnabled = true; //player is skipping rolling, meaning they can prospect without moving gM.sEnabled = false; //reset stake boolean, player still needs to do this gM.clearHighlights(); gM.calculateStakes(); // based on where the player has moved to, find the adjacent positions he/she can stake a claim gM.gameState.CurrentTurnState = GameStateManager.TurnState.TURN_STAKE; // move on to the next turn state if (gM.isOnline) { gM.jsonFx.PerformUpdate("update_game_state/" + (int)gM.gameState.CurrentTurnState + "/" + gM.ID); } break; case GameStateManager.TurnState.TURN_MOVE: FeedbackGUI.setText("Wouldn't be nice to interfere, would it?"); gM.players[clicker.StakeOwnerIndex].stakedCards[clicker.StakeIndex].transform.position = gM.players[gM.CurrentPlayerIndex].Position; clicker.StakeOwnerIndex = clicker.StakeIndex = -1; clicker.MovedStake = false; gM.clearHighlights(); gM.calculateStakes(); // based on where the player has moved to, find the adjacent positions he/she can stake a claim gM.gameState.CurrentTurnState = GameStateManager.TurnState.TURN_STAKE; //move on to the next turn state if (gM.isOnline) { gM.jsonFx.PerformUpdate("update_game_state/" + (int)gM.gameState.CurrentTurnState + "/" + gM.ID); } break; case GameStateManager.TurnState.TURN_STAKE: //player is not moving his stakes his turn (option is available in mining phase only) FeedbackGUI.setText("The claims you have are better anyway."); if (gM.cancelStake) { gM.clicker.resetStaking(); gM.cancelStake = false; gM.sEnabled = false; } else { gM.gameState.CurrentTurnState = GameStateManager.TurnState.TURN_MINE; if (gM.isOnline) { gM.jsonFx.PerformUpdate("update_game_state/" + (int)gM.gameState.CurrentTurnState + "/" + gM.ID); } gM.clearHighlights(); gM.calculateMines(); } break; case GameStateManager.TurnState.TURN_MINE: FeedbackGUI.setText("You'll find something better. No worries."); gM.endTurn(); //after the player takes a card, the turn ends break; } } } }
/// <summary> /// Handles the results of a player clicking on the Action button. /// </summary> public void handleAction() { if (GUI.Button(actionRect, actionText)) { if (gM.gameState.CurrentGameState == GameStateManager.GameState.GAME_END) { return; } //don't do anythign after game ends if (gM.players.Count <= 1) //if there aren't enough players, the button should not do anything { return; } //start the game if there are enough players and a button is hit if (gM.gameState.CurrentGameState == GameStateManager.GameState.GAME_SETUP) { gM.gameState.CurrentGameState = GameStateManager.GameState.GAME_PROSPECTING_STATE; if (gM.isOnline) { gM.jsonFx.PerformUpdate("update_game_state/" + (int)gM.gameState.CurrentGameState + "/" + gM.ID); } } switch (gM.gameState.CurrentTurnState) { case GameStateManager.TurnState.TURN_ROLL: // The player is choosing to roll gM.CurrentRoll = gM.Roll(); // roll the dice FeedbackGUI.setText("Please click on a space to move to. Double click to confirm, or click on the Action button."); gM.calculateMoveLocations(); // calculate where the player can move as a result of the dice roll // At the beginning, this bool is true - player can stay where he/she is by choosing not to roll. // Once the player rolls, he must move, so set this bool to false. showSkipButton = false; gM.gameState.CurrentTurnState = GameStateManager.TurnState.TURN_MOVE; //move on to the next turn state if (gM.isOnline) { gM.jsonFx.PerformUpdate("update_game_state/" + (int)gM.gameState.CurrentTurnState + "/" + gM.ID); } break; case GameStateManager.TurnState.TURN_MOVE: // the player is moving after rolling the dice if (gM.pEnabled) { if (gM.moves.Count > 1) { //after the player gets moved this is cleared, so if a stake is getting bumped and they click on the button again //it won't try to move the player clicker.movePlayer(); } //if a stake doesn't need to be moved at all, or it it's already been taken care of if (clicker.StakeOwnerIndex == -1 || clicker.MovedStake) { FeedbackGUI.setText("Please press a location to stake a claim on."); gM.calculateStakes(); // based on where the player has moved to, find the adjacent positions he/she can stake a claim gM.gameState.CurrentTurnState = GameStateManager.TurnState.TURN_STAKE; //move on to the next turn state if (gM.isOnline) { gM.jsonFx.PerformUpdate("update_game_state/" + (int)gM.gameState.CurrentTurnState + "/" + gM.ID); } clicker.StakeOwnerIndex = clicker.StakeIndex = -1; clicker.MovedStake = false; Vector2 pos = gM.players[gM.CurrentPlayerIndex].Position; clicker.TempCard = gM.board[(int)pos.x, (int)pos.y].GetComponent <Card>(); //reset to player's card } else { FeedbackGUI.setText("Please move your opponent's stake."); } } else { FeedbackGUI.setText("Once you roll you must move."); } break; case GameStateManager.TurnState.TURN_STAKE: //player is staking a claim after placing a marker if (gM.sEnabled) // make sure the player has actually placed a marker { //sEnabled is set to true in clickHandler's stakeClick() //clicker.selectedCard = false; // Either move on or let the next player go if (gM.gameState.CurrentGameState == GameStateManager.GameState.GAME_MINING_STATE) { gM.gameState.CurrentTurnState = GameStateManager.TurnState.TURN_MINE; if (gM.isOnline) { gM.jsonFx.PerformUpdate("update_game_state/" + (int)gM.gameState.CurrentTurnState + "/" + gM.ID); } showSkipButton = true; //the player can choose not to pick up a card this turn if he/she wants //clear board and show new highlights gM.clearHighlights(); gM.calculateMines(); } else { gM.endTurn(); } } else { if (gM.gameState.CurrentGameState == GameStateManager.GameState.GAME_MINING_STATE) { FeedbackGUI.setText("Please stake a claim or press skip."); } else if (gM.gameState.CurrentGameState == GameStateManager.GameState.GAME_PROSPECTING_STATE) { FeedbackGUI.setText("In the prospecting phase you must stake a claim."); } } break; case GameStateManager.TurnState.TURN_MINE: Debug.Log("turn state: TURN_MINE"); if (clicker.NumToMove == 0) { } else { FeedbackGUI.setText("A player is in a dangerous mine! Please move them to solid ground."); if (gM.players[clicker.indexToMove].Position != new Vector2(-1, -1)) { Vector2 pos = gM.players[clicker.indexToMove].Position; if (gM.isOnline) { gM.jsonFx.PerformUpdate("update_entity_pos/" + pos.x + "/" + pos.y + "/" + gM.players[clicker.indexToMove].ID); } clicker.NumToMove--; //one less that needs to be looked at //end the turn if all players are on valid spots now if (clicker.NumToMove <= 0) { FeedbackGUI.setText("Good thing. It's safe now."); gM.endTurn(); } else { //someone isn't, find their index for (int index = 0; index < gM.players.Count; index++) { if (gM.players[index].Position == new Vector2(-1, -1)) { clicker.indexToMove = index; } } } } } //endTurn(); break; default: Debug.Log("whoops"); break; } } }
public void OnApplicationQuit() { instance = null; }
private void mineClick(RaycastHit hit) { //Debug.Log("mine click"); for (int i = 0; i < gM.players[gM.CurrentPlayerIndex].stakedCards.Count; i++) { //check if that staked card is the one they clicked if (gM.players[gM.CurrentPlayerIndex].stakedCards[i] == tempCard && tempCard.data.Minable) { int row = tempCard.data.row; int col = tempCard.data.col; //clear the color of the mined card tempCard.transform.renderer.material.color = new Color(1, 1, 1, 1); //add the card to the player's hand gM.players[gM.CurrentPlayerIndex].hand.Add(tempCard); gM.UpdateBars(); //send the board position to null gM.board[tempCard.data.row, tempCard.data.col] = null; //do not mark the card as staked any more tempCard.data.staked = false; //move the card to the side of the board tempCard.transform.position = findHandPosition(gM.CurrentPlayerIndex); if (gM.players.Count > 2 && gM.CurrentPlayerIndex == 1) { gM.players[gM.CurrentPlayerIndex].hand[gM.players[gM.CurrentPlayerIndex].hand.Count - 1].transform.Rotate(new Vector3(0, 1, 0), 90.0f); } else if (gM.CurrentPlayerIndex == 3) { gM.players[gM.CurrentPlayerIndex].hand[gM.players[gM.CurrentPlayerIndex].hand.Count - 1].transform.Rotate(new Vector3(0, 1, 0), -90.0f); } //remove the card from the list of staked cards gM.players[gM.CurrentPlayerIndex].stakedCards.Remove(tempCard); GameObject stake = gM.players[gM.CurrentPlayerIndex].stakes[i]; //remove the stake from the list of stakes gM.players[gM.CurrentPlayerIndex].stakes.Remove(gM.players[gM.CurrentPlayerIndex].stakes[i]); //get rid of the stake GameObject Destroy(stake); if (gM.isOnline) { gM.jsonFx.PerformUpdate("update_card_mine/" + gM.CurrentPlayerIndex + "/" + tempCard.data.serverID); } //check to see if the mined card leaves any players on an empty space for (int n = 0; n < gM.players.Count; n++) { if (gM.players[n].Position == new Vector2(row, col)) { gM.players[n].Position = new Vector2(-1, -1); numToMove++; if (numToMove == 1) { indexToMove = n; gM.clearHighlights(); gM.calculateMoveLocations(new Vector2(row, col), 1); } } } //move on to the next player's turn if (numToMove == 0) { gM.endTurn(); } } } FeedbackGUI.setText("You have mined one of your staked claims."); }
private void stakeClickMiningPhase(RaycastHit hit) { FeedbackGUI.setText("Staking a claim! Press the Action button to confirm."); if (!selectedCard) { //selecting where to place a stake foreach (Vector2 pos in gM.possibleStakes) // go through all possible stake locations (should be 5 at most) { if (pos.Equals(PositionToVector2(hit.transform.position)) && !tempCard.data.staked) //see if card is valid and not already staked { if (tempStake == null) { selectedCard = true; //player has selected a card to stake lastCard = tempCard; //save selected card Debug.Log("last card 1: " + lastCard.transform.position); gM.clearHighlights(); //clear board highlights gM.calculateMines(); //now calculate already staked cards so a stake can be moved gM.cancelStake = true; } else { tempCardIndex = gM.players[gM.CurrentPlayerIndex].stakedCards.Count - 1; //free old card lastCard.data.staked = false; gM.players[gM.CurrentPlayerIndex].stakedCards[tempCardIndex].data.staked = false; gM.players[gM.CurrentPlayerIndex].stakedCards.Remove(gM.players[gM.CurrentPlayerIndex].stakedCards[tempCardIndex]); gM.players[gM.CurrentPlayerIndex].stakes.Remove(gM.players[gM.CurrentPlayerIndex].stakes[tempCardIndex]); // move the stake tempStake.transform.position = tempCard.transform.position + new Vector3(0.0f, 0.01f, 0.0f); //mark new card tempCard.data.staked = true; gM.players[gM.CurrentPlayerIndex].stakedCards.Add(tempCard); gM.players[gM.CurrentPlayerIndex].stakes.Add(tempStake); if (gM.isOnline) { gM.jsonFx.PerformUpdate("update_entity_pos/" + pos.x + "/" + pos.y + tempStake.GetComponent <Stake>().ID); } lastCard = tempCard; //sets the last card equal to the current card gM.clearHighlights(); gM.calculateStakeableCards(); break; } } } } else { //loop through number of stakes for (int i = 0; i < gM.players[gM.CurrentPlayerIndex].stakedCards.Count; i++) { //check if that staked card is the one they clicked if (gM.players[gM.CurrentPlayerIndex].stakedCards[i] == tempCard) { tempStake = gM.players[gM.CurrentPlayerIndex].stakes[i]; //save stake to move oldStakedCard = tempCard; //free old stake oldStakedCard = tempCard; tempCardIndex = i; tempCard.data.staked = false; gM.players[gM.CurrentPlayerIndex].stakedCards.Remove(gM.players[gM.CurrentPlayerIndex].stakedCards[i]); gM.players[gM.CurrentPlayerIndex].stakes.Remove(gM.players[gM.CurrentPlayerIndex].stakes[i]); // move the stake tempStake.transform.position = lastCard.transform.position + new Vector3(0.0f, 0.01f, 0.0f); //mark new stake lastCard.data.staked = true; gM.players[gM.CurrentPlayerIndex].stakedCards.Add(lastCard); gM.players[gM.CurrentPlayerIndex].stakes.Add(tempStake); gM.sEnabled = true; //stake has been placed, action button should move on to the next turn phase if (gM.isOnline) { gM.jsonFx.PerformUpdate("update_entity_pos/" + tempCard.data.row + "/" + tempCard.data.col + tempStake.GetComponent <Stake>().ID); } lastCard = tempCard; //sets the last card equal to the current card selectedCard = false; gM.clearHighlights(); gM.calculateStakeableCards(); } } } }
public void OnApplicationQuit() { instance = null; }