public bool checkIfAllRacersFinished(WholeRace wholeRace) { if (wholeRace.lstWholePlayers.All(x => x.finished == true)) { wholeRace.finishedRace = true; return true; } return false; }
public void convertLstTimeSpansToStrings(WholeRace wholeRace) { wholeRace.totalTimeString = wholeRace.totalTime.ToString(); wholeRace.timeOfstartString = wholeRace.timeOfStartFromPc.ToString(); foreach (var racer in wholeRace.lstWholePlayers) { racer.totalTimeString = racer.totalTime.ToString(); foreach (var lap in racer.lstLapsTimeFromHw) { racer.lstLapsTimeFromHwString.Add(lap.ToString()); } } }
public bool checkIfItIsLastLap(WholeRace wholeRace) { if (wholeRace.typOfRace == RaceType.lapRace) { foreach (var player in wholeRace.lstWholePlayers) { if (player.actualLap.Equals(wholeRace.numberOfLaps)) { return true; } } return false; } if (wholeRace.typOfRace == RaceType.timeRace) { } return false; }
public void checkIfItIsNotOverByLaps(WholeRace wholeRace) { int numberOfFinishedRacers = 0; foreach (var item in wholeRace.lstWholePlayers) { if (item.actualLap > wholeRace.numberOfLaps) { item.stopWatch.Stop(); item.actualLap = wholeRace.numberOfLaps; item.finished = true; } if (item.finished) { numberOfFinishedRacers++; } } if (numberOfFinishedRacers == wholeRace.numberOfRacers) { wholeRace.finishedRace = true; } }
private void generuj_Click(object sender, EventArgs e) { WholeRace wholeRace = new WholeRace(); // skryj prvni form RaceType typeOfRace = new RaceType(); var radio = getCheckedRadio(); if (radio.Name.Equals("radioButtonFreeRace")) { typeOfRace = RaceType.freeRace; } else if (radio.Name.Equals("radioButtonTimeRace")) { typeOfRace = RaceType.timeRace; } else { typeOfRace = RaceType.lapRace; } wholeRace.minimalLapTimeInSeconds = Decimal.ToInt32(numericUpDownMinimalSeconds.Value); wholeRace.typOfRace = typeOfRace; wholeRace.numberOfLaps = Decimal.ToInt32(NumericUpDownNumberOfLaps.Value); wholeRace.numberOfMinutes = Decimal.ToInt32(numericUpDownNumberOfMinutes.Value); wholeRace.numberOfRacers = Decimal.ToInt32(numericUpDownNumberOfRacers.Value); this.Hide(); // vytvor form a predej mu pocet jezdcu Form2 f2 = new Form2(wholeRace); f2.StartPosition = FormStartPosition.CenterScreen; f2.Width = 1333; f2.Height = 768; // zobraz tento form f2.ShowDialog(); }
public void startRace(WholeRace wholeRace) { }
public void startAllTimersForRace(WholeRace wholeRace, Timer timerForTimeRace) { foreach (var item in wholeRace.lstWholePlayers) { if (item.finished == false && wholeRace.rdy == true) { item.stopWatch.Start(); } } }
public void sortPlayersByRank(WholeRace wholeRace, List<Control> lstUserControlRacers) { int i = 1; // TODO: TED wholeRace.lstWholePlayers = wholeRace.lstWholePlayers.OrderByDescending(x => x.actualLap).ThenBy(y => y.totalTime).ToList(); //wholeRace.lstWholePlayers.OrderBy(x => x.LapsWithCurrentLapTime) foreach (var item in wholeRace.lstWholePlayers.ToList()) { //if (item.actualLap != 1) //{ // tady se mi to prepise, musim to resit jinde item.rankInPreviousLap = item.rank; item.rank = i; refreshAllPlayersRank(item.cartNumber, item.rank, lstUserControlRacers); i++; // } } }
public void SaveFinishedRaceToDb(WholeRace wholeRace) { // Race race = new Race(); // foreach (var item in wholeRace.lstWholePlayers) // { // UserAccount user = new UserAccount(); // user.Email = "*****@*****.**"; // user.Nick = item.Nick; // foreach (var lap in item.lstLapsTime) // { // TimeOfLap timeOfLap = new TimeOfLap(); // timeOfLap.UserAccount = user; // timeOfLap.LapTime = lap; // timeOfLap.NumberOfLap = item.lstLapsTime.IndexOf(lap) + 1; // timeOfLap.TimeOfLapStart = DateTime.Now; // timeOfLap.Race = race; // race.TimeOfLaps.Add(timeOfLap); // } // using (OurDbContext db = new OurDbContext()) // { // db.userAccounts.Add(user); // } // } // race.Laps = wholeRace.numberOfLaps; // race.TimeOfStart = DateTime.Now; // race.Racers = wholeRace.numberOfRacers; // race.Minutes = wholeRace.numberOfMinutes; // using (OurDbContext db = new OurDbContext()) // { // db.races.Add(race); // db.SaveChanges(); // } }
public bool checkIfThereIsMinimalLapTime(List<DateTime> lstTimesOfPass, DateTime timeOfPass, WholeRace wholeRace) { if (lstTimesOfPass.Count() > 0) { // TODO: pred RLS zmenit na 30 if ((timeOfPass - lstTimesOfPass.Last() ).TotalSeconds < wholeRace.minimalLapTimeInSeconds ) { return false; } return true; } return true; }
public void checkIfItIsNotOverByTime(WholePlayer player, WholeRace wholeRace) { TimeSpan minutesPassedByRacer = new TimeSpan(0, 0, 0, 0); TimeSpan numberOfMinutesForRace = new TimeSpan(0, 0, wholeRace.numberOfMinutes, 0, 0); foreach (var item in player.lstLapsTimeFromHw) { minutesPassedByRacer = minutesPassedByRacer.Add(item); } if (minutesPassedByRacer.TotalSeconds > numberOfMinutesForRace.TotalSeconds - 30 && player.IsMaxLapsInTimeRaceSet == false) { if (minutesPassedByRacer.TotalSeconds >= numberOfMinutesForRace.TotalSeconds) { player.MaxLapsInTimeRace = player.actualLap; player.IsMaxLapsInTimeRaceSet = true; } else { player.MaxLapsInTimeRace = player.actualLap + 1; player.IsMaxLapsInTimeRaceSet = true; } } }
public void TestWriteToJson(WholeRace wholeRace) { if (wholeRace.lstWholePlayers.Count() > 0) { JavaScriptSerializer ser = new JavaScriptSerializer(); string nameOfJson = deleteAllButNumbers(wholeRace.timeOfStartFromPc.ToShortDateString().ToString()) + "-" + deleteAllButNumbers(wholeRace.timeOfStartFromPc.ToLongTimeString()); string direction = "Jsons/NotCopied/" + nameOfJson; direction += ".json"; wholeRace.nameOfJson = nameOfJson; wholeRace.codeForOnlineTracking = nameOfJson + RandomString(5); // TODO: nagenerovat kod pro trackovani zavodu online string outputJSON = ser.Serialize(wholeRace); File.WriteAllText(direction, outputJSON); } }
public Form2(WholeRace wholeRaceFromFirstForm) { InitializeComponent(); //System.Threading.Thread t = new System.Threading.Thread(wc.sendJsonToWeb); //t.Start(); // udpHelper.StartConversation(); // label2.Anchor = AnchorStyles.Right; // label2.Dock = DockStyle.Top; DoubleBuffered = true; numberOfSecondsTimeRace = wholeRaceFromFirstForm.numberOfMinutes * 60; //bool n = Convert.ToBoolean(ConfigurationManager.AppSettings[AppKeys.CentralUnitIpAddress]); //string x = ConfigurationManager.AppSettings["TesterMode"]; //if (n) if (ConfigurationManager.AppSettings[ConfigKeys.TesterMode].Equals("false")) { buttonPass1.Hide(); buttonPass2.Hide(); buttonPass3.Hide(); buttonPass4.Hide(); buttonPass5.Hide(); buttonPass6.Hide(); buttonPass7.Hide(); buttonPass8.Hide(); } if (wholeRaceFromFirstForm.typOfRace.Equals(RaceType.lapRace)) { label4.Text = "Počet kol: " + wholeRaceFromFirstForm.numberOfLaps; } if (wholeRaceFromFirstForm.typOfRace.Equals(RaceType.timeRace)) { label4.Text = "Počet minut: " + wholeRaceFromFirstForm.numberOfMinutes; } label2.Enabled = true; label2.Location = new Point(0, 0); label2.BackColor = Color.Transparent; label2.Width = 300; Controls.Add(label2); Controls.Add(printBttn); printBttn.Name = "printBttn"; guiMaker.CreateFlowlayoutpanel(this, lstUserControlRacers); timerForCheckingBuffer.Interval = 100; timerForCheckingBuffer.Tick += new EventHandler (checkBuffer); DictKartHwId = jsonHelper.getJsonHwKartId(); Bitmap formColor = new Bitmap(1333, 768); using (Graphics g = Graphics.FromImage(formColor)) { Rectangle r = new Rectangle(0, 0, 1333, 768); using (LinearGradientBrush br = new LinearGradientBrush( r, Color.FromArgb(120, 120, 120), Color.FromArgb(30, 30, 30), LinearGradientMode.Vertical)) { g.FillRectangle(br, r); } } BackgroundImage = formColor; wholeRace = wholeRaceFromFirstForm; wholeRace.rdy = false; wholeRace.finishedRace = false; wholeRace.started = false; pfc.AddFontFile(@"Fonts\OpenSans-Semibold.ttf"); foreach (Control c in this.Controls) { c.Font = new Font(pfc.Families[0], 15, FontStyle.Regular); } label1.Font = new Font("Orator Std", 28, FontStyle.Bold); label1.Location = new Point(Width /2- label1.Width/2, 0); label1.ForeColor = Color.White; wholeRace.finishedRace = false; // spust metodu pro zobrazeni current time FormWithTimer(); // nastaveni flowLayoutPanelu setFlowLayoutPanelForRacers(); // vygeneruj jednotlive labely a dej je do control panelu generateLabels(); //zavolej metodu pro dynamicke vytvori policek pro vsechny jezdce a jejich vlastnosti generateUserControlRacerOnFlowPanel(wholeRace.numberOfRacers); }
public void print(WholeRace wholeRace, PrintPageEventArgs ev) { int mostLapOfAllRacers = 0; if (wholeRace.lstWholePlayers.Count() != 0) { WholePlayer firstPlayer = wholeRace.lstWholePlayers.FirstOrDefault(); WholePlayer playerWithBestLap = wholeRace.lstWholePlayers.FirstOrDefault(); WholePlayer playerWithWorstLap = wholeRace.lstWholePlayers.FirstOrDefault(); Graphics g = ev.Graphics; Font fontNadpis = new Font("Arial", 21, FontStyle.Bold); Font fontText = new Font("Arial", 16); SolidBrush brush = new SolidBrush(Color.Black); float positionY = 200.0F; g.DrawString("Motokáry Mošnov www.pskart.cz", new Font("Arial", 30, FontStyle.Bold), brush, new PointF(210.0F, 30.0F)); g.DrawString("začátek závodu: " + wholeRace.timeOfStartFromPc, fontText, brush, new PointF(50.0F, 650.0F)); g.DrawString("rezervace dráhy na tel. 603 517 006", fontText, brush, new PointF(450.0F, 650.0F)); //g.DrawString("Jan Dedek ([email protected])", fontText, brush, new PointF(450.0F, 680.0F)); //g.DrawString("www.mtgolem.cz", fontText, brush, new PointF(450.0F, 710.0F)); //g.DrawString("www.hasam.cz", fontText, brush, new PointF(450.0F, 740.0F)); g.DrawString("Kart Time Keeper vyrobili: Jan Dedek ([email protected]), www.mtgolem.cz , www.hasam.cz", fontText, brush, new PointF(50.0F, 700.0F)); g.DrawString("Závod dostupný na karts.aspone.cz po zadání kódu: "+wholeRace.codeForOnlineTracking, fontText, brush, new PointF(50.0F, 730.0F)); g.DrawString("pořadí", fontNadpis, brush, new PointF(50.0F, positionY)); g.DrawString("č. káry", fontNadpis, brush, new PointF(170.0F, positionY)); g.DrawString("přezdívka", fontNadpis, brush, new PointF(280.0F, positionY)); g.DrawString("ztráta", fontNadpis, brush, new PointF(500.0F, positionY)); g.DrawString("nejlepší", fontNadpis, brush, new PointF(610.0F, positionY)); g.DrawString("průměr", fontNadpis, brush, new PointF(730.0F, positionY)); g.DrawString("celkový", fontNadpis, brush, new PointF(850.0F, positionY)); g.DrawString("počet kol", fontNadpis, brush, new PointF(970.0F, positionY)); TimeSpan bestTotal = new TimeSpan(100, 0, 0, 0, 0); //Bitmap hasam = new Bitmap(@"Pictures\hasam.jpg"); //hasam.SetResolution(200, 200); //g.DrawImage(hasam, new PointF(890.0F, positionY)); if (wholeRace.typOfRace.Equals(RaceType.timeRace)) { foreach (var item in wholeRace.lstWholePlayers) { if (item.actualLap > wholeRace.playerWithMostLapsInTimeRace) { wholeRace.playerWithMostLapsInTimeRace = item.actualLap; } } } foreach (var item in wholeRace.lstWholePlayers) { if(item.actualLap > mostLapOfAllRacers) { mostLapOfAllRacers = item.actualLap; } if (wholeRace.typOfRace.Equals(RaceType.lapRace) && item.actualLap == wholeRace.numberOfLaps) { if (item.totalTime < bestTotal) { firstPlayer = item; bestTotal = item.totalTime; } } if (wholeRace.typOfRace.Equals(RaceType.timeRace)) { if (item.actualLap.Equals(wholeRace.playerWithMostLapsInTimeRace) && bestTotal > item.totalTime) { firstPlayer = item; bestTotal = item.totalTime; } } } foreach (var item in wholeRace.lstWholePlayers) { item.lstLapsTimeFromHw.Sort(); if (item.lstLapsTimeFromHw.LastOrDefault() > playerWithWorstLap.lstLapsTime.LastOrDefault()) { playerWithWorstLap = item; } if (item.lstLapsTimeFromHw.FirstOrDefault() < playerWithBestLap.lstLapsTimeFromHw.FirstOrDefault()) { playerWithBestLap = item; } //if (item.ls) //{ //} positionY = positionY + 50.0F; g.DrawString(item.rank.ToString(), fontText, brush, new PointF(50.0F, positionY)); g.DrawString(item.cartNumber.ToString(), fontText, brush, new PointF(170.0F, positionY)); g.DrawString(item.Nick, fontText, brush, new PointF(280.0F, positionY)); if (wholeRace.typOfRace.Equals(RaceType.lapRace)) { if (item.actualLap < wholeRace.numberOfLaps) { g.DrawString((mostLapOfAllRacers - item.actualLap).ToString() + " kol", fontText, brush, new PointF(500.0F, positionY)); } else { g.DrawString((item.totalTime - bestTotal).ToString("mm\\:ss\\.ff"), fontText, brush, new PointF(500.0F, positionY)); } } if (wholeRace.typOfRace.Equals(RaceType.timeRace)) { if (wholeRace.playerWithMostLapsInTimeRace.Equals(item.actualLap)) { g.DrawString((item.totalTime - bestTotal).ToString("mm\\:ss\\.ff"), fontText, brush, new PointF(500.0F, positionY)); } else { int LostLaps = wholeRace.playerWithMostLapsInTimeRace - item.actualLap; if (LostLaps.Equals(1)) { g.DrawString((wholeRace.playerWithMostLapsInTimeRace - item.actualLap).ToString() + " kolo", fontText, brush, new PointF(500.0F, positionY)); } if (LostLaps.Equals(2) || LostLaps.Equals(3) || LostLaps.Equals(4)) { g.DrawString((wholeRace.playerWithMostLapsInTimeRace - item.actualLap).ToString() + " kola", fontText, brush, new PointF(500.0F, positionY)); } if (LostLaps >= 5) { g.DrawString((wholeRace.playerWithMostLapsInTimeRace - item.actualLap).ToString() + " kol", fontText, brush, new PointF(500.0F, positionY)); } } } StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Far; g.DrawString((item.lstLapsTimeFromHw.FirstOrDefault()).ToString("mm\\:ss\\.ff"), fontText, brush, new PointF(610.0F, positionY)); // g.DrawString(item.lstLapsTimeFromHw.LastOrDefault().ToString("mm\\:ss\\.ff"), fontText, brush, new PointF(770.0F, positionY)); double doubleAverageTicks = item.lstLapsTimeFromHw.Average(timeSpan => timeSpan.Ticks); long longAverageTicks = Convert.ToInt64(doubleAverageTicks); g.DrawString(new TimeSpan(longAverageTicks).ToString("mm\\:ss\\.ff"), fontText, brush, new PointF(730.0F, positionY)); if (item.totalTime > new TimeSpan(1,0,0)) { g.DrawString(item.totalTime.ToString("hh\\:mm\\:ss\\.ff"), fontText, brush, new PointF(850.0F, positionY)); } else { g.DrawString(item.totalTime.ToString("mm\\:ss\\.ff"), fontText, brush, new PointF(850.0F, positionY)); } g.DrawString(item.actualLap.ToString(), fontText, brush, new PointF(1030.0F, positionY), stringFormat); } g.DrawString(firstPlayer.Nick + " vyhrál závod v celkovém čase " + firstPlayer.totalTime.ToString("mm\\:ss\\.ff"), fontText, brush, new PointF(50.0F, 100.0F)); g.DrawString(playerWithBestLap.Nick + " zajel nejlepší kolo závodu v čase " + playerWithBestLap.lstLapsTimeFromHw.FirstOrDefault().ToString("mm\\:ss\\.ff"), fontText, brush, new PointF(50.0F, 130.0F)); g.DrawString(playerWithWorstLap.Nick + " zajel nejhorší kolo závodu v čase " + playerWithBestLap.lstLapsTimeFromHw.LastOrDefault().ToString("mm\\:ss\\.ff"), fontText, brush, new PointF(50.0F, 160.0F)); } else { MessageBox.Show("Žádný hráč nedokončil regulerně závod, není co tisknout."); } }