Exemplo n.º 1
0
 public override void _ExitTree()
 {
     MainEvent.UnregisterListener(UIEventFired);
     UnitDeathEvent.UnregisterListener(EndGame);
     WinEvent.UnregisterListener(WinTriggered);
     LoseEvent.UnregisterListener(LostTriggered);
 }
Exemplo n.º 2
0
 private void LostTriggered(LoseEvent loseEvent)
 {
     enemySpawner.QueueFree();
     crystal.QueueFree();
     player.QueueFree();
     map.QueueFree();
 }
Exemplo n.º 3
0
 private void OnLose()
 {
     if (LoseEvent != null)
     {
         LoseEvent.Invoke();
     }
 }
Exemplo n.º 4
0
 private void OnCook(ESide side, float value)
 {
     if (value > CurrentRecipe.MaxFry)
     {
         LoseEvent?.Invoke();
     }
 }
Exemplo n.º 5
0
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        UnitDeathEvent.RegisterListener(UnitDeath);
        WinEvent.RegisterListener(WinTriggered);
        LoseEvent.RegisterListener(LoseTriggered);

        //Grab all the references for the scenes
        menuPanel    = GetNode <Node2D>("Menu");
        winPanel     = GetNode <Node2D>("Win");
        losePanel    = GetNode <Node2D>("Lose");
        creditsPanel = GetNode <Node2D>("Credits");
        uiPanel      = GetNode <Node2D>("UI");
        background   = GetNode <Sprite>("Background");


        //Grab a refference to all the buttons that we have
        startBtn     = GetNode <Button>("Start");
        exitBtn      = GetNode <Button>("Exit");
        menuBtn      = GetNode <Button>("Menubtn");
        smallExitBtn = GetNode <Button>("SmallExit");
        creditsBtn   = GetNode <Button>("Creditsbtn");

        //The buttons for the menu
        startBtn.Connect("pressed", this, nameof(ShowUI));
        exitBtn.Connect("pressed", this, nameof(ExitGame));
        menuBtn.Connect("pressed", this, nameof(ShowMenu));
        smallExitBtn.Connect("pressed", this, nameof(ExitGame));
        creditsBtn.Connect("pressed", this, nameof(ShowCredits));

        //Hide all the scenes at start up
        HideAll();
        ShowMenu();
    }
Exemplo n.º 6
0
 private void EndGame(UnitDeathEvent ude)
 {
     if (ude.UnitNode.IsInGroup("Player"))
     {
         enemySpawner.QueueFree();
         crystal.QueueFree();
         player.QueueFree();
         map.QueueFree();
     }
     if (ude.UnitNode.Name == "Crystal")
     {
         LoseEvent lei = new LoseEvent();
         lei.lost = true;
         lei.FireEvent();
     }
 }
Exemplo n.º 7
0
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        //Grabs the map scene from the Scene tree on the games start up
        mapScene           = ResourceLoader.Load("res://Scenes/Map.tscn") as PackedScene;
        playerScene        = ResourceLoader.Load("res://Scenes/Player.tscn") as PackedScene;
        crystalScene       = ResourceLoader.Load("res://Scenes/Crystal.tscn") as PackedScene;
        enemySpawnerScene  = ResourceLoader.Load("res://Scenes/EnemySpawner.tscn") as PackedScene;
        UIScene            = ResourceLoader.Load("res://Scenes/UI.tscn") as PackedScene;
        missilePickupScene = ResourceLoader.Load("res://Scenes/MissilePickup.tscn") as PackedScene;
        MainEvent.RegisterListener(UIEventFired);
        UnitDeathEvent.RegisterListener(EndGame);
        WinEvent.RegisterListener(WinTriggered);
        LoseEvent.RegisterListener(LostTriggered);

        ui      = UIScene.Instance();
        ui.Name = "UI";
        AddChild(ui);
    }
Exemplo n.º 8
0
 /// <summary>
 /// Вызывается при получении с сервера сообщения о проигрыше (закончились очки здоровья)
 /// </summary>
 public void Lose(int result)
 {
     LoseEvent?.Invoke(this, new LoseEventArgs(result));
 }
Exemplo n.º 9
0
 private void OnLose(Dice dice, string ret)
 {
     LoseEvent?.Invoke(this, ret);
 }
