Example #1
0
        public static void PopulateList(Player p, ListBox l)
        {
            l.Items.Clear();

            foreach (var v in p.inventory.Items)
            {
                l.Items.Add(((Block)Engine.GetNewBlock_ofType(v.Key)).displayName + ":   " + v.Value.ToString());
            }
        }
Example #2
0
        public static void SellAllItems(Player p)
        {
            foreach (var v in p.inventory.Items)
            {
                var key = v.Key;

                var block = (Block)Engine.GetNewBlock_ofType(key);

                int blockValue = block.value;

                p.money += blockValue * v.Value;
            }

            p.inventory.Items.Clear();
            p.Cargo = 0;
        }
Example #3
0
        public void PlaceBlock(Type newBlockType, Block target)
        {
            if (player.Cargo < player.CargoBayCapacity ||
                target.GetType() == typeof(Block_dirt) ||
                target.GetType() == typeof(Block_stone) ||
                target.GetType() == typeof(Block_air))
            {
                //places a block of a specified type at a specified location.
                if (target.penetrable || newBlockType == typeof(Block_air))
                {
                    int[] blockArrayLoc = (Engine.GetArrayLocation(target.Margin.Left, target.Margin.Top));

                    //replace block in worldarray and grid

                    targetGrid.Children.Remove(target);
                    blockArray[blockArrayLoc[0], blockArrayLoc[1]] = (Block)Engine.GetNewBlock_ofType(newBlockType);

                    blockArray[blockArrayLoc[0], blockArrayLoc[1]].setPosition(new Point(blockArrayLoc[0] * 25, blockArrayLoc[1] * 25));
                    targetGrid.Children.Add(blockArray[blockArrayLoc[0], blockArrayLoc[1]]);
                    Canvas.SetZIndex(blockArray[blockArrayLoc[0], blockArrayLoc[1]], 10);

                    if (newBlockType == typeof(Block_air))
                    {
                        blockArray[blockArrayLoc[0], blockArrayLoc[1]].penetrable = true;
                    }
                }
            }

            if (target.GetType() != typeof(Block_dirt) &&
                target.GetType() != typeof(Block_stone) &&
                target.GetType() != typeof(Block_air) &&
                player.Cargo < player.CargoBayCapacity)
            {
                player.Cargo += 1;
            }
        }