Example #1
0
    private void RemplirPotager()
    {
        for (int i = 0; i < jeu.Potager.Count; i++)
        {
            int idParcelle = -1; // c'est de l'herbe

            GameObject newParselle = Instantiate(parselle, new Vector3(jeu.Potager[i].PositionX, jeu.Potager[i].PositionY, 0f), new Quaternion(0f, 0f, 0f, 0f));
            newParselle.transform.parent = gameObject.transform;

            if (jeu.Potager[i].IdLegume == 8) // obligé car au chargement de la base on peut avoir des légumes plantés
            {
                idParcelle = 0;               // c'est de la terre
            }
            else if (jeu.Potager[i].IdLegume != 7 && jeu.Potager[i].IdLegume != 8)
            {
                idParcelle = jeu.Potager[i].IdLegume; // c'est un légume
            }
            newParselle.GetComponent <ParselleController>().IdParselle = idParcelle;
            newParselle.GetComponent <ParselleController>().IdPotager  = jeu.Potager[i].IdPotager;

            if (i > 3 && jeu.Potager[i].IdLegume != 7)
            {
                nbCarreTerre++;
            }

            if (idParcelle > 0) // on instancie que si c'est un légume
            {
                GameObject newLegume = Instantiate(legume[jeu.Potager[i].IdLegume - 1], new Vector3(jeu.Potager[i].PositionX + 0.54f, jeu.Potager[i].PositionY, 0f), new Quaternion(0f, 0f, 0f, 0f));

                newLegume.transform.parent = newParselle.transform;

                newParselle.GetComponent <ParselleController>().Legume = newLegume;

                LegumsController legumeC = newLegume.GetComponent <LegumsController>();
                legumeC.IdLegume       = idParcelle;
                legumeC.IdPotager      = jeu.Potager[i].IdPotager; // on lui passe le numéro de la parcelle en base
                legumeC.TempsPousseMin = jeu.GetDescription(jeu.GetLegume(idParcelle).IdDescription).TempsPousseMin;
                legumeC.TempsPousseMax = jeu.GetDescription(jeu.GetLegume(idParcelle).IdDescription).TempsPousseMax;
                legumeC.DatePlantage   = jeu.Potager[i].DatePlantage;
            }
        }
        if (nbCarreTerre >= 4)
        {
            nbCarreTerre -= 4;
        }
        else
        {
            nbCarreTerre = 0;
        }
    }
Example #2
0
    // Use this for initialization
    void Start()
    {
        ui = GameObject.FindGameObjectWithTag("UI").GetComponent <UIManager>();

        legumesMenu = new GameObject[9];
        RectTransform rt = (RectTransform)container.transform;

        float width  = rt.rect.width;
        float height = rt.rect.height;

        for (int i = 0; i < game.Legumes.Count; i++)
        {
            if (game.Legumes[i].IdLegume < 7)
            {
                GameObject newLegume = Instantiate(legumesInstatiable[i], new Vector3(width / 2 + 50, container.transform.position.y - ((100 + 10) + 350 * (i + 2)), 0f), new Quaternion(0f, 0f, 0f, 0f));
                newLegume.GetComponent <LegumsMenuController>().IdLegume = game.Legumes[i].IdLegume;
                newLegume.GetComponent <LegumsMenuController>().Nom      = game.Legumes[i].Nom;
                newLegume.GetComponent <LegumsMenuController>().Desc     = game.GetDescription(game.Legumes[i].IdDescription);
                newLegume.transform.SetParent(container.transform);
                newLegume.GetComponent <Button>().onClick.AddListener(scroll.GetComponent <ScollViewController>().ScrollTo);
                newLegume.GetComponent <Button>().onClick.AddListener(ClickLegume);
                legumesMenu[i] = newLegume;
                if (i == 2)
                {
                    legumeSelected = legumesMenu[i];
                }
            }
        }
    }
