Ejemplo n.º 1
0
        public void printBackpack()
        {
            PackNode current = head;

            Console.WriteLine("Backpack contents:");
            Console.WriteLine("Weight: {0}, Max Weight: {1}", presentWeight, maxWeight);
            //prints nothing if empty
            while (current != null)
            {
                Console.WriteLine("Name: {0} | Damage: {1} | Number in Bag: {2}", current.w.weaponName, current.w.damage, current.stock);
                current = current.next;
            }
            Console.WriteLine("");
        }
Ejemplo n.º 2
0
        public bool addItem(Weapon w, int numstock)
        {
            PackNode newNode = new PackNode(w, numstock);

            //if no items in backpack
            if (head == null)
            {
                head           = newNode;
                presentWeight += w.weight * numstock;
                return(true);
            }
            PackNode current = head;

            //loops until you find the item or get to the end
            while (current.next != null)
            {
                //once you find another copy of the purchased item, increases stock and weight
                if (current.w == w)
                {
                    current.stock += numstock;
                    presentWeight += (w.weight * numstock);
                    return(true);
                }
                current = current.next;
            }
            //if item purchased is the last item in the bag
            if (current.w == w)
            {
                current.stock += numstock;
                presentWeight += (w.weight * numstock);
                return(true);
            }
            //if item is not in the bag
            current.next   = newNode;
            presentWeight += (w.weight * numstock);
            return(true);
        }
Ejemplo n.º 3
0
 public Backpack(double mweight)
 {
     head          = null;
     presentWeight = 0;
     maxWeight     = mweight;
 }
Ejemplo n.º 4
0
 public PackNode(Weapon w, int s)
 {
     this.w = w;
     next   = null;
     stock  = s;
 }