Exemple #1
0
 public void Remove(Marbles.Type type, Marbles.Color color, uint amount)
 {
     // Check if type is already in a placement
     for (byte i = 0; i < Marbles.Count; i++)
     {
         if (Marbles[i].Type == type && Marbles[i].Color == color)
         {
             // If it is, increase it
             Marbles[i].Amount -= amount;
             return;
         }
     }
 }
Exemple #2
0
        public void Add(Marbles.Type type, Marbles.Color color, uint amount)
        {
            // Check if type is already in a placement
            for (byte i = 0; i < Marbles.Count; i++)
            {
                if (Marbles[i].Type == type && Marbles[i].Color == color)
                {
                    // If it is, increase it
                    Marbles[i].Amount += amount;
                    return;
                }
            }

            // Otherwise, simply add it
            Marbles.Add(new PlacementMarble(type, color, amount));
        }
Exemple #3
0
        public static Placement DeserializePlacement(byte[] contract, ref uint offset)
        {
            Placement placement  = new Placement();
            byte      numMarbles = contract[offset];

            offset++;
            for (uint i = 0; i < numMarbles; i++)
            {
                Marbles.Type type = (Marbles.Type)contract[offset];
                offset++;
                Marbles.Color color = (Marbles.Color)contract[offset];
                offset++;

                byte[] quantityBytes = new byte[4];
                Array.Copy(contract, offset, quantityBytes, 0, 4);
                uint quantity = BitConverter.ToUInt32(quantityBytes, 0);

                placement.Add(type, color, quantity);
                offset += 4;
            }

            return(placement);
        }
Exemple #4
0
 public PlacementMarble(Marbles.Type type, Marbles.Color color, uint amount)
 {
     Type   = type;
     Color  = color;
     Amount = amount;
 }