コード例 #1
0
        public void Play()
        {
            int            round = 1;
            string         da;
            ConsoleKeyInfo kt;

            Graphic.Frame();
            if (confirmTopic == true)
            {
L:
                mSRound.Play();
                Console.Clear();
                Graphic.Frame();
                Graphic.FramePlay();
                Graphic.WriteAt(topic.ToString(), 24, 6);
                da = crS.GetWord();
                int    trueChar = 0;
                string sochu    = "Gom " + crS.GetLength() + " chu cai.";
                if (round != 3)
                {
                    Graphic.WriteAt("Vong " + round.ToString(), 25, 8);
                }
                else
                {
                    Graphic.WriteAt("Vong dac biet", 25, 8);
                }
                Graphic.WriteAt("Diem vong " + round.ToString() + ": ", 63, 20);
                Graphic.WriteAt(plS.GetSumPoint().ToString(), 74, 17);
                Graphic.WriteAt("O chu Gom " + crS.GetLength() + " Chu Cai " + crS.GetSuggests(), 13, 10);
                for (int t = 0; t < da.Length - 1; t++)
                {
                    Graphic.WriteAt("══╦═", (30 - 2 * da.Length) + 2 + 4 * t, 12);
                    Graphic.WriteAt("║", (30 - 2 * da.Length) + 4 + 4 * t, 13);
                    Graphic.WriteAt("══╩═", (30 - 2 * da.Length) + 2 + 4 * t, 14);
                }
                Graphic.WriteAt("╔═", (30 - 2 * da.Length), 12);
                Graphic.WriteAt("║", (30 - 2 * da.Length), 13);
                Graphic.WriteAt("╚═", (30 - 2 * da.Length), 14);
                Graphic.WriteAt("══╗", (30 + 2 * da.Length) - 2, 12);
                Graphic.WriteAt("║", (30 + 2 * da.Length), 13);
                Graphic.WriteAt("══╝", (30 + 2 * da.Length) - 2, 14);
                int countfalse   = 0;
                int roundreaming = 3;
Q:
                Graphic.WriteAt("=> Nhan ENTER de quay", 15, 23);
                kt = Console.ReadKey();
                for (int cot = 17; cot < 60; cot++)
                {
                    Graphic.WriteAt(" ", cot, 16);
                    Graphic.WriteAt(" ", cot, 17);
                    Graphic.WriteAt(" ", cot, 19);
                    Graphic.WriteAt(" ", cot, 21);
                }
                ChoosePoint();
                if (spS.Getpoint() == 2)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    mSlol1.Play();
                    roundreaming = roundreaming - 1;
                    string ml = "Ha ha! Ban da bi mat 1 luot quay.";
                    Graphic.WriteAt(ml, 17, 16);
                    Console.ForegroundColor = ConsoleColor.Green;
                    goto Q;
                }
                if (spS.Getpoint() == 3)
                {
                    //f.Play();
                    Console.ForegroundColor = ConsoleColor.Red;
                    roundreaming            = roundreaming + 1;
                    string ml = "Chuc mung! Ban da them 1 lan quay.";
                    Graphic.WriteAt(ml, 17, 16);
                    Console.ForegroundColor = ConsoleColor.Green;
                    goto Q;
                }
                if (spS.Getpoint() == 1)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    plS.SetPoint(1);
                    string md = "Chuc mung Ban. Ban da duoc them 6000 diem";
                    Graphic.WriteAt(md, 17, 16);
                    Graphic.WriteAt(plS.Getpoint().ToString() + "     ", 73, 20);
                    Console.ForegroundColor = ConsoleColor.Green;
                    goto Q;
                }
                if (spS.Getpoint() == 0)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    mSlol2.Play();
                    plS.SetPoint(0);
                    string md = "Rat tiec! Ban da khong con diem nao.";
                    Graphic.WriteAt(md, 17, 16);
                    Graphic.WriteAt(plS.Getpoint().ToString() + "     ", 73, 20);
                    Console.ForegroundColor = ConsoleColor.Green;
                    goto Q;
                }
                Graphic.WriteAt("=> Ban chon chu : ", 15, 21);
                char c;
