diff --git a/FormMap.java b/FormMap.java index 2208630..1e42c4b 100644 --- a/FormMap.java +++ b/FormMap.java @@ -47,6 +47,7 @@ public class FormMap extends JComponent { _abstractMap = new SpikeMap(); break; case ("Rail Map"): + _abstractMap = new RailMap(); break; } } @@ -59,7 +60,7 @@ public class FormMap extends JComponent { speedLabel.setText("Speed: " + locomotive.Locomotive.getSpeed()); weightLabel.setText("Weight: " + (int)locomotive.Locomotive.getWeight()); colorLabel.setText("Color: " + locomotive.Locomotive.getBodyColor().getRed() + " " + locomotive.Locomotive.getBodyColor().getGreen() + " " + locomotive.Locomotive.getBodyColor().getBlue()); - if (_abstractMap != null) bufferImg = _abstractMap.CreateMap(1000, 500, new DrawningObjectLocomotive(locomotive)); + if (_abstractMap != null) bufferImg = _abstractMap.CreateMap(1000, 490, new DrawningObjectLocomotive(locomotive)); repaint(); }); @@ -74,7 +75,7 @@ public class FormMap extends JComponent { speedLabel.setText("Speed: " + locomotive.Locomotive.getSpeed()); weightLabel.setText("Weight: " + (int)locomotive.Locomotive.getWeight()); colorLabel.setText("Color: " + locomotive.Locomotive.getBodyColor().getRed() + " " + locomotive.Locomotive.getBodyColor().getGreen() + " " + locomotive.Locomotive.getBodyColor().getBlue() ); - if (_abstractMap != null) bufferImg = _abstractMap.CreateMap(1000, 500, new DrawningObjectLocomotive(locomotive)); + if (_abstractMap != null) bufferImg = _abstractMap.CreateMap(1000, 490, new DrawningObjectLocomotive(locomotive)); repaint(); }); statusPanel.add(mapSelectComboBox); @@ -114,13 +115,14 @@ public class FormMap extends JComponent { statusPanel.add(moveRightButton); formFrame.getContentPane().add(this); + super.repaint(); } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; - if (bufferImg != null) g2.drawImage(bufferImg, 0,0,1000,500,null); + if (bufferImg != null) g2.drawImage(bufferImg, 0,0,1000,490,null); super.repaint(); } diff --git a/RailMap.java b/RailMap.java new file mode 100644 index 0000000..836dac8 --- /dev/null +++ b/RailMap.java @@ -0,0 +1,58 @@ +import java.awt.*; + +public class RailMap extends AbstractMap{ + /// Цвет участка закрытого + private final Color barrierColor = Color.BLACK; + /// Цвет участка открытого + private final Color roadColor = Color.PINK; + + @Override + protected void DrawBarrierPart(Graphics g, int i, int j) + { + g.setColor(barrierColor); + g.fillRect( (int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x + + 1)), (int)(j * (_size_y + 1))); + } + + @Override + protected void DrawRoadPart(Graphics g, int i, int j) + { + g.setColor(roadColor); + g.fillRect( (int)(i * _size_x), (int)(j * _size_y), (int)(i * (_size_x + + 1)),(int)( j * (_size_y + 1))); + } + @Override + protected void GenerateMap() + { + _map = new int[100][100]; + _size_x = (float)_width / _map.length; + _size_y = (float)_height / _map[0].length; + int counter = 0; + for (int i = 0; i < _map.length; ++i) + { + for (int j = 0; j < _map[0].length; ++j) + { + _map[i][j] = _freeRoad; + } + } + while (counter < 1) + { + int y = _random.nextInt(85); + + for(int x = 0; x < 99; x++) + { + _map[x][y] = _barrier; + _map[x][y + 5] = _barrier; + + if (x % 5 == 0) + { + _map[x][y + 1] = _barrier; + _map[x][y + 2] = _barrier; + _map[x][y + 3] = _barrier; + _map[x][y + 4] = _barrier; + } + } + counter += 1; + } + } +} diff --git a/SimpleMap.java b/SimpleMap.java index 4311230..2e00387 100644 --- a/SimpleMap.java +++ b/SimpleMap.java @@ -38,7 +38,7 @@ public class SimpleMap extends AbstractMap{ while (counter < 50) { int x = _random.nextInt(100); - int y = _random.nextInt(100); + int y = _random.nextInt(85); if (_map[x][y] == _freeRoad) { _map[x][y] = _barrier; diff --git a/SpikeMap.java b/SpikeMap.java index 4e41c4d..c7bb422 100644 --- a/SpikeMap.java +++ b/SpikeMap.java @@ -38,7 +38,7 @@ public class SpikeMap extends AbstractMap{ while (counter < 15) { int x = _random.nextInt(95) + 1; - int y = _random.nextInt(95) + 1; + int y = _random.nextInt(85) + 1; if (_map[x][y] == _freeRoad) { _map[x][y] = _barrier;