示例#1
0
        public void AddThunderstorm(string name, CloudType type)
        {
            Thunderstorm thunderstorm = new Thunderstorm(this,
                                                         1000,
                                                         graphicManager,
                                                         ShapeType.ThunderStorm,
                                                         inputFactory.NewInputHandler(type))
            {
                velocity = new Vector(0, 0),
                position = new Vector(Random.Next(Settings.Width),
                                      Random.Next(Settings.Height))
            };

            Thunderstorms.Add(thunderstorm);
        }
示例#2
0
 public static string Create(Thunderstorm player, World world, int ticks)
 {
     StringBuilder builder = new StringBuilder();
     builder.AppendLine(beginStateLine(ticks));
     builder.AppendLine(youIndexLine(world, player));
     foreach (Thunderstorm cloud in world.Thunderstorms)
     {
         builder.AppendLine(cloudLine("THUNDERSTORM", cloud));
     }
     foreach (RainCloud cloud in world.RainClouds)
     {
         builder.AppendLine(cloudLine("RAINCLOUD", cloud));
     }
     builder.AppendLine(endStateLine());
     return builder.ToString();
 }
示例#3
0
        public void Update(Thunderstorm thunderstorm, World world, int iteration)
        {
            if (thunderstorm.IsDead() || !IsConnected())
            {
                Dispose();
                return;
            }

            thunderstorm.Name = playerName;

            state = new
                        {
                            player = thunderstorm,
                            world,
                            iteration
                        };

            while (commandQueue.Any())
            {
                ParseMessage(commandQueue.Dequeue(), thunderstorm);
            }
        }
示例#4
0
        private void ParseMessage(string messageReceived, Thunderstorm player)
        {
            char[] separators = new[] { '\n', '\r', '\f', '\0', (char) 3 };
            string[] strings = messageReceived.Split(separators, StringSplitOptions.RemoveEmptyEntries);

            IEnumerable<KeyValuePair<string, string>> lines = GetLines(strings);
            foreach (KeyValuePair<string, string> line in lines)
            {
                if (state == null)
                    continue;

                if (line.Key.Equals("WIND"))
                    SendMessage(player.Wind(ParseVector(line.Value)) ? "OK\n" : "IGNORED\n");

                if (line.Key.Equals("GET_STATE"))
                    this.SendMessage(StateProtocol.Create(state.player, state.world, state.iteration));
            }
        }
示例#5
0
 public void AddThunderstorm(string name, CloudType type)
 {
     Thunderstorm thunderstorm = new Thunderstorm(this,
                                                  1000,
                                                  graphicManager,
                                                  ShapeType.ThunderStorm,
                                                  inputFactory.NewInputHandler(type))
                                     {
                                         velocity = new Vector(0, 0),
                                         position = new Vector(Random.Next(Settings.Width),
                                                               Random.Next(Settings.Height))
                                     };
     Thunderstorms.Add(thunderstorm);
 }
示例#6
0
 private static string youIndexLine(World world, Thunderstorm player)
 {
     return "YOU {0}".Format(world.Thunderstorms.IndexOf(player));
 }