Example #1
0
        public Reality ScanReality(Fighter currentFighter, bool reflect)
        {
            var sync = ReadString();

            if (sync != "Begin")
            {
                throw new GameProtocolException("Synchronization fail");
            }

            var reality = new Reality();

            reality.ActiveFighter = currentFighter;

            int liveliness = ReadInt();

            EnsureInValues(liveliness, "живость", 0, 1);

            currentFighter.IsAlive = liveliness == 1;
            if (!currentFighter.IsAlive)
            {
                return(reality);
            }


            try
            {
                currentFighter.Coordinates = ReadPoint(reflect);
                currentFighter.Angle       = ReadAngle(reflect);
                currentFighter.Health      = ReadInt();
                currentFighter.Mana        = ReadInt();


                //System.Diagnostics.Debugger.Break();

                int unitCount = ReadInt();

                for (int i = 0; i < unitCount; i++)
                {
                    var coords = ReadPoint(reflect);
                    var team   = ReadInt();
                    EnsureInValues(team, "СВОЙ-ЧУЖОЙ..ZZZ!", 0, 1);

                    var f = new Unit(ReadString()[0]);
                    f.Health      = ReadInt();
                    f.Coordinates = coords;

                    if (team == 0)
                    {
                        reality.Friends.Add(f);
                    }
                    else
                    {
                        reality.Enemies.Add(f);
                    }
                }

                int friendCount = ReadInt();
                for (int i = 0; i < friendCount; i++)
                {
                    reality.Messages.Add(ReadString());
                }
            }
            catch (Exception e)
            {
                throw new GameProtocolException("Protocol missmatch in coordinates: " + e.Message);
            }

            return(reality);
        }
Example #2
0
 public void Update(Reality reality)
 {
     Fighter = reality.ActiveFighter;
     Enemies = reality.Enemies;
 }