K:
                Console.SetCursorPosition(33, 21);
                try
                {
                    c = char.ToUpper(Convert.ToChar(Console.ReadLine()));
                }
                catch (Exception)
                {
                    Graphic.WriteAt("Hay nhap vao mot ki tu", 17, 16);
                    goto K;
                }
                crS.Choose(c);
                for (int k = 0; k < da.Length; k++)
                {
                    if (c == da[k])
                    {
                        Graphic.WriteAt(c.ToString(), (30 - 2 * da.Length) + 2 + 4 * k, 13);
                    }
                }
                if (crS.Check() > 0)
                {
                    mSchTrue.Play();
                    trueChar = trueChar + Math.Abs(crS.Check());
                    string tb = "Chu " + c + ". Vang thua cac ban ! Co " + Math.Abs(crS.Check()).ToString() + " chu " + c;
                    plS.Score(spS.Getpoint() * Math.Abs(crS.Check()));
                    Graphic.WriteAt(tb, 17, 16);
                    Graphic.WriteAt(plS.Getpoint().ToString(), 73, 20);
                    if (trueChar == crS.GetLength())
                    {
                        Console.Clear();
                        Graphic.Frame();
                        Graphic.WriteAt("Xin chuc mung ban da chien thang vong " + round.ToString() + "!! ", 10, 9);
                        plS.SetPointRound(round - 1, plS.Getpoint());
                        Graphic.WriteAt("Tong diem : " + plS.GetSumPoint().ToString() + "d", 62, 13 + round);
                        plS.SetPoint(0);

                        round++;
                        if (round != 4)
                        {
                            crS.ChangeQuestion();
                        }
                        else
                        {
                            Graphic.WriteAt("Ban hoan thanh xuat sac ca ba vong", 10, 11);
                            Console.ReadKey();
                            return;
                        }
                        Graphic.WriteAt("Moi ban nhan ENTER de choi tiep vong sau ", 10, 11);
                        Console.ReadKey();
                        goto L;
                    }
                    else
                    {
                        goto Q;
                    }
                }
                else if (crS.Check() == 0)
                {
                    mSchFalse.Play();
                    countfalse = countfalse + 1;
                    string tb = "Chu " + c + " .Vang rat tiec ! Khong co chu " + c + " nao !";
                    Graphic.WriteAt(tb, 17, 16);
                    Graphic.WriteAt("Co len nao ban oi", 17, 17);
                    if (countfalse == 3 || roundreaming == 0)
                    {
                        Console.Clear();
                        Graphic.Frame();
                        Graphic.WriteAt("Ban da khong thanh cong o vong " + round.ToString(), 10, 9);
                        plS.SetPointRound(round - 1, plS.Getpoint());
                        plS.SetPoint(0);
                        crS.ChangeQuestion();
                        round = round + 1;
                        Graphic.WriteAt("Moi ban nhan ENTER de choi tiep vong sau ", 10, 11);
                        Console.ReadKey();
                        goto L;
                    }
                }
                else if (crS.Check() == -1)
                {
                    Graphic.WriteAt("Tu da duoc doan vui long doan tu khac", 17, 16);
                    goto K;
                }
                //else goto Q;
            }
            //}
            else
            {
                Graphic.WriteAt("Ban chua chon chu de cua tro choi .", 11, 7);
                Graphic.WriteAt("Xin vui long nhan ENTER de quay lai", 10, 9);
                Graphic.WriteAt("Tiep theo chon 2 de Dang ki chu de choi ! ", 8, 11);
                Graphic.WriteAt("Thank you !", 38, 13);
            }
        }
