Пример #1
0
        private static void sendStartGame(Game pacman)
        {
            Task[] tasks = new Task[RemoteServer.clients.Count];
            int    i     = 0;

            foreach (var x in RemoteServer.clients)
            {
                tasks[i] = Task.Factory.StartNew(() =>
                {
                    GameState gs = pacman.GetState(-1);
                    try
                    {
                        x.Value.Item1.ReadytoStart(gs);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.ToString());
                    }
                    lock (RemoteServer.gameHistory)
                    {
                        if (!RemoteServer.gameHistory.ContainsKey(-1))
                        {
                            RemoteServer.gameHistory.Add(-1, gs);
                        }
                    }
                });
                i++;
            }
            Task.WaitAll(tasks);
        }
Пример #2
0
        private static void gameCycle()
        {
            for (; ;)
            {
                if (RemoteServer.isFroozen)
                {
                    Console.WriteLine("freezed");
                    RemoteServer.frozen[4].WaitOne();
                }

                if (!RemoteServer.isPrimary)
                {
                    serverSet(RemoteServer.isPrimary);
                }

                Thread sendStates;
                Thread sendUpdates;
                //espera time round
                if (RemoteServer.roundQueue != null)
                {
                    game.GameLoop(RemoteServer.roundQueue);
                }

                int x = RemoteServer.round;
                RemoteServer.round++;

                lock (RemoteServer.roundQueue)
                    RemoteServer.roundQueue.Clear();

                GameState gs = game.GetState(x);
                sendUpdates = new Thread(() => sendUpdatesToServer(gs))
                {
                    Priority = ThreadPriority.Highest
                };
                sendUpdates.Start();
                sendStates = new Thread(() => sendGameStateToClients(game, x, gs))
                {
                    Priority = ThreadPriority.Highest
                };
                sendStates.Start();

                System.Threading.Thread.Sleep(MSEC_PER_ROUND + 10);
            }
        }