public void MenuShouldNotBeUsedWhenThereIsNoSoupAndTimeIsWithinRange_MoreThan4Plates_Test() { // Arrange DateTime elevenAm = new DateTime(2021, 5, 1, 11, 0, 0); BasePlate[] plates = new BasePlate[] { greyPlate, greyPlate, greyPlate, greenPlate, greenPlate, bluePlate }; CalculationStrategy expectedCalculationStrategy = CalculationStrategy.RegularStrategy; // Act CalculationStrategy chosenCalculationStrategy = this.strategySelector.GetCalculationStrategy(elevenAm, plates); //Assert Assert.Equal(expectedCalculationStrategy, chosenCalculationStrategy); }
public void MenuShouldBeUsedWhenThereIsSoupAndTimeIsWithinRange_Monday_AtStart_Test() { // Arrange DateTime elevenAm = new DateTime(2021, 5, 3, 11, 0, 0); BasePlate[] plates = new BasePlate[] { soupPlate, greyPlate, greyPlate, greenPlate, greenPlate, bluePlate }; CalculationStrategy expectedCalculationStrategy = CalculationStrategy.MenuStrategy; // Act CalculationStrategy chosenCalculationStrategy = this.strategySelector.GetCalculationStrategy(elevenAm, plates); //Assert Assert.Equal(expectedCalculationStrategy, chosenCalculationStrategy); }
public void MenuShouldBeUsedWhenThereIsSoupAndTimeIsNotWithinRange_Saturday_JustBeforeEnd_Test() { // Arrange DateTime elevenAm = new DateTime(2021, 5, 1, 16, 59, 59); BasePlate[] plates = new BasePlate[] { soupPlate, greyPlate, greyPlate, greenPlate, greenPlate, bluePlate }; CalculationStrategy expectedCalculationStrategy = CalculationStrategy.RegularStrategy; // Act CalculationStrategy chosenCalculationStrategy = this.strategySelector.GetCalculationStrategy(elevenAm, plates); //Assert Assert.Equal(expectedCalculationStrategy, chosenCalculationStrategy); }
public void Init(BasePlate _basePlate, int _number, PlateShadow _shadow) //初始化 { //初始化高光 mater = GetComponent <MeshRenderer>().material; mater.SetFloat("_Specular", 8); //初始化所在底盘,编号,影子,名子 basePlate = _basePlate; number = _number; shadow = _shadow; name = "Plate_" + number; //添加网格碰撞器并禁用 mc = gameObject.AddComponent <MeshCollider>(); mc.enabled = false; }
IEnumerator AutoMove(int n, BasePlate x, BasePlate y, BasePlate z) //自动移动 { if (n > 1) { yield return(AutoMove(n - 1, x, z, y)); MovePlate(x, z); yield return(new WaitForSeconds(0.1f)); yield return(AutoMove(n - 1, y, x, z)); } else { MovePlate(x, z); yield return(new WaitForSeconds(0.1f)); } }
public void SplitStrategyWithNullValuesTest2() { //Arrange BasePlate[] menuList = null; decimal menuPrice = 0m; bool expecteMenuCalculation = false; BasePlate[] emptyArray = new BasePlate[] { }; //Act MenuCalculationResult menuCalculationResult = this.menuSplitStrategy.ExtractOptimalMenu(menuList, this.SumPrice, menuPrice); //Assert Assert.NotNull(menuCalculationResult); Assert.Equal(expecteMenuCalculation, menuCalculationResult.CalculateAsMenu); Assert.Equal(emptyArray, menuCalculationResult.MenuPlates); Assert.Equal(emptyArray, menuCalculationResult.RemainingPlates); }
void SaveMove(int n, BasePlate x, BasePlate y, BasePlate z) //保存移动过程 { if (n > 1) { SaveMove(n - 1, x, z, y); //记录起点盘子和终点盘子 aQ.Enqueue(x); bQ.Enqueue(z); //记录移动函数的引用 funQ.Enqueue(MovePlate); SaveMove(n - 1, y, x, z); } else { aQ.Enqueue(x); bQ.Enqueue(z); funQ.Enqueue(MovePlate); } }
void MovePlate(BasePlate a, BasePlate b) //移动盘子 { Transform plate = a.plates.Peek().transform; //得到底座a的顶层盘子plate //如果底座b上没有盘子,就放在底座b之上 if (b.plates.Count == 0) { plate.position = b.transform.position + Vector3.up; } else//否则就将plate放到底座b的顶层盘子之上 { plate.position = b.plates.Peek().transform.position + Vector3.up; } //plate脱离底座a的管理,保存到底座b中 b.plates.Push(a.plates.Pop()); //每次移动刷新底座 a.RefBasePlate2(); b.RefBasePlate2(); }
void OnMouseUp() //弹起鼠标放置盘子 { //关闭影子 shadow.gameObject.SetActive(false); //非拖拽状态 BaseManager.Instance.isDrag = false; //是否可放置 if (BaseManager.Instance.isPlace == false) { return; } //该放置的位置 Transform th = BaseManager.Instance.posTH; //如果是原处之外的位置 if (th != transform) { transform.position = th.position + Vector3.up; //获取原本底盘 BasePlate oriBP = basePlate; BasePlate bp; //目标底座 if (th.tag == "Base") //如果目标是底座,改变所在底座 { bp = th.GetComponent <BasePlate>(); //目标底座 } else //如果目标是盘子,设该盘子的底座为自身底座 { Plate plate = th.GetComponent <Plate>(); plate.mc.enabled = false; //关闭该盘子的碰撞器 bp = plate.basePlate; } //改变底座 bp.plates.Push(oriBP.plates.Pop()); basePlate = bp; //刷新新底座和原底座 mc.enabled = false; basePlate.RefBasePlate(); oriBP.RefBasePlate(); } mater.SetFloat("_Specular", 8); }
public decimal GetPlatePrice(BasePlate plate) { if (plate == null) { throw new ArgumentNullException(nameof(plate)); } if (plate is SushiPlate) { SushiPlate sushiPlate = (SushiPlate)plate; switch (sushiPlate.Color) { case Color.Grey: return(4.95m); case Color.Green: return(3.95m); case Color.Yellow: return(2.95m); case Color.Red: return(1.95m); case Color.Blue: return(0.95m); default: throw new ArgumentOutOfRangeException(INVALID_ENUM_VALUE_EXCEPTION); } } else if (plate is SoupPlate) { return(2.5m); } else { throw new ArgumentException("No price definition available for the plate of type [" + plate.GetType().ToString() + "]"); } }
public void smoothEdges() { print("smoothing..."); for (int q = 0; q < grid.GetLength(0); q++) { for (int w = 0; w < grid.GetLength(1); w++) { BasePlate orgin = grid[q, w]; for (int i = 0; i < 5; i++) { try { BasePlate test = grid[orgin.gridX + 1, orgin.gridY]; }catch (IndexOutOfRangeException e) { continue; } //smoothes this tile with the one to the right int toRaiseTo = grid[orgin.gridX + 1, orgin.gridY].heightLayout[0, BasePlate.tileHeight *i / 5]; orgin.makeHill(BasePlate.tileWidth - 1, BasePlate.tileHeight * i / 5, toRaiseTo); } for (int i = 0; i < 5; i++) { try { BasePlate test = grid[orgin.gridX - 1, orgin.gridY]; } catch (IndexOutOfRangeException e) { continue; } //smoothes this tile with the one to the left int toRaiseTo = grid[orgin.gridX - 1, orgin.gridY].heightLayout[BasePlate.tileWidth, BasePlate.tileHeight *i / 5]; orgin.makeHill(0, BasePlate.tileHeight * i / 5, toRaiseTo); } for (int i = 0; i < 5; i++) { try { BasePlate test = grid[orgin.gridX, orgin.gridY + 1]; } catch (IndexOutOfRangeException e) { continue; } //smoothes this tile with the one on top int toRaiseTo = grid[orgin.gridX, orgin.gridY + 1].heightLayout[BasePlate.tileWidth * i / 5, 0]; orgin.makeHill(BasePlate.tileWidth * i / 5, BasePlate.tileWidth, toRaiseTo); } for (int i = 0; i < 5; i++) { try { BasePlate test = grid[orgin.gridX, orgin.gridY - 1]; } catch (IndexOutOfRangeException e) { continue; } //smoothes this tile with the one below int toRaiseTo = grid[orgin.gridX, orgin.gridY - 1].heightLayout[BasePlate.tileHeight, BasePlate.tileWidth *i / 5]; orgin.makeHill(0, BasePlate.tileWidth * i / 5, toRaiseTo); } orgin.generateTerrainFeatures(); } } }
public MenuCalculationResult ExtractOptimalMenu(BasePlate[] plates, Func <BasePlate[], decimal> regularPriceCalculation, decimal menuPrice) { if (plates == null) { return(new MenuCalculationResult() { CalculateAsMenu = false, MenuPlates = new BasePlate[] { }, RemainingPlates = new BasePlate[] { } }); } BasePlate soupPlate = plates.FirstOrDefault(plate => plate is SoupPlate); bool calculateAsMenu = false; List <BasePlate> basePlatesList = new List <BasePlate>(plates); List <BasePlate> menuPlatesList; BasePlate[] menuPlates; if (soupPlate != null) { //Soup menu basePlatesList.RemoveAll(plate => plate is SoupPlate); // Optimize price plate ordering by most expensive basePlatesList.Sort((x, y) => y.Price.CompareTo(x.Price)); int maxCount = basePlatesList.Count > 4 ? 4 : basePlatesList.Count; menuPlatesList = basePlatesList.GetRange(0, maxCount); menuPlatesList.Add(soupPlate); menuPlates = menuPlatesList.ToArray(); decimal originalPrice = regularPriceCalculation(menuPlates); calculateAsMenu = originalPrice > menuPrice; } else { //Five plates menu BasePlate redPlate = plates.FirstOrDefault(plate => plate.IsOfColor(Color.Red)); BasePlate bluePlate = plates.FirstOrDefault(plate => plate.IsOfColor(Color.Blue)); BasePlate plateToRemove; if (redPlate != null) { plateToRemove = redPlate; } else { plateToRemove = bluePlate; } basePlatesList.Remove(plateToRemove); basePlatesList.Sort((x, y) => y.Price.CompareTo(x.Price)); menuPlatesList = basePlatesList.GetRange(0, 4); menuPlatesList.Add(plateToRemove); menuPlates = menuPlatesList.ToArray(); decimal originalPrice = regularPriceCalculation(menuPlates); calculateAsMenu = originalPrice > menuPrice; } BasePlate[] remainingItems = null; if (calculateAsMenu) { List <BasePlate> fullListToRemoveMenu = new List <BasePlate>(plates); menuPlatesList.ForEach(plate => fullListToRemoveMenu.Remove(plate)); remainingItems = fullListToRemoveMenu.ToArray(); } else { menuPlates = new BasePlate[] { }; remainingItems = plates; } return(new MenuCalculationResult() { CalculateAsMenu = calculateAsMenu, MenuPlates = menuPlates, RemainingPlates = remainingItems }); }
public void Test() { BasePlate[] plates = new BasePlate[] { }; plates.ShouldBeConsiderForMenu(); }
private void Update() { foreach (Factory factory in factories.ToArray()) { if (factory.transform.position.y < water.getLevel()) { factories.Remove(factory); BasePlate basePlate = factory.transform.parent.GetComponentInChildren <BasePlate>(); factory.stopSmoking(); Destroy(factory); Destroy(basePlate.gameObject); } } foreach (Silo silo in silos.ToArray()) { if (silo.transform.position.y < water.getLevel()) { silos.Remove(silo); BasePlate basePlate = silo.transform.parent.GetComponentInChildren <BasePlate>(); Destroy(silo); Destroy(basePlate.gameObject); } } foreach (Store store in stores.ToArray()) { if (store.transform.position.y < water.getLevel()) { stores.Remove(store); BasePlate basePlate = store.transform.parent.GetComponentInChildren <BasePlate>(); Destroy(store); Destroy(basePlate.gameObject); } } foreach (Factory factory in factories) { factory.run(this); } foreach (Silo silo in silos) { silo.run(this); } foreach (Store store in stores) { store.run(this); } if (Input.GetKeyDown(KeyCode.Alpha1) || Input.GetKeyDown(KeyCode.Q) || Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.Z)) { selectedTool = Tool.Factory; factoryText.color = activeToolColor; siloText.color = passiveToolColor; storeText.color = passiveToolColor; } else if (Input.GetKeyDown(KeyCode.Alpha3) || Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.C)) { selectedTool = Tool.Silo; factoryText.color = passiveToolColor; siloText.color = activeToolColor; storeText.color = passiveToolColor; } else if (Input.GetKeyDown(KeyCode.Alpha2) || Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.X)) { selectedTool = Tool.Store; factoryText.color = passiveToolColor; siloText.color = passiveToolColor; storeText.color = activeToolColor; } if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 500.0f, LayerMask.GetMask("Hexagons"))) { Transform transform = hit.collider.transform; if (transform.position.y > water.getLevel() && transform.childCount == 0) { float angle = Random.Range(0.0f, 360.0f); Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.up); if (selectedTool == Tool.Factory && capital >= factoryPrice) { Instantiate(basePlatePrefab, transform.position, Quaternion.identity, transform); Factory factory = Instantiate(factoryPrefab, transform.position, rotation, transform); factories.Add(factory); weight += factoryWeight; channel(factoryPrice); } else if (selectedTool == Tool.Silo && capital >= siloPrice) { Instantiate(basePlatePrefab, transform.position, Quaternion.identity, transform); Silo silo = Instantiate(siloPrefab, transform.position, rotation, transform); silos.Add(silo); weight += siloWeight; channel(siloPrice); } else if (selectedTool == Tool.Store && capital >= storePrice) { Instantiate(basePlatePrefab, transform.position, Quaternion.identity, transform); Store store = Instantiate(storePrefab, transform.position, rotation, transform); stores.Add(store); weight += storeWeight; channel(storePrice); } } } } water.rise(pollution * pollutionFactor); float smog = Mathf.Clamp01(pollution * fogFactor); Color color = fogColor.Evaluate(smog); RenderSettings.fogColor = color; Camera.main.backgroundColor = color; RenderSettings.fogDensity = Mathf.Lerp(minimumDensity, maximumDensity, smog); island.sink(weight * -weightFactor); }