コード例 #2
0
ファイル: UIComponent.cs プロジェクト: danhtanhd/Console_game
        public void Play()
        {
            int            round = 1;
            string         da;
            ConsoleKeyInfo kt;

            Graphic.Frame();
            if (confirmTopic == true)
            #region Đã chọn chủ đề
            {
L:
                #region Khung ô chữ
                mSRound.Play();
                Console.Clear();
                Graphic.Frame();
                Graphic.FramePlay();
                Graphic.WriteAt(topic.ToString(), 24, 6);
                da = crS.GetWord();
                int    trueChar = 0;
                string sochu    = "Gom " + crS.GetLength() + " chu cai.";
                if (round != 3)
                {
                    Graphic.WriteAt("Vong " + round.ToString(), 25, 8);
                }
                else
                {
                    Graphic.WriteAt("Vong dac biet", 25, 8);
                }
                Graphic.WriteAt("Diem vong" + round.ToString() + ":", 63, 20);
                Graphic.WriteAt(plS.GetSumPoint().ToString(), 74, 17);
                Graphic.WriteAt("O chu Gom " + crS.GetLength() + " Chu Cai " + crS.GetSuggests(), 13, 10);
                for (int t = 0; t < da.Length - 1; t++)
                {
                    Graphic.WriteAt("══╦═", (30 - 2 * da.Length) + 2 + 4 * t, 12);
                    Graphic.WriteAt("║", (30 - 2 * da.Length) + 4 + 4 * t, 13);
                    Graphic.WriteAt("══╩═", (30 - 2 * da.Length) + 2 + 4 * t, 14);
                }
                Graphic.WriteAt("╔═", (30 - 2 * da.Length), 12);
                Graphic.WriteAt("║", (30 - 2 * da.Length), 13);
                Graphic.WriteAt("╚═", (30 - 2 * da.Length), 14);
                Graphic.WriteAt("══╗", (30 + 2 * da.Length) - 2, 12);
                Graphic.WriteAt("║", (30 + 2 * da.Length), 13);
                Graphic.WriteAt("══╝", (30 + 2 * da.Length) - 2, 14);
                int countfalse = 0;
                #endregion

Q:
                Graphic.WriteAt("=> Nhan ENTER de quay", 15, 23);
                kt = Console.ReadKey();
                for (int cot = 17; cot < 60; cot++)
                {
                    Graphic.WriteAt(" ", cot, 16);
                    Graphic.WriteAt(" ", cot, 17);
                    Graphic.WriteAt(" ", cot, 19);
                    Graphic.WriteAt(" ", cot, 21);
                }
                ChoosePoint();// chọn điểm

                #region Các trường hợp điểm đặc biệt

                if (spS.Getpoint() == 2)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    mSlol1.Play();
                    countfalse++;
                    string ml = "Ha ha! Ban da bi mat 1 luot quay.";
                    Graphic.WriteAt(ml, 17, 16);
                    Console.ForegroundColor = ConsoleColor.Green;
                    if (countfalse < 4)
                    {
                        goto Q;
                    }
                    else
                    {
                        if (countfalse == 4 && round < 4)
                        {
                            Console.Clear();
                            Graphic.Frame();
                            Graphic.WriteAt("Ban da khong thanh cong o vong " + round.ToString(), 10, 9);
                            plS.SetPointRound(round - 1, plS.Getpoint());
                            plS.SetPoint(0);
                            crS.ChangeQuestion();
                            round++;
                            countfalse = 0;
                            Graphic.WriteAt("Moi ban nhan ENTER de choi tiep vong sau ", 10, 11);
                            Console.ReadKey();
                            goto L;
                        }

                        else
                        {
                            if (countfalse == 3 && round == 4)
                            {
                                Graphic.WriteAt("Ban hoan thanh xong ca ba vong", 10, 11);
                                Graphic.WriteAt("Tong so diem ban dat duoc la: " + plS.GetSumPoint().ToString(), 10, 13);
                                Graphic.WriteAt("Ban co muon choi lai chu de nay (C/K)", 10, 11);
                                char k = char.ToUpper(Convert.ToChar(Console.ReadLine()));
                                if (k == 'C')
                                {
                                    crS.ChangeQuestion();
                                    round = 0;
                                    plS.NewGame();
                                }
                                else
                                {
                                    return;
                                }
                            }
                        }
                    }
                }
                if (spS.Getpoint() == 3)
                {
                    //f.Play();
                    Console.ForegroundColor = ConsoleColor.Red;
                    countfalse--;
                    string ml = "Chuc mung! Ban da them 1 lan quay.";
                    Graphic.WriteAt(ml, 17, 16);
                    Console.ForegroundColor = ConsoleColor.Green;
                    goto Q;
                }
                if (spS.Getpoint() == 1)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    plS.SetPoint(1);
                    string md = "Chuc mung Ban. Ban da duoc them 1000 diem";
                    Graphic.WriteAt(md, 17, 16);
                    Graphic.WriteAt(plS.Getpoint().ToString(), 74, 20);
                    Console.ForegroundColor = ConsoleColor.Green;
                    goto Q;
                }
                if (spS.Getpoint() == 0)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    mSlol2.Play();
                    plS.SetPoint(0);
                    string md = "Rat tiec! Ban da khong con diem nao.";
                    Graphic.WriteAt(md, 17, 16);
                    Graphic.WriteAt(plS.Getpoint().ToString() + "     ", 73, 20);
                    Console.ForegroundColor = ConsoleColor.Green;
                    goto Q;
                }
                #endregion
                Graphic.WriteAt("=> Ban chon chu : ", 15, 21);
                char c;
