public void Use(Item item) { if (!CanUse(item)) { return; } switch (item.Type) { case ItemType.Sword: Enemy = null; break; case ItemType.Key: NextRoom.Unlock(); break; case ItemType.Potion: Player.Heal(1); break; case ItemType.GreatPotion: Player.HealAll(); break; default: break; } if (item.IsConsumable) { Player.Items.Remove(item); } }
public void LoadUpRoom() { //Don't touch the stuff above. Variables go here. if (File.Exists(roomFilename)) { string jsonFromRoom = File.ReadAllText(roomFilename); NextRoom roomData = JsonUtility.FromJson <NextRoom>(jsonFromRoom); doors = GameObject.FindGameObjectsWithTag("Door"); if (roomData.roomTransition == true) { //get the door player is suppose to come through foreach (GameObject newDoor in doors) { int doorID = newDoor.GetComponent <DoorTransition>().door; if (doorID == roomData.iLeadTo) { Debug.Log(newDoor.GetComponent <DoorTransition>().doorSide); if (PlayerPrefs.GetInt("DoorSide") == 0) { player.transform.position = new Vector3(newDoor.transform.position.x + /*player.GetComponent<SpriteRenderer>().sprite.rect.x +*/ 25, newDoor.transform.position.y, 0); PlayerPrefs.SetInt("DoorSide", 0); } else if (PlayerPrefs.GetInt("DoorSide") == 1) { player.transform.position = new Vector3(newDoor.transform.position.x - /*player.GetComponent<SpriteRenderer>().sprite.rect.x -*/ 25, newDoor.transform.position.y, 0); player.GetComponent <InputState>().direction = Directions.Left; PlayerPrefs.SetInt("DoorSide", 0); } else { player.transform.position = new Vector3(newDoor.transform.position.x, newDoor.transform.position.y, 0); } } } File.Delete(roomFilename); } } else { jsonData = JsonUtility.ToJson(data, true); filename = Path.Combine(Application.streamingAssetsPath, SAVE_FILE); string jsonFromFile = File.ReadAllText(filename); SaveData copy = JsonUtility.FromJson <SaveData>(jsonFromFile); //Don't touch the stuff above. Variables go here. player.transform.position = copy.playerPosition; //GameObject.FindObjectOfType<DialogueStorage>().variables = copy.dialogue; //Don't touch the stuff below saveScreen.GetComponent <SaveScreen>().Resume(); textBox.gameObject.SetActive(true); textBox.text = "Game Loaded."; } }
public async Task Render() { // translate the camera if we're actively shifting if (Shifting) { LegendOf50.Instance.Graphics.Translate(-(int)CameraX, -(int)CameraY); } await CurrentRoom.Render(); if (NextRoom != null) { await NextRoom.Render(); } }
public IEnumerator WaitForFadeIn() { yield return(new WaitUntil(() => fadeCanvas.GetComponent <Fade>().screenIsDark == true)); room = new NextRoom() { iLeadTo = leadsTo, roomTransition = true }; json = JsonUtility.ToJson(room); filename = Path.Combine(Application.streamingAssetsPath, ROOM_MOVE); if (File.Exists(filename)) { File.Delete(filename); } File.WriteAllText(filename, json); Application.LoadLevel(goToScene); }
// This is the thread to query data private void QueryDataMain() { while (true) { int currentRepeatTimes = 0; for (currentRepeatTimes = 0; currentRepeatTimes < this._ReceiveDataRepeatTimes; currentRepeatTimes++) { Trace.WriteLine( string.Format( "RS232: Starting new room receive-check procedure with rep times {0}...", currentRepeatTimes), "Connection"); int j; for (j = 0; j < this._ReceiveDataCheckRepeatTimes; j++) { // Check if needs exit the thread if (!_IsRunning) { _Port.Close(); return; } bool checkReceivedSuccess = false; _Port.DiscardInBuffer(); SendRequestRoomInformationData(); //Send Data to RCU // Wait and Receive request data byte[] revBytes = null; bool receiveSuccess = true; try { revBytes = new byte[5]; int count = 0; while (count < revBytes.Length) { int nr = _Port.Read(revBytes, count, revBytes.Length - count); count += nr; // count += _Port.Read(revData, count, revData.Length - count); } } catch (Exception ex) { Trace.WriteLine(string.Format("RS232: Receive exception - {0}", ex.Message), "Connection"); receiveSuccess = false; } finally { _Port.DiscardInBuffer(); } string dataFormat = ConvertByteArrayToString(revBytes, 0, revBytes.Length); Trace.WriteLine( string.Format("RS232: Received {0} bytes data ... {1}", revBytes == null ? 0 : revBytes.Length, dataFormat), "Connection"); // Get the data if ((receiveSuccess) && (revBytes != null) && (revBytes.Length == 5)) { //Special CheckSum校验 int checkSumValue = 0; for (int k = 1; k <= revBytes.Length - 2; k++) { checkSumValue += revBytes[k]; } if ((byte)(checkSumValue % 256) == revBytes[revBytes.Length - 1]) { if ((256 - (_CurrentRoom.Number + _CurrentRoom.MyFloor.Number) % 256) == revBytes[0]) { if (j == 0) { _ReceiveCheckData = revBytes; checkReceivedSuccess = true; } else { //判断是不是与前几次相同 if (Utility.ArrayDataEquals(_ReceiveCheckData, revBytes)) { checkReceivedSuccess = true; } else { Trace.WriteLine("RS232: Unequal data check", "Connection"); } } } else { Trace.WriteLine("RS232: Unequal room number of received data", "Connection"); } } else { Trace.WriteLine("RS232: Checksum error", "Connection"); } } if (!checkReceivedSuccess) { Trace.WriteLine("RS232: Check data failed", "Connection"); break; } } if (j >= this._ReceiveDataCheckRepeatTimes) { //数据都正确 ApplyData(); //判断是否断网 if (_DisconnectList.ContainsKey(_CurrentRoom.ToString())) { _DisconnectList.Remove(_CurrentRoom.ToString()); } _CurrentRoom.MyATM.Connect(); break; //Query next room } } if (currentRepeatTimes >= this._ReceiveDataRepeatTimes) { CountDisconnectCurrentRoom(); } //Move to next room CurrentRoom = NextRoom; Trace.WriteLine( string.Format( "RS232: Moving to new room - {0}", NextRoom.ToString()), "Connection"); } }