полиморф

This commit is contained in:
AnnaLioness 2023-11-03 23:38:13 +04:00
parent aeaba7615e
commit 9d0594068b
5 changed files with 10 additions and 32 deletions

View File

@ -2,9 +2,6 @@ import java.awt.*;
public class DrawingContainerShip extends DrawingShip{
private IDecksDrawing iDecksDrawing;
public DrawingContainerShip(int speed, double weight, Color bodyColor, Color

View File

@ -125,9 +125,7 @@ public class DrawingShip {
{
return;
}
//Pen pen = new Pen(Color.Black);
//Brush adbrush = new SolidBrush(EntityContainerShip.AdditionalColor);
//Brush brBlue = new SolidBrush(Color.Blue);
g.setPaint(EntityShip.BodyColor);
// заполнение борта
int x[] = {_startPosX+ 20, _startPosX+40, _startPosX+110, _startPosX+130, _startPosX+ 20};

View File

@ -27,13 +27,13 @@ public class NewFormRand extends JFrame {
setLayout(null);
_ShipGenericDop = new ShipGenericDop<>(50,50,pictureBoxWidth,pictureBoxHeight);
canv.setBounds(0, 0, pictureBoxWidth, pictureBoxHeight);
_ShipGenericDop.AddShip(new EntityShip(200,200,Color.PINK));
_ShipGenericDop.AddShip(new EntityShip(200,200,Color.GRAY));
_ShipGenericDop.AddShip(new EntityContainerShip(200, 200, Color.GREEN, Color.BLUE, true, false, 2, 1));
_ShipGenericDop.AddShip(new EntityContainerShip(200, 200, Color.LIGHT_GRAY, Color.MAGENTA, false, true, 3, 3));
_ShipGenericDop.AddDeck(new DrawingDecks());
_ShipGenericDop.AddDeck(new DrawingDecksRect());
_ShipGenericDop.AddDeck(new DrawingDecksTrapez());
_ShipGenericDop.Add(new EntityShip(200,200,Color.PINK));
_ShipGenericDop.Add(new EntityShip(200,200,Color.GRAY));
_ShipGenericDop.Add(new EntityContainerShip(200, 200, Color.GREEN, Color.BLUE, true, false, 2, 1));
_ShipGenericDop.Add(new EntityContainerShip(200, 200, Color.LIGHT_GRAY, Color.MAGENTA, false, true, 3, 3));
_ShipGenericDop.Add(new DrawingDecks());
_ShipGenericDop.Add(new DrawingDecksRect());
_ShipGenericDop.Add(new DrawingDecksTrapez());
JButton creatButton = new JButton("создать");
creatButton.addActionListener(
new ActionListener() {

View File

@ -23,14 +23,6 @@ public class ShipGenericCollection<T extends DrawingShip, U extends IMoveableObj
_collection = new SetGeneric<T>(width * height);
}
/*public static int operator +(ShipGenericCollection<T, U> collect, T obj)
{
if (obj == null)
{
return -1;
}
return collect?._collection.Insert(obj) ?? -1;
}*/
public int Add(T obj)
{
if (obj == null)
@ -40,15 +32,6 @@ public class ShipGenericCollection<T extends DrawingShip, U extends IMoveableObj
return _collection.Insert(obj);
}
/*public static bool operator -(ShipGenericCollection<T, U> collect, int pos)
{
T obj = collect._collection.Get(pos);
if (obj != null)
{
return collect._collection.Remove(pos);
}
return false;
}*/
public T remove(int pos)
{
T obj = _collection.Get(pos);

View File

@ -21,7 +21,7 @@ public class ShipGenericDop<T extends EntityShip, U extends IDecksDrawing> {
_pictureHeight = pictureHeight;
rand = new Random();
}
public boolean AddShip(T ship){
public boolean Add(T ship){
if(ship == null){
return false;
}
@ -31,7 +31,7 @@ public class ShipGenericDop<T extends EntityShip, U extends IDecksDrawing> {
Ships.add(countShips++, ship);
return true;
}
public boolean AddDeck(U deck){
public boolean Add(U deck){
if(deck == null){
return false;
}