Example #3
0
    public void PlanterLegumeParcelle(GameObject potage)
    {
        GameObject legumeShop = shop.GetComponent <ShopController>().GetLegumeSelected();

        idParselle = legumeShop.GetComponent <LegumsMenuController>().IdLegume;
        GameObject newLegume = Instantiate(legumes[idParselle - 1], new Vector3(transform.position.x + 0.54f, transform.position.y), new Quaternion(0f, 0f, 0f, 0f));

        LegumsController legumeC = newLegume.GetComponent <LegumsController>();

        legumeC.IdLegume       = idParselle;
        legumeC.IdPotager      = IdPotager;
        legumeC.TempsPousseMin = jeu.GetDescription(jeu.GetLegume(idParselle).IdDescription).TempsPousseMin;
        legumeC.TempsPousseMax = jeu.GetDescription(jeu.GetLegume(idParselle).IdDescription).TempsPousseMax;

        string datePlantage = ui.GetDateJeu();

        Debug.Log(datePlantage);
        legumeC.DatePlantage = datePlantage;

        newLegume.transform.parent = this.transform;

        legume = newLegume;


        databaseUpdate.UpdatePotager(new Potager(idPotager, idParselle, datePlantage));

        string dateSortie = ui.GetDateJeu();

        databaseUpdate.UpdateProfilDate(dateSortie);
        jeu.Profil.DateSortie = dateSortie;

        GameObject newXp = Instantiate(plusXp, new Vector3(transform.position.x + 0.54f, transform.position.y), new Quaternion(0f, 0f, 0f, 0f));

        newXp.GetComponent <PlusExpController>().SetXp(100);

        potage.GetComponent <PotageController>().HideParselles();
        ui.GetComponent <UIManager>().SetBulleOpened(false);

        if (potage.GetComponent <PotageController>().Agandissable())
        {
            GameObject newFermier = Instantiate(fermier);
            newFermier.transform.SetParent(ui.gameObject.transform);
            newFermier.GetComponent <FermierController>().SetPhraseNonAgrandissable();
        }
    }
Example #4
0
    /*public static T GetCopyOf<T>(this Component comp, T other) where T : Component
     * {
     *      Type type = comp.GetType();
     *      if (type != other.GetType()) return null; // type mis-match
     *      BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Default | BindingFlags.DeclaredOnly;
     *      PropertyInfo[] pinfos = type.GetProperties(flags);
     *      foreach (var pinfo in pinfos) {
     *              if (pinfo.CanWrite) {
     *                      try {
     *                              pinfo.SetValue(comp, pinfo.GetValue(other, null), null);
     *                      }
     *                      catch { } // In case of NotImplementedException being thrown. For some reason specifying that exception didn't seem to catch it, so I didn't catch anything specific.
     *              }
     *      }
     *      FieldInfo[] finfos = type.GetFields(flags);
     *      foreach (var finfo in finfos) {
     *              finfo.SetValue(comp, finfo.GetValue(other));
     *      }
     *      return comp as T;
     * }*/

    // Use this for initialization
    void Start()
    {
        legumesMenu = new GameObject[8];
        RectTransform rt = (RectTransform)container.transform;

        float width  = rt.rect.width;
        float height = rt.rect.height;

        for (int i = 0; i < game.Legumes.Length; i++)
        {
            GameObject newLegume = Instantiate(legume, new Vector3(width / 2 + 50, container.transform.position.y - ((100 + 10) + 350 * (i + 2)), 0f), new Quaternion(0f, 0f, 0f, 0f));
            newLegume.GetComponent <LegumsMenuController>().IdLegume = game.Legumes[i].IdLegume;
            newLegume.GetComponent <LegumsMenuController>().Nom      = game.Legumes[i].Nom;
            newLegume.GetComponent <LegumsMenuController>().Desc     = game.GetDescription(game.Legumes[i].IdDescription);
            newLegume.transform.SetParent(container.transform);
            newLegume.GetComponent <Button>().onClick.AddListener(scroll.GetComponent <ScollViewController>().ScrollTo);
            newLegume.GetComponent <Button>().onClick.AddListener(ClickLegume);
            legumesMenu[i] = newLegume;
        }
    }
