Exemple #1
0
        /// <summary>
        /// Parse the login sting
        /// </summary>
        public void Login(string line)
        {
            if (line.ToLower().StartsWith("login "))
            {
                if (line.Length >= 6)
                {
                    username = line.Substring(6, line.Length - 6);
                    Server.Update(200, Server.gameState.GetMapSizeX() + ", " + Server.gameState.GetMapSizeY());
                    Console.WriteLine("Logged in as: " + username);
                }
            }

            // Send the map
            Server.SendMap(username);

            // Spawn the player to a random part of the map
            Random randomizer = new Random();
            bool   placed     = false;

            while (!placed)
            {
                int xPos = randomizer.Next(0, Server.gameState.GetMapSizeX());
                int yPos = randomizer.Next(0, Server.gameState.GetMapSizeY());
                if (CheckCollision(xPos, yPos))
                {
                    // Initialize the player
                    cookieCount = 20;
                    Server.Update(104, username + ", " + xPos + ", " + yPos + ", " + cookieCount);
                    x      = xPos;
                    y      = yPos;
                    placed = true;
                }
            }
        }