protected override void Initialize(System.Web.Routing.RequestContext requestContext) { base.Initialize(requestContext); spiel=(Spiel)Session["Spiel"]; if (spiel == null) { spiel = new Spiel(Server.MapPath("~/app_data/wwm.csv")); Session["Spiel"] = spiel; } }
private void DplSpielfeld_Loaded(object sender, RoutedEventArgs e) { Spiel.InitSpieler(100, this); Karte.InitKarten(); Uri cardback = new Uri("../../Memes/cardback.png", UriKind.Relative); // Eine zufällige Karte als Startkarte nehmen int index = new Random().Next(Karte.möglicheKarten.Count); imgDeckZiehen.Tag = Karte.möglicheKarten[index]; }
private void DatenFüllen() { spiel = API.GetGameById(MainWindow.AktuelleId); container.DataContext = spiel; //lblName.Content = spiel.Name; //lblPublisher.Content = spiel.Publisher; //lblErscheinung.Content = DatumGenerieren(spiel.Erscheinungsdatum); //lblMindestalter.Content = spiel.Mindestalter.ToString(); //lblPreis.Content = spiel.Preis.ToString(); //lblBewertung.Content = spiel.Bewertung.ToString(); //lblSteam.Content = CheckBoxConverter(spiel.IstSteam); }
private void ListGames_SelectionChanged(object sender, SelectionChangedEventArgs e) { ListBox list = sender as ListBox; if (list.SelectedItem != null) { Spiel spiel = (Spiel)list.SelectedItem; MainWindow.AktuelleId = spiel.Id; MainWindow.UCContainer.Children.Remove(this); MainWindow.UCContainer.Children.Add(new Einzelansicht()); } }
public ActionResult Create([Bind(Include = "SpielKeyGUID,EANNummer,Name,FK_Tarifkategorie,Spielkategorie,FK_Filiale")] Spiel game) { if (ModelState.IsValid) { game.SpielKeyGUID = Guid.NewGuid(); m_gameRepository.Create(game); return(RedirectToAction("Index")); } ViewBag.FK_Filiale = new SelectList(m_branches, "FilialKeyGUID", "Vereinsname", game.FK_Filiale); ViewBag.FK_Tarifkategorie = new SelectList(m_priceCategories, "TarifkategorieKeyGUID", "Bezeichnung", game.FK_Tarifkategorie); return(View("Create", game)); }
public async Task <StatusCodeResult> Post([FromBody] Spiel value) { var success = await _store.SaveAsync(value); if (!success) { return(BadRequest()); } else { return(Ok()); } }
private async void SpielSelected(object sender, ItemClickEventArgs e) { if (!ServiceBase.IsOnline()) { Windows.UI.Popups.MessageDialog dialog = new Windows.UI.Popups.MessageDialog("Du bist gerade leider nicht online. Bitte prüfe deine Verbindung."); await dialog.ShowAsync(); return; } Spiel spiel = e.ClickedItem as Spiel; this.Frame.Navigate(typeof(SpielEditPage), spiel); }
// GET: Game/Delete/5 public ActionResult Delete(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Spiel spiel = m_gameRepository.GetGame(id.Value); if (spiel == null) { return(HttpNotFound()); } return(View(spiel)); }
public void ACBilderLadenFunc(object parameter) { View.Dialoge.dlgBilder dlgPicSelector = new View.Dialoge.dlgBilder(System.IO.Path.Combine(Environment.CurrentDirectory, "Bilder")); if ((bool)dlgPicSelector.ShowDialog() == true) { BilderOrdner = dlgPicSelector.FolderPath; if (Spiel.LoadPictures(BilderOrdner)) { GameBoardClear(); SpielStarten(); } } }
public void Spielende_mit_Gewinn_in_Diagonale() { var sut = new Schiedsrichter(); var spiel = new Spiel(); var result = Spielfortschritt.Läuft; spiel.Spielbrett[0, 0] = Spiel.Spielfeldzustände.O; spiel.Spielbrett[1, 1] = Spiel.Spielfeldzustände.O; spiel.Spielbrett[2, 2] = Spiel.Spielfeldzustände.O; sut.SpielstandBestimmen(spiel, fortschritt => result = fortschritt, _ => Assert.Fail()); Assert.AreEqual(result, Spielfortschritt.OGewinnt); }
public MainWindow() { BitmapImage appIcon = new BitmapImage(); appIcon.BeginInit(); appIcon.UriSource = new Uri("pack://application:,,,/Content/graphics/spielfeld3232.png"); appIcon.EndInit(); Icon = appIcon; InitializeComponent(); spiel = new Spiel(this.grid); spiel.Status += AktualisiereStatus; spiel.Verloren += Spiel_Verloren; SetImageControls(); }
// GET: Game/Edit/5 public ActionResult Edit(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Spiel game = m_gameRepository.GetGame(id.Value); if (game == null) { return(HttpNotFound()); } ViewBag.FK_Filiale = new SelectList(m_branches, "FilialKeyGUID", "Vereinsname", game.FK_Filiale); ViewBag.FK_Tarifkategorie = new SelectList(m_priceCategories, "TarifkategorieKeyGUID", "Bezeichnung", game.FK_Tarifkategorie); return(View("Edit", game)); }
public static async Task AktualisiereHighscoresAsync(Spiel spiel) { if (App.OFFLINE_MODE) { return; } Request <Spiel> request = new Request <Spiel>(); request.obj = spiel; await request.HttpRequestAsync(App.FUNCTION_UPDATE_HIGHSCORE); spiel.rekordhalter = request.obj.rekordhalter; spiel.globaleBestzeit = request.obj.globaleBestzeit; spiel.globalerDurschnitt = request.obj.globalerDurschnitt; }
public MainViewModel() { spiel = new Spiel(); spiel.LoadSpieler(); spiel.BesterSpieler(); BtdReg = new UserCommands(Registrieren); BtdStart = new UserCommands(starten); BtdSave = new UserCommands(speichern); Btd1 = new UserCommands(setzeStein); Btd2 = new UserCommands(setzeStein); Btd3 = new UserCommands(setzeStein); Btd4 = new UserCommands(setzeStein); Btd5 = new UserCommands(setzeStein); Btd6 = new UserCommands(setzeStein); Btd7 = new UserCommands(setzeStein); }
private void btnSpeichern_Click(object sender, EventArgs e) { double wert; if (txtBezeichnung.Text.Equals("") || txtGewinn.Text.Equals("")) { MessageBox.Show("Bitte füllen Sie sowohl Bezeichnung als auch Gewinn aus!"); return; } try { wert = Double.Parse(txtWert.Text, System.Globalization.NumberStyles.Currency); } catch { MessageBox.Show("Bitte geben Sie eine gültige Zahl ein!"); return; } if (this.Text.Equals("Gewinnspiel hinzufügen")) { Spiel s = new Spiel(); s.SpielID = Convert.ToInt32(txtGewinnspielID.Text); s.Bezeichnung = txtBezeichnung.Text; s.Gewinn = txtGewinn.Text; s.Wert = wert; s.Ausgelost = cbAusgelost.Checked; s.Bildpfad = txtBildpfad.Text; frmLogin.frmLog.gewinnspielListe.Add(s); } else //Gewinnspiel bearbeiten { foreach (Spiel s in frmLogin.frmLog.gewinnspielListe) { if (s.SpielID == Convert.ToInt32(txtGewinnspielID.Text)) { s.Bezeichnung = txtBezeichnung.Text; s.Gewinn = txtGewinn.Text; s.Wert = wert; s.Ausgelost = cbAusgelost.Checked; s.Bildpfad = bildpfad; break; } } } frmLogin.frmLog.serialisierenSpiel(); this.Close(); }
public void Spiel_läuft_weiter_mit_Spielerwechsel() { var sut = new Schiedsrichter(); var spiel = new Spiel(); var result = new Spiel(); spiel.Spielbrett[0, 1] = Spiel.Spielfeldzustände.X; Assert.AreEqual(Spiel.Spieler.X, spiel.AktuellerSpieler); sut.SpielstandBestimmen(spiel, _ => Assert.Fail(), aktualisiertesSpiel => result = aktualisiertesSpiel); Assert.AreEqual(Spiel.Spieler.O, result.AktuellerSpieler); sut.SpielstandBestimmen(result, _ => Assert.Fail(), aktualisiertesSpiel => result = aktualisiertesSpiel); Assert.AreEqual(Spiel.Spieler.X, result.AktuellerSpieler); }
// GET: Rental/New?gameId=.. public ActionResult New(Guid?gameId) { if (!gameId.HasValue) { return(new HttpStatusCodeResult(400)); } Spiel game = m_gameRepository.GetGame(gameId.Value); if (game != null) { m_rentalRepository.AddRental(GetCurrentUserId(), game.SpielKeyGUID); return(RedirectToAction("Index", "Rental")); } return(new HttpStatusCodeResult(400)); }
public void StartetDasSpiel() { Spiel s = new Spiel("Firefox", DateTime.Now, "C:/Program Files (x86)/Mozilla Firefox/firefox.exe", "mail", "mozila", 0); string[] pfadTeile = s.GetInstalationspfad.Split('/'); string processname = pfadTeile.Last().Split('.').First(); Process[] proA = Process.GetProcessesByName(processname); foreach (Process pro in proA) { pro.Kill(); System.Threading.Thread.Sleep(1000); } Controller.StartGame(s); Assert.AreEqual(1, Process.GetProcessesByName("firefox").Length); }
public Spiel GetCopy() { Spiel original = this; return(new Spiel { id_spiel = original.id_spiel, spiel = original.spiel, globaleBestzeit = original.globaleBestzeit, globalerDurschnitt = original.globalerDurschnitt, rekordhalter = original.rekordhalter, schlechtesteZeit = original.schlechtesteZeit, bestzeit = original.bestzeit, durchschnitt = original.durchschnitt, anzahl_gespielt = original.anzahl_gespielt, akummulierteSpielzeit = original.akummulierteSpielzeit }); }
public void Punkte(Spiel spiel, int ausgang) //ausgang = 0 -> Gast, ausgang = 1 -> Heim, ausgang = 3 -> Unentschieden { switch (ausgang) { case 0: foreach (var mannschaft in mannschaften) { if (mannschaft.Name == spiel.Gast) { mannschaft.Punkte += 3; break; } } break; case 1: foreach (var mannschaft in mannschaften) { if (mannschaft.Name == spiel.Heim) { mannschaft.Punkte += 3; break; } } break; case 2: foreach (var mannschaft in mannschaften) { if (mannschaft.Name == spiel.Heim) { mannschaft.Punkte += 1; } if (mannschaft.Name == spiel.Gast) { mannschaft.Punkte += 1; } } break; default: break; } }
/* Spiel starten */ private void StarteSpiel() { if (Liste.SelectedIndex == -1) { return; } int tilesize = 2; if (tb1.IsChecked.Value) { tilesize = 3; } else if (tb2.IsChecked.Value) { tilesize = 4; } else if (tb3.IsChecked.Value) { tilesize = 5; } Spiel spiel = null; if (tb1.IsChecked.Value) { spiel = SpielHighscores.GetInstance().spiele[SpielHighscores.SCHIEBEPUZZLE_LEICHT]; } else if (tb2.IsChecked.Value) { spiel = SpielHighscores.GetInstance().spiele[SpielHighscores.SCHIEBEPUZZLE_NORMAL]; } else if (tb3.IsChecked.Value) { spiel = SpielHighscores.GetInstance().spiele[SpielHighscores.SCHIEBEPUZZLE_SCHWER]; } StarteSpielBtn.IsEnabled = false; WaitRing.IsActive = true; progress.Visibility = Visibility.Visible; puzzle = new SchiebepuzzleController(spiel, tilesize, dateien[(Border)Liste.SelectedItem], tbQuadratisch.IsChecked.Value, ActionStarteSpiel); }
// GET: Rental/New?gameId=.. public ActionResult New(Guid?gameId) { if (System.Web.HttpContext.Current.User != null && System.Web.HttpContext.Current.User.Identity.IsAuthenticated) { if (!gameId.HasValue) { return(new HttpStatusCodeResult(400)); } Spiel game = m_gameRepository.GetGame(gameId.Value); if (game != null) { m_rentalRepository.AddRental(GetCurrentUserId(), game.SpielKeyGUID); return(RedirectToAction("Index", "Rental")); } } return(View("ErrorLogin")); }
/// <summary> /// creates a new rental obect /// </summary> /// <param name="customerId">id of customer who rents</param> /// <param name="gameId">id of the game to rent</param> /// <returns>true if successful, otherwise false</returns> public bool AddRental(Guid customerId, Guid gameId) { using (DbContext = new LudothekEntities()) { using (var transaction = DbContext.Database.BeginTransaction()) { try { Spiel game = DbContext.Spiel.FirstOrDefault(g => g.SpielKeyGUID == gameId); Kunde customer = DbContext.Kunde.FirstOrDefault(c => c.KundenKeyGUID == customerId); if (game == null || !game.IsAvailable) { transaction.Dispose(); return(false); } Ausleihe rental = new Ausleihe { AusleiheKeyGUID = Guid.NewGuid(), Startdatum = DateTime.Now, Enddatum = DateTime.Now.AddDays(7), Kunde = customer, Spiel = game }; game.IsAvailable = false; DbContext.Entry(game).State = EntityState.Modified; DbContext.Ausleihe.Add(rental); DbContext.SaveChanges(); transaction.Commit(); return(true); } catch (Exception e) { transaction.Rollback(); return(false); } } } }
public void Spielende_durch_Unentschieden() { var sut = new Schiedsrichter(); var spiel = new Spiel(); var result = Spielfortschritt.Läuft; spiel.Spielbrett[0, 0] = Spiel.Spielfeldzustände.O; spiel.Spielbrett[0, 1] = Spiel.Spielfeldzustände.X; spiel.Spielbrett[0, 2] = Spiel.Spielfeldzustände.O; spiel.Spielbrett[1, 0] = Spiel.Spielfeldzustände.X; spiel.Spielbrett[1, 1] = Spiel.Spielfeldzustände.O; spiel.Spielbrett[1, 2] = Spiel.Spielfeldzustände.X; spiel.Spielbrett[2, 0] = Spiel.Spielfeldzustände.O; spiel.Spielbrett[2, 1] = Spiel.Spielfeldzustände.O; spiel.Spielbrett[2, 2] = Spiel.Spielfeldzustände.X; sut.SpielstandBestimmen(spiel, fortschritt => result = fortschritt, _ => Assert.Fail()); Assert.AreEqual(result, Spielfortschritt.Unentschieden); }
public static void AddStats(StackPanel left, StackPanel right, Spiel spiel) { left.Children.Add(NewTBlock("Name: ")); left.Children.Add(NewTBlock("Spiele: ")); left.Children.Add(NewTBlock("Bestzeit: ")); left.Children.Add(NewTBlock("Schlechteste Zeit: ")); left.Children.Add(NewTBlock("Durchschnitt: ")); left.Children.Add(NewTBlock("")); left.Children.Add(NewTBlock("Rekordhalter")); left.Children.Add(NewTBlock("Globale Bestzeit")); left.Children.Add(NewTBlock("Globaler Durchschnitt")); right.Children.Add(NewTBlock(spiel.spiel)); right.Children.Add(NewTBlock(spiel.anzahl_gespielt)); right.Children.Add(NewTBlock(spiel.bestzeit)); right.Children.Add(NewTBlock(spiel.schlechtesteZeit)); right.Children.Add(NewTBlock(spiel.durchschnitt)); right.Children.Add(NewTBlock("")); right.Children.Add(NewTBlock(spiel.rekordhalter)); right.Children.Add(NewTBlock(spiel.globaleBestzeit)); right.Children.Add(NewTBlock(spiel.globalerDurschnitt)); }
// Counter Erhöht public void Timer(TextBlock count, TextBlock best, TextBlock globalBest, Spiel spiel) { count.Text = "Zeit: " + spiellogik.counter.GetFormatedCount() + (spiellogik.TimePenaltiesTotal == 0 ? "" : " + " + Counter.GetFormatedCount(spiellogik.TimePenaltiesTotal)); int time = (int)spiellogik.counter.GetTimeSpan().TotalMilliseconds; if (time > spiel.globaleBestzeit || spiel.globaleBestzeit == 0) { globalBest.Visibility = Visibility.Collapsed; } else { globalBest.Opacity = 1 - time / (double)spiel.globaleBestzeit; } if (time > spiel.bestzeit || spiel.bestzeit == 0) { best.Visibility = Visibility.Collapsed; } else { best.Opacity = 1 - time / (double)spiel.bestzeit; } }
private void lvGewinnspiele_Click(object sender, EventArgs e) { lvTeilnehmer.Items.Clear(); if (lvGewinnspiele.SelectedItems.Count == 0) { MessageBox.Show("Bitte wählen Sie ein Gewinnspiel aus!"); return; } lvItem = lvGewinnspiele.SelectedItems[0]; foreach (Spiel s in frmLogin.frmLog.gewinnspielListe) { if (s.SpielID == Convert.ToInt32(lvItem.SubItems[1].Text)) { spielAktuell = s; if (s.ListeTeilnehmer != null) { foreach (Teilnehmer t in s.ListeTeilnehmer) { lvItemT = new ListViewItem(t.TeilnehmerID.ToString()); lvItemT.SubItems.Add(t.Vorname); lvItemT.SubItems.Add(t.Nachname); lvItemT.SubItems.Add(t.GebDatum.ToShortDateString()); lvItemT.SubItems.Add(t.Geschlecht.ToString()); lvItemT.SubItems.Add(t.Email); lvItemT.SubItems.Add(t.Deaktiviert.ToString()); lvItemT.SubItems.Add(t.Admin.ToString()); lvItemT.SubItems.Add(t.AnzahlSpiele.ToString()); lvTeilnehmer.Items.Add(lvItemT); } lvTeilnehmer.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); lvTeilnehmer.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); } break; } } }
protected void Ausleihen_Click(object sender, EventArgs e) { var aktiveAusleihen = _context.Ausleihe.Where(x => !x.Zurueckgegeben).ToList(); if (aktiveAusleihen.Count != 3) { DateTime now = DateTime.Now; Spiel spiel = _context.Spiel.Where(x => x.ID == new Guid(lstVerfuegbareSpiele.SelectedValue)).FirstOrDefault(); Ausleihe letzteAusleihe = _context.Ausleihe.OrderByDescending(x => x.Nummer).FirstOrDefault(); int nummer = 1; if (letzteAusleihe != null) { nummer = letzteAusleihe.Nummer + 1; } Ausleihe ausleihe = new Ausleihe() { ID = Guid.NewGuid(), Nummer = nummer, SpielNummer = spiel.Spielnummer, SpielBezeichnung = spiel.Name, Verlag = spiel.Verlag.Name, FK_Kunde_ID = _benutzerID, Ausleihdatum = now, AnzVerlängerungen = 0, Rueckgabedatum = DateTime.Now.AddDays(7), Zurueckgegeben = false }; _context.Ausleihe.Add(ausleihe); _context.SaveChanges(); lstVerfuegbareSpiele.DataSource = Spiele; lstVerfuegbareSpiele.DataBind(); lstAusleihe.DataSource = Ausleihen; lstAusleihe.DataBind(); } }
private void SpielendePrüfen(Spiel spiel, Action <Spielfortschritt> onSpielende, Action onSpielLäuftWeiter) { //TODO: richtige gewinnermittlung implementieren if (spiel.Spielbrett[1, 1] == Spiel.Spielfeldzustände.X) { onSpielende(Spielfortschritt.XGewinnt); } else if (spiel.Spielbrett[2, 2] == Spiel.Spielfeldzustände.O) { onSpielende(Spielfortschritt.OGewinnt); } else { foreach (var r in spiel.Reihen) { if (r.Any(f => f == Spiel.Spielfeldzustände.Frei)) { onSpielLäuftWeiter(); return; } } onSpielende(Spielfortschritt.Unentschieden); } }
public static Spiel CreateSpiel(int id) { Spiel spiel = new Spiel(); spiel.Id = id; return spiel; }
public SchiebepuzzleController(Spiel spiel, int tiles, StorageFile file, bool schneideQuadratisch, Action onFinished) { this.InitializeComponent(); spiellogik = new SpielLogik(spiel, this, () => new Schiebepuzzle(tiles, file, schneideQuadratisch, onFinished)); }
public static async System.Threading.Tasks.Task <HttpResponseMessage> runAsync([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log) { string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); Request <SpielHighscores> request = JsonConvert.DeserializeObject <Request <SpielHighscores> >(requestBody); try { using (SqlConnection con = new SqlConnection(Environment.GetEnvironmentVariable("DB_CONNECTION_STRING"))) { con.Open(); // TOKEN überprüfen HttpResponseMessage message = FUNCTIONS <SpielHighscores> .checkToken(request, con); if (message != null) { return(message); } // Anfrage bearbeiten request.obj = new SpielHighscores(); string sql = "Select * from Spiel"; using (SqlCommand com1 = new SqlCommand(sql, con)) { using (SqlDataReader reader = com1.ExecuteReader()) { while (reader.Read()) { Spiel spiel = new Spiel(); request.obj.spiele.Add(reader.GetInt32(0), spiel); spiel.id_spiel = reader.GetInt32(0); spiel.spiel = reader.GetString(1); spiel.globaleBestzeit = reader.GetInt32(2); spiel.globalerDurschnitt = reader.GetInt32(3); spiel.rekordhalter = reader.GetString(5); if (spiel.globaleBestzeit == Int32.MaxValue) { spiel.rekordhalter = "Niemand"; spiel.globaleBestzeit = 0; } } } foreach (int key in request.obj.spiele.Keys) { sql = "Select * from Highscore where id_spiel=" + key + " and id_nutzer=" + request.Id; using (SqlCommand com2 = new SqlCommand(sql, con)) { using (SqlDataReader reader2 = com2.ExecuteReader()) { reader2.Read(); Spiel spiel = request.obj.spiele[reader2.GetInt32(1)]; spiel.bestzeit = reader2.GetInt32(2); spiel.schlechtesteZeit = reader2.GetInt32(3); spiel.durchschnitt = reader2.GetInt32(4); spiel.anzahl_gespielt = reader2.GetInt32(5); spiel.akummulierteSpielzeit = reader2.GetInt64(6); if (spiel.bestzeit == Int32.MaxValue) { spiel.bestzeit = 0; } } } } } } request.Success = true; } catch (SqlException e) { request.Success = false; request.Error = e.Message; request.Errorcode = e.ErrorCode; } return(new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(request)) }); }
public void AddToSpiel(Spiel spiel) { base.AddObject("Spiel", spiel); }
private void Startbutton_Click(object sender, EventArgs e) { Spiel sp = new Spiel(_leiterschlangen.ToList()); var statistik = sp.Spielen((int)anzSimulationennumericUpDown.Value); label4.Text = statistik.DurchschnittWürfe.ToString(); label5.Text = statistik.MinWürfe.ToString(); label6.Text = statistik.MaxWürfe.ToString(); chart1.Annotations.Clear(); //Durschschnitt try { VerticalLineAnnotation va = new VerticalLineAnnotation(); ChartArea ca = chartSimulation.ChartAreas[0]; Series s1 = chartSimulation.Series[0]; va.AxisX = ca.AxisX; //va.AllowMoving = true; va.IsInfinitive = true; va.ClipToChartArea = ca.Name; va.Name = "Sim Durchschnitt"; va.LineColor = Color.Red; va.LineWidth = 2; va.X = (int)statistik.DurchschnittWürfe; chartSimulation.Annotations.Add(va); ErgebnisMatrixdgv.Rows[(int)statistik.DurchschnittWürfe - 1].DefaultCellStyle.BackColor = Color.Red; } catch (Exception ex) { } //Minimum try { VerticalLineAnnotation va = new VerticalLineAnnotation(); ChartArea ca = chartSimulation.ChartAreas[0]; Series s1 = chartSimulation.Series[0]; va.AxisX = ca.AxisX; //va.AllowMoving = true; va.IsInfinitive = true; va.ClipToChartArea = ca.Name; va.Name = "Sim Minimum"; va.LineColor = Color.Blue; va.LineWidth = 2; va.X = (int)statistik.MinWürfe; chartSimulation.Annotations.Add(va); ErgebnisMatrixdgv.Rows[(int)statistik.MinWürfe - 1].DefaultCellStyle.BackColor = Color.DeepSkyBlue; } catch (Exception) { } //Maximum try { VerticalLineAnnotation va = new VerticalLineAnnotation(); ChartArea ca = chartSimulation.ChartAreas[0]; Series s1 = chartSimulation.Series[0]; va.AxisX = ca.AxisX; //va.AllowMoving = true; va.IsInfinitive = true; va.ClipToChartArea = ca.Name; va.Name = "Sim Maximum"; va.LineColor = Color.Green; va.LineWidth = 2; va.X = (int)statistik.MaxWürfe; chartSimulation.Annotations.Add(va); ErgebnisMatrixdgv.Rows[(int)statistik.MaxWürfe - 1].DefaultCellStyle.BackColor = Color.LawnGreen; } catch (Exception) { } //ChartSimulation chartSimulation.Series[0].Points.Clear(); for (int i = 0; i < statistik.Würfe.Length; i++) { chartSimulation.Series[0].Points.AddY(statistik.Würfe[i] / (decimal)statistik.GesammtSpiele); } chartSimulation.Series[1].Points.Clear(); int[] value = new int[statistik.Würfe.Length]; decimal gesammt = 0; for (int i = 0; i < statistik.Würfe.Length; i++) { gesammt += statistik.Würfe[i] * i; value[i] = (int)gesammt; } for (int i = 0; i < statistik.Würfe.Length; i++) { chartSimulation.Series[1].Points.AddY(value[i] / gesammt); } Berechnungen(statistik.MaxWürfe); }
private void Berechnungen(double simulationmax) { //Matrix DataGridview Matrixdgv.Rows.Clear(); Matrixdgv.Columns.Clear(); Matrixdgv.Columns.Add(new DataGridViewTextBoxColumn { AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells, HeaderText = "nach\r\nvon" }); for (int i = 1; i <= Program.Spielfelder; i++) { Matrixdgv.Columns.Add(new DataGridViewTextBoxColumn { AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells, HeaderText = i.ToString() }); } //[von,nach] decimal[,] matrix = new decimal[Program.Spielfelder, Program.Spielfelder]; var spiel = new Spiel(_leiterschlangen.ToList()); for (int x = 0; x < matrix.GetLength(0); x++) { foreach (var ziel in spiel.Felder[x].Ziele) { matrix[x, ziel.FeldNummer - 1] += 1.0m / ((decimal)Program.WürfelSeiten); } } for (int i = 0; i < Program.Spielfelder; i++) { object[] data = new object[Program.Spielfelder + 1]; data[0] = i + 1; for (int j = 0; j < Program.Spielfelder; j++) { data[j + 1] = matrix[j, i]; } Matrixdgv.Rows.Add(data); } Application.DoEvents(); //MatrixBerechnungdgv ErgebnisMatrixdgv.Rows.Clear(); ErgebnisMatrixdgv.Columns.Clear(); ErgebnisMatrixdgv.Columns.Add(new DataGridViewTextBoxColumn { AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells, HeaderText = "Wdh Nummer" }); for (int i = 0; i < Program.Spielfelder; i++) { ErgebnisMatrixdgv.Columns.Add(new DataGridViewTextBoxColumn { AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells, HeaderText = (i + 1).ToString() }); } //int anz1 = (int)simulationmax; int anz1 = 400; decimal[][] vectorsave = new decimal[anz1 + 1][]; decimal[] vector = new decimal[Program.Spielfelder]; vector[0] = 1.0m; vectorsave[0] = vector; for (int i = 0; i < anz1; i++) { decimal[] erg = new decimal[Program.Spielfelder]; for (int x = 0; x < matrix.GetLength(0); x++) { for (int y = 0; y < matrix.GetLength(1); y++) { decimal vectorfaktor = vector[y]; decimal matrixfaktor = matrix[y, x]; erg[x] += matrixfaktor * vectorfaktor; } } vectorsave[i + 1] = erg; vector = erg; object[] obj = new object[erg.Length + 1]; obj[0] = i + 1; for (int j = 0; j < erg.Length; j++) { obj[j + 1] = erg[j]; } ErgebnisMatrixdgv.Rows.Add(obj); } //Chart1 chart1.Series[0].Points.Clear(); //foreach (var vectors in vectorsave) //{ // chart1.Series[0].Points.AddY(vectors.Last()); //} for (int i = 0; i < vectorsave.Length; i++) { chart1.Series[0].Points.AddY(vectorsave[i].Last()*100.0m); } decimal[] values = new decimal[vectorsave.Length]; values[0] = 0; chart1.Series[1].Points.AddY(0); for (int i = 1; i < vectorsave.Length; i++) { decimal value = vectorsave[i].Last() - vectorsave[i - 1].Last(); chart1.Series[1].Points.AddY(value); } decimal sum = 0; for (int i = 0; i < vectorsave.Length; i++) { sum += vectorsave[i].Last() * i; } decimal sum2 = 0m; decimal sum3 = 0m; for (int i = 0; i < vectorsave.Length; i++) { if (vectorsave[i].Last() == 0m) sum3++; sum2 += vectorsave[i].Last(); } decimal halfSum = sum / sum2; decimal mySum = 0m; var schritt = 0; for (int i = 0; i < vectorsave.Length; i++) { mySum += vectorsave[i].Last() * i; schritt = i; if (halfSum < mySum) break; } MessageBox.Show(schritt + "\r\n" + (sum3 + schritt)); }