Example #5
0
    void OnMouseDown()
    {
        GameObject potage = gameObject.transform.parent.gameObject;

        if (!ui.GetComponent <UIManager>().GetBulleOpened() && !potage.GetComponent <PotageController>().ParsellesShown&& !potage.GetComponent <PotageController>().ParsellesPotageShown)
        {
            if (idParselle >= 0)     // si c'est de la terre
            {
                if (idParselle == 0) // pas de légumes
                {
                    if (!cadreShown)
                    {
                        GameObject newBulle = Instantiate(bulles[1], new Vector3(transform.position.x + 3f, transform.position.y), new Quaternion(0f, 0f, 0f, 0f));
                        newBulle.GetComponent <BulleController>().SetParselleClicked(gameObject);
                        newBulle.GetComponent <Canvas>().worldCamera = Camera.main;
                        ShowCadre();
                        ui.GetComponent <UIManager>().SetBulleOpened(true);
                    }
                    else // on plante
                    {
                        GameObject legumeShop = shop.GetComponent <ShopController>().GetLegumeSelected();
                        idParselle = legumeShop.GetComponent <LegumsMenuController>().IdLegume;
                        GameObject newLegume = Instantiate(legumes[idParselle - 1], new Vector3(transform.position.x + 0.54f, transform.position.y), new Quaternion(0f, 0f, 0f, 0f));
                        legume = newLegume;

                        newLegume.GetComponent <LegumsController>().IdLegume       = idParselle;
                        newLegume.GetComponent <LegumsController>().IdPotager      = IdPotager;
                        newLegume.GetComponent <LegumsController>().TempsPousseMin = jeu.GetDescription(jeu.GetLegume(idParselle).IdDescription).TempsPousseMin;
                        newLegume.GetComponent <LegumsController>().TempsPousseMax = jeu.GetDescription(jeu.GetLegume(idParselle).IdDescription).TempsPousseMax;
                        //TODO : newLegume.GetComponent<LegumsController>().DateSortie = ui.GetDateJeu();

                        GameObject newXp = Instantiate(plusXp, new Vector3(transform.position.x + 0.54f, transform.position.y), new Quaternion(0f, 0f, 0f, 0f));
                        newXp.GetComponent <PlusExpController>().SetXp(100);

                        potage.GetComponent <PotageController>().HideParselles();
                        ui.GetComponent <UIManager>().SetBulleOpened(false);
                    }
                }
                else // ya un légume
                {
                    GameObject newBulle = Instantiate(bulles[0], new Vector3(transform.position.x + 3f, transform.position.y), new Quaternion(0f, 0f, 0f, 0f));
                    newBulle.GetComponent <BulleController>().SetParselleClicked(gameObject);
                    newBulle.GetComponent <Canvas>().worldCamera = Camera.main;
                    ShowCadre();
                    ui.GetComponent <UIManager>().SetBulleOpened(true);
                }
            }
        }
        else if (potage.GetComponent <PotageController>().ParsellesShown&& APiocher()) // on veut piocher
        {
            if (potage.GetComponent <PotageController>().Agandissable())
            {
                idParselle = 0;
                potage.GetComponent <PotageController>().NbCarreTerre = potage.GetComponent <PotageController>().NbCarreTerre + 1;
                HideCadre();
            }
            else
            {
                Debug.Log("Terrain non agrandissable, vous pouvez l'agrandir tous les 2500 points");
            }
        }
        else if (potage.GetComponent <PotageController>().ParsellesPotageShown&& AArroser()) // on veut arroser
        {
            Arroser();
        }
        else
        {
            if (GameObject.FindGameObjectWithTag("Bulle") != null)
            {
                GameObject.FindGameObjectWithTag("Bulle").GetComponent <BulleController>().Close();
            }
        }

        /*if (transform.GetChild(0).GetComponent<SpriteRenderer>().color.a > 0f)
         * {
         *  transform.GetChild(0).GetComponent<SpriteRenderer>().color = new Color(1f, 1f, 1f, 0f);
         *  ShowFond();
         * }*/
    }