/// <summary> /// replace figura by number /// </summary> /// <param name="number">number figura</param> /// <param name="figura">new figura for replace</param> public void ReplaceByNumber(int number, Figura figura) { if (number > 0 && number <= Box.Count) { Box[--number] = figura; } else { throw new Exception("Номера заданной фигуры не существует"); } }
/// <summary> /// extracting a shape by number with removing a shape from the box /// </summary> /// <param name="number">number figura</param> /// <returns>figura of box</returns> public Figura DeleteByNumber(int number) { if (number > 0 && number <= Box.Count) { Figura figura = Box[--number]; Box.Remove(figura); return(figura); } else { throw new Exception("Такого номера фигуры нету!"); } }
/// <summary> /// search for a similar figure to a given one /// </summary> /// <param name="figura">similar figure</param> /// <returns>strok about similar figure</returns> public string FindBySample(Figura figura) { for (int i = 0; i < Box.Count; i++) { if (Box[i].GetType() == figura.GetType() && Box[i].TypeMaterial == figura.TypeMaterial && Box[i].Color == figura.Color) { return(Box[i].ToString()); } } return("Похожей фигуры на заданную не было найдено!"); }
/// <summary> /// method for add figura in box /// </summary> /// <param name="figura">figura for add</param> public void AddFigura(Figura figura) { if (Box.Count < 20) { if (Box.Count > 0 && Box[Box.Count - 1].Equals(figura)) { throw new Exception("Нельзя добавлять одну и туже фигуру дважды"); } Box.Add(figura); } else { throw new Exception("Коробка не может иметь больше 20 фигур"); } }