예제 #1
0
        /// <summary>
        /// Method that runs the game
        /// </summary>
        /// <remarks>Generates number and logs losers and winners</remarks>
        public void StartGame()
        {
            Random rand = new Random();

            int number    = rand.Next(0, NumCount);
            int colourNum = rand.Next(0, 1);

            foreach (Gambler gambler in Gamblers)
            {
                RouletteResultEventArgs args = new RouletteResultEventArgs(gambler);

                if (gambler.IsWinner(number, colours[colourNum]))
                {
                    gambler.WonSum();

                    if (win != null)
                    {
                        win(this, args);
                    }
                }
                else
                {
                    gambler.LoseSum();

                    if (lose != null)
                    {
                        lose(this, args);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Method-listener of lose event
        /// </summary>
        /// <param name="sender">Object-parent of event</param>
        /// <param name="args">Object helper with additional data of the event</param>
        /// <remarks>Write all information about gamblers into file</remarks>
        public static void LoseLog(object sender, RouletteResultEventArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("Instanse with additional data is null!");
            }

            using (StreamWriter writer = new StreamWriter(winPath, true, System.Text.Encoding.Default))
            {
                writer.Write(args.Gambler);
            }
        }