Пример #1
0
        private void picPlayCard_Click(object sender, EventArgs e) // user play
        {
            // get the picturebox that was clicked
            PictureBox picCard = (PictureBox)sender;
            // determine the position of the picturebox that was clicked
            int columnNum = ((TableLayoutPanel)((Control)sender).Parent).GetPositionFromControl(picCard).Column;

            // ...you will need to continue this yourself in part C...
            //MessageBox.Show(string.Format("Clicked column {0}", columnNum)); // temporary
            if (!CrazyEights.IsUserTurn)
            {
                UpdateInstructions("Not you turn!");
                return;
            }
            CrazyEights.ActionResult actionResult = CrazyEights.UserPlayCard(columnNum);
            switch (actionResult)
            {
            case CrazyEights.ActionResult.SuitRequired:
                new Choose_Suit_Form().ShowDialog(this);
                CrazyEights.UserPlayCard(columnNum, eightSuit);
                ComputerAction();
                break;

            case CrazyEights.ActionResult.WinningPlay:
                UpdateInstructions("You Win!");
                UpdateUIEnable(false);
                break;

            case CrazyEights.ActionResult.ValidPlayAndExtraTurn:
                UpdateInstructions("You get extra turn!");
                break;

            case CrazyEights.ActionResult.ValidPlay:
                ComputerAction();
                UpdateInstructions("You turn!");
                break;

            case CrazyEights.ActionResult.InvalidPlayAndMustDraw:
                UpdateInstructions("You have not card can play and must draw!");
                break;

            case CrazyEights.ActionResult.InvalidPlay:
                UpdateInstructions("You cannot play this card!");
                break;
            }
            DisplayHand(CrazyEights.UserHand, tblUserHand);
            DisplayHand(CrazyEights.ComputerHand, tblComputerHand);
            picDiscardpile.Image = Images.GetCardImage(CrazyEights.TopDiscard);
            this.Controls.Owner.Update();

            if (!CrazyEights.IsPlaying)
            {
                UpdateUIEnable(false);
            }
        }
 private void btn_Deal_Click(object sender, EventArgs e)
 {
     DisplayHand(CrazyEights.UserHand, tbh_user);
     DisplayHand(CrazyEights.ComputerHand, tbh_computer);
     picBox_Left.Image  = Images.GetBackOfCardImage();
     picBox_right.Image = Images.GetCardImage(CrazyEights.TopDiscard);
     CrazyEights.UserDrawCard();
     CrazyEights.ActionResult text = CrazyEights.UserDrawCard();
     UpdateInstructions(text.ToString(), true);
     DisplayHand(CrazyEights.UserHand, tbh_user);
     //Choose_a_suit form = new Choose_a_suit ();
     //form.ShowDialog();
     //lbl_click_to_deal.Text = form.Getchoosenstring;
 }
    static void ComputerTurn()
    {
        Console.WriteLine("================");
        Console.WriteLine("Computer's turn!");
        Console.WriteLine("================");

        // Repeat as long as it is the computer's turn and the game is not over
        while (!CrazyEights.IsUserTurn && CrazyEights.IsPlaying)
        {
            DisplayBoard();
            CrazyEights.ActionResult result = CrazyEights.ComputerAction();
            Console.ReadLine();
            Console.WriteLine(result);
        }
    }
