Exemple #1
0
        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;
                }
            }
        }
Exemple #2
0
        private void bttnMakeRaceRdy_Click(object sender, EventArgs e)
        {
            if (keeper.areAllKartNumbersFilled(lstUserControlRacers) && keeper.areThereNoDuplicatesInKartsNumbers(lstUserControlRacers))
            {

                //startUdpServer();
                //udpHelper.StartUdpServer();
                //udpHelper.StartConversation();
                //timerForCheckingBuffer.Start();

                if (buttonForStartRacePressed == false)
                {
                    wholeRace.rdy = true;
                    string path = @"Jsons/later" + jsonHelper.deleteAllButNumbers(DateTime.Now.ToString()) + ".txt";
                    File.Create(path);
                    wholeRace.PathToTxt = path;

                    //System.Threading.Thread t = new System.Threading.Thread(wc.sendJsonToWeb);
                    //t.Start();
                    guiMaker.addToButtonsForCancelRaceKartNumbers(lstUserControlRacers);
                    guiMaker.addToButtonsForFinishRacer(lstUserControlRacers);
                    Controls.Find("btnGenerateNicks", true).FirstOrDefault().Enabled = false;
                    Controls.Find("btnMakeRaceRdy", true).FirstOrDefault().Enabled = false;

                    List<WholePlayer> lstWholePlayers = new List<WholePlayer>();
                    foreach (var item in lstUserControlRacers)
                    {

                        item.Controls.Find("TextBoxNick", true).FirstOrDefault().Enabled = false;
                        item.Controls.Find("textBoxKartNumber", true).FirstOrDefault().Enabled = false;
                        item.Controls.Find("totalTime", true).FirstOrDefault().Enabled = false;
                        item.Controls.Find("email", true).FirstOrDefault().Enabled = false;

                        // timer slouzi pro aktualizaci elapsed time z stopwatch
                        Timer timer = new Timer();
                        // stopwatch stopuji cas, spusteni probiha na zaklade dat z HW
                        Stopwatch stopWatch = new Stopwatch();
                        // co 100 setin refreshuj cas v textboxech
                        timer.Interval = 100;
                        timer.Start();
                        // narizuje co se ma vykonat co 100 setin - aktualizace textboxu na elapsed time z stopwatch
                        timer.Tick += (senderr, ee) => { item.Controls.Find("textBoxTimeOfCurrentLap", true).FirstOrDefault().Text = stopWatch.Elapsed.ToString(formatTimeSpanWithMinutes); };
                        item.Controls.Find("textBoxCurrentLap", true).FirstOrDefault().Text = "0";
                        // vytvorim daneho hrace a priradim mu jeden timer a stopwatch
                        WholePlayer wholePlayer = new WholePlayer();
                        wholePlayer.timer = timer;
                        wholePlayer.totalTime = new TimeSpan();
                        wholePlayer.stopWatch = stopWatch;
                        wholePlayer.actualLap = 0;
                        wholePlayer.lstTimesOfPass = new List<DateTime>();
                        wholePlayer.lstLapsTimeFromHwString = new List<string>();
                        wholePlayer.MaxLapsInTimeRace = 10000000;
                        wholePlayer.lstLapsTime = new List<TimeSpan>();
                        wholePlayer.lstLapsTimeFromHw = new List<TimeSpan>();
                        //string stringH = "Kart" + wholePlayer.cartNumber.ToString()
                        //wholePlayer.carHwId = Properties.Settings.Default[Object(stringH)];
                        wholePlayer.Nick = item.Controls.Find("TextBoxNick", true).FirstOrDefault().Text;

                        wholePlayer.cartNumber = int.Parse(item.Controls.Find("textBoxKartNumber", true).FirstOrDefault().Text);
                        if (item.Controls.Find("email", true).FirstOrDefault().Text.Equals("") || item.Controls.Find("email", true).FirstOrDefault().Text == null)
                        {
                            wholePlayer.email = "unknown";
                        }
                        else
                        {
                            wholePlayer.email = item.Controls.Find("email", true).FirstOrDefault().Text;
                        }

                        wholePlayer.carHwId = DictKartHwId.FirstOrDefault(x => x.Value == wholePlayer.cartNumber).Key;

                        lstWholePlayers.Add(wholePlayer); // do listu wholePlayers, ktery je v objektu wholeRace vloz playera
                    }
                    wholeRace.lstWholePlayers = lstWholePlayers;

                    buttonForStartRacePressed = true;
                    timerForCheckingBuffer.Start();
                    udpHelper.StartUdpServer(this);
                    //
                    //udpHelper.StartConversation();

                    //  udpHelper.StartConversation2();
                }
            }
        }