Exemplo n.º 10
0
        /// <summary>
        /// Ход пиратов
        /// </summary>
        /// <returns>Новое положение пиратов</returns>
        public Position PirateGo()
        {
            //Если : пираты уже на границе поля - поражение
            if (_PirateLocation[0] == 0 || _PirateLocation[0] == 21 || _PirateLocation[1] == 0 || _PirateLocation[1] == 15)
            {
                LoseEvent.Invoke(this, new EventArgs());
                return(null);
            }

            //Рейтинг выбора движения для пиратов
            //[0] - северо-запад
            //[1] - северо-восток
            //[2] - юго-восток
            //[3] - юго-запад
            var rating = new int[] { 10000, 10000, 10000, 10000 };

            //Определение разрешенных направлений
            for (var i = 0; i < 4; i++)
            {
                var address = GetNewPosition(_PirateLocation, (Direction)i);
                //Если : путь кораблю в соответствующем направлении закрыт - туда не ходим
                if (_Plane[address[0]][address[1]].Status == StatusPoint.Mine)
                {
                    rating[i] = -10000;
                }
            }

            //Проверка зажат-ли кораблик минами
            if (rating[0] == -10000 && rating[1] == -10000 && rating[2] == -10000 && rating[3] == -10000)
            {
                WinEvent.Invoke(this, new EventArgs());
                return(null);
            }


            #region Определение рейтинга ближайшего пути:

            //Каждая сторона света убавляет рейтинга по дальности до границы напрямую
            rating[0] -= _BalanceCurse * (_PirateLocation[1]); rating[1] -= _BalanceCurse * (_PirateLocation[1]);
            rating[1] -= _BalanceCurse * (21 - _PirateLocation[0]); rating[2] -= _BalanceCurse * (21 - _PirateLocation[0]);
            rating[2] -= _BalanceCurse * (15 - _PirateLocation[1]); rating[3] -= _BalanceCurse * (15 - _PirateLocation[1]);
            rating[3] -= _BalanceCurse * (_PirateLocation[0]); rating[0] -= _BalanceCurse * (_PirateLocation[0]);

            #endregion

            #region  Определение рейтинга опасности:

            //Каждая мина на прямой и по сторонам от главного курса уменьшает рейтинг пути
            for (var i = 0; i < 4; i++)
            {
                var   tick    = 0;
                int[] address = _PirateLocation;
                int[] temp    = null;

                //Ведем подсчет, пока не достигнем конца курса
                while (true)
                {
                    //Получаем первое смещение по курсу
                    address = GetNewPosition(address, (Direction)i);

                    //Если : уперлись в границу карты - выход
                    if (address == null)
                    {
                        break;
                    }

                    //Каждая мина изменяет рейтинг пути
                    if (_Plane[address[0]][address[1]].Status == StatusPoint.Mine)
                    {
                        tick++;
                    }

                    //Учитываем мину при повороте курса против часовой стрелки
                    temp = GetNewPosition(address, RollCourse(i - 1));
                    if (temp != null && _Plane[temp[0]][temp[1]].Status == StatusPoint.Mine)
                    {
                        tick++;
                    }
                    //Учитываем мину при повороте курса по часовой стрелке
                    temp = GetNewPosition(address, RollCourse(i + 1));
                    if (temp != null && _Plane[temp[0]][temp[1]].Status == StatusPoint.Mine)
                    {
                        tick++;
                    }
                }

                rating[i] -= _BalanceMines * tick;
            }

            #endregion

            #region Определение рейтинга вариативности:

            //Кол-во вариантов выбора пути после совершения хода
            for (var i = 0; i < 4; i++)
            {
                var   tick    = 0;
                var   address = GetNewPosition(_PirateLocation, (Direction)i);
                int[] temp    = null;

                for (var j = 0; j < 4; j++)
                {
                    temp = GetNewPosition(address, (Direction)j);
                    if (temp != null && _Plane[temp[0]][temp[1]].Status == StatusPoint.Mine)
                    {
                        tick++;
                    }
                }

                rating[i] -= _BalanceVariables * tick;
            }

            #endregion

            var dic = new Dictionary <int, int>(4);
            for (var i = 0; i < 4; i++)
            {
                dic.Add(i, rating[i]);
            }

            //Смена локации корабля
            _Plane[_PirateLocation[0]][_PirateLocation[1]].Status = StatusPoint.Empty;

            _PirateLocation = GetNewPosition(_PirateLocation, (Direction)GetTopCurse(dic, GetTopCurse(dic, 0, 1), GetTopCurse(dic, 2, 3)));

            _Plane[_PirateLocation[0]][_PirateLocation[1]].Status = StatusPoint.Ship;
            return(_Plane[_PirateLocation[0]][_PirateLocation[1]]);
        }
Exemplo n.º 11
0
 public override void _ExitTree()
 {
     UnitDeathEvent.UnregisterListener(UnitDeath);
     WinEvent.UnregisterListener(WinTriggered);
     LoseEvent.UnregisterListener(LoseTriggered);
 }
Exemplo n.º 12
0
 private void LoseTriggered(LoseEvent le)
 {
     ShowLose();
 }
 /// <summary>
 /// Окончание игры
 /// </summary>
 public void Stop()
 {
     timer.Change(Timeout.Infinite, 0);
     LoseEvent?.Invoke(this, new LoseEventArgs(result));
 }
Exemplo n.º 14
0
 private void OnCastleDestroy()
 {
     StopGame();
     LoseEvent?.Invoke();
 }