private void InitalizeHand() { bool done = false; while (!done) { _data.PlayerHand.Cards.Clear(); _data.DeckManager.Shuffle(); for (int i = 0; i < _data.OpponentsHands.Length; i++) { _data.OpponentsHands[i].Cards.Clear(); } Hand[] hands = new Hand[_data.OpponentsHands.Length + 1]; _data.OpponentsHands.CopyTo(hands, 0); hands[_data.OpponentsHands.Length] = _data.PlayerHand; _data.DeckManager.Deal(hands, CARDS_PER_HAND); if (_data.DeckManager.Table[0] != null && _data.DeckManager.Table[0].Rank != CardRank.Eight) { done = true; } } _currentPlayer = _startingPlayer; _suitOverride = CardSuit.None; _mouseUp = false; _prompt = ""; _undoPointer = 0; _lastMouseButton = MouseButtons.None; _lastCardsPlayed.Clear(); _direction = Hand.PlayDirection.Forward; _skipFlag = false; SetPrompt(); //if (_currentPlayer == 0) //{ // _prompt = Properties.Resources.Caption_YourTurn; //} }
public frmMain() { InitializeComponent(); this.FormClosed += new FormClosedEventHandler(Form1_FormClosed); _data = new GameData(_numOpponents, 1); this.SetStyle( ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true); _state = GameState.NotPlaying; _rocketQueue.setCanvas(Size); //_rocketQueue = new RocketQueue(new Random(), Size); _direction = Hand.PlayDirection.Forward; _gameLoopThread = new System.Threading.Thread(GameLoop); _gameLoopThread.Start(); _tableCenter = Size.Width / 2; }
private void PlayCard(Card cardToPlay, CrazyEightsHand hand) { // put card onto table _data.DeckManager.Table.Add(cardToPlay); // remove from player hand //_data.OpponentsHands[_currentPlayer - 1].Cards.Remove(cardToPlay); hand.Cards.Remove(cardToPlay); if (_undoPointer < _lastCardsPlayed.Count - 1) { // prune list past _redoPointer _lastCardsPlayed.RemoveRange(_undoPointer + 1, _lastCardsPlayed.Count - (_undoPointer + 1)); } _lastCardsPlayed.Add(cardToPlay); _undoPointer = _lastCardsPlayed.Count - 1; if (cardToPlay.Rank == CardRank.Ace) { if (_direction == Hand.PlayDirection.Forward) { _direction = Hand.PlayDirection.Reverse; } else { _direction = Hand.PlayDirection.Forward; } } else if (cardToPlay.Rank == CardRank.Two && !_data.DeckManager.IsEmpty) { _playerHasDrawn = false; // increment the two's count _dueceCount++; // draw two int nextPlayer = NextPlayer(); // get hand of next player CrazyEightsHand nextPlayerHand = null; if (nextPlayer == 0) { nextPlayerHand = _data.PlayerHand; } else { nextPlayerHand = _data.OpponentsHands[nextPlayer - 1]; } if (nextPlayerHand.Cards.Find(c => c.Rank == CardRank.Two) == null) { _lastDrawnCards.Clear(); for (int i = 0; i < _dueceCount; i++) { Card drawCard; DrawCard(nextPlayer, out drawCard); _lastDrawnCards.Add(drawCard); DrawCard(nextPlayer, out drawCard); _lastDrawnCards.Add(drawCard); } _playerHasDrawn = true; // if next is player and player doesn't have any two's if (nextPlayer == 0) { ShowDrawTwoDialog(); } _dueceCount = 0; } } else if (cardToPlay.Rank == CardRank.Queen) { // trick here, increment player so when // we increment next player, it will skip _skipFlag = true; } //_redoPointer = _lastCardsPlayed.Count; }