Beispiel #1
0
        public void HealthBlock()
        {
            var block = new GameObjectFactory().CreateBlock();

            block.blockType        = BlockType.Health;
            block.Position         = this.Reload();
            block.HelthPoints      = 1;
            block.Can_Be_Destroyed = true;
            this.blocks.Add(block);
        }
Beispiel #2
0
        /// <summary>
        /// Генерация сущностей на игровом поле
        /// </summary>
        private void GenerateMap()
        {
            var rnd  = new Random();
            var room = Owner as IRoom;

            this.Width  = room.GameSetings.MapSize.Width;
            this.Height = room.GameSetings.MapSize.Height;
            //int tankCount = room.Gamers.Count();
            int objectCount = (this.height * this.width) / (10 * room.GameSetings.ObjectsSize * room.GameSetings.ObjectsSize);

            //         foreach (var t in room.Gamers)
            //         {
            //	this.NewGamer(t);
            //}
            while (objectCount > 0)
            {
                var obj = new GameObjectFactory().CreateBlock();
                //var obj = new Block();
                obj.Size             = room.GameSetings.ObjectsSize;
                obj.Position         = this.Reload();
                obj.Can_Be_Destroyed = true;
                obj.blockType        = (BlockType)colInd.Next(0, 4);
                switch (obj.blockType)
                {
                case BlockType.Brick: obj.HelthPoints = 2;
                    break;

                case BlockType.Brick2: obj.HelthPoints = 2;
                    break;

                case BlockType.Concrete: obj.Can_Be_Destroyed = false;
                    break;

                case BlockType.Tree: obj.HelthPoints = 1;
                    break;

                default:
                    break;
                }
                //obj.Is_Alive = true;
                blocks.Add(obj);
                //objects.Add(obj);
                objectCount--;
            }

            this.mapgen = true;
        }
Beispiel #3
0
        // Нужно вызывать эту чепуху при новом игроке в комнате, метод ниже мне не подходит, по причине - мне не нужен ендпоинт, мне нужен гуид
        /// <summary>
        /// Метод интегрирующий нового игрока на игровое поле
        /// </summary>
        /// <param name="gamer"> Новый игрок</param>
        public void NewGamer(IGamer gamer)
        {
            var obj = new GameObjectFactory().CreateTank();
            //var obj = new Tank();
            var room = Owner as IRoom;

            obj.Size        = room.GameSetings.ObjectsSize;
            obj.Tank_ID     = gamer.Passport;
            obj.Name        = gamer.Name;
            obj.Lives       = 1;
            obj.HelthPoints = 5;
            //obj.Is_Alive = true;
            obj.Can_Be_Destroyed = true;
            obj.Can_Shoot        = true;
            obj.Direction        = Direction.Up;
            obj.Position         = this.Reload();
            tanks.Add(obj);
            //objects.Add(obj);
        }
Beispiel #4
0
        /// <summary>
        /// Метод реализирующий выстрел
        /// </summary>
        /// <param name="entity">Сущность осуществившая выстрел</param>
        private void Fire(IEntity entity)
        {
            //ITank tank = (ITank)objects.FirstOrDefault(t => (t as ITank)?.Tank_ID == (entity as ITank)?.Tank_ID);
            ITank tank = tanks.FirstOrDefault(t => t?.Tank_ID == (entity as ITank)?.Tank_ID);

            if (tank.Can_Shoot)
            {
                var bullet = new GameObjectFactory().CreateBullet();
                //var bullet = new Bullet();
                var room = Owner as IRoom;
                bullet.Size      = room.GameSetings.Bullet_size;
                bullet.Direction = tank.Direction;
                bullet.Parent_Id = tank.Tank_ID;
                tanks.FirstOrDefault(t => t.Tank_ID == tank.Tank_ID).Can_Shoot = false;
                bullet.Is_Alive         = true;
                bullet.Can_Be_Destroyed = true;
                bullet.Command          = EntityAction.Move;
                switch (bullet.Direction)
                {
                case Direction.Left:
                    bullet.Position = new Rectangle(new Point(tank.Position.Left - bullet.Size - 1, tank.Position.Top + (tank.Size / 2) - (bullet.Size / 2)), new Size(bullet.Size, bullet.Size));
                    break;

                case Direction.Right:
                    bullet.Position = new Rectangle(new Point(tank.Position.Right + 1, tank.Position.Top + (tank.Size / 2) - (bullet.Size / 2)), new Size(bullet.Size, bullet.Size));
                    break;

                case Direction.Up:
                    bullet.Position = new Rectangle(new Point(tank.Position.Left + (tank.Size / 2) - (bullet.Size / 2), tank.Position.Top - bullet.Size - 1), new Size(bullet.Size, bullet.Size));
                    break;

                case Direction.Down:
                    bullet.Position = new Rectangle(new Point(tank.Position.Left + (tank.Size / 2) - (bullet.Size / 2), tank.Position.Bottom + 1), new Size(bullet.Size, bullet.Size));
                    break;
                }
                //if(bullets.FirstOrDefault(s=>s.Parent_Id==bullet.Parent_Id)==null)
                bullets.Add(bullet);
                //if(objects.FirstOrDefault(s=>(s as IBullet)?.Parent_Id==bullet.Parent_Id)==null)
                //objects.Add(bullet);
            }
            entity.Command = EntityAction.None;
        }