/// <summary> /// Starts and resets game /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonStartGame_Click_1(object sender, EventArgs e) { //refresh table listBox1.Items.Clear(); listBox2.Items.Clear(); pictureBoxTable.Refresh(); //set the pictureboxes human1.PictureBoxHand = pictureBoxHand; computer1.PictureBoxHand = pictureBoxCompHand; human1.PictureBoxKeepers = pictureBoxPlayedCards; computer1.PictureBoxKeepers = pictureBoxCompPlayedKeepers; b.PictureBoxTable = pictureBoxTable; //set the table graphics to the board Graphics paperTable = pictureBoxTable.CreateGraphics(); b.PaperTable = paperTable; //set the Keepers played graphics to each player Graphics paperHumankeepers = pictureBoxPlayedCards.CreateGraphics(); human1.PaperKeepers = paperHumankeepers; Graphics paperCompKeepers = pictureBoxCompPlayedKeepers.CreateGraphics(); computer1.PaperKeepers = paperCompKeepers; //set the cards in hand graphics to each player Graphics paperHumanHand = pictureBoxHand.CreateGraphics(); human1.PaperHand = paperHumanHand; Graphics paperCompHand = pictureBoxCompHand.CreateGraphics(); computer1.PaperHand = paperCompHand; //remove all cards on the table if (b.TableList.Count > 0) { for (int i = b.TableList.Count - 1; i > 0; i--) { b.TableList.RemoveAt(i); } } b.CumulativeXPosTable = b.RESETXPOS; //create a new deck d = new Deck(); //set current rule currentRule = b.BasicRule; //set current goal currentGoal = null; b.RedrawBoard(); ResetPlayers(human1); ResetPlayers(computer1); buttonTakeTurn.Visible = true; buttonPlayCard.Visible = false; }
/// <summary> /// the base method for draws a new rule, adds it to the table list and removes from hand /// </summary> /// <param name="board"></param> /// <param name="num"></param> /// <returns></returns> public RuleCard PlayNewRuleBase(Board board, int num) { //the new rule to be added RuleCard nR1; //converts from card to new rule RuleCard nR = (RuleCard)_hand[num]; //creates new object, not just reference object if (nR is DrawRule) { nR1 = new DrawRule(nR.Bitmap, nR.Num); } else if (nR is PlayRule) { nR1 = new PlayRule(nR.Bitmap, nR.Num); } else if (nR is HandLimitRule) { nR1 = new HandLimitRule(nR.Bitmap, nR.Num); } else { nR1 = new KeeperLimitRule(nR.Bitmap, nR.Num); } //if the only thing in the list is the basic rule, draw new rule to the side if (board.TableList.Count == 1) { nR1.XPos = board.CumulativeXPosTable; board.PaperTable.DrawImage(nR1.Bitmap, nR1.XPos, nR1.YPos); board.CumulativeXPosTable += nR1.WIDTH + nR1.GAP; } //else there is at least already one rule on the table else { //for every new rule in the list not counting the basic rule for (int n = 1; n < board.TableList.Count; n++) { //if the nR1 is the same rule type as a rule already there, draw over it if (nR1.GetType() == board.TableList[n].GetType()) { nR1.XPos = board.TableList[n].XPos; board.PaperTable.DrawImage(nR1.Bitmap, board.TableList[n].XPos, board.TableList[n].YPos); //We Want to remove the rule that we are drawing over but not if it is a DrawRule if (board.TableList[n] is DrawRule) { } else { board.TableList.RemoveAt(n); } break; } //if we've gone passed every new rule and we didn't hit the break above, it is a unique new rule so draw to the side if (n == board.TableList.Count - 1) { nR1.XPos = board.CumulativeXPosTable; board.PaperTable.DrawImage(nR1.Bitmap, nR1.XPos, nR1.YPos); board.CumulativeXPosTable += nR1.WIDTH + nR1.GAP; } } } board.TableList.Add(nR1); _hand.RemoveAt(num); return(nR1); }
/// <summary> /// Plays the card currently selected /// </summary> /// <param name="player"></param> private void PlayCard(Player player) { bool keeperLimitMet = true; //before we play any cards, are we in compliance with the keeperLimitRule? foreach (RuleCard rc in b.TableList) { if (rc is KeeperLimitRule) { keeperLimitMet = rc.CheckRule(player); break; } } //we can play a keeper regardless of keeperLimitRule status if (currentSelected is Keeper) { player.PlayKeeper(currentGoal); player.NumOfKeepersInHand--; } //if We are in compliance of the keeper limit. I don't even know if this is a rule but i want it to be if (keeperLimitMet || currentSelected is Keeper) { if (currentSelected is RuleCard) { currentRule = player.PlayNewRule(b); //If the new Rule is a draw card rule, we need to draw cards when we play the rule if (currentRule is DrawRule) { PlayDrawRule(player); } } else if (currentSelected is Goal) { currentGoal = player.PlayGoal(b); } else if (currentSelected is Action) { //just for passing in for the trade card action card Player playerOther; if (player is Human) { playerOther = computer1; } else { playerOther = human1; } player.PlayAction(player, playerOther, d, b); } //This should be the only time we subtract from NumInHand and Add to NumInHand player.NumInHand--; player.NumCardsPlayed++; currentSelected = null; player.DisplayHand(); Test(player); //to pause each time computer plays a card if (player is Computer) { MessageBox.Show("Computer played a card"); } //if someone won if (player.CheckForWin(currentGoal)) { string name = "You"; if (player is Computer) { name = "The Computer"; } MessageBox.Show(name + " achieved the goal. Game is over"); //make it so the only button available is start button buttonPlayCard.Visible = false; buttonEndTurn.Visible = false; buttonTakeTurn.Visible = false; } } //else we haven't complied with the keeperlimit rule AND tried playing a non-keeper card so show message and play no card else { //computer might do this too but we don't want to show a message when it does if (player is Human) { MessageBox.Show("There is a keeper limit in play." + "\n" + "You must adhere to the keeper limit before you can play a non-keeper card"); } } }