コード例 #1
0
ファイル: DBManagement.cs プロジェクト: IMS94/Tic-Tac-Toe
        /*
         *  Get the top ten in each difficulty.
         */

        public static NamesAndScores getSinglePlayerScores(int difficulty)
        {
            using (SqlConnection con = new SqlConnection(Tik_tak_toe_pro.Properties.Settings.Default.DataConnectionString))
            {
                try
                {
                    using (SqlCommand command =
                               new SqlCommand(String.Format("SELECT TOP 10 * FROM [singleplayer] WHERE score>'0' and difficulty='{0}' ORDER BY [score] DESC", difficulty), con))
                    {
                        SqlDataReader reader;
                        con.Open();
                        reader = command.ExecuteReader();

                        NamesAndScores data = new NamesAndScores();

                        while (reader.Read())
                        {
                            Console.WriteLine(reader.GetName(0) + " " +
                                              reader.GetString(1) + " " + reader.GetInt32(2).ToString() + " " + reader.GetInt32(3));
                            data.names.Add(reader.GetString(1));
                            data.scores.Add(reader.GetInt32(2));
                        }
                        con.Close();
                        return(data);
                    }
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                    return(null);
                }
            }
        }
コード例 #2
0
        public FormLeaderBoard(LeaderBoard leaderBoardE, Setting settingE)
        {
            InitializeComponent();
            leaderBoard        = leaderBoardE;
            setting            = settingE;
            lbname.BackColor   = Color.Black;
            lbscore.BackColor  = Color.Black;
            btadd.BackColor    = Color.Green;
            pbeasy.BackColor   = Color.Orange;
            lblEasy.ForeColor  = Color.Orange;
            pbhard.BackColor   = Color.Transparent;
            pbmedium.BackColor = Color.Transparent;
            lblscore.Text      = this.leaderBoard.getScore(setting.current[1], setting.current[2]).ToString();


            NamesAndScores lists = DBManagement.getSinglePlayerScores(1);

            easyBoardNameRefs = lists.names;
            easyBoardScore    = lists.scores;

            lists = DBManagement.getSinglePlayerScores(2);
            mediumBoardNameRefs = lists.names;
            mediumBoardScore    = lists.scores;

            lists             = DBManagement.getSinglePlayerScores(3);
            hardBoardNameRefs = lists.names;
            hardBoardScore    = lists.scores;

            this.addTolist(easyBoardNameRefs, easyBoardScore);
        }
コード例 #3
0
        private void btadd_Click(object sender, EventArgs e)
        {
            if (tbnewname.Text.Length < 3)
            {
                return;
            }

            //add to database
            DBManagement.addSinglePlayerScores(tbnewname.Text, getScore(setting.current[1], setting.current[2]), setting.difficultyLevel);

            if (setting.difficultyLevel == 1)
            {
                NamesAndScores lists = DBManagement.getSinglePlayerScores(1);
                easyBoardNameRefs = lists.names;
                easyBoardScore    = lists.scores;
            }
            else if (setting.difficultyLevel == 2)
            {
                NamesAndScores lists = DBManagement.getSinglePlayerScores(2);
                mediumBoardNameRefs = lists.names;
                mediumBoardScore    = lists.scores;
            }
            else
            {
                NamesAndScores lists = DBManagement.getSinglePlayerScores(3);
                hardBoardNameRefs = lists.names;
                hardBoardScore    = lists.scores;
            }
            if (pbeasy.BackColor.Equals(Color.Orange))
            {
                pbeasy.BackColor   = Color.Orange;
                pbhard.BackColor   = Color.Transparent;
                pbmedium.BackColor = Color.Transparent;
                this.addTolist(easyBoardNameRefs, easyBoardScore);
            }
            else if (pbhard.BackColor.Equals(Color.Orange))
            {
                pbeasy.BackColor   = Color.Transparent;
                pbhard.BackColor   = Color.Orange;
                pbmedium.BackColor = Color.Transparent;
                this.addTolist(hardBoardNameRefs, hardBoardScore);
            }
            else if (pbmedium.BackColor.Equals(Color.Orange))
            {
                pbeasy.BackColor   = Color.Transparent;
                pbhard.BackColor   = Color.Transparent;
                pbmedium.BackColor = Color.Orange;
                this.addTolist(mediumBoardNameRefs, mediumBoardScore);
            }
            setting.current[0] = 0;
            setting.current[1] = 0;
            setting.current[2] = 0;
            btadd.Enabled      = false;
        }
コード例 #4
0
ファイル: DBManagement.cs プロジェクト: IMS94/Tic-Tac-Toe
        /*
            Get the top ten in each difficulty.
         */
        public static NamesAndScores getSinglePlayerScores(int difficulty)
        {
            using (SqlConnection con = new SqlConnection(Tik_tak_toe_pro.Properties.Settings.Default.DataConnectionString))
            {
                try
                {
                    using (SqlCommand command =
             new SqlCommand(String.Format("SELECT TOP 10 * FROM [singleplayer] WHERE score>'0' and difficulty='{0}' ORDER BY [score] DESC",difficulty), con))
                    {
                        SqlDataReader reader;
                        con.Open();
                        reader = command.ExecuteReader();

                        NamesAndScores data = new NamesAndScores();

                        while (reader.Read())
                        {
                            Console.WriteLine(reader.GetName(0)+" "+
                                reader.GetString(1)+" "+reader.GetInt32(2).ToString()+" "+reader.GetInt32(3));
                            data.names.Add(reader.GetString(1));
                            data.scores.Add(reader.GetInt32(2));
                        }
                        con.Close();
                        return data;
                    }
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                    return null;
                }

            }
        }