public Board GetCopyWithHiddenPieces(Side side) { // Board dependencies PieceInfo[,] pieceGrid = new PieceInfo[WIDTH, HEIGHT]; PieceContainer piecesA = side == Side.A ? PiecesA.DeepCopy() : PiecesA.DeepCopyWithHiddenPieces(); PieceContainer piecesB = side == Side.A ? PiecesB.DeepCopyWithHiddenPieces() : PiecesB.DeepCopy(); // Place alive pieces back into grid foreach (PieceInfo pieceInfo in piecesA.ActivePieces) { BoardPosition pos = pieceInfo.BoardPosition; pieceGrid[pos.x, pos.y] = pieceInfo; } foreach (PieceInfo pieceInfo in piecesB.ActivePieces) { BoardPosition pos = pieceInfo.BoardPosition; pieceGrid[pos.x, pos.y] = pieceInfo; } return(new Board( pieceGrid, piecesA, piecesB, BoardChange, CurrentGamePhase, CurrentGameOutput, CurrentSide)); }
public void Awake() { _playerInput = GetComponent <PlayerInput>(); _characterController = GetComponent <CharacterController>(); _pieceContainer = GetComponent <PieceContainer>(); _carryingLayer = animator.GetLayerIndex("CarryPiece"); }
public override void SetupMoves() { MoveSet = new Move[1]; List <Vector2Int> pointList = PieceContainer.LineMoveCreator("07070707", Side); MoveSet[0] = new Move(new AttackMove(), pointList); }
public override void SetupMoves() { MoveSet = new Move[3]; List <Vector2Int> pointList1 = PieceContainer.LineMoveCreator("00000001", Side); MoveSet[0] = new Move(new PureMove(), pointList1); List <Vector2Int> pointList2 = PieceContainer.PointMoveCreator(new List <(int, int)> { (0, 2) }, Side);
public override void SetupMoves() { MoveSet = new Move[2]; List <Vector2Int> pointList1 = PieceContainer.LineMoveCreator("00010001", Side); MoveSet[0] = new Move(new AttackMove(), pointList1); List <Vector2Int> pointList2 = PieceContainer.LineMoveCreator("01000100", Side); MoveSet[1] = new Move(new PureAtttack(), pointList2); }
public virtual void Initialize(GameManager gameManager, Board board, PieceContainer myPieces, PieceContainer otherPieces) { this.gameManager = gameManager; this.board = board; this.myPieces = myPieces; this.otherPieces = otherPieces; for (int i = 0; i < PieceContainer.MAX_CAPACITY; i++) { myPieces[i].ID = i; } }
public PieceContainer DeepCopyWithHiddenPieces() { PieceContainer newPieceContainer = DeepCopy(); // Invalidate all pieces foreach (PieceInfo pieceInfo in newPieceContainer) { pieceInfo.Rank = PieceRank.Invalid; } return(newPieceContainer); }
private void Start() { // PieceContainer dependencies List <PieceInfo> piecesA = new List <PieceInfo>(PieceContainer.MAX_CAPACITY); List <PieceInfo> piecesB = new List <PieceInfo>(PieceContainer.MAX_CAPACITY); // Get the piece gameobjects foreach (Piece piece in FindObjectsOfType <Piece>()) { pieceInfoMap.Add(piece.Info, piece); if (piece.Info.Side == Side.A) { piecesA.Add(piece.Info); } else if (piece.Info.Side == Side.B) { piecesB.Add(piece.Info); } else { Debug.LogError("Piece has no side!"); return; } } // Board dependencies PieceInfo[,] pieceGrid = new PieceInfo[Board.WIDTH, Board.HEIGHT]; PieceContainer pieceContainerA = new PieceContainer(piecesA); PieceContainer pieceContainerB = new PieceContainer(piecesB); GamePhase startingGamePhase = GamePhase.Spawn; Side startingGameOutput = Side.None; Side startingSide = Side.A; // Initialize board Board = new Board( pieceGrid, pieceContainerA, pieceContainerB, null, startingGamePhase, startingGameOutput, startingSide); // Initialize actors actorA.Initialize(this, Board, pieceContainerA, pieceContainerB); actorB.Initialize(this, Board, pieceContainerB, pieceContainerA); // TODO: Configure which can spawn first actorA.PerformSpawn(); }
public List <MoveInfo> GetAllValidMoves() { List <MoveInfo> allPossibleMoves = new List <MoveInfo>(); PieceContainer pieces = CurrentSide == Side.A ? PiecesA : PiecesB; foreach (PieceInfo piece in pieces.ActivePieces) { foreach (MoveInfo move in GetPieceValidMoves(piece)) { allPossibleMoves.Add(move); } } return(allPossibleMoves); }
public Board(PieceInfo[,] pieceGrid, PieceContainer piecesA, PieceContainer piecesB, BoardChange?boardChange, GamePhase currentGamePhase, Side currentGameOutput, Side currentSide) { PieceGrid = pieceGrid; PiecesA = piecesA; PiecesB = piecesB; BoardChange = boardChange; CurrentGamePhase = currentGamePhase; CurrentGameOutput = currentGameOutput; CurrentSide = currentSide; }
/// <summary> /// 触手のはさむアクション /// </summary> void TentacleAction() { //触手の間のピースを取得 Piece[] btwp = GetPiecesBetweenTentacle(); if (btwp != null && !currentPieceContainer) { //遠かったらはさめない if (!CheckRetentionContainer(PieceContainer.GetContainerSize(btwp))) { return; } Debug.Log("はさめたよ"); //はさむ currentPieceContainer = PieceContainer.CreateContainer(btwp); //アニメーション変更 int id; id = StageGenerator.GetPiece(currenTentacle[0].GetTargetPosition()).id; currenTentacle[0].SetAnimatonState(Tentacle.GetHoldState(id)); if (id == 5) { AudioManager.Play(SEType.Hot, 0.5f); } if (id == 6) { AudioManager.Play(SEType.Cold, 0.5f); } id = StageGenerator.GetPiece(currenTentacle[1].GetTargetPosition()).id; currenTentacle[1].SetAnimatonState(Tentacle.GetHoldState(id)); if (id == 5) { AudioManager.Play(SEType.Hot, 0.5f); } if (id == 6) { AudioManager.Play(SEType.Cold, 0.5f); } //音再生 AudioManager.Play(SEType.HasamuNormal); } }
public override void Initialize( GameManager gameManager, Board board, PieceContainer myPieces, PieceContainer otherPieces) { base.Initialize(gameManager, board, myPieces, otherPieces); foreach (PieceInfo pieceInfo in otherPieces) { RankPossibilities rankPossibilities = new RankPossibilities(); enemyPieces.Add(pieceInfo.ID, rankPossibilities); } pieceCounterPanel.UpdateText(piecePool); TogglePieceVisibility(); }
/// <summary> /// コンテナを削除 /// </summary> public static void DestroyCurrentContainer() { if (!currentPieceContainer) { return; } currentPieceContainer.DestroyContainer(); currentPieceContainer = null; for (int i = 0; i < 2; i++) { Tentacle t = myPlayer.currenTentacle[i]; if (t && t.state != TentacleAnimState.Return) { myPlayer.currenTentacle[i].SetAnimatonState(TentacleAnimState.Move); } } }
void FreezePiece(PieceContainer container) { List<int> rowsToClear = new List<int> (); foreach (Piece piece in container.pieces) { int row = Mathf.CeilToInt (piece.transform.position.y + blockHalf) + ((height/2) * multiplier) - 1; if (row >= numOfRows || row < 0) continue; if (space [row] == null) { space [row] = new List<Piece> (); } space [row].Add (piece); if (space [row].Count == clearRowNum) { if (rowsToClear.IndexOf(row) == -1) { rowsToClear.Add (row); } } } rowsToClear.Sort (); rowsToClear.Reverse (); Clear (rowsToClear); AddPiece (); }
public Computer BuildComputer(ComputerDescriptor descriptor, ComputerSizeType size) { Computer computer = ComputerManager.InstantiatePrefab(size); if (computer != null) { bool pieceAdded = false; for (int i = 0; i < descriptor.CPUS; i++) { PieceContainer container = computer.gameObject.AddComponent <PieceContainer>(); container.AllowedPieceTypes.Add(PieceManager.CPU); Piece piece = PieceManager.InstantiatePiece(PieceManager.CPU); piece.Health = 0; container.disablePiece = true; container.AddPiece(piece); computer.PieceContainers.Add(container); pieceAdded = true; } for (int i = 0; i < descriptor.GTX; i++) { PieceContainer container = computer.gameObject.AddComponent <PieceContainer>(); container.AllowedPieceTypes.Add(PieceManager.GTX); Piece piece = PieceManager.InstantiatePiece(PieceManager.GTX); piece.Health = 0; container.disablePiece = true; container.AddPiece(piece); computer.PieceContainers.Add(container); pieceAdded = true; } for (int i = 0; i < descriptor.HDD; i++) { PieceContainer container = computer.gameObject.AddComponent <PieceContainer>(); container.AllowedPieceTypes.Add(PieceManager.HDD); Piece piece = PieceManager.InstantiatePiece(PieceManager.HDD); piece.Health = 0; container.disablePiece = true; container.AddPiece(piece); computer.PieceContainers.Add(container); pieceAdded = true; } for (int i = 0; i < descriptor.PS; i++) { PieceContainer container = computer.gameObject.AddComponent <PieceContainer>(); container.AllowedPieceTypes.Add(PieceManager.PS); Piece piece = PieceManager.InstantiatePiece(PieceManager.PS); piece.Health = 0; container.disablePiece = true; container.AddPiece(piece); computer.PieceContainers.Add(container); pieceAdded = true; } if (!pieceAdded) { PieceContainer container = computer.gameObject.AddComponent <PieceContainer>(); container.AllowedPieceTypes.Add(PieceManager.PS); Piece piece = PieceManager.InstantiatePiece(PieceManager.PS); piece.Health = 0; container.disablePiece = true; container.AddPiece(piece); computer.PieceContainers.Add(container); } } computer.ui.SetIcons(computer.PieceContainers); return(computer); }
public void Awake() { _pieceContainer = GetComponent <PieceContainer>(); }
public Piece(int side) { Side = side; PieceContainer = new PieceContainer(); SetupMoves(); }
private void ProcessClickedSquare(Square clicked) { Debug.Log("Clicked square"); if (!isSquareSelected) { Debug.Log("Update Selected"); selectedSquare = clicked; ChessGame.Square smth = new ChessGame.Square(clicked.file + 1, clicked.rank + 1); Debug.Log(smth.ToString()); ChessGame.Piece current = ChessGame.getPiece(smth); if (current == null) { Debug.Log("Not a piece"); return; } if (current.c_ != ChessGame.getTurn()) { Debug.Log("Turn " + ChessGame.getTurn() + " piece : " + current.ToString()); return; } isSquareSelected = true; List <ChessGame.Command> validMoves = current.getAvailableMoves(out bool temp); foreach (ChessGame.Command move in validMoves) { // get the highlight square and convert it to board square ChessGame.Square highlight = move.getHighlight(); Square boardSquare = new Square(highlight.row_ - 1, highlight.col_ - 1); GameObject o = Instantiate(moveHighlightPrefab); o.SetActive(true); o.transform.position = boardSquare.getCenter(); tileHighlights.Add(o); } } else { isSquareSelected = false; foreach (GameObject highlight in tileHighlights) { Destroy(highlight); } ChessGame.Square square = new ChessGame.Square(selectedSquare.file + 1, selectedSquare.rank + 1); ChessGame.Piece current = ChessGame.getPiece(square); ChessGame.Square to = new ChessGame.Square(clicked.file + 1, clicked.rank + 1); ChessGame.Command chosen = null; List <ChessGame.Command> validMoves = current.getAvailableMoves(out bool temp); foreach (ChessGame.Command move in validMoves) { if (move.getHighlight().equals(to)) { chosen = move; break; } } if (chosen != null) { switch (chosen.t_) { case ChessGame.Command.Type.MOVE: ChessGame.Move move = (ChessGame.Move)chosen; Debug.Log(move.ToString()); ChessGame.Square oldSquare = move.start_; ChessGame.Square newSquare = move.end_; Square oldBoardSquare = new Square(oldSquare.row_ - 1, oldSquare.col_ - 1); Square newBoardSquare = new Square(newSquare.row_ - 1, newSquare.col_ - 1); PieceContainer piece = getPieceAtSquare(oldBoardSquare); Debug.Assert(piece != null); piece.UpdateLocation(newBoardSquare, this); gameManager.move(move); break; case ChessGame.Command.Type.TAKE: ChessGame.Take take = (ChessGame.Take)chosen; Debug.Log(take.ToString()); ChessGame.Square oldTakerSquare = take.start_; ChessGame.Square newTakerSquare = take.end_; Square oldTakerBoardSquare = new Square(oldTakerSquare.row_ - 1, oldTakerSquare.col_ - 1); Square newTakerBoardSquare = new Square(newTakerSquare.row_ - 1, newTakerSquare.col_ - 1); ChessGame.Square takenSquare = take.taken_.s_; Square takenBoardSquare = new Square(takenSquare.row_ - 1, takenSquare.col_ - 1); PieceContainer taker = getPieceAtSquare(oldTakerBoardSquare); PieceContainer taken = getPieceAtSquare(takenBoardSquare); Debug.Assert(taker != null); taker.UpdateLocation(newTakerBoardSquare, this); // remove taken pieces.Remove(taken); taken.DoShrinkAnimation(this); gameManager.move(take); break; case ChessGame.Command.Type.CASTLE: ChessGame.Castle castle = (ChessGame.Castle)chosen; Debug.Log(castle.ToString()); ChessGame.Square oldRookSquare = castle.start_rook_; ChessGame.Square newRookSquare = castle.end_rook_; Square oldRookBoardSquare = new Square(oldRookSquare.row_ - 1, oldRookSquare.col_ - 1); Square newRookBoardSquare = new Square(newRookSquare.row_ - 1, newRookSquare.col_ - 1); ChessGame.Square oldKingSquare = castle.start_king_; ChessGame.Square newKingSquare = castle.end_king_; Square oldKingBoardSquare = new Square(oldKingSquare.row_ - 1, oldKingSquare.col_ - 1); Square newKingBoardSquare = new Square(newKingSquare.row_ - 1, newKingSquare.col_ - 1); PieceContainer rook = getPieceAtSquare(oldRookBoardSquare); PieceContainer king = getPieceAtSquare(oldKingBoardSquare); rook.UpdateLocation(newRookBoardSquare, this); king.UpdateLocation(newKingBoardSquare, this); gameManager.move(castle); break; case ChessGame.Command.Type.PROMOTION: ChessGame.Promotion promotion = (ChessGame.Promotion)chosen; Debug.Log(promotion.ToString()); ChessGame.Square oldPawnSquare = promotion.start_; ChessGame.Square newPawnSquare = promotion.end_; Square oldPawnBoardSquare = new Square(oldPawnSquare.row_ - 1, oldPawnSquare.col_ - 1); Square newPawnBoardSquare = new Square(newPawnSquare.row_ - 1, newPawnSquare.col_ - 1); PieceContainer pawn = getPieceAtSquare(oldPawnBoardSquare); pawn.UpdateLocation(newPawnBoardSquare, this); promotion.setUpgrade(ChessGame.Type.QUEEN); if (promotion.other_ != null) { PieceContainer other = getPieceAtSquare(newPawnBoardSquare); pieces.Remove(other); other.DoShrinkAnimation(this); } pieces.Remove(pawn); pawn.DoShrinkAnimation(this); GameObject model; if (ChessGame.getTurn() == ChessGame.Color.WHITE) { model = whiteQueen; } else { model = blackQueen; } PieceContainer queen = new PieceContainer(model, newPawnBoardSquare); pieces.Add(queen); queen.DoGrowAnimation(this); gameManager.move(promotion); break; default: Debug.LogError("Shouldn't get here"); break; } // rotate the camera StartCoroutine(SmoothCameraMove()); } if (ChessGame.end() == 1) { Debug.Log("END OF GAME"); if (ChessGame.getTurn() == ChessGame.Color.BLACK) { Debug.Log("WHITE WON"); canvas.GetComponent <WinTextManager>().DisplayWinText(true, false); } else { Debug.Log("BLACK WON"); canvas.GetComponent <WinTextManager>().DisplayWinText(false, false); } } else if (ChessGame.end() == 2) { Debug.Log("DRAW GAME"); canvas.GetComponent <WinTextManager>().DisplayWinText(true, true); } } }