public void Adding_same_item_more_than_once_should_sum_quanitities() { var box = new Box(); var item = new Item { Name = "Test Item" }; box.AddItem(3, item); Assert.Equal(3, box.Contents.First().Quantity); box.AddItem(2, item); Assert.Equal(5, box.Contents.First().Quantity); Assert.Equal(1, box.Contents.Count); }
public void Adding_new_item_to_box_should_have_correct_quantity() { var box = new Box(); box.AddItem(3, new Item { Name = "Test Item" }); Assert.Equal(3, box.Contents.First().Quantity); }
public void Adding_item_with_negative_quanity_throws_error() { var box = new Box(); var item = new Item { Name = "Test Item" }; Assert.Throws<InvalidOperationException>(() => box.AddItem(-3, item)); }
static void Main(string[] args) { { Console.WriteLine("1: "); int[] numbers = { 4, 6, 10, 8, 2 }; int result = SumArray(numbers); Console.WriteLine("Sum Result: " + result); } Console.WriteLine(); { Console.WriteLine("2: "); string str = "Hello World"; string reversedStr = ReverseStr(str); Console.WriteLine("Reverse: {0} -> {1}", str, reversedStr); } Console.WriteLine(); { Console.WriteLine("3: "); int[] numbers = ConvertToArray <int>(123, 321, 456, 654); Console.Write("["); foreach (object obj in numbers) { Console.Write("{0}, ", obj.ToString()); } Console.WriteLine("]"); } { Console.WriteLine("4:"); Box box = new Box(123, 321); Console.WriteLine("Box: {0}", box.ToString()); box.AddItem("Wooh"); Console.WriteLine("Box: {0}", box.ToString()); } { Console.WriteLine("5:"); Box box = new Box(123, 321); Box box2 = new Box(123, 321, 456); Console.WriteLine("Box 1: {0}", box.ToString()); Console.WriteLine("Box 2: {0}", box2.ToString()); Console.WriteLine("(box == box2) = {0}", box.Equals(box2)); } { Console.WriteLine("6:"); string str = "abc"; PrintAnagram(str.ToCharArray(), 0); } Console.Read(); }
public void DropItem(Item i, int x, int y) { Box b = GetBox(x, y); if (b == null) { SetBox(x, y); b = GetBox(x, y); } b.AddItem(i); }
public void Can_reduce_an_item_without_removing_it() { var box = new Box(); var item = new Item {Name = "Test Item"}; box.AddItem(2, item); Assert.Equal(2, box.Contents.First(x => x.Item == item).Quantity); box.ReduceItem(1, item); Assert.Equal(1, box.Contents.First(x => x.Item == item).Quantity); }
static void Main(string[] args) { Box <string> box = new Box <string>(); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { box.AddItem(Console.ReadLine()); } Console.WriteLine(box); }
static void Main(string[] args) { var box = new Box <string>(); var n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { var element = Console.ReadLine(); box.AddItem(element); } var elementToCompareWith = Console.ReadLine(); Console.WriteLine(box.CompareByValue <string>(elementToCompareWith)); }
/// <summary> /// 开始采集 /// </summary> private void StartCollect() { timeText += Time.deltaTime; CollectData collectData = collect.GetCollectData(Time.deltaTime); slider.UpdateSlider(1 - collectData.remainingTime / collectData.maxTime, $"正在采集{collect.Name}"); if (collectData.number > 0) { collectNum += collectData.number; if (timeText >= 1.5f) { Instantiate(textObj, canvas).GetComponent <TextShow>() .SetMessageText($"{collectData.collectType}:+{collectNum}"); box.AddItem(new ItemData() { number = collectNum, name = collectData.collectType.ToString() }); collectNum = 0; timeText = 0; } } if (collectData.isDone) { FinishCollectInit(); if (collectNum != 0) { Instantiate(textObj, canvas).GetComponent <TextShow>() .SetMessageText($"{collectData.collectType}:+{collectNum}"); box.AddItem(new ItemData() { number = collectNum, name = collectData.collectType.ToString() }); } collectNum = 0; } }
static void Main(string[] args) { Box <string> box = new Box <string>(); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { box.AddItem(Console.ReadLine()); } string compareElement = Console.ReadLine(); Console.WriteLine(box.CompareTo(compareElement)); }
static void Main(string[] args) { var box = new Box <int>(); var n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { var element = int.Parse(Console.ReadLine()); box.AddItem(element); } var indexes = Console.ReadLine().Split(" ").Select(int.Parse).ToArray(); var index1 = indexes[0]; var index2 = indexes[1]; box.SwapElements <int>(index1, index2); Console.WriteLine(box); }
static void Main(string[] args) { Box <int> box = new Box <int>(); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { box.AddItem(int.Parse(Console.ReadLine())); } int[] swapCommand = Console.ReadLine().Split().Select(int.Parse).ToArray(); int firstIndex = swapCommand[0]; int secondIndex = swapCommand[1]; box.Swap(firstIndex, secondIndex); Console.WriteLine(box); }
void Start() { // 没有加载数据就直接不执行 if (!GameSave.Single.isLoad) { return; } else { GameSave.Single.LoadGameData(); PlayerInputManage.single.GetComponent <PlayerState>().playerData = GameSave.Single.gameData.playerData; PlayerInputManage.single.GetComponent <PlayerState>().UpdateStateUI(); } foreach (var x in GameSave.Single.gameData.houseDatas) { houseDatas.Add(x); } foreach (var x in GameSave.Single.gameData.houseTemplateDatas) { houseTemplateDatas.Add(x); } GameSave.Single.gameData.houseDatas.Clear(); GameSave.Single.gameData.houseTemplateDatas.Clear(); box = PlayerInputManage.single.GetComponent <PlayerInteraction>().box; foreach (var x in houseDatas) { House house = Instantiate(ResourcePath.Single.house[x.name], x.position, x.rotation).GetComponent <House>(); house.NPCNumber = x._NPC; house.warehouse = x.itemData.Clone(); } foreach (var x in houseTemplateDatas) { GameObject temp = Instantiate(ResourcePath.Single.house[x.name], x.position, x.rotation); temp.GetComponent <Collider>().isTrigger = false; } foreach (var x in GameSave.Single.gameData.playerData.itemDatas) { box.AddItem(x); } PlayerInputManage.single.transform.position = GameSave.Single.gameData.playerData.position; PlayerInputManage.single.transform.rotation = GameSave.Single.gameData.playerData.rotation; }
public static List <Box> LoadShipBoxes(string xmlFile) { string shipName; Box bx; DateTime? scad; List <Box> grp; XDocument doc = XDocument.Load(xmlFile); shipName = doc.Root.FirstAttribute.Value; grp = new List <Box>(); foreach (XElement item in doc.Root.Elements("box")) { // SET ANCHE NOME SHIP come VALORE IN <box shipName="ciao"> bx = new Box(shipName, int.Parse(item.Element("id").Value.ToString())); // LOAD ITEMS DA BOX LIST; foreach (XElement cod in item.Elements()) { scad = null; if (cod.Name.ToString() != "id") { if (cod.Attribute("scadenza") != null) { scad = DateTime.Parse(cod.Attribute("scadenza").Value.ToString()); } bx.AddItem(new BoxItem(cod.Name.ToString(), int.Parse(cod.Value), scad)); //, si)); } } grp.Add(bx); } grp.Sort((x, y) => x.id.CompareTo(y.id)); return(grp); }
public void OnDrop(PointerEventData eventData) { // 如果拖动的是“可拖动UI”就什么也不做 if (eventData.pointerDrag.tag == "DragUI") { return; } // 如果当前格子上有物品 if (Article != null) { ArticleUI temp = eventData.pointerDrag.GetComponent <ArticleUI>(); // 将一样的物品进行堆叠 if (Article.itemData.name == temp.itemData.name) { // 将拖拽的物品的格子对该物品的引用置空 temp.ArticleGrid.Article = null; Box box = transform.parent.parent.GetComponent <Box>(); // 清除箱子对该物品的引用 box.box.Remove(temp); // 进行物品添加 box.AddItem(temp.itemData.Clone()); // 删除拖拽的该物品 Destroy(temp.gameObject); } // 否则将这个物品移动到用户拖拽过来的物品之前的格子(交换位置) else { Article.ChangeGrid(temp.ArticleGrid); } } eventData.pointerDrag.transform.SetParent(transform); // 新来的物品设置为自身的子物品 Article = eventData.pointerDrag.GetComponent <ArticleUI>(); // 拿到引用物品 Article.ArticleGrid = this; // 将物品对格子的引用设为自己 }
public void Can_remove_an_item() { var box = new Box(); var item = new Item {Name = "Test Item"}; box.AddItem(1, item); Assert.Equal(1, box.Contents.Count(x => x.Item == item)); box.RemoveItem(item); Assert.Empty(box.Contents); }
public void Reducing_an_item_by_equal_or_more_than_current_quantity_removes_item() { var box = new Box(); var item = new Item {Name = "Test Item"}; box.AddItem(2, item); Assert.Equal(2, box.Contents.First(x => x.Item == item).Quantity); box.ReduceItem(2, item); Assert.Equal(0, box.Contents.Count(x => x.Item == item)); }