Пример #1
0
 public void AddTank(Player player, AbstractTank.Type tankType, int x, int y, Texture.Rotation rotation)
 {
     switch (tankType)
     {
         case AbstractTank.Type.PlayerNormal:
             tanks.Add(new NormalTank(player, x, y, rotation));
             break;
         case AbstractTank.Type.PlayerFast:
             tanks.Add(new FastTank(player, x, y, rotation));
             break;
     }
 }
Пример #2
0
 public void DrawTank(int x, int y, AbstractTank.Type type, Texture.Rotation rotation)
 {
     switch (type)
     {
         case AbstractTank.Type.PlayerNormal:
             DrawTexture(x, y, tankTextureList[0], rotation);
             //DrawTank(x, y, 0);
             break;
         case AbstractTank.Type.PlayerFast:
             break;
     }
 }
Пример #3
0
 private PointF TankPositionOnMap(AbstractTank tank)
 {
     return new PointF((tank.X + windowWidth / 2) / ElementWidth,
                       (tank.Y - windowHeight / 2) / ElementHeight * -1);
 }
Пример #4
0
        private List<MapObject.Types> NextMapObjects(Level level, AbstractTank tank, Texture.Rotation rotation)
        {
            PointF tankPositionOnMap = TankPositionOnMap(tank);
            List<MapObject.Types> objects = new List<MapObject.Types>();

            switch (rotation)
            {
                case Texture.Rotation.Top:
                    if (((int)(tankPositionOnMap.Y)).Equals(0))
                    {
                        return new List<MapObject.Types> { MapObject.Types.TEMPORARY };
                    }
                    objects.Add(level.MapInstance[(int)tankPositionOnMap.Y - 1][(int)tankPositionOnMap.X].Type);//get current tank pos MapObject
                    if (tankPositionOnMap.X - ((int)tankPositionOnMap.X) > 0)//if tank is on two MapObjects
                    {
                        objects.Add(level.MapInstance[(int)tankPositionOnMap.Y - 1][(int)tankPositionOnMap.X + 1].Type);
                    }
                    break;
                case Texture.Rotation.Bottom:
                    if (((int)(tankPositionOnMap.Y)).Equals(19))
                    {
                        return new List<MapObject.Types> { MapObject.Types.TEMPORARY };
                    }
                    objects.Add(level.MapInstance[(int)tankPositionOnMap.Y + 1][(int)tankPositionOnMap.X].Type);
                    if (tankPositionOnMap.X - ((int)tankPositionOnMap.X) > 0)
                    {
                        objects.Add(level.MapInstance[(int)tankPositionOnMap.Y + 1][(int)tankPositionOnMap.X + 1].Type);
                    }
                    break;
                case Texture.Rotation.Right:
                    if (((int)(tankPositionOnMap.X)).Equals(18))
                    {
                        return new List<MapObject.Types> { MapObject.Types.TEMPORARY };
                    }
                    objects.Add(level.MapInstance[(int)tankPositionOnMap.Y][(int)tankPositionOnMap.X + 1].Type);
                    if (tankPositionOnMap.Y - ((int)tankPositionOnMap.Y) > 0)
                    {
                        objects.Add(level.MapInstance[(int)tankPositionOnMap.Y + 1][(int)tankPositionOnMap.X + 1].Type);
                    }
                    break;
                case Texture.Rotation.Left:
                    if (((int)(tankPositionOnMap.X)).Equals(0))
                    {
                        return new List<MapObject.Types> { MapObject.Types.TEMPORARY };
                    }
                    objects.Add(level.MapInstance[(int)tankPositionOnMap.Y][(int)tankPositionOnMap.X - 1].Type);
                    if (tankPositionOnMap.Y - ((int)tankPositionOnMap.Y) > 0)
                    {
                        objects.Add(level.MapInstance[(int)tankPositionOnMap.Y + 1][(int)tankPositionOnMap.X - 1].Type);
                    }
                    break;
            }
            return objects;
        }