K:
                Console.SetCursorPosition(33, 21);
                try
                {
                    c = char.ToUpper(Convert.ToChar(Console.ReadLine()));
                }
                catch (Exception)
                {
                    Graphic.WriteAt("Hay nhap vao mot ki tu", 17, 16);
                    Graphic.WriteAt("                 ", 33, 16);
                    goto K;
                }
                crS.Choose(c);
                crS.Check();// kiểm tra kí tự vừa đoán
                if (crS.GetCheck() > 0)
                #region Đoán đúng
                {
                    for (int k = 0; k < da.Length; k++)
                    {
                        if (c == da[k])
                        {
                            Graphic.WriteAt(c.ToString(), (30 - 2 * da.Length) + 2 + 4 * k, 13);
                        }
                    }
                    mSchTrue.Play();
                    trueChar = trueChar + crS.GetCheck();
                    string tb = "Chu " + c + ". Vang thua cac ban ! Co " + crS.GetCheck().ToString() + " chu " + c;
                    plS.Score(spS.Getpoint() * crS.GetCheck());
                    Graphic.WriteAt(tb, 17, 16);
                    Graphic.WriteAt(plS.Getpoint().ToString(), 74, 20);
                    if (trueChar == crS.GetLength())
                    {
                        Console.Clear();
                        Graphic.Frame();
                        Graphic.WriteAt("Xin chuc mung ban da chien thang vong " + round.ToString() + "!! ", 10, 9);
                        plS.SetPointRound(round - 1, plS.Getpoint());
                        Graphic.WriteAt("Tong diem:" + plS.GetSumPoint().ToString() + "d", 62, 13 + round);
                        plS.SetPoint(0);
                        round++;
                        countfalse = 0;
                        if (round == 4)
                        {
                            Graphic.WriteAt("Ban hoan thanh xuat sac ca ba vong", 10, 11);
                            Graphic.WriteAt("Tong so diem ban dat duoc la: " + plS.GetSumPoint().ToString(), 10, 13);
                            Graphic.WriteAt("Ban có muon choi lai chu de nay (C/K)", 10, 11);
                            char k = char.ToUpper(Convert.ToChar(Console.ReadLine()));
                            if (k == 'C')
                            {
                                try
                                {
                                    crS.ChangeQuestion();
                                }
                                catch (Exception)
                                {
                                    Graphic.WriteAt("Da het cau hoi cua chu de " + crS.GetTopic(), 10, 9);
                                    Graphic.WriteAt("Nhan enter de quay lai lua chon chu de ", 10, 12);
                                    Console.ReadKey();
                                    return;
                                }
                                round = 0;
                                plS.NewGame();
                            }
                            else
                            {
                                return;
                            }
                        }
                        try
                        {
                            crS.ChangeQuestion();
                        }
                        catch (Exception)
                        {
                            Graphic.WriteAt("Da het cau hoi cua chu de " + crS.GetTopic(), 10, 9);
                            Graphic.WriteAt("Nhan enter de quay lai lua chon chu de ", 10, 12);
                            Console.ReadKey();
                            return;
                        }
                        Graphic.WriteAt("Moi ban nhan ENTER de choi tiep vong sau ", 10, 11);
                        Console.ReadKey();
                        goto L;
                    }
                    else
                    {
                        goto Q;
                    }
                }
                #endregion
                else
                if (crS.GetCheck() == -1)
                #region Đoán trùng
                {
                    Graphic.WriteAt("Ban da doan chu nay", 17, 16);
                    countfalse++;
                    // Đoán sai 3 lần nhưng chưa phải vòng đặc biệt
                    if (countfalse == 4 && round < 4)
                    {
                        Console.Clear();
                        Graphic.Frame();
                        Graphic.WriteAt("Ban da khong thanh cong o vong " + round.ToString(), 10, 9);
                        plS.SetPointRound(round - 1, plS.Getpoint());
                        plS.SetPoint(0);
                        try
                        {
                            crS.ChangeQuestion();
                        }
                        catch (Exception)
                        {
                            Graphic.WriteAt("Da het cau hoi cua chu de " + crS.GetTopic(), 10, 9);
                            Graphic.WriteAt("Nhan enter de quay lai lua chon chu de ", 10, 12);
                            Console.ReadKey();
                            return;
                        }
                        round++;
                        countfalse = 0;
                        Graphic.WriteAt("Moi ban nhan ENTER de choi tiep vong sau ", 10, 11);
                        Console.ReadKey();
                        goto L;
                    }
                    // Đoán sai 3 lần và ở vòng đặc biệt
                    else if (countfalse == 3 && round == 4)
                    {
                        Graphic.WriteAt("Ban hoan thanh xong ca ba vong", 10, 11);
                        Graphic.WriteAt("Tong so diem ban dat duoc la: " + plS.GetSumPoint().ToString(), 10, 13);
                        Graphic.WriteAt("Ban co muon choi lai chu de nay (C/K)", 10, 11);
                        char k = char.ToUpper(Convert.ToChar(Console.ReadLine()));
                        if (k == 'C')
                        {
                            try
                            {
                                crS.ChangeQuestion();
                            }
                            catch (Exception)
                            {
                                Graphic.WriteAt("Da het cau hoi cua chu de " + crS.GetTopic(), 10, 9);
                                Graphic.WriteAt("Nhan enter de quay lai lua chon chu de ", 10, 12);
                                Console.ReadKey();
                                return;
                            }
                            round = 0;
                            plS.NewGame();
                        }
                        else
                        {
                            return;
                        }
                    }

                    goto Q;
                }
                #endregion
                else
                if (crS.GetCheck() == 0)
                #region Đoán sai
                {
                    mSchFalse.Play();
                    countfalse = countfalse + 1;
                    string tb = "Chu " + c + " .Vang rat tiec ! Khong co chu " + c + " nao !";
                    Graphic.WriteAt(tb, 17, 16);
                    Graphic.WriteAt("Co len nao ban oi", 17, 17);
                    #region Đoán sai 3 lần nhưng chưa phải vòng đặc biệt
                    if (countfalse == 4 && round < 4)
                    {
                        Console.Clear();
                        Graphic.Frame();
                        Graphic.WriteAt("Ban da khong thanh cong o vong " + round.ToString(), 10, 9);
                        plS.SetPointRound(round - 1, plS.Getpoint());
                        plS.SetPoint(0);
                        try
                        {
                            crS.ChangeQuestion();
                        }
                        catch (Exception)
                        {
                            Graphic.WriteAt("Da het cau hoi cua chu de " + crS.GetTopic(), 10, 9);
                            Graphic.WriteAt("Nhan enter de quay lai lua chon chu de ", 10, 12);
                            Console.ReadKey();
                            return;
                        }
                        round++;
                        countfalse = 0;
                        Graphic.WriteAt("Moi ban nhan ENTER de choi tiep vong sau ", 10, 11);
                        Console.ReadKey();
                        goto L;
                    }
                    #endregion
                    #region Đoán sai 3 lần và ở vòng đặc biệt
                    if (countfalse == 3 && round == 4)
                    {
                        Graphic.WriteAt("Ban hoan thanh xong ca ba vong", 10, 11);
                        Graphic.WriteAt("Tong so diem ban dat duoc la: " + plS.GetSumPoint().ToString(), 10, 13);
                        Graphic.WriteAt("Ban có muon choi lai chu de nay (C/K)", 10, 11);
                        char k = char.ToUpper(Convert.ToChar(Console.ReadLine()));
                        if (k == 'C')
                        {
                            try
                            {
                                crS.ChangeQuestion();
                            }
                            catch (Exception)
                            {
                                Graphic.WriteAt("Da het cau hoi cua chu de " + crS.GetTopic(), 10, 9);
                                Graphic.WriteAt("Nhan enter de quay lai lua chon chu de ", 10, 12);
                                Console.ReadKey();
                                return;
                            }
                            round      = 0;
                            countfalse = 0;
                            plS.NewGame();
                            goto L;
                        }
                        else
                        {
                            return;
                        }
                    }
                    #endregion
                    else
                    {
                        goto Q;
                    }
                }

                #endregion
            }
            #endregion
            else
            {
                Graphic.WriteAt("Ban chua chon chu de cua tro choi .", 11, 7);
                Graphic.WriteAt("Xin vui long nhan ENTER de quay lai", 10, 9);
                Graphic.WriteAt("Tiep theo chon 2 de Dang ki chu de choi ! ", 8, 11);
                Graphic.WriteAt("Thank you !", 38, 13);
            }
        }