public void OnMovementFinished() { if (IsPlayerWin()) { Signals.Invoke(ESignalType.PlayerWin, currentPlayerIndex); if (players.Count == 1) { Signals.Invoke(ESignalType.PuzzleComplete, 3); } return; } else { bool anyTurning = false; bool allLegal = true; foreach (Piece piece in CurrentPlayer.pieces) { anyTurning |= piece.IsRotating(); allLegal &= IsValidPosition(piece); } bool hasTurned = currentSelectedPiece != null && currentSelectedPiece.IsRotated(); if (allLegal && !anyTurning && hasTurned) { NextPlayer(); } } }
public static void SelectGame(int?index = null) { currentGame?.End(); if (HextwistStateMachine.GameType == HextwistStateMachine.EGameType.Puzzle) { currentGameIndex = index ?? ++currentGameIndex; currentGame = ObjectFactory.Game(Progression.Puzzles[currentGameIndex]); } else { currentGame = ObjectFactory.Game(Progression.PvPGamePrefab); } Signals.Invoke(ESignalType.CamPosition, currentGame.GetBoardBounds()); Signals.Invoke(ESignalType.GameStart, currentGameIndex); }
void SelectPiece(Piece piece) { if (currentSelectedPiece != null) { if (currentSelectedPiece.lockSelected) { return; } currentSelectedPiece.ResetRotation(); lastSelectedPiece = currentSelectedPiece; lastSelectedPiece.Mode = Piece.EMode.Inactive; } currentSelectedPiece = piece; if (piece) { piece.Mode = Piece.EMode.Selected; } Signals.Invoke(ESignalType.PieceSelected, piece); }
void NextPlayer() { CurrentPlayer.SetActivePlayer(false); currentPlayerIndex = (currentPlayerIndex + 1) % numPlayers; CurrentPlayer.SetActivePlayer(true); currentBoard.HighlightPlayer(currentPlayerIndex + 1); Signals.Invoke(ESignalType.PlayerTurn, currentPlayerIndex); if (currentSelectedPiece != null) { currentSelectedPiece.LockRotation(); if (numPlayers == 1) { lastSelectedPiece = currentSelectedPiece; } currentSelectedPiece = null; } }
protected virtual void Click() { Signals.Invoke(signal); }
void MakeNextPlacementPiece() { int numPieces = AllPieces.Count(); //have all the pieces been placed? if (Mathf.FloorToInt(numPieces / numPlayers) == PieceDatas.Count) { //start with player 0 currentPlayerIndex = players.Count - 1; Signals.Invoke(ESignalType.SetupComplete); NextPlayer(); return; } //for two players go 01100110 etc. currentPlayerIndex = Mathf.Clamp(Mathf.FloorToInt(numPieces / numPlayers) % 2 == 0 ? numPieces % numPlayers : (numPlayers - 1) - numPieces % numPlayers, 0, (numPlayers - 1)); int index = Mathf.FloorToInt(numPieces / 2); PieceData PieceData = PieceDatas[index]; Piece piece = ObjectFactory.Piece(PieceData); piece.name = PieceData.piecePrefab.name + " " + CurrentPlayer.Name; CurrentPlayer.pieces.Add(piece); if (piece.lockPivotHex) { piece.SetPivotHex(PieceData.lockedPivotHex, true); } piece.OnPieceClicked.AddListener(OnPieceClickedSetup); piece.OnMovementFinished.AddListener(OnMovementFinished); piece.OuterInactive = PieceColourPallet.OuterInactive(currentPlayerIndex); piece.OuterPivot = PieceColourPallet.OuterPivot(currentPlayerIndex); piece.OuterSelected = PieceColourPallet.OuterSelected(currentPlayerIndex); piece.InnerPivot = PieceColourPallet.InnerPivot(currentPlayerIndex); piece.InnerActive = PieceColourPallet.InnerActive(currentPlayerIndex); piece.InnerDisabled = PieceColourPallet.InnerDisabled(currentPlayerIndex); if (PieceData.useStartPosition) { PiecePlaced(piece); } else { SelectPiece(piece); currentBoard.HighlightPlayer(currentPlayerIndex); Signals.Invoke(ESignalType.PlayerTurn, currentPlayerIndex); } if (currentSelectedPiece) { SetPieceModeSetup(currentSelectedPiece); } }
protected override void Click() { Signals.Invoke(signal, levelIndex); }