List <Card> GetXCards(int x, int y) { List <Card> cardsInX = new List <Card>(); for (int i = 0; i < (int)Card.Element.Count; ++i) { int ix = x - (i + 1); CardPlacement cplace = GetPlacement(ix, y); if (cplace == null || !cplace.HasCard) { break; } cardsInX.Add(cplace.cardInside); } for (int i = 0; i < (int)Card.Element.Count; ++i) { int ix = x + (i + 1); CardPlacement cplace = GetPlacement(ix, y); if (cplace == null || !cplace.HasCard) { break; } cardsInX.Add(cplace.cardInside); } return(cardsInX); }
void AddPendingPlacement(CardPlacement newPlacement) { if (newPlacement != null && pendingPlacements.Contains(newPlacement) == false) { pendingPlacements.Add(newPlacement); } }
List <Card> GetYCards(int x, int y) { List <Card> cardsInY = new List <Card>(); for (int i = 0; i < (int)Card.Element.Count; ++i) { int iy = y - (i + 1); CardPlacement cplace = GetPlacement(x, iy); if (cplace == null || !cplace.HasCard) { break; } cardsInY.Add(cplace.cardInside); } for (int i = 0; i < (int)Card.Element.Count; ++i) { int iy = y + (i + 1); CardPlacement cplace = GetPlacement(x, iy); if (cplace == null || !cplace.HasCard) { break; } cardsInY.Add(cplace.cardInside); } return(cardsInY); }
public void TryPlaceCard() { var mousePos = Input.mousePosition; //mousePos.z = GameCamera.GetGameCamera( 0 ).currentViewDistance - 1.1f; // select distance from the camera //mousePos = GameCamera.GetCamera( 0 ).ScreenToWorldPoint( mousePos ); mousePos.z = (Camera.main.farClipPlane - Camera.main.nearClipPlane) * .5f; // select distance from the camera mousePos = Camera.main.ScreenToWorldPoint(mousePos); Ray r = new Ray(mousePos, Vector3.right); RaycastHit[] hits; hits = Physics.RaycastAll(r, 1000f); for (int i = 0; i < hits.Length; ++i) { CardPlacement cplace = hits[i].collider.GetComponent <CardPlacement>(); if (cplace != null) { if (cplace.TryPlaceCardHere(this) == false) { break; } } } ClearHeldStatus(); }
public CardPlacement AddPlacement(int x, int y) { if (HasPlacement(x, y)) { return(null); } if (board.ContainsKey(x) == false) { board.Add(x, new Dictionary <int, CardPlacement>()); } GameObject placement = (GameObject)Instantiate(cardPlacementPrefab, transform, false); CardPlacement cplace = placement.GetComponent <CardPlacement>(); cplace.posX = x; cplace.posY = y; cplace.transform.localPosition = new Vector3(0f, y, -x); //add placement to board board[x][y] = cplace; //notify the game object it's now active in the board placement.SetActive(true); //keep track of it placements.Add(cplace); //notify the camera to keep track of this //GameCamera.GetGameCamera(0).AddObjectToTracking(placement); return(cplace); }
int CanPlaceACard(int x, int y) { CardPlacement cplace = gameBoard.GetPlacement(x, y); if (cplace == null) { return(-1); } if (cplace.HasCard) { return(-1); } for (int i = 0; i < hand.HandSize; ++i) { if (usedCards.Contains(i)) { continue; } bool result = cplace.TryPlaceCardHere(hand.currentHand[i]); if (result) { usedCards.Add(i); return(i); } } return(-1); }
bool CheckSizeRule(int x, int y) { List <Card> cardsInX = new List <Card>(); List <Card> cardsInY = new List <Card>(); for (int i = 0; i < (int)Card.Element.Count; ++i) { int ix = x - (i + 1); CardPlacement cplace = GetPlacement(ix, y); if (cplace == null || !cplace.HasCard) { break; } cardsInX.Add(cplace.cardInside); } for (int i = 0; i < (int)Card.Element.Count; ++i) { int ix = x + (i + 1); CardPlacement cplace = GetPlacement(ix, y); if (cplace == null || !cplace.HasCard) { break; } cardsInX.Add(cplace.cardInside); } if (cardsInX.Count >= (int)Card.Element.Count) { return(false); } for (int i = 0; i < (int)Card.Element.Count; ++i) { int iy = y - (i + 1); CardPlacement cplace = GetPlacement(x, iy); if (cplace == null || !cplace.HasCard) { break; } cardsInY.Add(cplace.cardInside); } for (int i = 0; i < (int)Card.Element.Count; ++i) { int iy = y + (i + 1); CardPlacement cplace = GetPlacement(x, iy); if (cplace == null || !cplace.HasCard) { break; } cardsInY.Add(cplace.cardInside); } if (cardsInY.Count >= (int)Card.Element.Count) { return(false); } return(true); }
public void ReturnToHand() { if (ownedHand != null) { transform.SetParent(ownedHand.transform); } boardPlacement.cardInside = null; boardPlacement = null; }
public void NotifyPlacement(CardPlacement wherePlaced) { int x = wherePlaced.posX; int y = wherePlaced.posY; pendingCards.Add(wherePlaced.cardInside); AddPendingPlacement(AddPlacement(x - 1, y)); AddPendingPlacement(AddPlacement(x, y - 1)); AddPendingPlacement(AddPlacement(x, y + 1)); AddPendingPlacement(AddPlacement(x + 1, y)); UpdatePlacements(); }
bool TryFillY(int x, int y, int size) { CardPlacement cplace = gameBoard.GetPlacement(x, y); if (cplace == null) { return(false); } if (cplace.HasCard) { return(false); } if (hand.CardsInHand < size) { return(false); } int handIndex = CanPlaceACard(x, y); if (handIndex >= 0) { if (size == 1) { return(true); } bool result = TryFillY(x, y - 1, size - 1); if (!result) { result = TryFillY(x, y + 1, size - 1); } return(result); } return(false); }
public bool RemovePlacement(CardPlacement c) { return(RemovePlacement(c.posX, c.posY)); }