Esempio n. 1
0
        //PLAY AGAIN BUTTON.....................................................
        private void PlayAgains(object control, EventArgs e)
        {
            AgainF delegateA = new AgainF(FAgain);

            delegateA.Invoke("Playagain", "");
        }
Esempio n. 2
0
        //SURE MOVE.....................................................................
        private void SureMoveUser(object control, EventArgs e)
        {
            if (conditionToAllFunction == true)
            {
                for (int numberCountAS = 0; numberCountAS <= handleScanning.Length - 1; numberCountAS++)
                {
                    if (finalCondition == "true")
                    {
                        int countCheck = 0, numberCountFinal = 0;
                        if (numberCountAS <= 7)
                        {
                            numberCountFinal = DoLoopEach(countCheck, numberCountFinal, numberCountAS);

                            //GAME ENDED......................................
                            if (numberCountFinal == 3)
                            {
                                AgainF delegateA = new AgainF(FAgain);
                                delegateA.Invoke("", "ShowWin");
                                break;
                            }

                            if (numberCountAS == 7)
                            {
                                if (numberCountFinal != 3)
                                {
                                    int numCountF1 = 0, numCountF2 = 0;
                                    foreach (Panel panS in JarOfClickingBox.Controls)
                                    {
                                        numCountF1++;
                                        if (String.IsNullOrEmpty(panS.AccessibleName))
                                        {
                                            numCountF2 += 1;
                                        }
                                    }
                                    if (numCountF1 == 9)
                                    {
                                        if (numCountF2 != 0)
                                        {
                                            Panel pan = (Panel)(JarOfClickingBox.Controls["panel" + numberHandlePan]);
                                            pan.AccessibleDescription = "DoneSureMove";
                                            handleNameOfPan           = "";
                                            conditionToNumberCount    = "";
                                            SureMove.Enabled          = false;
                                            ConditionToNonClick       = true;
                                            numberTime = 60;
                                            time.Stop();
                                            if (numberCount == 0)
                                            {
                                                numberCount++;
                                                JarOfNameMove.Text = handleData[numberCount];
                                                handleXandOS       = handleXandOA[numberCount];
                                            }
                                            else
                                            {
                                                numberCount--;
                                                JarOfNameMove.Text = handleData[numberCount];
                                                handleXandOS       = handleXandOA[numberCount];
                                            }
                                            time.Start();
                                            timer2.Stop();
                                        }
                                        else
                                        {
                                            AgainF delegateA = new AgainF(FAgain);
                                            delegateA.Invoke("", "ShowWinsTie");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                List <int>    intJar = new List <int>(), intJar2 = new List <int>();
                List <string> ScanningAddPanel = new List <string>();
                string        handlePan        = "";
                conditionFinalCatch = "false";
                Random random = new Random();

                int numberRandom = 0, numberConditionScanning = 0;
                for (int jarCount = 0; jarCount < st.Length; jarCount++)
                {
                    if (jarCount <= 7)
                    {
                        if (st[jarCount, 0] == handleNameOfPan)
                        {
                            intJar.Add(jarCount);
                        }
                        else if (st[jarCount, 1] == handleNameOfPan)
                        {
                            intJar.Add(jarCount);
                        }
                        else
                        {
                            intJar.Add(jarCount);
                        }
                    }

                    if (jarCount + 1 >= st.Length)
                    {
                        for (int jarCount3 = 0; jarCount3 < intJar.ToArray().Length; jarCount3++)
                        {
                            int countCheck = 0, numberCountFinal = 0;
                            int numberCountFinalSee = DoLoopEach(countCheck, numberCountFinal, intJar.ToArray()[jarCount3]);

                            if (numberCountFinalSee == 2)
                            {
                                handlePan = "";
                                SeeIfHave(intJar.ToArray()[jarCount3], "Scanning");
                                if (handlePan != "")
                                {
                                    intJar2.Add(intJar.ToArray()[jarCount3]);
                                }
                            }
                            else if (numberCountFinalSee == 3)
                            {
                                conditionFinalCatch = "true";
                                handleScore[0]++;
                                WinnerSee.Text    = textBox4.Text;
                                Player1.Text      = textBox4.Text;
                                Player1S.Text     = handleScore[0].ToString();
                                Player2.Text      = "A.I";
                                Player2S.Text     = handleScore[1].ToString();
                                GameEnded.Visible = true;
                            }

                            if (jarCount3 >= (intJar.ToArray().Length - 1))
                            {
                                if (conditionFinalCatch == "false")
                                {
                                    if (intJar2.ToArray().Length > 0)
                                    {
                                        if (intJar2.ToArray().Length > 1)
                                        {
                                            numberRandom = random.Next(0, intJar2.ToArray().Length - 1);
                                        }
                                        else
                                        {
                                            numberRandom = 0;
                                        }

                                        SeeIfHave(numberRandom, "have");

                                        numberCount = 1;
                                        Panel panUser = (Panel)(JarOfClickingBox.Controls[handleNameOfPan]);
                                        Panel panAI   = (Panel)(JarOfClickingBox.Controls[handlePan]);
                                        panUser.AccessibleDescription = "DoneSureMove";

                                        foreach (Panel panss in JarOfClickingBox.Controls)
                                        {
                                            if (panss.Name == handlePan)
                                            {
                                                foreach (Label lbss in panss.Controls)
                                                {
                                                    lbss.Text = "O";
                                                }
                                                panss.AccessibleName = "O";
                                            }
                                        }
                                        panAI.AccessibleDescription = "DoneSureMove";

                                        for (int numberCountASs = 0; numberCountASs <= handleScanning.Length - 1; numberCountASs++)
                                        {
                                            if (numberCountASs <= 7)
                                            {
                                                handleXandOS = "O";
                                                int countChecks = 0, numberCountFinals = 0;
                                                int backHandleNum = DoLoopEach(countChecks, numberCountFinals, numberCountASs);
                                                if (backHandleNum == 3)
                                                {
                                                    delay.Start();
                                                }
                                            }

                                            if (numberCountASs + 1 >= handleScanning.Length)
                                            {
                                                handleNameOfPan        = "";
                                                handleXandOS           = "X";
                                                conditionToNumberCount = "";
                                                SureMove.Enabled       = false;
                                                ConditionToNonClick    = true;
                                                numberTime             = 60;
                                                time.Stop();
                                                time.Start();
                                                timer2.Stop();
                                            }
                                        }
                                    }
                                    else
                                    {
                                        int countSeeIf = 0;
                                        foreach (Control Conp in JarOfClickingBox.Controls)
                                        {
                                            if (Conp is Panel)
                                            {
                                                foreach (Control conlb in Conp.Controls)
                                                {
                                                    if (conlb.GetType() == typeof(Label))
                                                    {
                                                        if (conlb.Text != "")
                                                        {
                                                            countSeeIf++;
                                                        }
                                                    }
                                                }
                                            }
                                        }

                                        if (countSeeIf != 9)
                                        {
                                            Panel panUser = (Panel)(JarOfClickingBox.Controls[handleNameOfPan]);
                                            panUser.AccessibleDescription = "DoneSureMove";

                                            foreach (Panel ScanningPan in JarOfClickingBox.Controls)
                                            {
                                                numberConditionScanning++;
                                                if (ScanningPan.AccessibleName == "")
                                                {
                                                    ScanningAddPanel.Add(ScanningPan.Name);
                                                }

                                                if (JarOfClickingBox.Controls.Count == numberConditionScanning)
                                                {
                                                    int randomNumber = random.Next(0, ScanningAddPanel.ToArray().Length - 1);
                                                    foreach (Panel panF in JarOfClickingBox.Controls)
                                                    {
                                                        if (ScanningAddPanel.ToArray()[randomNumber] == panF.Name)
                                                        {
                                                            foreach (Label lbs in panF.Controls)
                                                            {
                                                                lbs.Text = "O";
                                                            }
                                                            panF.AccessibleName        = "O";
                                                            panF.AccessibleDescription = "DoneSureMove";
                                                        }
                                                    }
                                                }
                                            }

                                            handleNameOfPan        = "";
                                            conditionToNumberCount = "";
                                            SureMove.Enabled       = false;
                                            ConditionToNonClick    = true;
                                            numberTime             = 60;
                                            time.Stop();
                                            time.Start();
                                            timer2.Stop();
                                        }
                                        else
                                        {
                                            GameEnded.Visible = true;
                                            WinnerSee.Text    = "Tie";
                                            Player1.Text      = handleUserAndAi[0];
                                            Player2.Text      = handleUserAndAi[1];
                                            Player1S.Text     = handleScore[0].ToString();
                                            Player2S.Text     = handleScore[1].ToString();
                                            numberTime        = 60;
                                            time.Stop();
                                            time.Start();
                                            timer2.Stop();
                                        }
                                    }
                                }
                            }
                        }


                        void SeeIfHave(int jarCount4, string HandleCon)
                        {
                            foreach (Panel pan in JarOfClickingBox.Controls)
                            {
                                if (pan.Name == (HandleCon != "Scanning" ? st[intJar2.ToArray()[jarCount4], 0]: st[jarCount4, 0]))
                                {
                                    foreach (Label lb in pan.Controls)
                                    {
                                        if (lb.Text == "")
                                        {
                                            handlePan = (HandleCon != "Scanning" ? st[intJar2.ToArray()[jarCount4], 0] : st[jarCount4, 0]);
                                        }
                                    }
                                }

                                if (pan.Name == (HandleCon != "Scanning" ? st[intJar2.ToArray()[jarCount4], 1] : st[jarCount4, 1]))
                                {
                                    foreach (Label lb in pan.Controls)
                                    {
                                        if (lb.Text == "")
                                        {
                                            handlePan = (HandleCon != "Scanning" ? st[intJar2.ToArray()[jarCount4], 1] : st[jarCount4, 1]);
                                        }
                                    }
                                }

                                if (pan.Name == (HandleCon != "Scanning" ? st[intJar2.ToArray()[jarCount4], 2] : st[jarCount4, 2]))
                                {
                                    foreach (Label lb in pan.Controls)
                                    {
                                        if (lb.Text == "")
                                        {
                                            handlePan = (HandleCon != "Scanning" ? st[intJar2.ToArray()[jarCount4], 2] : st[jarCount4, 2]);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }