Exemple #1
0
        public GameServer(bool networked)
        {
            if (instance != null)
            {
                Console.WriteLine(SINGLETON_VIOLATED);
            }

            instance    = this;
            development = !networked;

            timer = new Stopwatch();
            rnd   = new Random();

            timer.Start();

            networkServer = new NetworkServer(networked);
            matchHandler  = new MatchHandler(Match.DefaultMatch, networkServer, this);

            // Create the initial game map.
            CreateMap();

            // Create the leaves for the game.
            CreateRandomLeaves(Constants.NUM_LEAVES);
            //CreateLeaves(100, -10, 10, -10, 10);
        }
Exemple #2
0
        /// <summary>
        /// Initializes the match handler.
        /// </summary>
        public MatchHandler(Match toHandle, NetworkServer networkHandler, GameServer game)
        {
            if (instance != null)
            {
                Console.WriteLine("DOUBLE INSTANTIATING MATCH HANDLER!");
            }

            instance = this;

            match           = toHandle;
            network         = networkHandler;
            this.game       = game;
            matchResetTimer = new Stopwatch();
            statsTimer      = new Timer
            {
                AutoReset = true,
                Interval  = 1000
            };
            statsTimer.Elapsed += (sender, args) =>
            {
                foreach (PlayerServer player in GameServer.instance.playerServerList)
                {
                    network.SendAll(PacketUtil.Serialize(new StatResultPacket(player.playerStats, player.Id)));
                }
            };
        }