/// <summary> /// Finishes an exercice, displaying its score if asked to and reloading. /// </summary> /// <param name="exercice"></param> public void FinishExercice(Exercice exercice, bool displayScore = true) { if (displayScore) { MessageBox.Show(string.Format("L'exercice est fini ! Vous avez obtenu un score de {0} !", exercice.Score), "Exercice terminé !", MessageBoxButtons.OK, MessageBoxIcon.Information); } LoadExercices(); }
/// <summary> /// Loads an exercice by asking its difficulty. /// </summary> /// <param name="exercice">The exercice to load.</param> public void LoadExercice(Exercice exercice) { ExerciceDialogDifficulty dialog = new ExerciceDialogDifficulty(); if (dialog.ShowDialog() == DialogResult.OK) { menuItemHome.Enabled = true; string instructions; if ((instructions = exercice.GetInstructions()) != "") { MessageBox.Show(instructions, "Consigne de l'exercice", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1); } panelExercice.Controls.Clear(); panelExercice.Controls.Add(exercice); exercice.Difficulty = dialog.SelectedDifficulty; exercice.Initialize(); exercice.Run(); } }
/// <summary> /// Loads all exercices located in the Plugins folder. /// </summary> public void LoadExercices() { menuItemNew.DropDownItems.Clear(); menuItemHome.Enabled = false; panelExercice.Controls.Clear(); try { DisplayBackground(); TableLayoutPanel tableLayoutPanelMenu = new TableLayoutPanel(); tableLayoutPanelMenu.Dock = DockStyle.Left; tableLayoutPanelMenu.AutoSize = true; tableLayoutPanelMenu.Padding = new Padding(20, 0, 0, 0); tableLayoutPanelMenu.BackColor = Color.Transparent; tableLayoutPanelMenu.ColumnCount = 1; tableLayoutPanelMenu.RowStyles.Add(new RowStyle(SizeType.AutoSize)); panelExercice.Controls.Add(tableLayoutPanelMenu); Panel pictureBoxTitle = new Panel(); pictureBoxTitle.Dock = DockStyle.Top; pictureBoxTitle.Width = 300; pictureBoxTitle.Padding = new Padding(0, 20, 0, 20); pictureBoxTitle.BackgroundImage = Resources.logo_title; pictureBoxTitle.BackgroundImageLayout = ImageLayout.Zoom; tableLayoutPanelMenu.Controls.Add(pictureBoxTitle, 0, 0); int indexLoading = 0; foreach (string pathPlugin in Directory.GetFiles(Directory.GetCurrentDirectory() + DirectoryPlugins, "*.dll", SearchOption.AllDirectories)) { foreach (Type type in Assembly.LoadFile(pathPlugin).GetTypes()) { if (type.IsClass && !type.IsAbstract && type.IsSubclassOf(typeof(Exercice))) { Exercice exercice = (Exercice)Activator.CreateInstance(type); exercice.Form = this; Exercices.Add(exercice); Action <object, EventArgs> onClick = new Action <object, EventArgs>((sender, e) => { LoadExercice(exercice); }); ToolStripMenuItem menuItem = new ToolStripMenuItem(); menuItem.Name = "menuItemNew" + type.Name; menuItem.Text = exercice.Title; menuItem.Click += onClick.Invoke; menuItemNew.DropDownItems.Add(menuItem); Button menuButton = new Button(); menuButton.Name = "menuButton" + type.Name; menuButton.Text = exercice.Title; menuButton.Height = 60; menuButton.Dock = DockStyle.Top; menuButton.Click += onClick.Invoke; tableLayoutPanelMenu.Controls.Add(menuButton); tableLayoutPanelMenu.RowCount++; tableLayoutPanelMenu.RowStyles.Add(new RowStyle(SizeType.Percent, 100)); tableLayoutPanelMenu.Controls.Add(menuButton, 0, indexLoading + 1); indexLoading++; } } } } catch (Exception exception) { DisplayError(exception.Message); } }