Exemple #1
0
    private void Start()
    {
        int playerIndex;

        for (playerIndex = 0; playerIndex < MainScreen.Players.otherPlayers.Length; playerIndex++)
        {
            if (MainScreen.Players.otherPlayers[playerIndex].player == MainScreen.ThisPlayerID)
            {
                break;
            }
        }

        int myId;

        if (index < playerIndex)
        {
            myId = index;
        }
        else
        {
            myId = index + 1;
        }

        username.text = MainScreen.Players.otherPlayers[myId].player_username;
        StartCoroutine(Network.GetTexture(MainScreen.Players.otherPlayers[myId].player_avatar,
                                          texture => avatar.sprite = texture.ToSprite(), URL.Headers()));
        foreach (var o in GameObject.FindGameObjectsWithTag("Loading"))
        {
            o.SetActive(false);
        }
    }
Exemple #2
0
    private void GetPlayers()
    {
        StartCoroutine(Network.GetRequest(URL.GetPlayers, response =>
        {
            response  = "{\"otherPlayers\":" + response + "}";
            Players   = JsonUtility.FromJson <Players>(response);
            var index = 0;
            foreach (var player in _playersScoreboard)
            {
                Debug.Log(Players.otherPlayers[index].player);
                if (Players.otherPlayers[index].player == ThisPlayerID)
                {
                    ThisPlayerPlayerColor = (PlayerColors)index;
                    _myPlayer.UpdateColor(ThisPlayerPlayerColor);
                    index++;
                }

                Players.otherPlayers[index].Color = (PlayerColors)index;
                player.InitViews(Players.otherPlayers[index]);
                index++;
            }

            UpdateTurn(22);
        }, URL.Headers()));
    }
Exemple #3
0
 public void UpdatePlayer()
 {
     StartCoroutine(Network.GetRequest(URL.Personal, response =>
     {
         var personal            = JsonUtility.FromJson <Personal>(response);
         Personal                = personal;
         brick.text              = personal.brick_count.ToString();
         longestArmy.text        = personal.has_largest_army ? "2" : "0";
         playedSoldiers.text     = personal.knight_card_played.ToString();
         soldiers.text           = personal.knight.ToString();
         longestRoad.text        = personal.has_long_road_card ? "2" : "0";
         yearOfPlenty.text       = personal.year_of_plenty.ToString();
         monopoly.text           = personal.monopoly_count.ToString();
         roadBuilding.text       = personal.road_building_count.ToString();
         wheat.text              = personal.wheat_count.ToString();
         wood.text               = personal.wood_count.ToString();
         stone.text              = personal.stone_count.ToString();
         sheep.text              = personal.sheep_count.ToString();
         victoryPoint.text       = personal.victory_point.ToString();
         totalPoint.text         = $"امتیاز کل: {personal.point}";
         username.text           = personal.player_username;
         MainScreen.ThisPlayerID = personal.player;
         StartCoroutine(Network.GetTexture(personal.player_avatar,
                                           texture => { profileImage.sprite = texture.ToSprite(); }, URL.Headers()));
     }, URL.Headers()));
 }
Exemple #4
0
    private void OnMouseDown()
    {
        //todo: check road bought
        if (!GameController.ShouldRoadClickable)
        {
            return;
        }
        if (GameController.Turn != MainScreen.ThisPlayerID)
        {
            return;
        }
        if (!IsRoadPositionValid())
        {
            // todo Uncomment for build.
            MainScreen.showDialog("خطا", "نمی توانید جاده خود را اینجا بسازید");
            return;
        }

        builtID = MainScreen.ThisPlayerID;
        ChangeRoadColor(MainScreen.ThisPlayerPlayerColor.GetColor());
        Debug.Log(gameObject.name);
        GameController.ShouldRoadClickable = false;
        if (GameController.Action == GameState.init1 || GameController.Action == GameState.init2)
        {
            var body = "{\"vertex\": " + MainScreen.SelectedSettlement + ", \"road_v1\": " + s1.name +
                       ", \"road_v2\": " + s2.name + "}";
            StartCoroutine(Network.PostRequest(GameController.Action == GameState.init1 ? URL.Init1 : URL.Init2, body,
                                               s => { }, URL.Headers(), true));
        }
    }
Exemple #5
0
    /**
     * It's time to roll the dice. Post to server if it's your turn.
     */
    public void Dice(string[] args)
    {
        var turn = int.Parse(args[0]);

        if (turn == ThisPlayerID)
        {
            StartCoroutine(Network.PostRequest(URL.Dice, string.Empty, s => { }, URL.Headers()));
        }
    }
Exemple #6
0
 private void GetBoardInfo()
 {
     StartCoroutine(Network.GetRequest(URL.GetBoard, response =>
     {
         response    = $"{{\"board\":{response}}}";
         _catanBoard = JsonUtility.FromJson <Tiles>(response);
         InitBoard();
     }, URL.Headers()));
 }
    public void OnBankTradeStarted()
    {
        if (give.options.Contains(desert))
        {
            return;
        }

        string request;

        if (give.options[give.value].text == "آجر")
        {
            request = "brick";
        }
        else if (give.options[give.value].text == "چوب")
        {
            request = "wood";
        }
        else if (give.options[give.value].text == "گوسفند")
        {
            request = "sheep";
        }
        else if (give.options[give.value].text == "سنگ")
        {
            request = "stone";
        }
        else
        {
            request = "wheat";
        }

        string will;

        if (want.options[want.value].text == "آجر")
        {
            will = "brick";
        }
        else if (want.options[want.value].text == "چوب")
        {
            will = "wood";
        }
        else if (want.options[want.value].text == "گوسفند")
        {
            will = "sheep";
        }
        else if (want.options[want.value].text == "سنگ")
        {
            will = "stone";
        }
        else
        {
            will = "wheat";
        }

        StartCoroutine(Network.PostRequest(URL.TradeBank, "{\"give\": \"" + request + "\", \"want\": \"" + will + "\"}", s => { },
                                           URL.Headers(), true));
    }
Exemple #8
0
    private void BuyRoad()
    {
        var personal = UpdateMyPlayer.Personal;

        if (personal.brick_count == 0 || personal.wood_count == 0)
        {
            return;
        }
        StartCoroutine(Network.PostRequest(URL.CreateRoad, string.Empty, s => { }, URL.Headers()));
    }
Exemple #9
0
    private void BuyDevelopmentCard()
    {
        var personal = UpdateMyPlayer.Personal;

        if (personal.sheep_count == 0 || personal.wheat_count == 0 || personal.stone_count == 0)
        {
            return;
        }

        StartCoroutine(Network.PostRequest(URL.BuyDevelopmentCard, string.Empty, s =>
        {
            s = s.Trim('"');
            string message;
            string title;
            switch (s)
            {
            case "victory":
                message = "تبریک! شما یک قدم به پیروزی نزدیکتر شدید.";
                title   = "کارت پیروزی";
                break;

            case "monopoly":
                message = "یک کارت مونوپولی برای شما.";
                title   = "کارت مونوپولی";
                break;

            case "year_of_plenty":
                message = "یک کارت سال فراوانی به کارت های شما اضافه شد.";
                title   = "کارت سال فراوانی";
                break;

            case "road_building":
                message = "شما در قرعه کشی بانک برنده کمک هزینه ساخت دو جاده شده اید.";
                title   = "کارت ساخت جاده";
                break;

            case "knight":
                message = "امنیت قلمرو خود را بیش از پیش تضمین کنید.";
                title   = "کارت شوالیه";
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            // var result = DisplayDialog(title, message, "باشه.");
        }, URL.Headers()));
    }
Exemple #10
0
    public void OnBuyStarted()
    {
        if (_willingBrick.text == "0" &&
            _willingWheat.text == "0" &&
            _willingWood.text == "0" &&
            _willingSheep.text == "0" &&
            _willingStone.text == "0" ||
            _offeringBrick.text == "0" &&
            _offeringWheat.text == "0" &&
            _offeringWood.text == "0" &&
            _offeringSheep.text == "0" &&
            _offeringStone.text == "0")
        {
            return;
        }

        var data = new TradeRequest
        {
            give = new Trade
            {
                brick = int.Parse(_offeringBrick.text),
                sheep = int.Parse(_offeringSheep.text),
                stone = int.Parse(_offeringStone.text),
                wheat = int.Parse(_offeringWheat.text),
                wood = int.Parse(_offeringWood.text)
            },
            want = new Trade
            {
                brick = int.Parse(_willingBrick.text),
                sheep = int.Parse(_willingSheep.text),
                stone = int.Parse(_willingStone.text),
                wheat = int.Parse(_willingWheat.text),
                wood = int.Parse(_willingWood.text)
            }
        };
        StartCoroutine(Network.PostRequest(URL.Trade, JsonUtility.ToJson(data), s => { }, URL.Headers(), true));
    }
Exemple #11
0
 private void GetProfileImage(string url)
 {
     StartCoroutine(Network.GetTexture(url, SetProfileImage, URL.Headers()));
 }
Exemple #12
0
 public void Pass()
 {
     StartCoroutine(Network.PostRequest(URL.Pass, string.Empty, s => { }, URL.Headers()));
 }