Пример #4
0
        private void picDrawpile_Click(object sender, EventArgs e)
        {
            if (!CrazyEights.IsUserTurn)
            {
                UpdateInstructions("Not you turn!");
                return;
            }
            CrazyEights.ActionResult actionResult = CrazyEights.UserDrawCard();
            switch (actionResult)
            {
            case CrazyEights.ActionResult.CannotDraw:
                UpdateInstructions("You cannot draw!");
                break;

            case CrazyEights.ActionResult.DrewPlayableCard:
                break;

            case CrazyEights.ActionResult.DrewUnplayableCard:
                UpdateInstructions("No card can play, draw go on!");
                break;

            case CrazyEights.ActionResult.DrewAndNoMovePossible:
                ComputerAction();
                break;

            case CrazyEights.ActionResult.DrewAndResetPiles:
                UpdateInstructions("No body can play, reset piles");
                break;

            case CrazyEights.ActionResult.FlippedDeck:
                UpdateInstructions("Flipped Deck");
                break;
            }

            if (CrazyEights.IsDrawPileEmpty)
            {
                picDrawpile.Image = null;
            }
            else
            {
                picDrawpile.Image = Images.GetBackOfCardImage();
            }

            DisplayHand(CrazyEights.UserHand, tblUserHand);
            DisplayHand(CrazyEights.ComputerHand, tblComputerHand);
            picDiscardpile.Image = Images.GetCardImage(CrazyEights.TopDiscard);
            this.Controls.Owner.Update();
        }
        /// <summary>
        /// Tells us which card, at which position was selected.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void picPlayCard_Click(object sender, EventArgs e)
        {
            // get the picturebox that was clicked

            PictureBox picCard = (PictureBox)sender;

            // determine the position of the picturebox that was clicked
            int columnNum = ((TableLayoutPanel)((Control)sender).Parent).GetPositionFromControl(picCard).Column;


            //lbl_click_to_deal.Text == CrazyEights.ActionResult();
            if (CrazyEights.IsPlaying == true)
            {
                if (CrazyEights.IsUserTurn == true)
                {
                    CrazyEights.UserPlayCard(columnNum);

                    DisplayHand(CrazyEights.UserHand, tbh_user);
                    picBox_Left.Image  = Images.GetBackOfCardImage();
                    picBox_right.Image = Images.GetCardImage(CrazyEights.TopDiscard);
                    CrazyEights.ActionResult text = CrazyEights.UserPlayCard(columnNum);
                    UpdateInstructions(text.ToString(), true);
                    if (CrazyEights.ActionResult.SuitRequired == CrazyEights.UserPlayCard(columnNum))
                    {
                        Choose_a_suit form = new Choose_a_suit();
                        form.ShowDialog();
                    }
                }
                else if (CrazyEights.IsPlaying == false)
                {
                    CrazyEights.ComputerAction();

                    DisplayHand(CrazyEights.ComputerHand, tbh_computer);
                    picBox_Left.Image  = Images.GetBackOfCardImage();
                    picBox_right.Image = Images.GetCardImage(CrazyEights.TopDiscard);
                    CrazyEights.ActionResult comptext = CrazyEights.ComputerAction();
                    UpdateInstructions(comptext.ToString(), true);
                }
            }

            // ...you will need to continue this yourself in part C...
            // MessageBox.Show(string.Format("Clicked column {0}", columnNum)); //temporary
        }
Пример #6
0
        private void ComputerAction()
        {
            DisplayHand(CrazyEights.UserHand, tblUserHand);
            DisplayHand(CrazyEights.ComputerHand, tblComputerHand);
            picDiscardpile.Image = Images.GetCardImage(CrazyEights.TopDiscard);
            this.Controls.Owner.Update();

            UpdateInstructions("Computer turn!", true);
            CrazyEights.ActionResult actionResult = CrazyEights.ComputerAction();
            Console.WriteLine(actionResult);
            switch (actionResult)
            {
            case CrazyEights.ActionResult.DrewPlayableCard:
                UpdateInstructions("Drew a card", true);
                ComputerAction();
                break;

            case CrazyEights.ActionResult.DrewUnplayableCard:
                UpdateInstructions("Drew a card", true);
                ComputerAction();
                break;

            case CrazyEights.ActionResult.DrewAndNoMovePossible:
                break;

            case CrazyEights.ActionResult.DrewAndResetPiles:
                picDrawpile.Image = null;
                UpdateInstructions("Drew and reset piles", true);
                picDrawpile.Image = Images.GetBackOfCardImage();
                break;

            case CrazyEights.ActionResult.FlippedDeck:
                UpdateInstructions("Flipped deck", true);
                ComputerAction();
                break;

            case CrazyEights.ActionResult.WinningPlay:
                UpdateInstructions("Computer Win!");
                UpdateUIEnable(false);
                break;

            case CrazyEights.ActionResult.ValidPlayAndExtraTurn:
                UpdateInstructions("Get extern turn!");
                ComputerAction();
                break;

            case CrazyEights.ActionResult.ValidPlay:
                break;
            }

            if (CrazyEights.IsDrawPileEmpty)
            {
                picDrawpile.Image = null;
            }
            else
            {
                picDrawpile.Image = Images.GetBackOfCardImage();
            }

            DisplayHand(CrazyEights.UserHand, tblUserHand);
            DisplayHand(CrazyEights.ComputerHand, tblComputerHand);
            picDiscardpile.Image = Images.GetCardImage(CrazyEights.TopDiscard);
            this.Controls.Owner.Update();
        }