Пример #1
0
 public void Play()
 {
     GameEnded            = false;
     MainGameMessage.text = "";
     MapSetupMessage.text = "";
     CellController.ClearSelection();
     CellController.Locked = false;
     CellController.Attack = false;
     ScreenController.Change("Matchmaking");
     StartCoroutine(FindMatch());
 }
Пример #2
0
    public void Finish()
    {
        switch (playerController.ValidateMap())
        {
        case 404:
            ErrorMsg.text = "Invalid formation";
            CellController.ClearSelection();
            break;

        case 100:
            ErrorMsg.text = "Place all your ships";
            break;

        default:
            ErrorMsg.text = "Waiting for the other player...";
            MainController.SendMap();
            CellController.Locked = true;
            break;
        }
    }
Пример #3
0
    public IEnumerator WaitForReady()
    {
        yield return(new WaitForSeconds(.5f));

        if (!GameEnded)
        {
            WWWForm form = new WWWForm();
            form.AddField("id", MatchId);

            WWW w = new WWW(SERVER_ADDRESS + "?act=read_match", form);
            yield return(w);

            if (!string.IsNullOrEmpty(w.error))
            {
                print(w.error);
            }
            else
            {
                print(w.text);
                string[] datas    = w.text.Split(';');
                bool     p1_ready = false;
                bool     p2_ready = false;
                string   map      = null;
                foreach (string data in datas)
                {
                    string[] keypair = data.Split('=');
                    switch (keypair[0])
                    {
                    case "p1_ready":
                        p1_ready = keypair[1] == "1" ? true : false;
                        break;

                    case "p2_ready":
                        p2_ready = keypair[1] == "1" ? true : false;
                        break;

                    case "map1":
                        if (!IsPlayer1)
                        {
                            map = keypair[1].Replace('$', '=').Replace('&', ';');
                        }
                        break;

                    case "map2":
                        if (IsPlayer1)
                        {
                            map = keypair[1].Replace('$', '=').Replace('&', ';');
                        }
                        break;
                    }
                }
                if (p1_ready && p2_ready)
                {
                    GameEnded = false;
                    CellController.ClearSelection();
                    ScreenController.Change("MainGame");
                    MainGameTitle.text = IsPlayer1 ? "Your turn" : "Enemy's turn";
                    if (!IsPlayer1)
                    {
                        StartCoroutine(WaitForTurn());
                    }
                    CellController.Locked = !IsPlayer1;
                    CellController.Attack = true;
                    if (map != null)
                    {
                        LoadMap(map);
                    }
                }
                else
                {
                    StartCoroutine(WaitForReady());
                }
            }
        }
    }