/// <summary> /// Restart het spel met dezelfde instellingen en namen als het vorig spel /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void ButtonSpeelOpnieuw_Click(object sender, EventArgs e) { this.pictureBoxSpeelOpnieuw.BackgroundImage = (Bitmap)Properties.Resources.ResourceManager.GetObject("SpeelOpnieuwButtonEndgame2D"); await Task.Delay(300); this.pictureBoxSpeelOpnieuw.BackgroundImage = (Bitmap)Properties.Resources.ResourceManager.GetObject("SpeelOpnieuwButtonEndgame"); if (BaseGame.Gamemode == 2 && GameMultiplayerOnline.Reset()) { return; } this.Close(); this.Dispose(); GC.Collect(); BaseGame.Reset(); if (BaseGame.Gamemode == 0) { GameSingleplayer.Start(BaseGame.Height, BaseGame.Width, BaseGame.Naam1); } else if (BaseGame.Gamemode == 1) { GameMultiplayerLocal.Start(BaseGame.Height, BaseGame.Width, BaseGame.Naam1, BaseGame.Naam2); } else if (BaseGame.Gamemode == 2) { GameMultiplayerOnline.Reset2(); } }
/// <summary> /// Deze methode wisslet de speler die ann beurt is wanneer hij word gecalled. /// </summary> public static void VolgendeBeurt() { if (Gamemode == 0) { GameSingleplayer.VolgendeBeurt(); } else if (Gamemode == 1) { GameMultiplayerLocal.VolgendeBeurt(); } else if (Gamemode == 2) { GameMultiplayerOnline.VolgendeBeurt(); } }
/// <summary> /// redirect naar de exit game methode van de betreffende gamemode. /// </summary> public static void Exitgame() { Geluid.GameOver(); if (Gamemode == 0) { GameSingleplayer.Exit(); } else if (Gamemode == 1) { GameMultiplayerLocal.Exit(); } else if (Gamemode == 2) { GameMultiplayerOnline.Exit(); } }
/// <summary> /// redirect naar de end game van de betreffende gamemode en slaat highscores op. /// </summary> public static void Endgame() { Geluid.GameOver(); BaseGame.GameResultatenOpslaan(); if (Gamemode == 0) { GameSingleplayer.End(); } else if (Gamemode == 1) { GameMultiplayerLocal.End(); } else if (Gamemode == 2) { GameMultiplayerOnline.End(); } }
/// <summary> /// leest 1 string uit een .sav file. decrypt deze string en deserialized de string. /// vervolgens start de methode een nieuwe game en initialized hij de varibelen uit de string in de game. /// </summary> public static void Loadgame() { //get bestands path met open file dialog OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "save files (*.sav)|*.sav|All files (*.*)|*.*"; string ofdname = ofd.FileName; if (ofd.ShowDialog() == DialogResult.OK) { Bestandslocatie = Path.GetFullPath(ofd.FileName); } if (Bestandslocatie == null || Bestandslocatie == "") //voorkomt lege bestandslocatie error { return; } try { string Readdata = System.IO.File.ReadAllText(Bestandslocatie); //read Readdata = Utils.Decrypt(Readdata, "ditiseenwachtwoord"); Loaddata = Utils.StringToArray(Readdata) as string[]; //convert naar array } catch { MessageBox.Show("error"); } Geluid.Player.Stop(); Geluid.Player.Dispose(); switch (Convert.ToInt32(Loaddata[0])) { case 0: //singleplayer GameSingleplayer.Start(Convert.ToInt32(Loaddata[4]), Convert.ToInt32(Loaddata[5]), Loaddata[15]); Initiate(); break; case 1: //multiplayer GameMultiplayerLocal.Start(Convert.ToInt32(Loaddata[4]), Convert.ToInt32(Loaddata[5]), Loaddata[15], Loaddata[16]); Initiate(); break; } GC.Collect(); }
/// <summary> /// zet alle ingevoerde data in variabelen. en called de startgame methode van de gekozen gamemode. /// vervolgens word de form geclosed en gedisposed. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void pictureBoxStartmenuStart_Click_1(object sender, EventArgs e) { this.pictureBoxStart.BackgroundImage = (Bitmap)Properties.Resources.ResourceManager.GetObject("StartButtonGroen2D"); await Task.Delay(300); this.pictureBoxStart.BackgroundImage = (Bitmap)Properties.Resources.ResourceManager.GetObject("StartButtonGroen"); Geluid.Player.Stop(); Geluid.Player.Dispose(); GC.Collect(); int h, w; if (comboGametype.Text == "Kies spelmodus") { MessageBox.Show("Voer een spelmodus in", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (comboGametype.Text != "Join Multiplayer") { switch (comboSpelgrootte.Text) { //vooet grote van het speelveld in case "2x2": h = 2; w = 2; break; case "2x3": h = 2; w = 3; break; case "2x4": h = 2; w = 4; break; case "3x4": h = 3; w = 4; break; case "4x4": h = 4; w = 4; break; default: MessageBox.Show("Voer de grootte van het speelveld in", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { h = 0; w = 0; } //voert naam in en called stargame switch (comboGametype.Text) { case "Singleplayer": string naam = textboxNaam1.Text; if (naam == null || naam.Length == 0) { naam = "Speler 1"; } GameSingleplayer.Start(h, w, naam); this.Close(); this.Dispose(); break; case "Local Multiplayer": string naam1 = textboxNaam1.Text; if (naam1 == null || naam1.Length == 0) { naam1 = "Speler 1"; } string naam2 = textboxNaam2.Text; if (naam2 == null || naam2.Length == 0) { naam2 = "Speler 2"; } GameMultiplayerLocal.Start(h, w, naam1, naam2); this.Close(); this.Dispose(); break; case "Host Multiplayer": pictureBoxStart.BackgroundImage = this.pictureBoxStart.BackgroundImage = (Bitmap)Properties.Resources.ResourceManager.GetObject("VerbindenButtonGroen"); pictureBoxStart.Enabled = false; string naams = textboxNaam1.Text; if (naams == null || naams.Length == 0) { naams = "Speler 1"; } int port = (int)textboxPort.Value; mpworker = new BackgroundWorker(); mpworker.DoWork += delegate(object o, DoWorkEventArgs args) { args.Result = ManagerServer.Server(port); }; mpworker.RunWorkerCompleted += delegate(object o, RunWorkerCompletedEventArgs args) { if ((bool)args.Result) { GameMultiplayerOnline.Start(h, w, naams, true); this.Close(); this.Dispose(); } this.pictureBoxStart.BackgroundImage = (Bitmap)Properties.Resources.ResourceManager.GetObject("StartButtonGroen"); }; mpworker.RunWorkerAsync(); //Errorbox wordt weergegeven door Server method break; case "Join Multiplayer": pictureBoxStart.BackgroundImage = this.pictureBoxStart.BackgroundImage = (Bitmap)Properties.Resources.ResourceManager.GetObject("VerbindenButtonGroen"); await Task.Delay(10); string naamt = textboxNaam1.Text; if (naamt == null || naamt.Length == 0) { naamt = "Speler 2"; } string ip = textboxIp.Text; int port2 = (int)textboxPort.Value; if (ManagerClient.Client(ip, port2)) { GameMultiplayerOnline.Start(h, w, naamt, false); this.Close(); this.Dispose(); } this.pictureBoxStart.BackgroundImage = (Bitmap)Properties.Resources.ResourceManager.GetObject("StartButtonGroen"); //Errorbox wordt weergegeven doe Client method break; case "Kies spelmodus": MessageBox.Show("Voer een spelmodus in", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }