示例#1
0
    // Highlight all playable cards in hand
    public IEnumerator HighlightPlayableCards()
    {
        CoroutineWithData cd = new CoroutineWithData(this, RESTTemplate.SyncPOST(SERVER_NAME + PLAYABLE_REQUEST, JsonUtility.ToJson(playableRequest)));

        yield return(cd.coroutine);

        string resultBody = (string)cd.result;

        Debug.Log(resultBody);
        playableCardView = JsonUtility.FromJson <PlayableCardView>(resultBody);

        foreach (PlayableCard playableCard in playableCardView.playableCards)
        {
            new HighlightCommand(playerArea, playableCard.cardIndex, false).AddToQueue();
        }
    }
示例#2
0
    // Game flow including start, syncing visuals, and finish
    public IEnumerator GameFlow()
    {
        // Start the match
        CoroutineWithData cd1 = new CoroutineWithData(this, RESTTemplate.SyncPOST(SERVER_NAME + START_REQUEST, JsonUtility.ToJson(playersRequest)));

        yield return(cd1.coroutine);

        // Start syncing the match
        while (true)
        {
            CoroutineWithData cd2 = new CoroutineWithData(this, GameSync());
            yield return(cd2.coroutine);
        }

        // Finish the match?
    }
示例#3
0
    // Sync game view with the server
    public IEnumerator GameSync()
    {
        // Get the new game view
        CoroutineWithData cd = new CoroutineWithData(this, RESTTemplate.SyncPOST(SERVER_NAME + SYNC_REQUEST, JsonUtility.ToJson(playersRequest)));

        yield return(cd.coroutine);

        string   resultBody  = (string)cd.result;
        GameView newGameView = JsonUtility.FromJson <GameView>(resultBody);

        // play monsters
        PlayMonsters(opponentArea, ref gameView.opponent.monsters, newGameView.opponent.monsters);
        PlayMonsters(playerArea, ref gameView.player.monsters, newGameView.player.monsters);

        // adjust guts
        SyncGuts(opponentArea, ref gameView.opponent.gutsPool, newGameView.opponent.gutsPool);
        SyncGuts(playerArea, ref gameView.player.gutsPool, newGameView.player.gutsPool);

        // draw
        SyncHand(opponentArea, ref gameView.opponent.hand, newGameView.opponent.hand, false);
        SyncHand(playerArea, ref gameView.player.hand, newGameView.player.hand, true);

        // adjust deck size
        SyncDeck(opponentArea, ref gameView.opponent.deckSize, newGameView.opponent.deckSize);
        SyncDeck(playerArea, ref gameView.player.deckSize, newGameView.player.deckSize);

        // play opponent attack request or defend request
        SyncTable(opponentArea, playerArea,
                  ref gameView.attackView, newGameView.attackView,
                  ref gameView.defendView, newGameView.defendView,
                  ref gameView, newGameView);

        // sync monster state
        SyncMonsters(opponentArea, ref gameView.opponent.monsters, newGameView.opponent.monsters);
        SyncMonsters(playerArea, ref gameView.player.monsters, newGameView.player.monsters);

        // show game phase
        SyncPlayerAndPhase(playerArea, ref gameView.currentPlayer, newGameView.currentPlayer, ref gameView.phase, newGameView.phase);

        yield return(new WaitForSeconds(1));
    }