Skip to content

Commit

Permalink
Добавлен вид "Паразиты"
Browse files Browse the repository at this point in the history
  • Loading branch information
xlam committed Aug 3, 2018
1 parent c337a0a commit 06cb1de
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ru/cyberbiology/test/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import ru.cyberbiology.test.util.ProjectProperties;
import ru.cyberbiology.test.view.ViewBasic;
import ru.cyberbiology.test.view.ViewMultiCell;
import ru.cyberbiology.test.view.ViewPest;

public class MainWindow extends JFrame implements IWindow
{
Expand Down Expand Up @@ -75,7 +76,8 @@ public class MainWindow extends JFrame implements IWindow
IView[] views = new IView[]
{
new ViewBasic(),
new ViewMultiCell()
new ViewMultiCell(),
new ViewPest()
};
JMenuItem recordItem;
JMenuItem snapShotItem;
Expand Down
81 changes: 81 additions & 0 deletions ru/cyberbiology/test/view/ViewPest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package ru.cyberbiology.test.view;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;

import javax.swing.JPanel;
import ru.cyberbiology.test.Bot;

import ru.cyberbiology.test.World;
import ru.cyberbiology.test.prototype.view.IView;

public class ViewPest implements IView
{

public ViewPest()
{
// TODO Auto-generated constructor stub
}

@Override
public String getName()
{
return "Паразиты";
}

@Override
public Image paint(World world,JPanel canvas) {
int w = canvas.getWidth();
int h = canvas.getHeight();
//Создаем временный буфер для рисования
Image buf = canvas.createImage(w, h);
//подеменяем графику на временный буфер
Graphics g = buf.getGraphics();

g.drawRect(0, 0, world.width * World.BOTW + 1, world.height * World.BOTH + 1);

world.population = 0;
world.organic = 0;
world.pests = 0;
world.pestGenes = 0;
for (int y = 0; y < world.height; y++) {
for (int x = 0; x < world.width; x++) {
if (world.matrix[x][y] == null) {
g.setColor(Color.WHITE);
g.fillRect(x * World.BOTW,y * World.BOTH, World.BOTW, World.BOTH);
} else if ((world.matrix[x][y].alive == 1) || (world.matrix[x][y].alive == 2)) {
g.setColor(new Color(200, 200, 200));
g.fillRect(x * World.BOTW, y * World.BOTH, World.BOTW, World.BOTH);
world.organic = world.organic + 1;
} else if (world.matrix[x][y].alive == 3) {
g.setColor(Color.BLACK);
g.drawRect(x * World.BOTW, y * World.BOTH, World.BOTW, World.BOTH);

int pestGenes = 0;
for (int i=0; i<Bot.MIND_SIZE; i++)
if (world.matrix[x][y].mind[i] == 49)
pestGenes++;

int colorRed = 200;
int colorGreen = 200;
int colorBlue = 200;

if (pestGenes > 0) {
world.pests++;
colorRed = 127 + pestGenes * 2;
colorGreen = 0;
colorBlue = 0;
}

world.pestGenes += pestGenes;

g.setColor(new Color(colorRed, colorGreen, colorBlue));
g.fillRect(x * World.BOTW + 1, y * World.BOTH + 1,World.BOTW-1, World.BOTH-1);
world.population = world.population + 1;
}
}
}
return buf;
}
}

0 comments on commit 06cb1de

Please sign in to comment.