public IEnumerator TakeTurn(ConversationGrid grid) { inventory.UpdatePlayableDeck(); Card[] cards = inventory.GetHand(); CardGrid tempCard = UnityEngine.Object.Instantiate(grid.cardGridPrefab); grid.activeCard = tempCard; Dictionary <int, List <Move> > possibleMoves = new Dictionary <int, List <Move> >(); int maxScore = int.MinValue; foreach (Vector2 spotCandidate in grid.availableSpots) { foreach (Card cardCandidate in cards) { for (int i = 0; i < 4; i++) { tempCard.card = cardCandidate; tempCard.x = Mathf.RoundToInt(spotCandidate.x); tempCard.y = Mathf.RoundToInt(spotCandidate.y); tempCard.rotation = i; int score = grid.GetCardScore(false); if (score < maxScore) { continue; } maxScore = Mathf.Max(maxScore, score); if (!possibleMoves.ContainsKey(score)) { possibleMoves.Add(score, new List <Move>()); } possibleMoves[score].Add( new Move { card = cardCandidate, spot = spotCandidate, rotation = i } ); } } yield return(null); } UnityEngine.Object.Destroy(tempCard.gameObject); grid.activeCard = null; List <Move> moves = possibleMoves[maxScore]; Move move = moves[UnityEngine.Random.Range(0, moves.Count)]; grid.SpawnCard(move.card, null); grid.activeCard.x = Mathf.RoundToInt(move.spot.x); grid.activeCard.y = Mathf.RoundToInt(move.spot.y); grid.activeCard.transform.Rotate(0, 0, -90 * move.rotation); grid.activeCard.rotation = move.rotation; grid.OnCardRelease(grid.activeCard); }
public void OnEndDrag(PointerEventData ev) { CardGrid targetCardGrid = possibleCardGrid == null || !possibleCardGrid.canAddCard ? parentCardGrid : possibleCardGrid; if (targetCardGrid != null) { transform.SetParent(targetCardGrid.transform); } if (targetCardGrid != parentCardGrid) { parentCardGrid.RemoveCard(gameObject); targetCardGrid.AddCard(gameObject); siblingIndex = transform.GetSiblingIndex(); } else { transform.SetSiblingIndex(siblingIndex); } if (cGroup != null) { cGroup.blocksRaycasts = true; } parentCardGrid = null; possibleCardGrid = null; }
public void OnCardDrag(CardGrid card) { ResetEdgeAndNeighborsColor(); highlight.localPosition = new Vector3(card.x, card.y, 0); highlight.gameObject.SetActive(CanPlaceCard(card.x, card.y)); rotateButton.gameObject.SetActive(false); }
private async Task OnDeal() { ResetCards(); var(computerCards, playerCards, sharedCard) = Game.GetHands(); var orig = _cgDeck.GetNextCardPosition(sharedCard[0]); await Deal(playerCards, computerCards, sharedCard, new List <CardCtrl> { computerCards[0], computerCards[2] }, PlayerType.Computer); var playerCribCards = new List <CardCtrl> { _cgPlayer.Cards[0], _cgPlayer.Cards[1] }; var index = 2; foreach (var card in playerCribCards) { await CardGrid.AnimateMoveOneCard(_cgPlayer, _cgDiscarded, card, index ++, false, MOVE_CARDS_ANIMATION_DURATION, 0); } CardGrid.TransferCards(_cgPlayer, _cgDiscarded, playerCribCards); }
private void SetEdgeColorBonus(int edgeIndex) { CardGrid otherCard = GetAdjacentCard(edgeIndex); activeCard.SetEdgeColor((edgeIndex + 4 - activeCard.rotation) % 4, Color.green); otherCard?.SetEdgeColor((edgeIndex + 6 - otherCard.rotation) % 4, Color.green); }
private void SetEdgeColorPenalty(int edgeIndex) { CardGrid otherCard = GetAdjacentCard(edgeIndex); activeCard.SetEdgeColor((edgeIndex + 4 - activeCard.rotation) % 4, Color.red); otherCard?.SetEdgeColor((edgeIndex + 6 - otherCard.rotation) % 4, Color.red); }
private void IntializeGame() { CardsOnBoard.Clear(); _occupiedBoardPositions = new bool[_numBoardPositionsRow, _numBoardPositionsRow]; MyCardGrid = new CardGrid(); _myCardDeck = new CardDeck(); CurrentCard = _myCardDeck.DrawCard(); CardBase card0 = _myCardDeck.DrawCard(); card0.Position = new BindPoint(_cardWidth * CenterCol, _cardHeight * CenterRow); IntPoint gridPos = (IntPoint)pos2GridConv.Convert(card0.Position, null, _cardWidth, null); AddCardToBoard(card0); Players = new ObservableCollection <PlayerBase> { new PlayerThisHuman(), new PlayerPc(), new PlayerOtherHuman() }; CurrentPlayer = Players[0]; }
private void Button_Click(object sender, RoutedEventArgs e) { if (gameWorld == null) { return; } if (BombUpDown.Value == null) { return; } List <int> cards = new List <int>(); int numPlayer = gameWorld.Players.Count; for (int i = 0; i < numPlayer; ++i) { IntegerUpDown cardUpDown = CardGrid.FindName(string.Format("Player{0}UpDown", i)) as IntegerUpDown; if (cardUpDown == null || cardUpDown.Value == null) { return; } cards.Add((int)cardUpDown.Value); cardUpDown.Value = 0; } gameWorld.AddGame((int)BombUpDown.Value, cards); BombUpDown.Value = 0; UpdatePlayerScoreLabels(); ScoreListViewer.Items.Refresh(); }
public async Task AnimateMoveComputerCardstoCrib(List <CardCtrl> computerCribCards, bool moveCards = true) { double beginTime = 0; var taskList = new List <Task>(); var animationDuration = FlipAnimationDuration; if (_firstDeal) { animationDuration *= 4; _firstDeal = false; } var tList = CardGrid.MoveListOfCards(_cgComputer, _cgCrib, computerCribCards, animationDuration, beginTime); if (tList != null) { taskList.AddRange(tList); } await Task.WhenAll(taskList); if (moveCards) { CardGrid.TransferCards(_cgComputer, _cgCrib, computerCribCards); } }
public void SetData(CardBase clickedCard, CardGrid grid) { GameManager.Instance.isShaking = true; gameObject.SetActive(true); this.clickedCard = clickedCard; this.grid = grid; }
void ClearData() { grid = null; clickedCard = null; gameObject.SetActive(false); GameManager.Instance.isShaking = false; }
private void ResetEdgeAndNeighborsColor() { for (int i = 0; i < 4; i++) { CardGrid otherCard = GetAdjacentCard(i); activeCard.SetEdgeColor((i + 4 - activeCard.rotation) % 4, Color.black); otherCard?.SetEdgeColor((i + 6 - otherCard.rotation) % 4, Color.black); } }
public void OnChooseCard(CardBase chosenCard, CardGrid cardGrid) // 카드가 있던 곳임 리스트 지워줘야 해. { CardBase card = putCardQueue.Dequeue(); OnScored(card, cardGrid); OnScored(chosenCard, cardGrid); TryExecuteChoiceCallback(); }
public void OnScored(CardBase card, CardGrid cardGrid = null) // 카드를 얻을 때 { CardManager.Instance.TransportCard(card); if (cardGrid != null) { cardGrid.placedCards.Remove(card); } targetUserData.ownCards.Add(card); }
public void SetData(CardBase lCard, CardBase rCard, CardGrid grid) { this.lCard = lCard; this.rCard = rCard; this.grid = grid; lCardImg.sprite = this.lCard.cardData.icon; rCardImg.sprite = this.rCard.cardData.icon; gameObject.SetActive(true); }
private void UpdateCardBonus(CardGrid card) { int baseScore = card.card.GetScore(); int extra = GetCardScore() - baseScore; card.SetCenterText( baseScore.ToString() + (extra < 0 ? "" : "+") + extra.ToString()); }
private async Task AnimationEndHand(PlayerType dealer) { var taskList = new List <Task>(); var cribOwnerGrid = dealer == PlayerType.Computer ? _cgComputer : _cgPlayer; taskList.AddRange(AnimateFlipAllCards(cribOwnerGrid.Cards, CardOrientation.FaceDown, true)); taskList.AddRange(CardGrid.AnimateMoveAllCards(cribOwnerGrid, _cgDeck, MOVE_CARDS_ANIMATION_DURATION, 0, AnimateMoveOptions.MoveSequentlyEndingAtZero, false)); await Task.WhenAll(taskList); }
public void OnBeginDrag(PointerEventData ev) { siblingIndex = transform.GetSiblingIndex(); parentCardGrid = transform.parent.GetComponent <CardGrid>(); transform.SetParent(GameManager.tableLayout); // put the card to layout if (cGroup != null) { cGroup.blocksRaycasts = false; } }
void ClearData() { this.lCard = null; this.rCard = null; this.grid = null; lCardImg.sprite = null; rCardImg.sprite = null; GameManager.Instance.isChoicing = false; gameObject.SetActive(false); }
public void SetWinStage(int stage) { activeCard = null; foreach (var card in cards) { card.SetClickable( card.source == CardGrid.CardSource.PLAYER && stage == 1 || card.source == CardGrid.CardSource.OTHER && stage == 2 ); } winStage = stage; }
public void OnShaked(CardBase clickedCard, CardGrid cardGrid, bool bShaked = true) { clickedCard.img.raycastTarget = false; cardGrid.Set(clickedCard); OnShakedCallback.Invoke(); // 이거 없으면 지랄난거라 널체크하면 안될듯.. OnShakedCallback = null; if (bShaked) { rule.Shake(); } }
public void TakePairCard(CardGrid putGrid) // 내가 낸 패인데, 두개만 있는거면 가져오기 { if (putGrid.placedCards.Count == 2) { while (putGrid.placedCards.Count != 0) { gm.OnScored(putGrid.placedCards[0], putGrid); } putGrid.Reset(); } }
public void OnMouseUp() { if (!Draggable()) { return; } if (draggedCard != null) { draggedCard.OnMouseUp(); draggedCard = null; } }
void PlaceCard() // 알아서 4번 돌림 { CardBase card = gm.GetRandomCard(gm.useCardList); // 랜덤으로 하나 뽑고 CardGrid grid = CardFinder.GetSameMonthCardsGrid(gm.cardGrids, card); if (grid == null) { grid = gm.GetNullGrid(); } grid.Set(card); card.gameObject.SetActive(true); }
public void SetGameState(NPC npc) { GameState state = npc.gameState; foreach (CardGrid card in state.cards) { CardGrid newInstance = Instantiate(cardGridPrefab); newInstance.Init(this, card.card, null, CardGrid.CardSource.SAVED); newInstance.x = card.x; newInstance.y = card.y; newInstance.rotation = card.rotation; newInstance.transform.localPosition = new Vector3(card.x, card.y, 0); newInstance.transform.Rotate(0, 0, -90 * card.rotation); newInstance.confirmedOnBoard = true; cards.Add(newInstance); } blockedSquares = new HashSet <Vector2>(npc.blockedSpots); if (cards.Count > 0) { UpdateAvailableSpots(); } gridScale = Camera.main.orthographicSize * 2 / GridSquaresVertical; transform.localScale = Vector3.one * gridScale; transform.position = new Vector3( (1 - BoardWidth) * gridScale / 2 + 2, (1 - BoardHeight) * gridScale / 2 + 1, 0); confirmButton.interactable = false; for (int x = 0; x < BoardWidth; x++) { for (int y = 0; y < BoardHeight; y++) { if (blockedSquares.Contains(new Vector2(x, y))) { continue; } Transform gridSquare = Instantiate(gridSquarePrefab); gridSquare.SetParent(transform); gridSquare.localScale = Vector3.one; gridSquare.localPosition = new Vector3(x, y, 0); if (cards.Count == 0) { availableSpots.Add(new Vector2(x, y)); } } } }
public void ConfirmMove() { cards.Add(activeCard); activeCard.Confirm(); GameManager.score += GetCardScore(); scoreText.text = "Score: " + GameManager.score.ToString(); activeCard.ResetCenterText(); activeCard = null; confirmButton.interactable = false; rotateButton.gameObject.SetActive(false); UpdateAvailableSpots(); }
//Sets up the game screen with all images turnet upside down by default public GamePage(Player[] players) { Players = players; InitializeComponent(); Labelnameplayer.Content = Players[0].Name + " is aan zet"; GridData = new CardGrid(CardGridEl, Config.GridSize); GridData.AllCards .Select(card => card.Element) .ToList() .ForEach(toggleButton => { toggleButton.Click += OnCardClick; }); UpdatePlayerScore(Players[0]); UpdatePlayerScore(Players[1]); }
public void SpawnCard(Card c, CardInventory parent) { CardGrid cardGrid = Instantiate(cardGridPrefab); if (parent) { parent.draggedCard = cardGrid; } cardGrid.Init(this, c, parent, parent == null ? CardGrid.CardSource.OTHER : CardGrid.CardSource.PLAYER); if (activeCard != null) { activeCard.CancelMoveFromInventory(); } activeCard = cardGrid; confirmButton.interactable = true; }
public void Putcard() { CardBase followCard = GameManager.Instance.followUpCardQueue.Dequeue(); followCard.gameObject.SetActive(true); CardGrid followCardTargetGrid = CardFinder.GetSameMonthCardsGrid(GameManager.Instance.cardGrids, followCard); if (followCardTargetGrid == null) // 같은 월이 깔린게 없으면 그냥 비어있는데에 내려놓습니다. { followCardTargetGrid = GameManager.Instance.GetNullGrid(); followCardTargetGrid.Set(followCard); } else { int count = followCardTargetGrid.placedCards.Count; switch (count) { case 1: // 뒷패를 깠는데 하나만 있다는 거면, 무조건 가져오면 됨. GameManager.Instance.OnScored(followCard); GameManager.Instance.OnScored(followCardTargetGrid.placedCards[0], followCardTargetGrid); followCardTargetGrid.Reset(); break; case 2: // 두 개가 있다는 거면 둘 중 하나를 선택하게 하면 됨. followCard.MoveCardToGrid(followCardTargetGrid); GameManager.Instance.choiceCallBackQueue.Enqueue(() => GameManager.Instance.ChoiceCard(followCardTargetGrid.placedCards[0], followCardTargetGrid.placedCards[1], followCardTargetGrid)); GameManager.Instance.putCardQueue.Enqueue(followCard); break; case 3: // 3개 있으면 다 가져오고 while (followCardTargetGrid.placedCards.Count > 0) { GameManager.Instance.OnScored(followCardTargetGrid.placedCards[0], followCardTargetGrid); } GameManager.Instance.OnScored(followCard); // 내가 낸 것도 가져오기. GameManager.Instance.choiceCallBackQueue.Clear(); followCardTargetGrid.Reset(); break; } } GameManager.Instance.TryExecuteChoiceCallback(); }
public void OnCardRelease(CardGrid card) { if (!CanPlaceCard(card.x, card.y)) { if (card.firstDrag) { card.CancelMoveFromInventory(); return; } card.CancelMoveSnapBack(); } UpdateCardBonus(card); card.transform.localPosition = new Vector3(card.x, card.y, 0); rotateButton.gameObject.SetActive(true); rotateButton.transform.position = Camera.main.WorldToScreenPoint(card.transform.position) + new Vector3(80, 80, 0); }