Exemplo n.º 1
0
        private void OpenDialog(Point cellClicked, Point screenPosition)
        {
            game.GameState = MizJam1Game.GameStates.OpenDialog;
            dialog         = new UIMenu(screenPosition, new Point(500, 500), true)
            {
                SpaceBetweenChildren = 5,
                Vertical             = true
            };
            Unit enemy;

            bool attackDirectly = false;

            if ((enemy = GetUnit(cellClicked)) != null && enemy.Enemy)
            {
                UIImage              attack               = new UIImage(game.Dialogs[MizJam1Game.Actions.Attack], game.SelectedDialogs[MizJam1Game.Actions.Attack]);
                Point                moveTarget           = threatenedPositions[cellClicked].From;
                MoveUnitCommand      moveUnit             = new MoveUnitCommand(this, SelectedUnit.Position, moveTarget);
                MoveAndAttackCommand moveAndAttackCommand = new MoveAndAttackCommand(moveUnit, this, SelectedUnit, enemy);
                attack.AddCommand(moveAndAttackCommand);
                dialog.AddChild(attack);
                attackDirectly = true;
            }

            if (!attackDirectly)
            {
                foreach (var threat in threatenedPositions)
                {
                    if ((enemy = GetUnit(threat.Key)) != null && enemy.Enemy)
                    {
                        UIImage             attackSelect        = new UIImage(game.Dialogs[MizJam1Game.Actions.Attack], game.SelectedDialogs[MizJam1Game.Actions.Attack]);
                        SelectAttackCommand selectAttackCommand = new SelectAttackCommand(this);
                        attackSelect.AddCommand(selectAttackCommand);
                        dialog.AddChild(attackSelect);
                        break;
                    }
                }
            }

            if (cellClicked == SelectedUnit.Position)
            {
                UIImage       defend        = new UIImage(game.Dialogs[MizJam1Game.Actions.Defend], game.SelectedDialogs[MizJam1Game.Actions.Defend]);
                DefendCommand defendCommand = new DefendCommand(this, SelectedUnit.Position);
                defend.AddCommand(defendCommand);
                dialog.AddChild(defend);
            }
            MoveUnitCommand moveCommand = null;

            if (canGoPositions.Contains(cellClicked))
            {
                UIImage move = new UIImage(game.Dialogs[MizJam1Game.Actions.Move], game.SelectedDialogs[MizJam1Game.Actions.Move]);
                moveCommand = new MoveUnitCommand(this, SelectedUnit.Position, cellClicked);
                move.AddCommand(moveCommand);
                dialog.AddChild(move);
                canGoPositions = new HashSet <Point>()
                {
                    cellClicked
                };
            }

            if (!attackDirectly)
            {
                UIImage reroll = new UIImage(game.Dialogs[MizJam1Game.Actions.Reroll], game.SelectedDialogs[MizJam1Game.Actions.Reroll]);
                if (moveCommand == null)
                {
                    moveCommand = new MoveUnitCommand(this, SelectedUnit.Position, SelectedUnit.Position);
                }
                ICommand rerollCommand = new MoveAndRerollCommand(moveCommand, this, SelectedUnit);
                reroll.AddCommand(rerollCommand);
                dialog.AddChild(reroll);
            }

            if (cellClicked == SelectedUnit.Position)
            {
                UIImage     wait        = new UIImage(game.Dialogs[MizJam1Game.Actions.Wait], game.SelectedDialogs[MizJam1Game.Actions.Wait]);
                WaitCommand waitCommand = new WaitCommand(this, cellClicked);
                wait.AddCommand(waitCommand);
                dialog.AddChild(wait);
            }

            UIImage  cancel        = new UIImage(game.Dialogs[MizJam1Game.Actions.Cancel], game.SelectedDialogs[MizJam1Game.Actions.Cancel]);
            ICommand cancelCommand = new CancelCommand(this);

            cancel.AddCommand(cancelCommand);
            dialog.AddChild(cancel);

            dialog.SetScale(3);

            if (dialog.Position.X + dialog.Size.X > 1500)
            {
                dialog.Position = new Point(screenPosition.X - dialog.Size.X, dialog.Position.Y);
            }
            if (dialog.Position.Y + dialog.Size.Y > 1080)
            {
                dialog.Position = new Point(dialog.Position.X, screenPosition.Y - dialog.Size.Y);
            }
        }