예제 #1
0
        //on card click will raise event in card image control class
        //clicked card will go through player attack/defend phase method
        private void Card_Click(object sender, EventArgs e)
        {
            CardImageControl clickedCardControl = new CardImageControl();

            clickedCardControl = (CardImageControl)sender;

            //if (myPlayerTwo.getIsDefending() == false)
            //{
            //    myPlayerOne.setIsDefending(true);
            //}
            //else if (myPlayerTwo.getIsDefending() == true)
            //{
            //    myPlayerOne.setIsDefending(false);
            //}

            //checks to see if computer is defending if so human player attack phas starts and computer
            //defend phase begins
            if (myPlayerTwo.getIsDefending() == true)
            {
                myPlayerOne.AttackingPhase(myRiver, (clickedCardControl.Card));

                myPlayerTwo.DefendingPhase(myRiver, myDeck.getTrumpCard());


                //checks to see if computer is defending if not will log round in output file
                //will reset round and have human start defending
                if (myPlayerTwo.getIsDefending() == false)
                {
                    roundNumber += 1;

                    GameLog.LogRound(GameLog, roundNumber, myPlayerOne, myPlayerTwo, myRiver);


                    for (int i = 0; i < myRiver.length(); i++)
                    {
                        myHandTwo.AddCardToHand(myRiver.GetCard(i));
                    }
                    myRiver.ClearRiver();
                    lblComputerAttacking.Visible = true;
                    lblHumanAttacking.Visible    = false;
                    try
                    {
                        myPlayerOne.RefillHand(myDeck);
                        myPlayerTwo.RefillHand(myDeck);
                    }
                    catch (Exception)
                    {
                    }

                    btnPickUp.Enabled      = true;
                    btnCeaseAttack.Enabled = false;

                    myPlayerTwo.AttackingPhase(myRiver);
                }
            }

            //human is defending, from computer attacks
            else
            {
                myPlayerOne.DefendingPhase(myRiver, myDeck.getTrumpCard(), (clickedCardControl.Card));
                myPlayerTwo.AttackingPhase(myRiver);

                //if human no longer defending, round over and reset, computer is now defending
                if (myPlayerTwo.getIsDefending() == true)
                {
                    roundNumber += 1;

                    GameLog.LogRound(GameLog, roundNumber, myPlayerOne, myPlayerTwo, myRiver);

                    for (int i = 0; i < myRiver.length(); i++)
                    {
                        discardDisplayList.Add(myRiver.GetCard(i));
                    }
                    myRiver.ClearRiver();
                    lblComputerAttacking.Visible = false;
                    lblHumanAttacking.Visible    = true;
                    try
                    {
                        myPlayerOne.RefillHand(myDeck);
                        myPlayerTwo.RefillHand(myDeck);
                    }
                    catch (Exception)
                    {
                    }
                    btnPickUp.Enabled      = false;
                    btnCeaseAttack.Enabled = true;
                }
            }



            DisplayAllCardLists();

            //logs who won the game and win/loss ratios
            if (myPlayerOne.getHand().length() == 0)
            {
                playerOneWins   += 1;
                playerTwoLosses += 1;
                MessageBox.Show("GAME OVER: PLAYER ONE HAS WON");
                GameLog.Log("\n*****GAME OVER: PLAYER ONE HAS WON***** \n");
                GameLog.Log("\n PlayerOne Win/Loss Ratio " + playerOneWins.ToString() + "/" + playerOneLosses.ToString());
                GameLog.Log("\n PlayerTwo Win/Loss Ratio " + playerTwoWins.ToString() + "/" + playerTwoLosses.ToString() + "\n");
                ResetGame();
            }

            if (myPlayerTwo.getHand().length() == 0)
            {
                playerTwoWins   += 1;
                playerOneLosses += 1;
                MessageBox.Show("GAME OVER: PLAYER TWO HAS WON");
                GameLog.Log("\n*****GAME OVER: PLAYER TWO HAS WON***** \n");
                GameLog.Log("\n PlayerOne Win/Loss Ratio " + playerOneWins.ToString() + "/" + playerOneLosses.ToString());
                GameLog.Log("\n PlayerTwo Win/Loss Ratio " + playerTwoWins.ToString() + "/" + playerTwoLosses.ToString() + "\n");
                ResetGame();
            }
        }