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; } } }
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)); }
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); }
public PlacementMarble(Marbles.Type type, Marbles.Color color, uint amount) { Type = type; Color = color; Amount = amount; }