Пример #1
0
        /// <summary>
        /// Receives move requests from clients.
        /// </summary>
        /// <param name="ss">The ss.</param>
        private static void ReceiveMoveRequest(SocketState ss)
        {
            String request = ss.Builder.ToString();

            string[] parts = Regex.Split(request, @"(?<=[\n])");

            bool thrust = false;
            bool fire   = false;
            int  r      = 0;
            int  l      = 0;

            foreach (string part in parts)
            {
                if (part.Length == 0)
                {
                    continue;
                }
                if (part[part.Length - 1] != '\n')
                {
                    break;
                }

                if (part.Contains("T"))
                {
                    thrust = true;
                }
                if (part.Contains("F"))
                {
                    fire = true;
                }
                if (part.Contains("R"))
                {
                    r++;
                }
                if (part.Contains("L"))
                {
                    l++;
                }

                ss.Builder.Remove(0, part.Length);
            }

            lock (world) {
                Ship ship = world.GetShip(ss.ID);
                if (ship.HP > 0)
                {
                    if (thrust)
                    {
                        ship.Thrust = true;
                    }
                    else
                    {
                        ship.Thrust = false;
                    }
                    if (fire)
                    {
                        if (ship.Fire(shotDelay * msPerFrame))
                        {
                            world.AddProjectile(ship.id, ship.Loc.GetX(), ship.Loc.GetY(), ship.Dir.GetX(), ship.Dir.GetY());
                            //DB - increase ShotsFired
                            ship.ShotsFired++;
                        }
                    }
                    if (r > l)
                    {
                        ship.ToTurn = 1;
                    }
                    else if (l > r)
                    {
                        ship.ToTurn = -1;
                    }
                    else
                    {
                        ship.ToTurn = 0;
                    }
                }
            }

            Network.GetData(ss);
        }