public void StartGame()
        {
            // Intis
            int players = clientHandlers.Count;

            form.gameStarted = true;
            form.SetGameStarted();
            gameLogic = new GameLogic(questions, ids);

            foreach (ClientHandler client in clientHandlers)
            {
                client.Write(TcpProtocol.SendId(client.id));
            }

            // Start the game loop
            while (true)
            {
                var currentQuestion = gameLogic.NextQuestion();
                if (currentQuestion == null)
                {
                    EndGame();
                    form.gameStarted = false;
                    form.SetGameStarted();
                    return;
                }

                // Send out the question + scores to the clients
                Broadcast(TcpProtocol.QuestionScoresSend(currentQuestion, gameLogic.GetScores()));

                // Wait for all clients to be finished (in threads)
                int finishedClients = 0;
                while (finishedClients != players)
                {
                    foreach (ClientHandler client in clientHandlers)
                    {
                        int playerTime = TcpProtocol.TimeParse(client.Read());
                        gameLogic.AddToScore(client.id, playerTime);
                        finishedClients++;

                        //for debugging
                        Console.WriteLine(@"Playertime: " + playerTime);
                        Console.WriteLine(@"PlayerID: " + client.id + @"Score: " + gameLogic.GetScore(client.id));
                    }
                    Thread.Sleep(1);
                }
            }
        }
Esempio n. 2
0
 void CheckHit()
 {
     foreach (TankShot shot in RefGameLogic.RefPlayer.ShotsRef)
     {
         if (shot.Active)
         {
             if (SphereIntersect(shot))
             {
                 Active = false;
                 Explosion.DefuseColor = new Vector3(0.713f, 0.149f, 0.286f);
                 Explosion.Spawn(Position, 5, 30);
                 shot.HitTarget();
                 RefGameLogic.AddToScore(100);
             }
         }
     }
 }