Ejemplo n.º 1
0
    public void Win(Player player)
    {
        PlayerHolder.GetInstance().ToggleToWin();

        _won = true;

        _players.ForEach(p => { p.Stop(); });

        playerIntroduction.gameObject.SetActive(false);
        remainingFields.gameObject.SetActive(false);
        zoomPanel.SetActive(false);
        walkInfo.SetActive(false);
        heartImages.ToList().ForEach(image => image.gameObject.SetActive(false));

        winInfo.text = winInfo.text
                       .Replace("{{prefix}}", player.IsBot() ? "Bot" : "Player")
                       .Replace("{{id}}", player.GetPublicId().ToString());

        winInfo.gameObject.SetActive(true);

        followingCamera.SetTarget(player.transform);
        followingCamera.RotateAround();

        var firework = Resources.Load <GameObject>("Firework");

        foreach (var spawner in fireworkSpawner)
        {
            var instance = Instantiate(firework);
            instance.transform.position = spawner.position;
        }

        pressSpace.SetActive(false);
        infoRestart.SetActive(true);
    }
Ejemplo n.º 2
0
    private void Awake()
    {
        Instance = this;

        var names  = NameEngine.GetNames(4);
        var amount = PlayerHolder.GetInstance().GetPlayerAmount();

        _players.AddRange(new[]
        {
            SpawnPlayer(names[0], 1),
            SpawnPlayer(names[1], 2, amount < 2),
            SpawnPlayer(names[2], 3, amount < 3),
            SpawnPlayer(names[3], 4, amount < 4)
        });

        var position = startField.transform.position;

        _players[0].transform.position = position + startField.GetOffset(1);
        _players[1].transform.position = position + startField.GetOffset(2);
        _players[2].transform.position = position + startField.GetOffset(3);
        _players[3].transform.position = position + startField.GetOffset(4);

        RenderInfoPanel();

        StartTurn();
    }
Ejemplo n.º 3
0
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.P))
        {
            _paused = !_paused;

            pause.SetActive(_paused);
            Time.timeScale = _paused ? 0f : 1f;
        }

        if (infoRestart.activeSelf && Input.GetKeyDown(KeyCode.Return))
        {
            PlayerHolder.GetInstance().ToggleToDefault();
            SceneManager.LoadScene("Game");
        }

        if (_won)
        {
            return;
        }

        if (_waitTimer > 0f)
        {
            _waitTimer -= Time.deltaTime;
            return;
        }

        skipInfo.SetActive(false);
        rollAgainInfo.SetActive(false);

        if (_startTurnAfterWait)
        {
            _moving       = false;
            _inProgress   = false;
            _diceFinished = false;

            Destroy(_dice);
            if (_dice2)
            {
                Destroy(_dice2);
            }

            _activePlayer++;
            if (_activePlayer >= _players.Count)
            {
                _activePlayer = 0;
            }

            StartTurn();

            _startTurnAfterWait = false;

            return;
        }

        if (_won)
        {
            return;
        }

        var player = _players[_activePlayer];

        if (!_inProgress)
        {
            if (player.IsBot())
            {
                _botTimer -= Time.deltaTime;
            }

            if (player.ShouldSkip())
            {
                player.Skipped();
                skipInfo.SetActive(true);
                pressSpace.SetActive(false);
                Wait(2f);

                return;
            }

            if (Input.GetKeyDown(KeyCode.Space) || (player.IsBot() && _botTimer <= 0f))
            {
                clicker.Play();
                pressSpace.SetActive(false);
                StartNewTurn();
            }

            return;
        }

        if (_inProgress && !_diceFinished)
        {
            return;
        }

        if (_moving)
        {
            return;
        }

        _moving = true;

        player.SetField(player.GetField().GetNext());
        player.RegisterMovementFinishedCallback(() => { HandleFinishedMovement(player); });
    }
Ejemplo n.º 4
0
 public void StartGame()
 {
     PlayerHolder.GetInstance().SetPlayerAmount((int)playerSlider.value);
     SceneManager.LoadScene("Game");
 }