Exemplo n.º 1
0
        public void writingCountGames()        //игра
        {
            for (int i = 0; i < model.ListUsers.Count; i++)
            {
                if (model.ListUsers[i] != null)
                {
                    GetCountGamesInfo gamesInfo = new GetCountGamesInfo();
                    gamesInfo.count = model.CountGamers;

                    CTransfers.Writing(gamesInfo, model.ListNs[i]);
                }
            }
            if (model.CountGamers == 1 && model.workingGame)
            {
                for (int i = 0; i < model.ListUsers.Count; i++)
                {
                    if (model.ListUsers[i] != null)
                    {
                        foreach (GeneralInfo g in model.ListGInfo)
                        {
                            if (g.Name == model.ListUsers[i].Name)
                            {
                                g.Wins += 1;
                            }
                        }
                        CTransfers.Writing(new GetCountWinsInfo(), model.ListNs[i]);
                        break;
                    }
                }
                ControllersS.cServer.StopServer();
            }
        }
Exemplo n.º 2
0
        public override void Process(ModelServer Model)
        {
            foreach (Item item in items)
            {
                for (int i = 1; i <= Model.ListUsers[num].Items.Length; i++)
                {
                    if (Model.ListUsers[num].Items[i].IdItem == item.IdItem)
                    {
                        Item voidItem = new Item();
                        Model.ListUsers[num].Items[i] = voidItem;                         //Удаляем вещь из инвентаря игрока
                        voidItem.IdItem = -1;
                        item.Location   = itemLocation;
                        lock (Model.Map.ListItems)
                        {
                            Model.Map.ListItems.Add(item);                             //Добавляем вещь на карту
                        }

                        break;
                    }
                }
                itemLocation.X += 25;
            }
            foreach (NetworkStream nStream in Model.ListNs)             //Даём актуальную инфу всем игрокам об удалённом с карты предмете
            {
                GetInfoItems items = new GetInfoItems();
                items.listItems = Model.Map.ListItems;
                CTransfers.Writing(items, nStream);
            }
        }
Exemplo n.º 3
0
        public override void Process(ModelServer Model)
        {
            for (int i = 1; i < Model.ListUsers[num].Items.Length; i++)
            {
                if (Model.ListUsers[num].Items[i].Name == null)
                {
                    Model.ListUsers[num].Items[i] = item;                     //Кладём вещь игроку

                    lock (Model.Map.ListItems)
                    {
                        for (int j = 0; j < Model.Map.ListItems.Count; j++)
                        {
                            if (Model.Map.ListItems[j].IdItem == item.IdItem)
                            {
                                Model.Map.ListItems.RemoveAt(j);                                                                                                                       //Удаляем вещь с карты
                            }
                        }
                    }

                    foreach (NetworkStream nStream in Model.ListNs)                     //Даём актуальную инфу всем игрокам об удалённом с карты предмете
                    {
                        GetInfoItems items = new GetInfoItems();
                        items.listItems = Model.Map.ListItems;
                        CTransfers.Writing(items, nStream);
                    }
                    break;
                }
            }
        }
Exemplo n.º 4
0
        public void InfoUsers(object tc)        //игра
        {
            TcpClient tcp = (TcpClient)tc;

            Thread.Sleep(200);
            NetworkStream nStream = tcp.GetStream();
            bool          PrivateWorkingThread = true;

            while (model.workingThread && PrivateWorkingThread)
            {
                try
                {
                    AngelToZone angel = new AngelToZone();
                    angel.listUserInfo = model.ListUsers;
                    GetBulletsInfo buletsInfo = new GetBulletsInfo();
                    lock (model.ListBullet)
                        buletsInfo.listBulets = model.ListBullet.ToList <BulletInfo>();
                    GetGrenadesInfo grenadesInfo = new GetGrenadesInfo();
                    lock (model.ListGrenade)
                        grenadesInfo.grenadesInfo = model.ListGrenade.ToList <GrenadeInfo>();

                    CTransfers.Writing(angel, nStream);
                    CTransfers.Writing(buletsInfo, nStream);
                    CTransfers.Writing(grenadesInfo, nStream);
                    Thread.Sleep(10);
                }
                catch (System.IO.IOException err)
                {
                    //ErrorEvent(err.Message + " |Ошибка в ControllerServer, методе InfoUsers");
                    PrivateWorkingThread = false;
                }
            }
        }
