Example #1
0
        public GameState GetState()
        {
            try
            {
                writer.WriteLine("GET_STATE");
                writer.Flush();

                GameState state = new GameState();
                bool end = false;
                while (!end)
                {
                    string line = reader.ReadLine();
                    if (line != null)
                    {
                        string[] msg = line.Split(' ');
                        switch (msg[0])
                        {
                            case "BEGIN_STATE": break;
                            case "END_STATE": end = true; break;
                            case "THUNDERSTORM": state.Thunderstorms.Add(
                                new Cloud(
                                    float.Parse(msg[1], NumberFormatInfo.InvariantInfo),
                                    float.Parse(msg[2], NumberFormatInfo.InvariantInfo),
                                    float.Parse(msg[3], NumberFormatInfo.InvariantInfo),
                                    float.Parse(msg[4], NumberFormatInfo.InvariantInfo),
                                    float.Parse(msg[5], NumberFormatInfo.InvariantInfo)));
                                break;
                            case "RAINCLOUD": state.Rainclouds.Add(
                                new Cloud(
                                    float.Parse(msg[1], NumberFormatInfo.InvariantInfo),
                                    float.Parse(msg[2], NumberFormatInfo.InvariantInfo),
                                    float.Parse(msg[3], NumberFormatInfo.InvariantInfo),
                                    float.Parse(msg[4], NumberFormatInfo.InvariantInfo),
                                    float.Parse(msg[5], NumberFormatInfo.InvariantInfo)));
                                break;
                            case "YOU": state.MeIndex = int.Parse(msg[1]); break;
                        }
                    }
                }
                return state;
            }
            catch (Exception) { return null; }
        }
Example #2
0
        public GameState GetState()
        {
            try
            {
                writer.WriteLine("GET_STATE");
                writer.Flush();

                GameState state = new GameState();
                bool end = false;
                while (!end)
                {
                    string line = reader.ReadLine();
                    if (line == null)
                        continue;

                    string[] msg = line.Split(' ');
                    switch (msg[0])
                    {
                        case "BEGIN_STATE":
                            state.Iteration = int.Parse(msg[1]);
                            break;
                        case "END_STATE": end = true; break;
                        case "BUMPERSHIP":
                            state.Bumperships.Add(new Bumpership(
                                float.Parse(msg[1], NumberFormatInfo.InvariantInfo),
                                float.Parse(msg[2], NumberFormatInfo.InvariantInfo),
                                float.Parse(msg[3], NumberFormatInfo.InvariantInfo),
                                float.Parse(msg[4], NumberFormatInfo.InvariantInfo),
                                float.Parse(msg[5], NumberFormatInfo.InvariantInfo)));
                            break;
                        case "STAR":
                            state.Stars.Add(new Vector(float.Parse(msg[1], NumberFormatInfo.InvariantInfo),
                                                       float.Parse(msg[2], NumberFormatInfo.InvariantInfo)));
                            break;
                        case "YOU": state.MeIndex = int.Parse(msg[1]); break;
                    }
                }
                return state;
            }
            catch (Exception) { return null; }
        }