Skip to content

Commit

Permalink
Add container class
Browse files Browse the repository at this point in the history
finish Sink and fridge #3
  • Loading branch information
MandelV committed Dec 8, 2018
1 parent ab50076 commit faa927a
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 24 deletions.
77 changes: 77 additions & 0 deletions Model/Container.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Model
{
public abstract class Container<T>
{
protected List<T> _Slots;
public readonly int NumberSlots;
public bool Available;

public Container(int numberSlots)
{
_Slots = getNewStorage<T>(numberSlots);
NumberSlots = numberSlots;
Available = true;
}

/**
* Construct new Storage with max or infinite Items. 0 = infinite.
*/
public static List<R> getNewStorage<R>(int numberSlots)
{
if (numberSlots > 0)
{
return new List<R>(numberSlots);
}
else
{
return new List<R>();
}
}
public virtual int Size
{
get => _Slots.Count;
}
public virtual void AddItem(T item)
{
if (item == null) throw new ArgumentNullException("Container : item null");

if (NumberSlots > 0 && _Slots.Count + 1 > NumberSlots) throw new Exception("Container : Storage is full");
_Slots.Add(item);
}

public virtual void AddItems(ref List<T> items)
{
if (items == null) throw new ArgumentNullException("Container : items null");
if(NumberSlots > 0 && _Slots.Count + items.Count > NumberSlots) throw new Exception("Container : Storage is full");

_Slots.AddRange(items);
}

public virtual void removeItem(T item)
{
if (item == null) throw new ArgumentNullException("Container : item null");
_Slots.Remove(item);

}
public virtual T removeItem(int index)
{
if(index < _Slots.Count + 1)
{
T item = _Slots.ElementAt(index);
if (item != null) _Slots.Remove(item);
return item;
}
else
{
return default(T);
}

}
}
}
14 changes: 13 additions & 1 deletion Model/CookingFires.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,19 @@

namespace Model
{
public class CookingFires
public class CookingFires : TaskProcessor
{
private Recipe _Recipe;

public CookingFires()
{


}





}
}
3 changes: 2 additions & 1 deletion Model/Fridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

namespace Model
{
public class Fridge
public class Fridge : Container<Ingredient>
{
public Fridge(int numberSlots) : base(numberSlots){}
}
}
1 change: 1 addition & 0 deletions Model/Model.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<Compile Include="Client.cs" />
<Compile Include="Cloth.cs" />
<Compile Include="ClothType.cs" />
<Compile Include="Container.cs" />
<Compile Include="CookingFires.cs" />
<Compile Include="DiningRoom.cs" />
<Compile Include="Counter.cs" />
Expand Down
4 changes: 4 additions & 0 deletions Model/Recipe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ namespace Model
public class Recipe
{
private Dictionary<Ingredient, int> ingredients;
private List<Tool> tools;
private int cookingTimeRemaining;
private int bakingTimeRemaining;


public Recipe(int cookingTimeRemaining, int bakingTimeRemaining)
{
createRecipe(cookingTimeRemaining, bakingTimeRemaining, new Dictionary<Ingredient, int>());
Expand All @@ -29,7 +31,9 @@ private void createRecipe(int cookingTimeRemaining, int bakingTimeRemaining, Dic
}

public int BakingTimeRemaining { get => bakingTimeRemaining; set => bakingTimeRemaining = (value > 0) ? value : 1; }

public int CookingTimeRemaining { get => cookingTimeRemaining; set => cookingTimeRemaining = (value > 0) ? value : 1; }

public Dictionary<Ingredient, int> Ingredients { get => ingredients; set => ingredients = value; }

}
Expand Down
49 changes: 28 additions & 21 deletions Model/Sink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,44 @@

namespace Model
{
public class Sink
public class Sink : Container<WasheableTool>
{
private List<WasheableTool> _WashingTools;
public bool Available;

public void addDirtyTool(WasheableTool tool) {
if (tool.Clean) _WashingTools.Add(tool);
}
public void addDirtyTools(List<WasheableTool> tools)
{
tools.ForEach(tool =>
{
if (tool.Clean) _WashingTools.Add(tool);
});
}

public List<WasheableTool> cleanTools()
public Sink(int numberSlots) : base(numberSlots){}

public List<WasheableTool> WashingTools()
{
if(_WashingTools.Count == 0) return null;

if(_Slots.Count == 0) throw new Exception(" Sink : You cannot Washing tools when the Sink is empty !");
//Set number Item can be get by Diver.
Random random = new Random();
int numItem = random.Next(1, 6);

List<WasheableTool> tools = new List<WasheableTool>(numItem);

tools.AddRange(_WashingTools.GetRange(0, numItem));
tools.ForEach(tool => tool.Clean = true);
tools.AddRange(_Slots.GetRange(0, numItem));
tools.ForEach(tool => tool.Clean = true);

tools.ForEach(t => _Slots.Remove(t));

return tools;

}

public override void AddItem(WasheableTool item)
{
if (item.Clean) base.AddItem(item);
}

public override void AddItems(ref List<WasheableTool> items)
{
if(items.TrueForAll(item => item.Clean == false))
{
base.AddItems(ref items);
}
else
{
throw new Exception("Sink : There are item not dirty");
}

}
}
}
2 changes: 1 addition & 1 deletion Model/WasheableTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Model
{
public class WasheableTool : Tool
public class WasheableTool : Model.Tool
{
public bool Clean;
public WasheableTool(ToolsType toolType) : base(toolType) { Clean = true; }
Expand Down

0 comments on commit faa927a

Please sign in to comment.