public async void AsyncWaitForMove() { while (true) { Move nextMove = await Net.Recieve(); if (nextMove.Selected == GameState.TURN_PASS) { this.Invoke((MethodInvoker) delegate { DisplayNotification("YOUR OPPONENT PASSED - IT IS YOUR TURN"); }); } else if (nextMove.Selected == GameState.CARD_DRAW) { this.Invoke((MethodInvoker) delegate { DisplayNotification("YOUR OPPONENT DREW A CARD"); }); } // Make the card selected for half a second or so, to show what the opponent is doing CardBox SelectedBox = null; if (nextMove.Selected.AsCard() is MinionCard m && m.OnBoard) { foreach (CardBox b in EnemyBoard.GetCards()) { if (b.CardReferenced.Id == nextMove.Selected) { SelectedBox = b; } } }
// onClick for card elements public void CardClicked(CardBox card) { GameState Game = card.CardReferenced.Game; if (card.CardReferenced is HeroCard || card.CardReferenced.Game.CurrentPower == card.CardReferenced || !card.CardReferenced.Game.IsP1Turn) { return; } // Get the game from the top-level gamebox by traversing up until we find the gamebox Control GameB = this; while (!(GameB is GameBox)) { GameB = GameB.Parent; } GameBox GameUI = GameB as GameBox; GameUI.HideNotif(); if (GameUI.SelectedCard == null && (!card.CardPlayableIndicator.Visible || card.CardPlayableIndicator.BackColor == card.RED_IND || card.CardReferenced.Owner == Game.PlayerTwo)) { return; } // If nothing is selected yet, we set the selected card if (GameUI.SelectedCard == null) { GameUI.SelectedCard = CardReferenced; BackgroundImage = Properties.Resources.SelectedCardBody; return; } // Otherwise the move is completed and processe Move NextMove = new Move(GameUI.SelectedCard.Id, CardReferenced.Id); if (GameUI.SelectedCard.IsPlayable(NextMove)) { GameUI.Game.ProcessMove(NextMove); GameUI.Net.Send(NextMove); } GameUI.SelectedCard = null; GameUI.RenderState(GameUI.Game); }
public void UpdateUI(PowerCard p) { PowerCard = p; if (PowerCard == null) { NoPowerImage.Image = Properties.Resources.NoCardGraphic; NoPowerImage.BringToFront(); return; } NoPowerImage.SendToBack(); Controls.Remove(Visual); Visual = new CardBox(PowerCard as BaseCard) { Top = Height - GameBox.CARD_HEIGHT, Left = (this.Width - GameBox.CARD_WIDTH) / 2 }; Visual.SetPlayabilityVisibility(false); Controls.Remove(Visual); Controls.Add(Visual); }
public void UpdateUI() { SuspendLayout(); // To update, we have to: // UPDATE existing boxes with card info (they track their cards) // If their card no longer is in this zone, DELETE the box // CREATE new boxes for cards that aren't displayed // Whilst keeping order // Optimization trick: // track which cards aren't new by keeping track of their indexes // Defaults to false - true if the card will be rendered bool[] RenderedFlag = new bool[TrackedCards.Count]; List <CardBox> PendingRemove = new List <CardBox>(); foreach (CardBox box in DisplayedCards) { int Ind = TrackedCards.IndexOf(box.CardReferenced as T); if (Ind == -1) { PendingRemove.Add(box); Controls.Remove(box); } else { box.UpdateUI(); RenderedFlag[Ind] = true; } } foreach (CardBox box in PendingRemove) { DisplayedCards.Remove(box); } for (int i = 0; i < RenderedFlag.Length; i++) { if (!RenderedFlag[i]) { CardBox Box = new CardBox(TrackedCards[i]) { // Make it temporarily invisible Top = 2000, }; DisplayedCards.Add(Box); Controls.Add(Box); } } // Now reposition int CoordY = (Height - GameBox.CARD_HEIGHT) / 2; int FirstX; if (DisplayedCards.Count % 2 == 0) { // x = mid – (n / 2) * (g + w) + 0.5 * g FirstX = (this.Width / 2) - (DisplayedCards.Count / 2) * (GameBox.CARD_WIDTH + GameBox.CARD_SPACING) + (GameBox.CARD_SPACING / 2); } else { // mid – (n / 2) * (g + w) – 0.5 * w FirstX = (this.Width / 2) - (DisplayedCards.Count / 2) * (GameBox.CARD_WIDTH + GameBox.CARD_SPACING) - (GameBox.CARD_WIDTH / 2); } int NextX = FirstX; foreach (CardBox c in DisplayedCards) { c.Left = NextX; c.Top = CoordY; NextX += (GameBox.CARD_WIDTH + GameBox.CARD_SPACING); } ResumeLayout(); }