Пример #5
0
        private List<MapObject.Types> CurrentMapObjects(Level level, AbstractTank tank, Texture.Rotation rotation)
        {
            PointF tankPositionOnMap = TankPositionOnMap(tank);
            float fX = (float)Math.Round(tankPositionOnMap.X, 0), fY = (float)Math.Round(tankPositionOnMap.Y, 0);
            List<MapObject.Types> objects = new List<MapObject.Types>();

            switch (rotation)
            {
                case Texture.Rotation.Top:
                    objects.Add(level.MapInstance[(int)tankPositionOnMap.Y][(int)tankPositionOnMap.X].Type);
                    if (!tank.Y.Equals((int) (windowHeight/2 - fY*elementHeight)) &&
                        tankPositionOnMap.X - ((int)tankPositionOnMap.X) > 0)
                    {
                        objects.Add(level.MapInstance[(int) tankPositionOnMap.Y][(int) tankPositionOnMap.X + 1].Type);
                    }
                    break;
                case Texture.Rotation.Bottom:
                    objects.Add(level.MapInstance[(int)tankPositionOnMap.Y][(int)tankPositionOnMap.X].Type);
                    if (!(tank.Y - ElementHeight).Equals((int) (windowHeight/2 - (fY + 1)*elementHeight)) &&
                        tankPositionOnMap.X - ((int) tankPositionOnMap.X) > 0)
                    {
                        objects.Add(level.MapInstance[(int) tankPositionOnMap.Y][(int) tankPositionOnMap.X + 1].Type);
                    }
                    break;
                case Texture.Rotation.Right:
                    objects.Add(level.MapInstance[(int)tankPositionOnMap.Y][(int)tankPositionOnMap.X].Type);
                    if (!(tank.X + elementWidth).Equals((int) (-windowWidth/2 + (fX + 1)*ElementHeight)) &&
                        tankPositionOnMap.Y - ((int) tankPositionOnMap.Y) > 0)
                    {
                        objects.Add(level.MapInstance[(int) tankPositionOnMap.Y + 1][(int) tankPositionOnMap.X].Type);
                    }
                    break;
                case Texture.Rotation.Left:
                    objects.Add(level.MapInstance[(int)tankPositionOnMap.Y][(int)tankPositionOnMap.X].Type);
                    if (!tank.X.Equals((int) (-windowWidth/2 + fX*elementWidth)) &&
                        tankPositionOnMap.Y - ((int) tankPositionOnMap.Y) > 0)
                    {
                        objects.Add(level.MapInstance[(int) tankPositionOnMap.Y + 1][(int) tankPositionOnMap.X].Type);
                    }
                    break;
            }
            return objects;
        }
Пример #6
0
        public bool TankCanMove(Level level, AbstractTank tank, Texture.Rotation rotation)
        {
            PointF pos = TankPositionOnMap(tank);
            List<MapObject.Types> nextMapObjectType = NextMapObjects(level, tank, rotation);
            List<MapObject.Types> currentMapObjectType = CurrentMapObjects(level, tank, rotation);
            nextMapObjectType.RemoveAll(x => x.Equals(MapObject.Types.FOREST) || x.Equals(MapObject.Types.EMPTY));
            currentMapObjectType.RemoveAll(x => x.Equals(MapObject.Types.FOREST) || x.Equals(MapObject.Types.EMPTY));

            switch (rotation)
            {
                case Texture.Rotation.Top:
                    return windowHeight/2 - ((int) pos.Y)*elementHeight - tank.Y == 0
                               ? nextMapObjectType.Count.Equals(0)
                               : currentMapObjectType.Count.Equals(0);
                case Texture.Rotation.Bottom:
                    return windowHeight/2 - ((int) pos.Y)*elementHeight - elementHeight - tank.Y == -elementHeight
                               ? nextMapObjectType.Count.Equals(0)
                               : currentMapObjectType.Count.Equals(0);
                case Texture.Rotation.Right:
                    return -windowWidth/2 + ((int) pos.X)*elementWidth + elementWidth - tank.X == elementWidth
                               ? nextMapObjectType.Count.Equals(0)
                               : currentMapObjectType.Count.Equals(0);
                case Texture.Rotation.Left:
                    return -windowWidth/2 + ((int) pos.X)*elementWidth - tank.X == 0
                               ? nextMapObjectType.Count.Equals(0)
                               : currentMapObjectType.Count.Equals(0);
            }
            return false;
        }
Пример #7
0
 private void MoveTankRight(AbstractTank tank)
 {
 }
Пример #8
0
 private void MoveTankLeft(AbstractTank tank)
 {
 }
Пример #9
0
 private void MoveTankDown(AbstractTank tank)
 {
 }
Пример #10
0
 private void MoveTankUp(AbstractTank tank)
 {
 }