private void CheckClick() { if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject()) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); bool isHit = Physics.Raycast(ray, out RaycastHit hit, m_RayLength, m_ClickLayer.value); if (isHit) { bool isSlot = hit.collider.gameObject.CompareTag(BoardGameUtility.SlotTag); bool isMarble = hit.collider.gameObject.CompareTag(BoardGameUtility.MarbleTag); if (isSlot) { LudoSlot slot = hit.collider.GetComponent <LudoSlot>(); if (slot != null) { ClickSlot(slot); return; } } else if (isMarble) { LudoMarble marble = hit.collider.GetComponent <LudoMarble>(); if (marble != null) { ClickMarble(marble); return; } } } FreeSlots(); } }
public IEnumerator MoveMarble(int marbleIndex, int move, LudoGame game) { if (IsInPlay(marbleIndex) && move > 0) { LudoMarble marble = m_Marbles[marbleIndex]; int currentSlotIndex = game.Board.GetSlotIndex(m_PlayerIndex, marbleIndex); LudoSlot currentSlot = game.Board.GetSlot(currentSlotIndex); int targetSlotIndex = game.Board.GetTargetSlotIndex(m_PlayerIndex, currentSlotIndex, move); if (targetSlotIndex != LudoBoard.InvalidSlot) { LudoSlot targetSlot = game.Board.GetSlot(targetSlotIndex); LudoMarble targetMarble = targetSlot.m_Marble; LudoSlot[] moveSlots = game.Board.GetMoveSlots(m_PlayerIndex, currentSlotIndex, move); currentSlot.m_Marble = null; targetSlot.m_Marble = marble; yield return(StartCoroutine(marble.MovePlaySlots(moveSlots))); if (targetMarble != null) { //exit opponent's marble LudoBoardPlayer opponent = game.Board.GetOwnerPlayer(targetMarble); yield return(StartCoroutine(opponent.ExitMarble(targetMarble.m_MarbleIndex, game))); } } else { yield break; } } else { yield break; } }
public LudoBoardPlayer GetOwnerPlayer(LudoMarble marble) { int playerIndex = GetOwnerPlayerIndex(marble); if (playerIndex != InvalidPlayerIndex) { return(m_Players[playerIndex].m_Player); } else { return(null); } }
public int GetOwnerPlayerIndex(LudoMarble marble) { for (int i = 0; i < m_Players.Length; i++) { LudoBoardPlayer player = m_Players[i].m_Player; for (int j = 0; j < player.MarbleCount; j++) { LudoMarble playerMarble = player.GetMarble(j); if (playerMarble == marble) { return(i); } } } return(InvalidPlayerIndex); }
private void ClickMarble(LudoMarble marble) { int slotIndex = Board.GetSlotIndex(Game.PlayerIndex, marble.m_MarbleIndex); if (slotIndex != LudoBoard.InvalidSlot) { LudoSlot slot = Board.GetSlot(slotIndex); ClickSlot(slot); } else { LudoSlot[] homeSlots = Board.GetOwnerPlayer(marble).HomeSlots; for (int i = 0; i < homeSlots.Length; i++) { if (homeSlots[i].m_Marble == marble) { ClickSlot(homeSlots[i]); } } } }
public IEnumerator ExitMarble(int marbleIndex, LudoGame game) { if (IsInPlay(marbleIndex)) { LudoMarble marble = m_Marbles[marbleIndex]; for (int i = 0; i < m_HomeSlots.Length; i++) { if (m_HomeSlots[i].m_Marble == null) { m_HomeSlots[i].m_Marble = marble; int playSlotIndex = game.Board.GetSlotIndex(m_PlayerIndex, marbleIndex); LudoSlot slot = game.Board.GetSlot(playSlotIndex); slot.m_Marble = null; yield return(StartCoroutine(marble.Move(m_HomeSlots[i]))); break; } } } else { yield break; } }
public IEnumerator EnterMarble(int marbleIndex, LudoGame game) { if (!IsInPlay(marbleIndex)) { LudoMarble marble = m_Marbles[marbleIndex]; for (int i = 0; i < m_HomeSlots.Length; i++) { if (m_HomeSlots[i].m_Marble == marble) { m_HomeSlots[i].m_Marble = null; PlayerSlots playerSlots = game.Board.GetPlayerSlots(this); LudoSlot slot = game.Board.GetSlot(playerSlots.m_StartSlot); slot.m_Marble = marble; yield return(StartCoroutine(marble.Move(slot))); break; } } } else { yield break; } }
private void EnterMarble(LudoMarble marble) { LudoAction action = new LudoAction(LudoAction.ActionType.EnterBoard, marble.m_MarbleIndex); PlayTurn(action); }
private void MoveMarble(LudoMarble marble, int move) { LudoAction action = new LudoAction(LudoAction.ActionType.Move, marble.m_MarbleIndex, move); PlayTurn(action); }