コード例 #1
0
ファイル: Server.cs プロジェクト: mgrayston/School-Work-
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);
            // Read world settings and create new world and add stars etc.
            try {
                XDocument settings = XDocument.Parse(Resources.settings);
                XElement  root     = settings.Root;

                universeSize    = Convert.ToInt32(root.Element("UniverseSize").Value);    // 750
                msPerFrame      = Convert.ToInt32(root.Element("MSPerFrame").Value);      // 16
                engineStrength  = Convert.ToDouble(root.Element("EngineStrength").Value); // 0.08
                projectileSpeed = Convert.ToInt32(root.Element("ProjectileSpeed").Value); // 15
                shotDelay       = Convert.ToInt32(root.Element("ShotDelay").Value);       // 6
                respawnRate     = Convert.ToInt32(root.Element("RespawnRate").Value);
                starSize        = Convert.ToInt32(root.Element("StarSize").Value);        // 35
                shipSize        = Convert.ToInt32(root.Element("ShipSize").Value);        // 20
                turningRate     = Convert.ToDouble(root.Element("TurningRate").Value);    // 2
                mode            = root.Element("Mode").Value;
                Console.WriteLine(root.Element("Mode").Value);
                world = new World(universeSize);

                int starId = 0;
                foreach (XElement star in root.Elements("Star"))
                {
                    world.AddStar(new Star(starId, Convert.ToDouble(star.Element("mass").Value), Convert.ToInt32(star.Element("x").Value), Convert.ToInt32(star.Element("y").Value)));
                    ++starId;
                }
            }
            catch (Exception e) {
                Console.WriteLine("Settings could not be read: " + e.Message);
            }

            clients            = new List <SocketState>();
            worldStringBuilder = new StringBuilder();
            updateStopwatch    = new Stopwatch();
            random             = new Random();

            // Start a thread infinitely updating the world
            Thread worldUpdater = new Thread(start: UpdateWorld);

            updateStopwatch.Start();
            worldUpdater.Start();
            startTime = DateTime.Now;

            // Begin receiving clients
            Network.ServerAwaitingClientLoop(HandleNewClient);

            // Keep Main running until "close" is enterd into the terminal
            Console.WriteLine("Enter 'close' to terminate application: ");
            while (!Console.ReadLine().ToLower().Equals("close"))
            {
            }
            endTime = DateTime.Now;
            TimeSpan gameDuration = endTime - startTime;

            duration = gameDuration.TotalMinutes;

            //TODO - update database here
            int gameID = WriteGameData();

            WritePlayerData(gameID);
            Environment.Exit(0);
        }