public void SwapPiece(GameModel.Piece piece1, GameModel.Piece piece2, GameModel.Square toSqr, GameModel.Intersection toIntr) { MovePiece(piece1, toSqr); MovePiece(piece2, toIntr); GetPieceState(piece1).GetComponent<PieceScript>().CheckSprite(); GetPieceState(piece2).GetComponent<PieceScript>().CheckSprite(); }
// Swaps two pieces position public void SwapPiece(GameModel.Piece piece1, GameModel.Piece piece2) { Vector3 pos1 = GetPieceState(piece1).transform.position; Vector3 pos2 = GetPieceState(piece2).transform.position; MovePiece(piece1, pos2); MovePiece(piece2, pos1); }
// Although the name may be confusing, this returns a GameObject in-game, based on a given Piece public GameObject GetPieceState(GameModel.Piece piece) { foreach(GameObject item in m_pieces) { if(item.GetComponent<PieceScript>().Piece == piece) return item; } return null; }
// Removes a piece by passing its reference piece directly public void RemovePiece(GameModel.Piece piece) { GameObject removedPiece = GetPieceState(piece); if (!m_pieces.Contains(removedPiece)) return; removedPiece.SetActive(false); m_pieces.Remove(removedPiece); Destroy(removedPiece); }
public PieceScript(PieceType type, Color color, GameModel.Piece piece, Vector3 position) { m_type = type; m_color = color; gameObject.transform.position = position; if (!InitSprites()) { Debug.LogError("Error initializating sprites for " + GameModel.GetString.GetStr(piece.Type)); return; } CheckSprite(); gameObject.SetActive(true); }
/* ENDOF COORDINATES TRANSLATORS */ // Adds a new GameObject containing a SpriteRenderer, BoxCollider2D, PieceScript, fully initiated; on the board public void PlacePiece(GameModel.Piece piece, GameModel.Square square) { GameObject newPiece = new GameObject(piece.Type.ToString()); newPiece.AddComponent<SpriteRenderer>(); newPiece.AddComponent<BoxCollider2D>(); newPiece.AddComponent<PieceScript>(); newPiece.GetComponent<BoxCollider2D>().isTrigger = true; newPiece.GetComponent<PieceScript>().Collider = newPiece.GetComponent<BoxCollider2D>(); newPiece.GetComponent<PieceScript>().Type = piece.Type; newPiece.GetComponent<PieceScript>().Color = piece.Color; newPiece.GetComponent<PieceScript>().Square = square; newPiece.GetComponent<PieceScript>().Piece = piece; newPiece.GetComponent<PieceScript>().InitSprites(); newPiece.GetComponent<PieceScript>().CheckSprite(); m_pieces.Add(newPiece); Instantiate(newPiece, newPiece.transform.position, Quaternion.identity); }
public void PlacePiece(GameModel.Piece piece, GameModel.Intersection intersection) { if(piece.Type != PieceType.Tetraglobe) return; GameObject newPiece = new GameObject(GameModel.GetString.GetStr(piece.Type)); newPiece.AddComponent<SpriteRenderer>(); newPiece.AddComponent<BoxCollider2D>(); newPiece.AddComponent<PieceScript>(); newPiece.GetComponent<BoxCollider2D>().isTrigger = true; newPiece.GetComponent<PieceScript>().Collider = newPiece.GetComponent<BoxCollider2D>(); newPiece.GetComponent<PieceScript>().Type = piece.Type; newPiece.GetComponent<PieceScript>().Color = piece.Color; newPiece.GetComponent<PieceScript>().Intersection = intersection; newPiece.GetComponent<PieceScript>().Piece = piece; newPiece.GetComponent<PieceScript>().InitSprites(); newPiece.GetComponent<PieceScript>().CheckSprite(); m_pieces.Add(newPiece); Instantiate(newPiece, newPiece.transform.position, Quaternion.identity); }
internal void RestorePiece(GameModel.Piece pieceToRestore, GameModel.BoardPosition placeAtLogical) { _gameBoard.RestorePiece(pieceToRestore, placeAtLogical); }
internal void CapturePiece(GameModel.Piece pieceToCapture, GameModel.BoardPosition removeFromLogical) { _gameBoard.CapturePiece(pieceToCapture); }
internal void MovePiece(GameModel.Piece pieceToMove, GameModel.BoardPosition fromLogicalPosition, GameModel.BoardPosition toLogicalPosition) { _gameBoard.MovePiece(pieceToMove, toLogicalPosition); }
// Create a Globule on a given square public void CreateGlobule(GameModel.Piece piece, GameModel.Square toSqr) { PlacePiece(piece, toSqr); }
public void MovePiece(GameModel.Piece piece, GameModel.Square toSqr) { GetPieceState(piece).transform.position = ToUnityCoord(toSqr); }
public void MovePiece(GameModel.Piece piece, GameModel.Intersection toIntr) { GetPieceState(piece).transform.position = ToUnityCoord(toIntr); }
private void MovePiece(GameModel.Piece piece, Vector3 position) { GetPieceState(piece).transform.position = position; }