public IEnumerator OnMovePiece(object obj, MovePieceEventArgs e) { PieceUI pieceUi = activePlayer.piecesParent.GetChild(e.piece.index).GetComponent <PieceUI>(); Transform[] transforms = GetStepsTransform(e.steps.positions, e.steps.inGoalIndex); yield return(StartCoroutine(pieceUi.StepMove(transforms))); }
public void ClickDown(PieceObject piece) { if (finished) { return; } // Ignore if managed by AI or is not your turn if (piece.piece.side != currentSide || (ai1 && !currentSide) || (ai2 && currentSide)) { return; } List <Position> positions = model.GetMovements(piece.piece); markersPool.ClearAll(); if (piece.Equals(selectedPiece)) { selectedPiece = null; return; } selectedPiece = piece; selectedUIPiece = null; for (int i = 0; i < positions.Count; i++) { Marker marker = markersPool.GetInstance <Marker>(true); marker.Initialize(ClickDownMarker); marker.SetHexPosition(positions[i]); } }
public void ClickDownMarker(Marker marker) { if (selectedPiece != null) { model.MovePiece(selectedPiece.piece, (marker.x, marker.y, marker.z)); audioSource.PlayOneShot(soundArray[UnityEngine.Random.Range(0, soundArray.Length - 1)]); Position newPos = model.GetPiecePosition(selectedPiece.piece); selectedPiece.SetHexPosition(newPos.x, newPos.y, newPos.z); selectedPiece = null; } else if (selectedUIPiece != null) { if (selectedUIPiece.piece.side) { panels[1].RemovePiece(selectedUIPiece); } else { panels[0].RemovePiece(selectedUIPiece); } model.MovePiece(selectedUIPiece.piece, (marker.x, marker.y, marker.z)); audioSource.PlayOneShot(soundArray[UnityEngine.Random.Range(0, soundArray.Length - 1)]); Position newPos = model.GetPiecePosition(selectedUIPiece.piece); GameObject instance = piecesPool.GetInstance(true); instance.GetComponent <PieceObject>().Initialize(selectedUIPiece.piece, ClickDown); instance.GetComponent <PieceObject>().SetHexPosition(model.GetPiecePosition(selectedUIPiece.piece)); selectedUIPiece = null; } NextTurn(); }
// What is it's output when we click on a blank poimt on the board // Who sets HumanPlayer.legalMoves bool TryGetPieceUIAtPoint(Vector3 point, out PieceUI piece) { // RaycastHit hit; // Ray ray = viewCamera.ScreenPointToRay(point); // bool isColliding = Physics.Raycast(ray, out hit , pieceMask); // Collider2 pieceCollider = Physics2D.OverlapPoint(point, pieceMask); bool isColliding = GvrPointerInputModule.CurrentRaycastResult.isValid; if (isColliding) { if (GvrPointerInputModule.CurrentRaycastResult.gameObject.GetComponent <PieceUI>() != null) { piece = GvrPointerInputModule.CurrentRaycastResult.gameObject.GetComponent <PieceUI>(); if (piece.GetComponent <MeshCollider>().enabled) { isThereAPiece = true; } else { isThereAPiece = false; } return(true); } } piece = null; return(false); }
public IEnumerator OnGetInPiece(object obj, GetInPieceEventArgs e) { PieceUI pieceUi = activePlayer.piecesParent.GetChild(e.piece.index).GetComponent <PieceUI>(); Transform[] transforms = new Transform[] { blocksParent.GetChild(e.piece.position) }; yield return(StartCoroutine(pieceUi.StepMove(transforms))); }
public IEnumerator OnGetOutPiece(object obj, GetOutPieceEventArgs e) { PieceUI pieceUi = playersData[e.piece.player.index].piecesParent.GetChild(e.piece.index).GetComponent <PieceUI>(); Transform[] transforms = new Transform[] { playersData[e.piece.player.index].outsParent.GetChild(e.piece.position) }; SFX.instance.PlayPieceHitSound(); yield return(StartCoroutine(pieceUi.StepMove(transforms, 2))); }
// Hide the panels removes the game public void Clear() { panels[0].transform.parent.GetComponent <Animator>().SetBool("show", false); piecesPool.ClearAll(); markersPool.ClearAll(); hourglass.gameObject.SetActive(false); selectedPiece = null; selectedUIPiece = null; }
public void RemovePiece(PieceUI piece) { pieces.Remove(piece); piece.Remove(); foreach (PieceUI pui in pieces) { if (pui.piece.type == piece.piece.type && pui.piece.side == piece.piece.side && pui.piece.number == piece.piece.number - 1) { pui.GetComponent <Button>().enabled = true; } } }
public void ClickDown(HexObject piece) { if (typeof(Marker) == piece.GetType()) { // Add the rock to the board and place object RockObject tmp; if (selectedItem != null) { if (selectedItem.TryGetComponent <RockObject>(out tmp)) { model.GetBlockedPositions().Add(piece.GetHexPosition()); selectedItem.SetHexPosition(piece); selectedItem.gameObject.SetActive(true); selectedItem = null; markersPool.ClearAll(); } } else if (selectedUIPiece != null) { model.GetNotPlacedPieces().Remove(selectedUIPiece.piece); model.GetPlacedPieces().Add((piece.x, piece.y, piece.z), selectedUIPiece.piece); panels[0].RemovePiece(selectedUIPiece); panels[1].RemovePiece(selectedUIPiece); markersPool.ClearAll(); GameObject instance = piecesPool.GetInstance(true); instance.GetComponent <PieceObject>().Initialize(selectedUIPiece.piece, ClickDown); instance.GetComponent <PieceObject>().SetHexPosition(piece); selectedUIPiece = null; } } else if (typeof(RockObject) == piece.GetType()) { markersPool.ClearAll(); selectedItem = piece; } else if (typeof(PieceObject) == piece.GetType()) { if (selectedItem != null) { // Add a chain to the piece if (selectedItem.GetComponent <ChainObject>() != null) { ((PieceObject)piece).piece.blocked = true; selectedItem.SetHexPosition(piece); selectedItem.gameObject.SetActive(true); selectedItem = null; return; } } // Select piece selectedItem = piece; } }
public void Initialize(Board board, Action <Winner> endCallback, bool side = false) { bg.Initialize(ClickDownBackground); this.model = board; this.currentSide = side; this.endCallback = endCallback; this.finished = false; Dictionary <(int, int, int), Piece> placedPieces = model.GetPlacedPieces(); List <Piece> notPlacedPieces = model.GetNotPlacedPieces(); turnsCounter = board.GetMaxTurns(); if (turnsCounter > 0) { hourglass.gameObject.SetActive(true); hourglass.SetValue(turnsCounter, false); } else { turnsCounter = -1; } piecesPool.ClearAll(); foreach (KeyValuePair <(int, int, int), Piece> pair in placedPieces) { GameObject instance = piecesPool.GetInstance(true); instance.GetComponent <PieceObject>().Initialize(pair.Value, ClickDown); instance.GetComponent <PieceObject>().x = pair.Key.Item1; instance.GetComponent <PieceObject>().y = pair.Key.Item2; instance.GetComponent <PieceObject>().z = pair.Key.Item3; if (pair.Value.blocked) { GameObject chainInstance = chainsPool.GetInstance(true); chainInstance.GetComponent <HexObject>().SetHexPosition(pair.Value.position); } } foreach (Position p in model.GetBlockedPositions()) { GameObject instance = rocksPool.GetInstance(true); instance.GetComponent <HexObject>().SetHexPosition(p); } panels[0].Initialize(model, ClickPanelPiece); panels[1].Initialize(model, ClickPanelPiece); panels[0].transform.parent.GetComponent <Animator>().SetBool("show", true); audioSource = GetComponent <AudioSource>(); markersPool.ClearAll(); selectedPiece = null; selectedUIPiece = null; }
public IEnumerator AIMove(bool side) { yield return(new WaitForSeconds(1)); //DateTime inicio = DateTime.Now; // Find best move AI.AIResult ai = AI.FindBestMove(side, model, 0); //Debug.Log((DateTime.Now - inicio).Minutes + ":" + (DateTime.Now - inicio).Seconds + "." + (DateTime.Now - inicio).Milliseconds); //Debug.Log("Leaves: " + ai.leaves + ", Value: " + ai.bestValue); // Find piece to move in placed pieces foreach (PieceObject po in piecesPool.Next <PieceObject>()) { if (po.piece.Equals(ai.move.piece) && po.gameObject.activeSelf) { model.MovePiece(ai.move.piece, ai.move.position); audioSource.PlayOneShot(soundArray[UnityEngine.Random.Range(0, soundArray.Length - 1)]); Position newPos = model.GetPiecePosition(po.piece); po.SetHexPosition(ai.move.position.x, ai.move.position.y, ai.move.position.z); selectedPiece = null; selectedUIPiece = null; break; } } // Find piece to move in the panel foreach (PiecesPanel panel in panels) { foreach (PieceUI pui in panel.pieces) { if (pui.piece.Equals(ai.move.piece)) { model.MovePiece(ai.move.piece, ai.move.position); audioSource.PlayOneShot(soundArray[UnityEngine.Random.Range(0, soundArray.Length - 1)]); GameObject instance = piecesPool.GetInstance(true); instance.GetComponent <PieceObject>().Initialize(ai.move.piece, ClickDown); instance.GetComponent <PieceObject>().SetHexPosition(model.GetPiecePosition(ai.move.piece)); panel.RemovePiece(pui); selectedPiece = null; selectedUIPiece = null; break; } } } selectedPiece = null; selectedUIPiece = null; NextTurn(); }
bool TryGetPieceUIAtPoint(Vector2 point, out PieceUI piece) { Collider2D pieceCollider = Physics2D.OverlapPoint(point, pieceMask); if (pieceCollider != null) { if (pieceCollider.GetComponent <PieceUI>() != null) { piece = pieceCollider.GetComponent <PieceUI>(); return(true); } } piece = null; return(false); }
public void ClickPanelPiece(PieceUI piece) { selectedUIPiece = piece; selectedItem = null; markersPool.ClearAll(); for (int i = -4; i < 4; i++) { for (int j = -8; j < 8; j++) { Marker marker = markersPool.GetInstance <Marker>(true); marker.SetHexPosition(i, j, 0); marker.Initialize(ClickDown); } } }
// Callbacks public void LoadLevel() { piecesPool.ClearAll(); markersPool.ClearAll(); rocksPool.ClearAll(); chainsPool.ClearAll(); model = Serializer <Board> .FromJson(level.text); foreach (KeyValuePair <(int, int, int), Piece> pair in model.GetPlacedPieces()) { GameObject instance = piecesPool.GetInstance(true); instance.GetComponent <PieceObject>().Initialize(pair.Value, ClickDown); instance.GetComponent <PieceObject>().x = pair.Key.Item1; instance.GetComponent <PieceObject>().y = pair.Key.Item2; instance.GetComponent <PieceObject>().z = pair.Key.Item3; if (pair.Value.blocked) { GameObject chainInstance = chainsPool.GetInstance(true); chainInstance.GetComponent <HexObject>().SetHexPosition(pair.Value.position); } } foreach (Position p in model.GetBlockedPositions()) { GameObject instance = rocksPool.GetInstance(true); instance.GetComponent <RockObject>().Initialize(ClickDown); instance.GetComponent <HexObject>().SetHexPosition(p); } panels[0].Initialize(model, ClickPanelPiece); panels[1].Initialize(model, ClickPanelPiece); panels[0].transform.parent.GetComponent <Animator>().SetBool("show", true); selectedItem = null; selectedUIPiece = null; }
bool TryGetPieceUIAtPoint(Vector2 point, out PieceUI piece) { Collider2D pieceCollider = Physics2D.OverlapPoint(point, pieceMask); if (pieceCollider != null) { if (pieceCollider.GetComponent<PieceUI>() != null) { piece = pieceCollider.GetComponent<PieceUI>(); return true; } } piece = null; return false; }
public void ClickDownBackground() { markersPool.ClearAll(); selectedPiece = null; selectedUIPiece = null; }
public void ClickPiece(PieceUI piece) { clickPieceCallback(piece); }