Ejemplo n.º 1
0
        public Turn TryGetHumanTurn(Player player, GlInput input)//todo keyboard to input
        {
            this.RotateField(player.team);

            var keys = new Dictionary <Key, Point> {
                { Key.Left, PointDifference(this.RotatePoint(new Point(0, -1), player.team, 0), this.RotatePoint(new Point(0, 0), player.team, 0)) },
                { Key.Right, PointDifference(this.RotatePoint(new Point(0, 1), player.team, 0), this.RotatePoint(new Point(0, 0), player.team, 0)) },
                { Key.Up, PointDifference(this.RotatePoint(new Point(-1, 0), player.team, 0), this.RotatePoint(new Point(0, 0), player.team, 0)) },
                { Key.Down, PointDifference(this.RotatePoint(new Point(1, 0), player.team, 0), this.RotatePoint(new Point(0, 0), player.team, 0)) }
            };

            if (player.humanSelectsDestination)
            {
                if (input.KeyTime(Key.Enter) == 1)
                {
                    player.humanSelectsDestination = false;
                    if (GetAllPossibleDestinations(this.field, player.humanSource).Contains(player.humanDestination))
                    {
                        return(new Turn
                        {
                            firstValidCommand =
                                Tuple.Create(player.humanSource, player.humanDestination)
                            ,
                            colorOnTimeLine = player.color,
                            colorStatusOnTimeLine = Color.Red,
                            nameOnTimeLine = (this.roundNumber / 4).ToString(),
                            shortStatus = "Ручной ход"
                        });
                    }
                }
                foreach (var item in keys)
                {
                    if (input.KeyTime(item.Key) == 1)
                    {
                        var aim = player.humanDestination;
                        aim.Offset(item.Value);
                        if (Val(aim))
                        {
                            player.humanDestination = aim;
                        }
                    }
                }
            }
            else
            {
                if (input.KeyTime(Key.Enter) == 1)
                {
                    player.humanSelectsDestination = true;
                    player.humanDestination        = player.humanSource;
                }
                foreach (var item in keys)
                {
                    if (input.KeyTime(item.Key) == 1)
                    {
                        var aim = player.humanSource;
                        aim.Offset(item.Value);
                        if (Val(aim))
                        {
                            player.humanSource = aim;
                        }
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        public void DrawAll(Frame frame, double stage, double totalStage, bool humanMove, GlInput input) //todo human move??
        {
            if (allColors.Count == 0)
            {
                for (int i = 0; i <= 3; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        for (int k = 0; k < 4; k++)
                        {
                            allColors.Add(Color.FromArgb(i * 85, j * 85, k * 85));
                        }
                    }
                }
            }
            if (Debugger.IsAttached)
            {
                if (input.KeyTime(Key.Z) == 1)
                {
                    currentFieldColor = RandomColor();
                }
                if (input.KeyTime(Key.X) == 1)
                {
                    currentFieldOpacity += 0.1;
                    if (currentFieldOpacity > 1)
                    {
                        currentFieldOpacity = 0.5;
                    }
                }
                if (input.KeyTime(Key.C) == 1)
                {
                    topColorIndex++;
                    if (topColorIndex >= topColorList.Count)
                    {
                        topColorIndex = 0;
                    }
                    currentFieldColor = topColorList[topColorIndex];
                }
                if (input.KeyTime(Key.V) == 1)
                {
                    blackOpacity += 10;
                    if (blackOpacity >= 250)
                    {
                        blackOpacity = 40;
                    }
                }
                if (input.KeyTime(Key.B) == 1)
                {
                    blackOpacity = 0;
                    allColorIndex++;
                    if (allColorIndex >= allColors.Count)
                    {
                        allColorIndex = 0;
                    }
                    currentFieldColor = allColors[allColorIndex];
                }
            }

            // topColorIndex = 6;
            // currentFieldColor = topColorList[topColorIndex];
            blackOpacity        = 170;
            currentFieldOpacity = 0.90;

            //!!! будьте внимательны (ранний drawall перед любыми методами)
            int frameWidth = 112, frameHeight = 84;

            frame.CameraViewport(frameWidth, frameHeight);

            frame.Polygon(currentFieldColor, new Rect2d(0, 0, frameWidth, frameHeight)); //todo line around polygon

            var fieldCorner = new Vector2d((frameWidth - _arena.size.X - FrameworkSettings.Timeline.TileWidth) / 2, (frameHeight - _arena.size.Y) / 2);
            var lineWidth   = 0.4;

            //frame.Path(Color.Black, lineWidth, _arena + fieldCorner);
            //frame.Path(Color.Black, lineWidth, fieldCorner + new Vector2d(_arena.size.X / 2, 0), fieldCorner + new Vector2d(_arena.size.X / 2, _arena.size.Y));


            frame.SpriteCorner(ESprite.fieldPerfect, fieldCorner, sizeExact: _arena.size, opacity: currentFieldOpacity, depth: 1);
            // if (_manAnimators.Count != 0) //т е еще не было process turn
            //  {


            var blackColor = Color.FromArgb(blackOpacity, 0, 0, 0);

            frame.Polygon(blackColor, new Rect2d(0, 0, 1000, fieldCorner.Y));
            frame.Polygon(blackColor, new Rect2d(0, fieldCorner.Y, fieldCorner.X, _arena.size.Y));
            frame.Polygon(blackColor, new Rect2d(fieldCorner.X + _arena.size.X, fieldCorner.Y, 1000, _arena.size.Y));
            frame.Polygon(blackColor, new Rect2d(0, fieldCorner.Y + _arena.size.Y, 1000, 1000));


            for (int i = 0; i < _manList.Count; i++)
            {
                var man = _manList[i];
                if (i < 5)
                {
                    frame.SpriteCenter(ESprite.man03, _manAnimators[i].Get(stage) + fieldCorner, sizeOnlyWidth: 4, depth: 2, opacity: 1.0);
                }
                else
                {
                    frame.SpriteCenter(ESprite.man04, _manAnimators[i].Get(stage) + fieldCorner, sizeOnlyWidth: 4, depth: 2);
                }
                //frame.Circle(man.Color, _manAnimators[i].Get(stage) + fieldCorner, _manRadius);

                frame.TextCenter(EFont.playerNumbers, (i % 5).ToString(), _manAnimators[i].Get(stage) + fieldCorner, depth: 3);
            }

            //   var curMan = _manAnimators[6].Get(stage);



            //frame.Circle(Color.Gray, _ballAnimator.Get(stage) + fieldCorner, _ballRadius);
            if (_drawBall)
            {
                frame.SpriteCenter(ESprite.ball, _ballAnimator.Get(stage) + fieldCorner, sizeOnlyWidth: 2, depth: 2);
            }

            // }

            frame.TextBottomLeft(EFont.TeamOne, players[0].name, fieldCorner.X, fieldCorner.Y - 3); //todo framework text without declaration?
            frame.TextCustomAnchor(EFont.TeamTwo, players[1].name, 1, 1, fieldCorner.X + _arena.size.X, fieldCorner.Y - 3);

            frame.TextCustomAnchor(EFont.ScoreOne, players[0].score.ToString(), 1, 1, fieldCorner.X + _arena.size.X / 2 - 5, fieldCorner.Y - 3);
            frame.TextBottomLeft(EFont.ScoreTwo, players[1].score.ToString(), fieldCorner.X + _arena.size.X / 2 + 5, fieldCorner.Y - 3); //todo framework text without declaration?


            //frame.TextCustomAnchor(EFont.Time, roundNumber.ToString(), 0.5, 1, fieldCorner.X + _arena.size.X / 2, fieldCorner.Y - 3);


            if (GeomHelper.PointInSimpleRect(input.Mouse, _arena + fieldCorner))
            {
                var coord = input.Mouse - fieldCorner;
                var str   = string.Format("{0}  {1}", coord.X.Rounded(3), coord.Y.Rounded(3));
                frame.TextCustomAnchor(EFont.CoordsOnField, str, 0.5, 1, input.Mouse - Vector2d.UnitY * 1.5, depth: 101);
            }

            //  frame.SpriteCenter(ESprite.green, 100, 80, depth:1, sizeOnlyWidth:4);

            if (Debugger.IsAttached)
            {
                if (input.LeftMouseUp)
                {
                    var position = input.Mouse - fieldCorner;
                    if (GeomHelper.PointInSimpleRect(position, _arena))
                    {
                        _explosionStartedRound = roundNumber + 1;
                        explosionPosition      = position;
                    }
                }
            }

            if (roundNumber - _explosionStartedRound <= 2 && roundNumber >= _explosionStartedRound)
            {
                try
                {
                    frame.SpriteCenter(ESprite.explosion, explosionPosition + fieldCorner, sizeExact: new Vector2d(30), frameNumber:
                                       (int)((roundNumber - _explosionStartedRound) * 10 + stage * 10).ToRange(0, 30));
                }


                catch
                {
                }
            }

            if (_lastGoalRoundNumber != -1 && roundNumber - _lastGoalRoundNumber < _PARTY_AFTER_GOAL_TIME && roundNumber != _lastGoalRoundNumber)
            {
                frame.TextCenter(EFont.Goal, "ГОЛ !!!", fieldCorner + _arena.center, depth: 100000);
            }

            if (players.Sum(x => x.possession) > 0)
            {
                var pos = players[0].possession * 1.0 / players.Sum(x => x.possession);

                var one = (int)Math.Round(pos * 10000);
                var two = 10000 - one;

                double horsz = 0.6;
                var    rect  = new Rect2d(fieldCorner.X - horsz / 2, fieldCorner.Y + _arena.size.Y + 5.7, horsz, 2);

                frame.PolygonWithDepth(Color.FromArgb(150, 150, 150), 10, new Rect2d(fieldCorner.X, fieldCorner.Y + _arena.size.Y + 6.4, _arena.size.X, 0.6));
                frame.PolygonWithDepth(Color.FromArgb(150, 150, 150), 10, rect + Vector2d.UnitX * _arena.size.X * pos);

                //  if (this.GameFinished)
                {
                    frame.TextTopLeft(EFont.Possession, one.ToString(), fieldCorner.X, fieldCorner.Y + _arena.size.Y + 8, depth: 21);
                    frame.TextCustomAnchor(EFont.Possession, two.ToString(), 1, 0, fieldCorner.X + _arena.size.X, fieldCorner.Y + _arena.size.Y + 8, depth: 21);
                }
            }
        }