コード例 #1
0
    //Disconects a player and sends the info to the others
    public void DisconnectPlayer(int id)
    {
        WriteLog("Cliend disconnected - ID : " + id);
        string state = players.Remove(id);

        lock (lockGameState)
        {
            gameState += state;
        }

        players.CalculatePlayers();

        CheckRoundStatus();
    }
コード例 #2
0
    public string Update(float deltaTime, Hitbox[] hitboxes
                         , PlayerCollection players)
    {
        string ret = "";

        lock (lockBullets)
        {
            for (int index = 0; index < bullets.Count; index++)
            {
                bullets[index].Update(deltaTime);
                //Checks if the bullet collides with any wall and deletes it
                if (bullets[index].CollidesWith(hitboxes))
                {
                    ret += (int)ServerMessage.RemoveBullet + " "
                           + index + ":";
                    bullets.RemoveAt(index);
                    index--;
                }
                //Checks if the bullet collides with a player
                else
                {
                    int playerID = bullets[index].CollidesWith(players);

                    if (playerID != -1)
                    {
                        ret += (int)ServerMessage.RemoveBullet + " "
                               + index + ":";
                        players[playerID].AddOwnStatus(
                            (int)ServerMessage.DamagePlayer + " "
                            + bullets[index].Damage + ":");
                        players[playerID].TakeDamage(bullets[index].Damage);

                        if (!players[playerID].CheckDead())
                        {
                            ret += (int)ServerMessage.KillPlayer + " " +
                                   playerID + ":";
                            players.CalculatePlayers();
                        }

                        bullets.RemoveAt(index);
                        index--;
                    }
                }
            }
        }

        return(ret);
    }