Esempio n. 1
0
    public void Play(PlayerController player, int slot)
    {
        int teamIndex;

        if (IsGameOver)
        {
            teamIndex = this.players.IndexOf(player.UserId) % 2;
            PlaceMarker(teamIndex, slot - 1); // the troll is on you now
            return;
        }

        if (!this.players.Contains(player.UserId))
        {
            this.players.Add(player.UserId);
            state     = TavernGameState.Playing;
            teamIndex = this.players.IndexOf(player.UserId) % 2;
            gameManager.RavenBot.SendMessage(player.Name, Localization.MSG_TICTACTOE_JOINED, teamNames[teamIndex]);
            UpdateTeamListing();
        }
        else
        {
            teamIndex = this.players.IndexOf(player.UserId) % 2;
            UpdateTeamListing();
        }

        if (IsGameOver || playerTurn != teamIndex)
        {
            var errMessage = IsGameOver
                ? Localization.MSG_TICTACTOE_REJECT_GAMEOVER
                : Localization.MSG_TICTACTOE_REJECT_TURN;

            RejectPlay(player, errMessage);
            return;
        }

        var i = slot - 1;

        if (i < 0 || i > Grid.Length)
        {
            var errMessage = Localization.MSG_TICTACTOE_REJECT_NUMBER;
            RejectPlay(player, errMessage);
            return;
        }

        if (Grid[i] != 0)
        {
            var errMessage = Localization.MSG_TICTACTOE_REJECT_PLAYED;
            RejectPlay(player, errMessage);
            return;
        }

        PlaceMarker(teamIndex, i);

        UpdateTeamListing();

        if (CheckForWin(Grid, out var winner))
        {
            EndGame(winner);
        }
    }
Esempio n. 2
0
    public void ResetGame()
    {
        var toDelete = new List <GameObject>();

        for (var i = 0; i < GameObjects.childCount; ++i)
        {
            toDelete.Add(GameObjects.GetChild(i).transform.gameObject);
        }

        foreach (var delete in toDelete)
        {
            DestroyImmediate(delete);
        }

        for (var i = 0; i < 9; ++i)
        {
            this.Grid[i] = 0;
        }

        this.players.Clear();
        this.playerTurn    = 0;
        this.state         = TavernGameState.None;
        this.helpText.text = "!tictactoe\r\n" + infoTextColor + infoTextSize + "START GAME";
        UpdateLeaderBoard();
        //this.RedTeamWins.SetActive(false);
        //this.BlueTeamWins.SetActive(false);
        //this.NoTeamWins.SetActive(false);
        //this.ResetText.SetActive(false);
    }
Esempio n. 3
0
    public void Activate()
    {
        this.state         = TavernGameState.WaitingForPlayers;
        this.helpText.text = "!tictactoe 1-9\r\n" + infoTextColor + infoTextSize + "JOIN AND PLAY";

        var ioc = gameManager.gameObject.GetComponent <IoCContainer>();
        var evt = ioc.Resolve <EventTriggerSystem>();

        evt.TriggerEvent("ttt", TimeSpan.FromSeconds(1));
    }
Esempio n. 4
0
    private void EndGame(int result)
    {
        if (result == 0)
        {
            gameManager.RavenBot.Announce(Localization.MSG_TICTACTOE_END_DRAW);
        }
        else
        {
            var winningTeam = teamNames[result - 1];
            gameManager.RavenBot.Announce(Localization.MSG_TICTACTOE_WIN, winningTeam);
            RewardWinningTeam(result - 1);
        }

        UpdateWinBoard(result);

        this.state         = TavernGameState.GameOver;
        this.helpText.text = "!tictactoe reset\r\n" + infoTextColor + infoTextSize + "END GAME";
    }