コード例 #1
0
        /// <summary>
        /// Constructor for the server.  Starts the world and listening for clients
        /// </summary>
        private Server()
        {
            // create the hashset of clients
            clients = new Clients();


            // Sets ExtraGameMode to the multiplicitive identity.
            // Extra game modes will be represented as primes multiplied on.
            ExtraGameMode = 1;

            // Read info from the settings file
            readSettings(SETTINGSFILE);

            //Instantiates the world
            world = new World(boardWidth, boardHeight, FoodDensity, headroom, snakeLength, SnakeRecycleRate, ExtraGameMode);


            Console.WriteLine("Server Started up.");

            FrameTimer          = new System.Timers.Timer(MSPerFrame);
            FrameTimer.Elapsed += UpdateFrame;
            FrameTimer.Start();

            //Establishes a non-blocking loop to collect clients
            Networking.ServerAwaitingClientLoop(ClientConnected);

            // Keep console window open
            while (true)
            {
                Console.Read();
            }
        }
コード例 #2
0
        private void StartServer()
        {
            Console.WriteLine("Server waiting for client");
            Console.WriteLine("Press ctrl + c to send data to server!");
            // This begins an "event loop".
            // ConnectionRequested will be invoked when the first connection arrives.

            Networking.ServerAwaitingClientLoop(HandleNewClients);
        }
コード例 #3
0
        /// <summary>
        /// Starts the server, including a client connection loop and the game loop.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            settings = SpaceWarsSettings.ReadXML("settings.xml");
            clients  = new LinkedList <SocketState>();
            watch    = new Stopwatch();
            gameData = new StringBuilder();

            theWorld = new World(settings.GetSize(), settings.GetStars(), settings.GetShotDelay(), settings.GetRespawnDelay(), settings.TeamModeEnabled());

            Networking.ServerAwaitingClientLoop(HandleNewClient);

            watch.Start();

            gameLoop = new Thread(() =>
            {
                while (true)
                {
                    Update();
                }
            });

            gameLoop.Start();
        }
コード例 #4
0
        /// <summary>
        /// This is the main function that initializes everything, starts the task,
        /// starts and ends the stopwatch and also handlesnew client.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            id = 0;
            //initializing the stopwatch.
            watch = new Stopwatch();
            //calling the XmlRead.
            XmlRead();
            //setting the world to the new world.
            world = new World();
            //setting the star collection to star.
            world.starCollection[star.getStarId()] = star;
            //inintializing the world size to the Vector x and y.
            worldSize = new Vector2D(x, y);
            list      = new List <SocketState>();
            //Server awaiting client loop to handle a new client.
            Networking.ServerAwaitingClientLoop(HandleNewClient);

            //creating and initializing the Task.
            Task task = new Task(() =>
            {
                //starting the watch.
                watch.Start();
                while (true)
                {
                    //calling the Update method.
                    Update();
                    while (watch.ElapsedMilliseconds < MSPerFrame)
                    {
                    }
                    //restarting the watch.
                    watch.Restart();
                }
            });

            task.Start();
            Console.Read();
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: BasharHabash/Space-Wars
        /// <summary>
        /// Main method responsible for running all server processes.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // Allowing the program to update the database when closed
            Program.SetConsoleCtrlHandler(new HandlerRoutine(ConsoleCtrlCheck), true);

            // Program start time
            LastAccessedTime = DateTime.Now;

            // XML Settings are read and adjusted...
            ReadSettings("...//...//...//Resources/settings.xml");

            World        = new World();
            Clients      = new List <SocketState>();
            ShipID       = 0;
            ProjectileID = 0;

            // Initial Star Creation
            Star star = new Star();

            // Game mode alteration
            if (GAMEMODE_RandomDeadlyStar)
            {
                Random rand = new Random();
                star.loc = new Vector2D(rand.Next(-(UniverseSize / 2), UniverseSize / 2),
                                        rand.Next(-(UniverseSize / 2), UniverseSize / 2));
            }
            else
            {
                star.loc = new Vector2D(StarX, StarY);
            }

            // Star added to World
            World.Stars.Add(0, star);


            // Temporary lists initialized
            DeadShips        = new HashSet <Ship>();
            ResurrectedShips = new List <Ship>();
            DeadProjectiles  = new List <int>();
            ScoringShips     = new HashSet <int>();
            ShipHits         = new List <Ship>();

            Watch = new Stopwatch();

            // Begin event-driven callback for handling new clients
            Networking.ServerAwaitingClientLoop(HandleNewClient);
            System.Console.Out.WriteLine("Server is running, awaiting first client...");

            // Begin forever loop which handles client data and updates and sends World data based on
            // result
            while (true)
            {
                Watch.Start();
                while (Watch.ElapsedMilliseconds < TimePerFrame)
                {
                }
                Watch.Reset();

                Update();
            }
        }