Beispiel #1
0
        public void Start()
        {
            try
            {
                petThread.Start();

                while (!AppStatic.isExiting)
                {
                    if (isAutoCare == true) // If in Auto Care mode, this thread will take care of the Pet(Player simulation and auto testing Pet Class)
                    {
                        lock (AppStatic.objLock)
                        {
                            for (int i = 0; i < feedReq; i++)
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine("#Auto Care Mode# Food Provided at " + DateTime.Now);
                                Console.ResetColor();
                                feed.BeginInvoke(new AsyncCallback(AsyncFunctionCallBack), null); // Async call for adding a food
                            }
                            feedReq = 0;
                        }

                        if (needBed)
                        {
                            needBed = false;
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("#Auto Care Mode# Bed Provided at " + DateTime.Now);
                            Console.ResetColor();
                            bed.BeginInvoke(new AsyncCallback(AsyncFunctionCallBack), null); // Async call for providing a bed
                        }

                        if (needClean)
                        {
                            needClean = false;
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("#Auto Care Mode# Cleaned Popo at " + DateTime.Now);
                            Console.ResetColor();
                            clean.BeginInvoke(new AsyncCallback(AsyncFunctionCallBack), null); // Async call for cleaning
                        }
                    }
                    Thread.Sleep(MagicNumbers.PlayerInterval_ms); // Player simulation clock, each round period is ONE second
                }
                petThread.Join();                                 // wait till pet thread stopped
                Console.ForegroundColor = ConsoleColor.White;
                Console.BackgroundColor = ConsoleColor.Red;
                Console.WriteLine("Game Over, press ESC to exit"); // ready for exiting this app
                Console.ResetColor();
            }
            catch (Exception e) // May need to specify Exception types in the furture
            {
                Console.WriteLine(e.Message);
                AppStatic.log.Error(e.Message, e); //log4net
            }
        }