InventoryIcon SetIcon(InventoryEnum size, string item, RectTransform targetRect) // создание и настройка новой иконки { InventoryIcon target = null; foreach (InventoryIcon i in icons) { if (i.size == size) { target = i; } } if (target) { InventoryIcon clone = Instantiate(target) as InventoryIcon; clone.iconImage.sprite = Resources.Load <Sprite>(iconPath + "/" + item); clone.iconCountObject.SetActive(false); clone.gameObject.name = item; clone.item = item; clone.counter = 1; clone.iconCountText.text = "1"; clone.rectTransform.SetParent(targetRect); clone.rectTransform.localScale = Vector3.one; clone.rectTransform.position = Input.mousePosition; clone.gameObject.SetActive(true); return(clone); } return(null); }
// Use this for initialization void Start() { //SaveLoad.Load(); messagesToSend = new List <string>(); currentItem = InventoryEnum.HAND; changeIcon(0); enumToVeg = new Dictionary <VegetablesEnum, Vegetable>(); enumToVeg.Add(VegetablesEnum.CARROT, carrot); enumToVeg.Add(VegetablesEnum.TOMATO, tomato); instance = FindObjectsOfType <Manager>()[0]; mainMenuBtn.onClick.AddListener(loadMainMenu); exitButton.onClick.AddListener(exitGame); //Start of the game messages if (Game.current.currentDay == 1 && Game.current.currentTime == 6 * 60) { setAdviceMessage("You need to gain money (2000 gold a day after the second)\n so your grandpa doesn't kill you"); setAdviceMessage("Use your tools to plant either carrot or tomatoes"); setAdviceMessage("Use the hoe (2) to tile the ground\nUse the seeds (4/5) to plant\nUse the watering can to water"); setAdviceMessage("At night, the ghost of some of your plants (even seeds) will come to attack\nUse your gun to defend yourself."); setAdviceMessage("Tomatoes are worth 500g and take 2 days to grow\nCarrots are worth 200g and take a day to grow" + "\n40% of the carrots spawn a ghost, and 50% of tomatoes."); setAdviceMessage("Survive 5 days to find your grandpa\n(Don't forget to gain 2000 gold each day!)"); setAdviceMessage("Enter your house and sleep in the bed\nYou can sleep only after the battle at night\n2000 gold will be retrieved from you.\nYou will die if you don't have it."); setAdviceMessage("You can spend leftover money at the shop. It will be important for the final battle."); setAdviceMessage("If you are done for the day, press N to advance to dusk, right before the battle."); } generalMusicStart(); }
public void battleStart() { audioSource.clip = battleSong; audioSource.Play(); audioSource.loop = true; currentItem = InventoryEnum.GUN; changeIcon(5); setAdviceMessageImmediate("Gun selected"); }
public int GetInventoryInfo(InventoryEnum inventoryEnum) { if (inventory.ContainsKey(inventoryEnum)) { return(inventory[inventoryEnum]); } else { return(0); } }
public void AddToInventory(InventoryEnum inventoryEnum, int amount) { if (inventory.ContainsKey(inventoryEnum)) { inventory[inventoryEnum] += amount; } else { inventory.Add(inventoryEnum, amount); } }
// Update is called once per frame void Update() { if (!SceneManager.GetActiveScene().name.Equals("house")) { Game.current.currentTime += Time.deltaTime * (Game.current.currentTime >= 17 * 60 ? 1.8f : 3); } if (Game.stopped) { return; } if (Game.current.currentTime < 6 * 60 + 1 && !SceneManager.GetActiveScene().name.Equals("house")) { theLight = GameObject.Find("theLight").GetComponent <Light>(); Camera.main.GetComponent <Skybox>().material = skyBoxDay; theLight.intensity = 1f; } lifeText.text = "Life: " + (Game.current.currentLife < 0 ? 0 : Game.current.currentLife); if (dead) { return; } if (Game.current.currentLife <= 0) { die(); return; } int totalsec = (int)Game.current.currentTime; int hours = totalsec / 60; string ampm = "AM"; if (hours >= 12) { hours -= 12; ampm = "PM"; } int minutes = totalsec % 60; timeText.text = "Day " + Game.current.currentDay + " - " + (hours >= 10 ? "" : " ") + hours + ":" + (minutes < 10 ? "0" : "") + minutes + " " + ampm; if (Game.current.currentTime > 18 * 60) { timeText.text = "Day " + Game.current.currentDay + " - Night"; } goldText.text = "Gold: " + Game.current.currentMoney; //There are other obvious better ways if (Input.GetKey(KeyCode.Alpha1)) { currentItem = InventoryEnum.HAND; changeIcon(0); setAdviceMessageImmediate("Hand selected"); } if (Input.GetKey(KeyCode.Alpha2)) { currentItem = InventoryEnum.HOE; changeIcon(1); setAdviceMessageImmediate("Hoe selected"); } if (Input.GetKey(KeyCode.Alpha3)) { currentItem = InventoryEnum.CAN; changeIcon(2); setAdviceMessageImmediate("Watering can selected"); } if (Input.GetKey(KeyCode.Alpha4)) { currentItem = InventoryEnum.CARROTSEED; changeIcon(3); setAdviceMessageImmediate("Carrot seed selected"); } if (Input.GetKey(KeyCode.Alpha5)) { currentItem = InventoryEnum.TOMATOSEED; changeIcon(4); setAdviceMessageImmediate("Tomato seed selected"); } if (Input.GetKey(KeyCode.Alpha6)) { currentItem = InventoryEnum.GUN; changeIcon(5); setAdviceMessageImmediate("Gun selected"); } if (Input.GetKeyDown(KeyCode.Escape)) { SoundEffects.sf.playMenuClick(); menuPanel.gameObject.SetActive(!menuPanel.gameObject.activeSelf); } if (Input.GetKeyDown(KeyCode.N) && Game.current.currentTime < 18 * 60 && Game.current.currentTime >= 17 * 60 && SceneManager.GetActiveScene().name == "scene1") { Game.current.currentTime = 18 * 60; theLight = GameObject.Find("theLight").GetComponent <Light>(); theLight.intensity = 0.2f; Camera.main.GetComponent <Skybox>().material = skyBoxNight; } if (Input.GetKeyDown(KeyCode.N) && Game.current.currentTime < 17 * 60 && SceneManager.GetActiveScene().name == "scene1") { Game.current.currentTime = 17 * 60; } if (Input.GetKeyDown(KeyCode.C)) { Game.current.currentLife = 20; Game.current.currentMoney = 50000; setAdviceMessage("20 life and 50k gold (you pressed C)"); } /* * if (Input.GetKey(KeyCode.L)) * { * SaveLoad.Load(); * }*/ if (Game.current.currentTime > 17 * 60 && Game.current.dawnMessage == false) { audioSource.clip = duskSong; audioSource.Play(); if (Game.current.currentDay == 1) { clearMessages(); setAdviceMessage("You can't enter your house after 6PM\nUntil the battle is over\nBut you can run (left shift)."); setAdviceMessage("The crop ghosts appear on crops...\nStay away from them! (but not too far! Your weapon has a range)"); setAdviceMessage("Aim and shoot the gun to kill them.\nThe night is coming!\nSurvive!"); setAdviceMessageImmediate("Press N to battle"); } if (Game.current.currentDay == 5) { clearMessages(); setAdviceMessage("The final battle will begin soon..."); } Game.current.dawnMessage = true; StartCoroutine(LerpLight()); } if (Game.current.battleInProgress && Game.current.veggiesLeft == 0 && !Game.current.battleFinished) { audioSource.Stop(); if (Game.current.currentDay == 1) { clearMessages(); setAdviceMessage("You survived the first day..\nYou can go into the house and rest now.\nThe game will be saved."); } if (Game.current.currentDay == 5) { clearMessages(); setAdviceMessage("Hey son, I'm sorry for everything that I did\nMy spirit was possesed by another one\nAn angry farmer"); setAdviceMessage("Thank you\nI can rest now\nLive well"); endGame(); } Game.current.battleInProgress = false; Game.current.battleFinished = true; } checkGrandpa(); }
void LoadSettings() { if (!File.Exists(Path())) { return; } InventoryIcon tmp = null; string item = string.Empty; int counter = 0; InventoryEnum size = InventoryEnum.size1x1; Vector2 pos = Vector2.zero; string[] f_isLocked = new string[] {}; string[] f_item = new string[] {}; StreamReader reader = new StreamReader(Path()); while (!reader.EndOfStream) { string value = Crypt(reader.ReadLine()); string[] result = value.Split(new char[] { '=' }); if (result.Length == 1 && item == string.Empty) { item = value.Trim(new char[] { '[', ']' }); } switch (result[0]) // фильтруем ключи { case "IconSize": size = (InventoryEnum)System.Enum.Parse(typeof(InventoryEnum), result[1]); // string переводим в enum break; case "IconCounter": counter = int.Parse(result[1]); break; case "IconPositionX": pos.x = float.Parse(result[1]); break; case "IconPositionY": pos.y = float.Parse(result[1]); break; case "Field_isLocked": f_isLocked = result[1].Split(new char[] { ',' }); break; case "Field_item": f_item = result[1].Split(new char[] { ',' }); break; } if (value == string.Empty) { tmp = SetIcon(size, item, content); tmp.counter = counter; tmp.iconCountText.text = counter.ToString(); tmp.isInside = true; tmp.iconCountObject.SetActive(true); tmp.rectTransform.localPosition = pos; pIcon.Add(tmp); item = string.Empty; } } for (int i = 0; i < cells.Length; i++) { if (f_item[i] == "null") { cells[i].item = string.Empty; } else { cells[i].item = f_item[i]; } if (f_isLocked[i] == "0") { cells[i].isLocked = false; } else { cells[i].isLocked = true; } } reader.Close(); }