Exemplo n.º 5
0
        public bool SendingInformationAboutObjects(int num)        //игра
        {
            try
            {
                GetNumber gNumber = new GetNumber();
                gNumber.num = model.number;
                GetBushesInfo bushesInfo = new GetBushesInfo();
                bushesInfo.listBush = model.Map.ListBush;
                GetMapBordersInfo bordersInfo = new GetMapBordersInfo();
                bordersInfo.rectangle = model.Map.MapBorders;
                GetBoxesInfo boxesInfo = new GetBoxesInfo();
                boxesInfo.listBox = model.Map.ListBox;
                GetInfoItems itemsInfo = new GetInfoItems();
                itemsInfo.listItems = model.Map.ListItems;
                GetTreesInfo treesInfo = new GetTreesInfo();
                treesInfo.listTree = model.Map.ListTrees;

                CTransfers.Writing(gNumber, model.ListNs[num]);
                Thread.Sleep(100);
                CTransfers.Writing(bushesInfo, model.ListNs[num]);                // Отправка инфы о кустах
                Thread.Sleep(100);
                CTransfers.Writing(bordersInfo, model.ListNs[num]);               //Инфа о границах карты
                Thread.Sleep(100);
                CTransfers.Writing(boxesInfo, model.ListNs[num]);                 // Отправка инфы о коробках
                Thread.Sleep(100);
                CTransfers.Writing(treesInfo, model.ListNs[num]);                 // Отправка инфы о деревьях
                Thread.Sleep(100);
                CTransfers.Writing(itemsInfo, model.ListNs[num]);                 // Отправка инфы о вещах
                return(true);
            }
            catch (Exception) { return(false); }
        }
Exemplo n.º 6
0
        public void clientStart_Test1()
        {
            TcpClient client = new TcpClient();

            client.Connect("127.0.0.1", 1337);
            NetworkStream streamClient = client.GetStream();

            CTransfers.Writing("Test_1_2_3", streamClient);
        }
Exemplo n.º 7
0
        public override void Process(ModelServer Model)
        {
            this.Model = Model;
            byte[] ping = new byte[1];
            ping[0] = 2;
            PingInfoClient pic = new PingInfoClient();

            CTransfers.Writing(pic, Model.ListNs[this.num]);
        }
