public void OnEndDrag(PointerEventData eventData) { if (gameObject.tag == "flowerOwn") { RaycastHit hitInfo; if (ReturnClickedObject(out hitInfo).name == "collectBag") { float value = new PlantBuilder(gameObject.transform.GetChild(0).GetComponent <Image>().sprite.name).SetUniqueValues().SetCommonValues().Build().GetValue(); //Debug.Log(value); string[] p = gameObject.name.Split('_'); int y; int.TryParse(p[1], out y); int x; int.TryParse(p[2], out x); int[] index = { y, x }; GameObject.FindGameObjectWithTag("Player").GetComponent <Inventory>().AddFunds(100); GameObject.FindGameObjectWithTag("Player").GetComponent <Inventory>().RemoveItem(index); } } itemBeingDragged = null; GetComponent <CanvasGroup>().blocksRaycasts = true; if (transform.parent == startParent) { transform.position = startPosition; } }
public async Task Create_WithPlant_ShouldSavePlantInDatabase() { using (var context = new RamosiContext(options)) { // Arrange var plant = new PlantBuilder() .WithName("Plant") .WithPlantCharacteristic(new PlantCharacteristicBuilder().WithNotes("This is a characteristic")) .WithPlantCollection(new List <PlantCollection> { new PlantCollectionBuilder().WithNickname("Part of the collection") }); var repo = new PlantRepository(context); // Act repo.Create(plant); await repo.SaveChanges(); // Assert Assert.AreEqual(1, context.Plants.Count()); var created = context.Plants.First(); Assert.AreEqual("Plant", created.Name); Assert.AreEqual("This is a characteristic", created.PlantCharacteristic.Notes); Assert.AreEqual(1, created.PlantCollection.Count); Assert.AreEqual("Part of the collection", created.PlantCollection.First().Nickname); } }
public async Task Delete_WithNoMatchingPlantInRepo_ShouldNotDeleteExistingRecord() { using (var context = new RamosiContext(options)) { // Arrange var plant = new PlantBuilder() .WithGuid(guidOne) .WithName("Plant") .WithPlantCharacteristic(new PlantCharacteristicBuilder().WithNotes("This is a characteristic")) .WithPlantCollection(new List <PlantCollection> { new PlantCollectionBuilder().WithNickname("Part of the collection") }); context.Plants.Add(plant); context.SaveChanges(); var repo = new PlantRepository(context); // Act Assert.Throws <ArgumentException>(() => repo.Delete(guidTwo), $"No entity of type Plant with guid {guidTwo} was found"); await repo.SaveChanges(); // Assert Assert.AreEqual(1, context.Plants.Count()); Assert.AreEqual(guidOne, context.Plants.First().Guid); } }
public Plant(PlantBuilder builder) { m_name = builder.m_name; m_description = builder.m_description; m_cost = builder.m_cost; m_quality = builder.m_quality; m_growthStages = builder.m_growthStages; m_owner = builder.m_owner; m_growth = builder.m_growth; m_water = builder.m_water; m_emotion = builder.m_emotion; m_harvestable = builder.m_harvestable; }
public async Task Edit_WithNoPlantsInRepo_ShouldNotModifyDatabase() { using (var context = new RamosiContext(options)) { // Arrange var plant = new PlantBuilder(); var repo = new PlantRepository(context); // Act Assert.Throws <ArgumentException>(() => repo.Edit(plant), $"No entity of type Plant with guid {guidOne} was found"); await repo.SaveChanges(); // Assert Assert.IsFalse(context.Plants.Any()); } }
public async Task Edit_WithPlantWithMatchingGuidInRepo_ShouldNotEditPlantCharacteristicOrPlantCollection() { using (var context = new RamosiContext(options)) { // Arrange var plants = new List <Plant>() { new PlantBuilder() .WithName("one") .WithPlantCharacteristic(new PlantCharacteristicBuilder() .WithNotes("note one")) .WithPlantCollection(new List <PlantCollection>() { new PlantCollectionBuilder().WithNickname("nickname one") }), }; context.Plants.AddRange(plants); context.SaveChanges(); var plant = new PlantBuilder() .WithName("changed one!") .WithPlantCharacteristic(new PlantCharacteristicBuilder() .WithNotes("changed note one!")) .WithPlantCollection(new List <PlantCollection>() { new PlantCollectionBuilder().WithNickname("changed nickname one!") }); var repo = new PlantRepository(context); // Act repo.Edit(plant); await repo.SaveChanges(); // Arrange Assert.AreEqual(1, context.Plants.Count()); var plantsInDb = context.Plants.ToList(); Assert.AreEqual(guidOne, plantsInDb[0].PlantCharacteristic.Guid); Assert.AreEqual("note one", plantsInDb[0].PlantCharacteristic.Notes); Assert.AreEqual(guidOne, plantsInDb[0].PlantCollection[0].Guid); Assert.AreEqual("nickname one", plantsInDb[0].PlantCollection[0].Nickname); } }
void Update() { float v = Input.GetAxis("Vertical"); float h = Input.GetAxis("Horizontal"); if (movementEnable) { m_animator.SetInteger("vertical", (int)(h * 10f)); m_animator.SetInteger("horizontal", (int)(v * 10f)); if (h != 0 || v != 0) { m_animator.SetBool("isStay", false); if (nextFootstep) { nextFootstep = false; if (footstepLR) { audioSource.PlayOneShot(footstepLeft, 0.6f); footstepLR = !footstepLR; } else { audioSource.PlayOneShot(footstepRight, 0.3f); footstepLR = !footstepLR; } StartCoroutine(WaitForFootstep(0.3f)); } } else if (h == 0 && v == 0 && IsAllInputKeyUp()) { m_animator.SetBool("isStay", true); } transform.position += transform.forward * Time.deltaTime * v * speed; transform.position += transform.right * Time.deltaTime * h * speed; } SetDirection(m_animator.GetCurrentAnimatorStateInfo(0)); if (m_animator.GetBool("isStay") && isPickedUp == false) { if (Input.GetKeyDown(KeyCode.F)) { Collider[] colliders = FindNearbyColliders("pickable", 0.6f); if (colliders.Length != 0) { movementEnable = false; StartCoroutine(WaitToEnableMovement(0.75f)); isPickedUp = true; m_animator.SetBool("isPickedUp", isPickedUp); pickedObj = ClosestCollider(colliders).gameObject; pickedObj.GetComponent <Rigidbody>().isKinematic = true; pickedObj.GetComponent <Collider>().isTrigger = true; pickedObj.transform.parent = gameObject.transform.GetChild(0); pickedObj.transform.localPosition = Vector3.zero; } } //Code for player actions when using current tools if (Input.GetKeyDown(KeyCode.R)) { switch (GetComponent <Inventory>().CurrentTool()) { case Tool.Shovel: if (FindNearbyColliders("pickable", radiusOverlap).Length != 0) { Alert("Something block me..."); break; } //Must in stay action before use Shovel and not Ploughing if (m_animator.GetBool("isStay") && !m_animator.GetBool("isPloughing")) { if (FindNearbyColliders("PloughedGround", radiusOverlap).Length == 0 && FindNearbyColliders("Flowering", radiusOverlap).Length == 0) { //Ploughing the ground ready to plant if (canPlant) { //Shovel Animation Start and player movement disable movementEnable = false; m_animator.SetBool("isPloughing", true); StartCoroutine(WaitForPloughingAnim(0.85f)); audioSource.PlayOneShot(diggingSound, 1f); } else { Alert("I should only dig in the field..."); } } else { Alert("I have already dug here..."); } } break; case Tool.Dibber: int[] index = inventory.SearchBag("seed"); Debug.Log(index[0] + "," + index[1]); if (index[0] != -1) { //Search infront for ground to plant seed Collider[] colliders = FindNearbyColliders("PloughedGround", 0.6f); if (colliders.Length != 0) { GameObject nearbyGround = ClosestCollider(colliders).gameObject; //Planting the seed in the nearby ground. Transform newSeed = Instantiate(seed, nearbyGround.transform.position, plantingPoint.rotation); //Making the parent of the seed the ground its planted in newSeed.SetParent(nearbyGround.transform); //Changing the tag of the ground so another seed cannot be planted in it nearbyGround.tag = "Flowering"; //Creating new plant object and adding it to the seeds plantbehaviour script string plantName = inventory.GetPlantName(index); Plant newPlant = new PlantBuilder(plantName).SetUniqueValues().SetCommonValues().Build(); newSeed.GetComponent <PlantBehaviour>().SetPlant(newPlant); inventory.RemoveItem(index); Debug.Log(newSeed.GetComponent <PlantBehaviour>().GetPlant().GetName()); } else { Alert("There is no where to plant the seed..."); } } break; case Tool.WateringCan: //Search infront for seed to water Collider[] colliders1 = FindNearbyColliders("Flowering", 0.6f); Collider[] colliders2 = FindNearbyColliders("PloughedGround", 0.6f); List <Collider> collider = new List <Collider>(); collider.AddRange(colliders2); collider.AddRange(colliders1); Collider[] collider3 = collider.ToArray(); if (collider3.Length != 0) { GameObject nearbyGround = ClosestCollider(collider3).gameObject; if (!nearbyGround.transform.GetChild(0).gameObject.activeSelf) { audioSource.PlayOneShot(wateringSound, 1f); movementEnable = false; m_animator.SetBool("isWatering", true); StartCoroutine(WaitForWateringAnim(0.9f, nearbyGround)); } } else { Alert("There is nothing to water..."); } break; } } } else if (isPickedUp) { if (Input.GetKeyDown(KeyCode.F)) { movementEnable = false; StartCoroutine(WaitToEnableMovement(0.75f)); isPickedUp = false; m_animator.SetBool("isPickedUp", isPickedUp); ReleasePickedUpObj(); } } }
public async Task Edit_WithNoPlantWithMatchingGuidInRepo_ShouldNotEditExistingPlants() { using (var context = new RamosiContext(options)) { // Arrange var plants = new List <Plant>() { new PlantBuilder() .WithName("one") .WithPlantCharacteristic(new PlantCharacteristicBuilder() .WithNotes("note one")) .WithPlantCollection(new List <PlantCollection>() { new PlantCollectionBuilder().WithNickname("nickname one") }), new PlantBuilder() .WithGuid(guidTwo) .WithName("two") .WithPlantCharacteristic(new PlantCharacteristicBuilder() .WithGuid(guidTwo) .WithNotes("note two")) .WithPlantCollection(new List <PlantCollection>() { new PlantCollectionBuilder() .WithGuid(guidTwo) .WithNickname("nickname two") }), new PlantBuilder() .WithGuid(guidThree) .WithName("three") .WithPlantCharacteristic(new PlantCharacteristicBuilder() .WithGuid(guidThree) .WithNotes("note three")) .WithPlantCollection(new List <PlantCollection>() { new PlantCollectionBuilder() .WithGuid(guidThree) .WithNickname("nickname three") }), }; var plant = new PlantBuilder().WithGuid(guidFour); context.Plants.AddRange(plants); context.SaveChanges(); var repo = new PlantRepository(context); // Act Assert.Throws <ArgumentException>(() => repo.Edit(plant), $"No entity of type Plant with guid {guidFour} was found"); await repo.SaveChanges(); // Assert Assert.AreEqual(3, context.Plants.Count()); var plantsInDb = context.Plants.ToList(); Assert.AreEqual(guidOne, plantsInDb[0].Guid); Assert.AreEqual("one", plantsInDb[0].Name); Assert.AreEqual(guidOne, plantsInDb[0].PlantCharacteristic.Guid); Assert.AreEqual("note one", plantsInDb[0].PlantCharacteristic.Notes); Assert.AreEqual(guidOne, plantsInDb[0].PlantCollection[0].Guid); Assert.AreEqual("nickname one", plantsInDb[0].PlantCollection[0].Nickname); Assert.AreEqual(guidTwo, plantsInDb[1].Guid); Assert.AreEqual("two", plantsInDb[1].Name); Assert.AreEqual(guidTwo, plantsInDb[1].PlantCharacteristic.Guid); Assert.AreEqual("note two", plantsInDb[1].PlantCharacteristic.Notes); Assert.AreEqual(guidTwo, plantsInDb[1].PlantCollection[0].Guid); Assert.AreEqual("nickname two", plantsInDb[1].PlantCollection[0].Nickname); Assert.AreEqual(guidThree, plantsInDb[2].Guid); Assert.AreEqual("three", plantsInDb[2].Name); Assert.AreEqual(guidThree, plantsInDb[2].PlantCharacteristic.Guid); Assert.AreEqual("note three", plantsInDb[2].PlantCharacteristic.Notes); Assert.AreEqual(guidThree, plantsInDb[2].PlantCollection[0].Guid); Assert.AreEqual("nickname three", plantsInDb[2].PlantCollection[0].Nickname); } }