Пример #1
0
        public static MPlayer Load(string save)
        {
            string[] args = save.Split().ToArray();
            bool     tmp;
            bool     Exist = Boolean.TryParse(args[0], out tmp);
            double   x = double.Parse(args[1]), y = double.Parse(args[2]);
            Tuple <double, double> Speed = new Tuple <double, double>(double.Parse(args[3]), double.Parse(args[4]));
            MPlayer Pl = new MPlayer(Utily.GetTag(), x, y);

            Pl.Speed = Speed;
            Pl.Exist = Exist;
            return(Pl);
        }
Пример #2
0
        private void ShortUpDatePlayer(int Tag, int Time, Tuple <double, double> Line)
        {
            double  originX = players[Tag].x, originY = players[Tag].y;
            MPlayer Pl = players[Tag];

            if (IsEntityWillInSquare(Pl, Line, false))
            {
                players[Tag].x = originX;
                players[Tag].y = originY;
                return;
            }
            bool cross = false;

            foreach (var pl in players)
            {
                cross = cross || (pl.Value.Tag != Tag && IsCrossEntity(pl.Value, Pl));
            }
            if (cross)
            {
                players[Tag].x = originX;
                players[Tag].y = originY;
                return;
            }
            List <int> del = new List <int>();

            foreach (var d in drops)
            {
                if (IsCrossEntity(d.Value, Pl))
                {
                    bool b = d.Value.reason == Reason.BySpawner;
                    if (d.Value.reason == Reason.BySpawner)
                    {
                        Q.Enqueue(new MEventDrop(Tag, d.Value.Tag, d.Value.NumSpawner));
                    }
                    else
                    {
                        Q.Enqueue(new MEventDrop(Tag, d.Value.Tag));
                    }
                    del.Add(d.Key);
                }
            }
            for (int i = 0; i < del.Count; ++i)
            {
                drops.Remove(del[i]);
            }
        }
Пример #3
0
        public void LoadMap(string path)
        {
            using (StreamReader sr = File.OpenText(path))
            {
                string        s    = "";
                List <string> args = new List <string>();
                while ((s = sr.ReadLine()) != null)
                {
                    args.Add(s);
                }
                int[] tmp = args[0].Split().Select(x => int.Parse(x)).ToArray();
                this.width = tmp[0]; this.height = tmp[1];
                int couPl = int.Parse(args[1]);
                this.players = new Dictionary <int, MPlayer>();
                for (int i = 2; i < couPl + 2; ++i)
                {
                    string   stmp = args[i];
                    string[] Tmp  = stmp.Split().ToArray();
                    this.players.Add(int.Parse(Tmp[0]), MPlayer.Load(stmp));
                }
                int couArr = int.Parse(args[couPl + 2]);
                this.arrows = new Dictionary <int, MArrow>();
                for (int i = couPl + 3; i < couPl + 3 + couArr; ++i)
                {
                    string   stmp = args[i];
                    string[] Tmp  = stmp.Split().ToArray();
                    this.arrows.Add(int.Parse(Tmp[0]), MArrow.Load(stmp));
                }
                int couDro = int.Parse(args[couArr + couPl + 3]);
                this.drops = new Dictionary <int, MDrop>();
                for (int i = couPl + 4 + couArr; i < couPl + 4 + couArr + couDro; ++i)
                {
                    string   stmp = args[i];
                    string[] Tmp  = stmp.Split().ToArray();
                    this.drops.Add(int.Parse(Tmp[0]), MDrop.Load(stmp));
                }
                int nowline    = 4 + couArr + couDro + couPl;
                int countSpawn = int.Parse(args[nowline]);
                ++nowline;
                spawners = new List <Tuple <double, double> >();
                for (int i = 0; i < countSpawn; ++i)
                {
                    int x = int.Parse(args[nowline].Split()[0]), y = int.Parse(args[nowline].Split()[1]);
                    ++nowline;
                    spawners.Add(Utily.MakePair <double>(x, y));
                }
                int countSpawnDrop = int.Parse(args[nowline]);
                ++nowline;
                dropSpawners = new List <DropSpawner>();
                for (int i = 0; i < countSpawnDrop; ++i)
                {
                    int x = int.Parse(args[nowline].Split()[0]), y = int.Parse(args[nowline].Split()[1]);
                    int cnt = int.Parse(args[nowline].Split()[2]), id = int.Parse(args[nowline].Split()[3]);
                    ++nowline;
                    dropSpawners.Add(new DropSpawner(x, y, id, cnt));
                }
                tmp         = args[nowline].Split().Select(x => int.Parse(x)).ToArray();
                this.Pwidth = tmp[0] + 2; this.Pheight = tmp[1] + 2;
                this.Field  = new List <List <Square> >();
                for (int x = 0; x < this.Pwidth; ++x)
                {
                    this.Field.Add(new List <Square>());
                }

                for (int i = 0; i < this.Pwidth; i++)
                {
                    this.Field[i].Add(new Square(i, 0, 1));
                }
                for (int i = 1; i < this.Pheight - 1; i++)
                {
                    this.Field[0].Add(new Square(0, i, 1));
                    this.Field[this.Pwidth - 1].Add(new Square(this.Pwidth - 1, i, 1));
                }
                for (int y = 1; y < this.Pheight - 1; ++y)
                {
                    string line = args[y + nowline].Trim();
                    int[]  agrs = line.Split().Select(x => int.Parse(x)).ToArray();
                    for (int x = 1; x < Pwidth - 1; ++x)
                    {
                        this.Field[x].Add(new Square(x, y, agrs[x - 1]));
                    }
                }
                for (int i = 0; i < this.Pwidth; i++)
                {
                    this.Field[i].Add(new Square(i, this.Pheight - 1, 1));
                }
            }
        }