示例#1
0
    // End playing defense cards
    private void EndDefend()
    {
        // update the server
        Debug.Log("defend JSON");
        Debug.Log(JsonUtility.ToJson(defendRequest));
        RESTTemplate.AsyncPOST(SERVER_NAME + DEFEND_REQUEST, JsonUtility.ToJson(defendRequest));

        // play attack animation
        new AttackCommand(opponentArea, playerArea, gameView.attackView.user, gameView.attackView.targets[0]).AddToQueue();
        opponentArea.monsterVisual.turnOffAllHighlights();

        // reset defend request
        defendRequest.cardAndTargets = new List <DefendTarget>();
    }
示例#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
    // 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();
        }
    }
示例#4
0
    // Attack
    public void MakeAttack()
    {
        // disable button
        playerArea.button.GetComponent <Button>().interactable = false;

        // update the server
        Debug.Log(JsonUtility.ToJson(attackRequest));
        RESTTemplate.AsyncPOST(SERVER_NAME + ATTACK_REQUEST, JsonUtility.ToJson(attackRequest));

        // draw targeting arrow
        foreach (int targetIndex in attackRequest.targets)
        {
            new DrawArrowCommand(playerArea, opponentArea, attackRequest.user, targetIndex).AddToQueue();
        }

        // reset played cards
        playableRequest.playedCardIndexes = new List <int>();
    }
示例#5
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));
    }
示例#6
0
 // End playing attack cards
 private void EndAttack()
 {
     // update server
     Debug.Log(JsonUtility.ToJson(playersRequest));
     RESTTemplate.AsyncPOST(SERVER_NAME + END_ATTACK_REQUEST, JsonUtility.ToJson(playersRequest));
 }
示例#7
0
 // Convert played cards to guts
 private void MakeGuts()
 {
     // update the server
     gutsRequest.discards = playableRequest.playedCardIndexes;
     RESTTemplate.AsyncPOST(SERVER_NAME + GUTS_REQUEST, JsonUtility.ToJson(gutsRequest));
 }