示例#1
0
        public void eatPellet(int id, Player p)
        {
            for(int i = 0; i < pelletList.Length; ++i)
            {
                if(id == pelletList[i].id)
                {
                    p.increaseSize(pelletList[i].size);
                    p.addScore(1);
                    Console.WriteLine("Size: " + p.size);
                    int oldPelletID = pelletList[i].id;
                    spawnPellet(i);
                    Player[] lockedPlayerList;

                    lock (playerList)
                    {
                        lockedPlayerList = new Player[playerList.Count];
                        playerList.CopyTo(lockedPlayerList);
                    }
                    foreach (Player player in lockedPlayerList)
                    {
                        player.sendCommand(Command.eatPelletCommand(0, p, oldPelletID, pelletList[i]));
                    }
                    break;
                }
            }
        }
示例#2
0
        public void eatPlayer(Player p1, Player p2)
        {
            p2.isDead = true;
            p1.increaseSize(p2.size);
            p1.addScore(10);
            p2.resetPosition();

            Player[] lockedPlayerList;

            lock (playerList)
            {
                lockedPlayerList = new Player[playerList.Count];
                playerList.CopyTo(lockedPlayerList);
            }
            foreach (Player player in lockedPlayerList)
            {
                player.sendCommand(Command.eatPlayerCommand(0, p1, p2));
            }
            //p2.isDead = false;
        }