コード例 #1
0
ファイル: Menu.cs プロジェクト: Dashboard-X/theme-tune-quiz
        public Menu()
        {
            InitializeComponent();

            mDatabase = new TrackDatabase();
            mDatabase.Open();
        }
コード例 #2
0
        public SetupForm(TrackDatabase db)
        {
            mDatabase = db;

            InitializeComponent();
            PopulateLists();
            SetTotalTracks();
        }
コード例 #3
0
        public EditForm(TrackDatabase db)
        {
            mDatabase = db;

            InitializeComponent();
            InitalizeGrid();
            WindowState = FormWindowState.Maximized;
        }
コード例 #4
0
        public void AddRandomTracks(TrackDatabase database, HashSet<Track> ignoreTracks, string[] genres, int tracks, bool themesonly)
        {
            //Create a random generator
            Random random = new Random();

            //Create list of tracks for selection (ignoring tracks in previous playlists)
            TrackCollection picklist = new TrackCollection();
            foreach (Track track in database.Tracks) {
             	foreach (string s in genres) {
                    //Genre in Round and track not already used
                    if (String.Compare(track.Genre, s, true) == 0 && !ignoreTracks.Contains(track)) {
                        // Check whether only themes to be chosen
                        if (track.IsTheme || !themesonly) {
                            //Add to pick list
                            picklist.Add(track);
                        }
                    }
                }
            }

            // Shuffle the order first
            picklist.Shuffle();

            // Now sort by times played
            picklist.Sort(new Track.TrackTimesPlayedComparer());

            // Pick random tracks
            for (int i = 0; i < tracks; i++) {
                //Check if the list has any tunes
                if (picklist.Count == 0)
                    break;

                //Pick a random track from the selection list
                int ri = random.Next(0, picklist.Count);

                //Save in playlist
                Add(picklist[ri]);

                //Remove track from selection list
                picklist.RemoveAt(ri);
            }
        }
コード例 #5
0
        public FastAnswerForm(TrackDatabase db, string[] genres = null)
        {
            mDatabase = db;

            // Initialise the form
            InitializeComponent();
            pnlQuestions.Visible = true;
            pnlConclusion.Visible = false;

            // Create playlist
            mPlaylist = mDatabase.Tracks.GetFromGenre(genres);
            mPlaylist.Shuffle();

            // Now sort by times played
            mPlaylist.Sort(new Track.TrackTimesPlayedComparer());

            // Start the session
            mSessionTime.Start();
            NextTrack();
        }
コード例 #6
0
        public GenreSelectorDialog(TrackDatabase db)
        {
            mDatabase = db;
            mGenres = mDatabase.GetGenres();
            mSelectedGenres = new string[0];

            mForm = new Form();
            mForm.SuspendLayout();

            mForm.Text = "Genre Selection";
            mForm.MinimizeBox = false;
            mForm.MaximizeBox = false;
            mForm.FormBorderStyle = FormBorderStyle.FixedDialog;
            mForm.StartPosition = FormStartPosition.CenterScreen;
            mForm.Size = new Size(200, 250);

            mGenreCheckList = new CheckedListBox();
            mGenreCheckList.CheckOnClick = true;
            mGenreCheckList.IntegralHeight = false;
            mGenreCheckList.Location = new Point(3, 3);
            mGenreCheckList.Size = new Size(mForm.ClientSize.Width - 6, mForm.ClientSize.Height - 32);
            mGenreCheckList.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom;

            foreach (string genre in mGenres)
                mGenreCheckList.Items.Add(String.Format("{0} ({1})", genre, mDatabase.GetGenreTrackCount(genre)), true);

            mForm.Controls.Add(mGenreCheckList);

            mOKButton = new Button();
            //mOKButton.DialogResult = DialogResult.OK;
            mOKButton.Text = "OK";
            mOKButton.Location = new Point(mForm.ClientSize.Width - 78, mForm.ClientSize.Height - 26);
            mOKButton.Size = new Size(75, 23);
            mOKButton.Anchor = AnchorStyles.Right | AnchorStyles.Bottom;
            mOKButton.Click += new EventHandler(mOKButton_Click);
            mForm.Controls.Add(mOKButton);

            mForm.AcceptButton = mOKButton;

            mForm.ResumeLayout();
        }
コード例 #7
0
ファイル: Quiz.cs プロジェクト: Dashboard-X/theme-tune-quiz
 public Quiz(TrackDatabase db, string path)
 {
     LoadXMLQuiz(db, path);
 }
コード例 #8
0
ファイル: Quiz.cs プロジェクト: Dashboard-X/theme-tune-quiz
        private void LoadXMLQuiz(TrackDatabase db, string path)
        {
            Round r = null;
            bool inQuiz = false;
            bool inRound = false;
            bool inTrack = false;
            int missingtunes = 0;
            string name;
            string playMode;
            string text;

            XmlReader xmlReader;
            xmlReader = XmlReader.Create(path);
            mCreationTime = File.GetCreationTime(path);
            missingtunes = 0;
            while (xmlReader.Read()) {
                switch (xmlReader.NodeType) {
                    case XmlNodeType.Element:
                        switch (xmlReader.Name) {
                            case "Quiz":
                                inQuiz = true;
                                name = xmlReader.GetAttribute("Name");
                                if (name != null)
                                    Name = name;
                                break;
                            case "Round":
                                if (inQuiz) {
                                    inRound = true;
                                    name = xmlReader.GetAttribute("Name");
                                    playMode = xmlReader.GetAttribute("PlayMode");

                                    r = new Round();
                                    if (name != null)
                                        r.Name = name;
                                    if (playMode != null) {
                                        if (IsPositiveInt(playMode))
                                            r.PlayMode = Convert.ToInt32(playMode);
                                    }
                                }
                                break;
                            case "Track":
                                if (inRound) {
                                    inTrack = true;
                                }
                                break;
                        }
                        break;
                    case XmlNodeType.Text:
                        if (inTrack) {
                            text = xmlReader.Value;
                            if (text != null) {
                                // Check whether track is found in the database
                                if (db.Tracks.Contains(text))
                                    r.Tracks.Add(db.GetTune(text));
                                else
                                    missingtunes++;
                            }
                        }
                        break;
                    case XmlNodeType.EndElement:
                        switch (xmlReader.Name) {
                            case "Quiz":
                                inQuiz = false;
                                break;
                            case "Round":
                                if (r != null) {
                                    mRounds.Add(r);
                                    r = null;
                                }
                                inRound = false;
                                break;
                            case "Track":
                                inTrack = false;
                                break;
                        }
                        break;
                }
            }
            if (missingtunes > 0) {
                MessageBox.Show(missingtunes.ToString() + " tunes were not in database and have been removed from the quiz.", "Missing Tunes", MessageBoxButtons.OK);
            }
        }