示例#1
0
        public void CheckAll()
        {
            Inventaire inv = new Inventaire("", 3, 3);

            Assert.IsNull(TableDeCraft.CheckAll(inv));

            inv = new Inventaire("", 4, 4);
            Assert.IsNull(TableDeCraft.CheckAll(inv));

            inv.SetItem(3, new TroncDeChene_Item(1));
            Assert.IsNull(TableDeCraft.CheckAll(inv));

            inv.SetItem(0, new TroncDeChene_Item(32));
            Craft c = TableDeCraft.CheckAll(inv);

            Assert.AreEqual(c.To.id(), new PlancheDeChene(1).id());
            Assert.AreEqual(c.To.Quantite, 4);
        }
示例#2
0
        public void Craft(UI_Item[,] items, UI_Item to, Inventaire invcraft, Point toCoord, Point start)
        {
            Craft craft = TableDeCraft.CheckAll(invcraft);

            if (craft != null)
            {
                for (int x = 0; x < items.GetLength(0); x++)
                {
                    for (int y = 0; y < items.GetLength(1); y++)
                    {
                        Memoire.items.Remove(items[x, y]);
                        Memoire.form.Controls.Remove(items[x, y]);
                    }
                }

                if (to != null)
                {
                    Memoire.items.Remove(to);
                    Memoire.form.Controls.Remove(to);

                    if (Memoire.selected.item == null && to.item != null)
                    {
                        Memoire.form.Controls.Remove(Memoire.selected);
                        Memoire.selected = to;
                        to = null;
                        Memoire.form.Controls.Add(Memoire.selected);
                    }
                }

                bool a = true;
                for (int x = 0; x < items.GetLength(0); x++)
                {
                    for (int y = 0; y < items.GetLength(1); y++)
                    {
                        Item item = invcraft.GetItem(x + (y * items.GetLength(0)));
                        if (Memoire.selected != null && Memoire.selected.item != null &&
                            craft.To.id() == Memoire.selected.item.id() &&
                            item != null && craft.From[x, y] != null)
                        {
                            item.Quantite -= craft.From[x, y].Quantite;
                            if (item.Quantite == 0)
                            {
                                a = false;
                                invcraft.SetItem(x + (y * items.GetLength(0)), null);
                                item = null;
                            }
                        }
                        UI_Item uit = new UI_Item(item, Memoire.InvToScreen(start.X + x * 18, start.Y + y * 18));
                        Memoire.items.Add(uit);
                        Memoire.form.Controls.Add(uit);
                    }
                }
                if (a)
                {
                    UI_Item cit = new UI_Item(craft.To.Clone(), toCoord);
                    Memoire.items.Add(cit);
                    Memoire.form.Controls.Add(cit);
                }
            }
            if (craft == null && to != null && to.item != null)
            {
                Memoire.items.Remove(to);
                Memoire.form.Controls.Remove(to);
            }
        }