Exemplo n.º 8
0
        public void timerUsersInZone_Tick()        //игра
        {
            for (int i = 0; i < model.ListUsers.Count; i++)
            {
                if (model.ListUsers[i] != null)
                {
                    if (Math.Sqrt(Math.Pow(model.ListUsers[i].userLocation.X - model.Map.NextZone.ZoneCenterCoordinates.X, 2) + Math.Pow(model.ListUsers[i].userLocation.Y - model.Map.NextZone.ZoneCenterCoordinates.Y, 2)) > model.Map.NextZone.ZoneRadius)
                    {
                        model.ListUsers[i].flagZone = true;
                    }
                    else
                    {
                        model.ListUsers[i].flagZone = false;
                    }

                    if (model.Map.PrevZone != null && Math.Sqrt(Math.Pow(model.ListUsers[i].userLocation.X - model.Map.PrevZone.ZoneCenterCoordinates.X, 2) + Math.Pow(model.ListUsers[i].userLocation.Y - model.Map.PrevZone.ZoneCenterCoordinates.Y, 2)) > model.Map.PrevZone.ZoneRadius)
                    {
                        model.ListUsers[i].hp -= model.DamageZone;
                        if (model.ListUsers[i].hp <= 0)
                        {
                            SingalForDroping Signal = new SingalForDroping();
                            CTransfers.Writing(Signal, model.ListNs[i]);
                            Thread.Sleep(500);                            //Чтобы вещи успевали дропнуться до удаления игрока

                            PlayerDeath death = new PlayerDeath();
                            death.Killer = "ZONA";

                            CTransfers.Writing(death, model.ListNs[i]);

                            foreach (GeneralInfo g in model.ListGInfo)
                            {
                                if (g.Name == model.ListUsers[i].Name)
                                {
                                    g.Dies += 1;
                                }
                            }

                            GetKillsInfo kill = new GetKillsInfo();
                            kill.kill.killer = "ZONA";
                            kill.kill.dead   = model.ListUsers[i].Name;


                            for (int k = 0; k < model.ListUsers.Count; k++)
                            {
                                if (model.ListUsers[k] != null)
                                {
                                    CTransfers.Writing(kill, model.ListNs[k]);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 9
0
        public override void Process(ModelClient model)
        {
            ItemDroping itemDrop  = new ItemDroping();
            List <Item> listItems = new List <Item>();

            foreach (Item item in model.ListUsers[model.ThisUser.userNumber].Items)
            {
                if (item != null)
                {
                    if (item.Name != null)
                    {
                        listItems.Add(item);
                    }
                }
            }
            itemDrop.items        = listItems;
            itemDrop.itemLocation = model.ListUsers[model.ThisUser.userNumber].userLocation;
            itemDrop.num          = model.ThisUser.userNumber;
            CTransfers.Writing(itemDrop, model.NStream);
        }
Exemplo n.º 10
0
        async public void Bullet(object tmpObject)
        {
            bool       flagBreak = false;
            BulletInfo bulletInfo = (BulletInfo)tmpObject;
            double     X = bulletInfo.location.X, Y = bulletInfo.location.Y;

            X += (15.0 / bulletInfo.speed) * bulletInfo.speedX;
            bulletInfo.location.X = (int)X;
            Y += (15.0 / bulletInfo.speed) * bulletInfo.speedY;
            bulletInfo.location.Y = (int)Y;
            for (int i = 0; i < bulletInfo.timeLife; i++)
            {
                X += bulletInfo.speedX;
                bulletInfo.location.X = (int)X;
                Y += bulletInfo.speedY;
                bulletInfo.location.Y = (int)Y;
                for (int j = 0; j < model.ListUsers.Count; j++)
                {
                    if (model.ListUsers[j] != null && Math.Abs(model.ListUsers[j].userLocation.X - X) <= 9 && Math.Abs(model.ListUsers[j].userLocation.Y - Y) <= 9 && model.ListUsers[j].hp > 0)
                    {
                        byte[] popad = new byte[1];
                        popad[0] = 6;
                        model.ListUsers[j].hp -= bulletInfo.damage;
                        flagBreak              = true;
                        if (model.ListUsers[j].hp <= 0)
                        {
                            SingalForDroping Signal = new SingalForDroping();
                            CTransfers.Writing(Signal, model.ListNs[j]);

                            await Task.Delay(600);

                            foreach (GeneralInfo g in model.ListGInfo)
                            {
                                if (g.Name == model.ListUsers[j].Name)
                                {
                                    g.Dies += 1;
                                }
                                if (g.Name == bulletInfo.owner)
                                {
                                    g.Kills += 1;
                                }
                            }

                            GetKillsInfo kill = new GetKillsInfo();
                            kill.kill.killer = bulletInfo.owner;
                            kill.kill.dead   = model.ListUsers[j].Name;

                            for (int k = 0; k < model.ListUsers.Count; k++)
                            {
                                if (model.ListUsers[k] != null)
                                {
                                    if (model.ListUsers[k].Name == bulletInfo.owner)
                                    {
                                        model.ListUsers[k].kills += 1;
                                    }
                                    CTransfers.Writing(kill, model.ListNs[k]);
                                }
                            }

                            PlayerDeath pd = new PlayerDeath();
                            pd.Killer = bulletInfo.owner;
                            CTransfers.Writing(pd, model.ListNs[j]);
                        }
                        break;
                    }
                }
                try
                {
                    if (model.Map.bordersForBullets[bulletInfo.location.X, bulletInfo.location.Y])
                    {
                        flagBreak = true;
                    }
                }
                catch { break; }
                if (flagBreak)
                {
                    break;
                }
                Thread.Sleep(20);
            }
            lock (model.ListBullet)
            {
                model.ListBullet.TryTake(out bulletInfo);
            }
        }
Exemplo n.º 11
0
        public void Grenade(object tmpObject)
        {
            bool        flagfly = false, stop = false;
            GrenadeInfo grena = (GrenadeInfo)tmpObject;
            double      X = grena.location.X, Y = grena.location.Y;

            for (int i = 0; i < 250; i++)
            {
                grena.timeBoo--;
                if (grena.flagFly && !flagfly && !stop)
                {
                    grena.flagFly  = false;
                    grena.location = new Point(userInfo.userLocation.X, userInfo.userLocation.Y);
                    double interval = Math.Sqrt(Math.Pow(userInfo.mouseLocation.X - userInfo.userLocation.X, 2)
                                                + Math.Pow(userInfo.mouseLocation.Y - userInfo.userLocation.Y, 2));
                    double k = interval / 3;
                    grena.speedX = (userInfo.mouseLocation.X - userInfo.userLocation.X) / k;
                    grena.speedY = (userInfo.mouseLocation.Y - userInfo.userLocation.Y) / k;
                    X            = grena.location.X;
                    Y            = grena.location.Y;
                    flagfly      = true;
                }
                if (flagfly)
                {
                    X += grena.speedX;
                    grena.location.X = (int)X;
                    Y += grena.speedY;
                    grena.location.Y = (int)Y;
                    if (grena.timeLife > 0)
                    {
                        grena.timeLife--;
                    }
                    else
                    {
                        flagfly = false;
                        stop    = true;
                    }
                }
                else if (!stop)
                {
                    grena.location = userInfo.userLocation;
                }
                Thread.Sleep(20);
            }
            for (int j = 0; j < model.ListUsers.Count; j++)
            {
                if (model.ListUsers[j] != null && Math.Abs(model.ListUsers[j].userLocation.X - X) <= 59 && Math.Abs(model.ListUsers[j].userLocation.Y - Y) <= 59 && model.ListUsers[j].hp > 0)
                {
                    byte[] popad = new byte[1];
                    popad[0] = 6;
                    model.ListUsers[j].hp -= grena.damage;
                    if (model.ListUsers[j].hp <= 0)
                    {
                        SingalForDroping Signal = new SingalForDroping();
                        CTransfers.Writing(Signal, model.ListNs[j]);
                        Thread.Sleep(500);                        //Чтобы вещи успевали дропнуться до удаления игрока

                        foreach (GeneralInfo g in model.ListGInfo)
                        {
                            if (g.Name == model.ListUsers[j].Name)
                            {
                                g.Dies += 1;
                            }
                            if (g.Name == grena.owner)
                            {
                                g.Kills += 1;
                            }
                        }

                        GetKillsInfo kill = new GetKillsInfo();
                        kill.kill.killer = grena.owner;
                        kill.kill.dead   = model.ListUsers[j].Name;

                        for (int k = 0; k < model.ListUsers.Count; k++)
                        {
                            if (model.ListUsers[k] != null)
                            {
                                if (model.ListUsers[k].Name == grena.owner)
                                {
                                    model.ListUsers[k].kills += 1;
                                }
                                CTransfers.Writing(kill, model.ListNs[k]);
                            }
                        }

                        PlayerDeath pd = new PlayerDeath();
                        pd.Killer = grena.owner;
                        CTransfers.Writing(pd, model.ListNs[j]);
                    }
                }
            }
            Thread.Sleep(700);
            model.ListGrenade.TryTake(out grena);
        }
Exemplo n.º 12
0
        public void timerZone_Tick()        //игра
        {
            if (model.Map.NextZone.TimeTocompression > 0)
            {
                GetZoneCompression Compress = new GetZoneCompression();
                Compress.Count = model.Map.NextZone.TimeTocompression;

                foreach (NetworkStream n in model.ListNs)
                {
                    CTransfers.Writing(Compress, n);
                }

                model.Map.NextZone.TimeTocompression -= 1;
            }
            else
            {
                GetZoneCompression Compress = new GetZoneCompression();
                Compress.Count = model.Map.NextZone.TimeTocompression;

                foreach (NetworkStream n in model.ListNs)
                {
                    CTransfers.Writing(Compress, n);
                }

                timerZone.Stop();
                double x = model.Map.PrevZone.ZoneCenterCoordinates.X, y = model.Map.PrevZone.ZoneCenterCoordinates.Y, radius = model.Map.PrevZone.ZoneRadius;;
                double koef = Math.Sqrt(Math.Pow(model.Map.PrevZone.ZoneCenterCoordinates.X - model.Map.NextZone.ZoneCenterCoordinates.X, 2)
                                        + Math.Pow(model.Map.PrevZone.ZoneCenterCoordinates.Y - model.Map.NextZone.ZoneCenterCoordinates.Y, 2)) / 750;
                double k = Math.Sqrt(Math.Pow(model.Map.PrevZone.ZoneCenterCoordinates.X - model.Map.NextZone.ZoneCenterCoordinates.X, 2)
                                     + Math.Pow(model.Map.PrevZone.ZoneCenterCoordinates.Y - model.Map.NextZone.ZoneCenterCoordinates.Y, 2)) / koef;
                double speedX = (model.Map.PrevZone.ZoneCenterCoordinates.X - model.Map.NextZone.ZoneCenterCoordinates.X) / k;
                double speedY = (model.Map.PrevZone.ZoneCenterCoordinates.Y - model.Map.NextZone.ZoneCenterCoordinates.Y) / k;

                double speedRadius = (double)(model.Map.PrevZone.ZoneRadius - model.Map.NextZone.ZoneRadius) / 750;
                while (model.Map.PrevZone.ZoneRadius > model.Map.NextZone.ZoneRadius && model.workingGame)
                {
                    x -= speedX;
                    model.Map.PrevZone.ZoneCenterCoordinateX = (int)x;
                    y -= speedY;
                    model.Map.PrevZone.ZoneCenterCoordinateY = (int)y;
                    radius -= speedRadius;
                    model.Map.PrevZone.ZoneRadius = (int)radius;
                    for (int i = 0; i < model.ListUsers.Count; i++)
                    {
                        if (model.ListUsers[i] != null && model.ListNs[i].CanWrite)
                        {
                            GetPrevZoneInfo prevZoneInfo = new GetPrevZoneInfo();
                            prevZoneInfo.prevZone = model.Map.PrevZone;

                            CTransfers.Writing(prevZoneInfo, model.ListNs[i]);
                        }
                    }
                    Thread.Sleep(40);
                }
                if (model.workingGame)
                {
                    model.Map.PrevZone            = model.Map.NextZone;
                    model.Map.NextZone            = new Zone();
                    model.Map.NextZone.ZoneRadius = (int)model.Map.PrevZone.ZoneRadius / 2;
                    model.Map.NextZone.NewCenterZone(model.Map.MapBorders, model.Map.PrevZone.ZoneCenterCoordinates, model.Map.PrevZone.ZoneRadius);                    //не страдает ли тут MVC?
                    for (int i = 0; i < model.ListUsers.Count; i++)
                    {
                        if (model.ListUsers[i] != null)
                        {
                            GetZoneStartInfo nextZoneInfo = new GetZoneStartInfo();
                            nextZoneInfo.nextZone = model.Map.NextZone;

                            CTransfers.Writing(nextZoneInfo, model.ListNs[i]);
                        }
                    }
                    model.Map.NextZone.TimeTocompression = 60;
                    model.DamageZone += 2;
                    timerZone.Start();
                }
            }
        }