Map changes
This commit is contained in:
parent
530bd727ef
commit
da8e2d8d81
@ -1,19 +1,83 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
public class Map {
|
public class Map {
|
||||||
private TypeOfCell[][] map;
|
private TypeOfCell[][] map;
|
||||||
private Person person;
|
private Person person;
|
||||||
private Block block;
|
private LinkedList<Block> block;
|
||||||
private static Game game = new Game();
|
private Game game;
|
||||||
|
|
||||||
Map(int height, int width, Game game){
|
Map(int height, int width, Game game){
|
||||||
|
block = new LinkedList<Block>();
|
||||||
map = new TypeOfCell[height][width];
|
map = new TypeOfCell[height][width];
|
||||||
person = new Person(game);
|
this.game = game;
|
||||||
block = new Block(game);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Map(int height, int width, Game game, int xPerson, int yPerson){
|
Map(int height, int width, Game game, int xPerson, int yPerson){
|
||||||
|
block = new LinkedList<Block>();
|
||||||
|
this.game = game;
|
||||||
map = new TypeOfCell[height][width];
|
map = new TypeOfCell[height][width];
|
||||||
person = new Person(game);
|
if ((height < xPerson || xPerson < 0) || (width < yPerson || yPerson < 0)){
|
||||||
block = new Block(game);
|
map[0][0] = TypeOfCell.PERSON;
|
||||||
// if (height < )
|
}
|
||||||
|
else map [xPerson][yPerson] = TypeOfCell.PERSON;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map(int height, int width, Game game,int xPerson, int yPerson, TypeOfCell type){
|
||||||
|
block = new LinkedList<Block>();
|
||||||
|
this.game = game;
|
||||||
|
map = new TypeOfCell[height][width];
|
||||||
|
if ((height - 1 < xPerson || xPerson <= 0) || (width - 1 < yPerson || yPerson <= 0)){
|
||||||
|
map[1][1] = TypeOfCell.PERSON;
|
||||||
|
}
|
||||||
|
else map [xPerson][yPerson] = TypeOfCell.PERSON;
|
||||||
|
|
||||||
|
for (int i = 0; i < map.length; i++){
|
||||||
|
for (int j = 0; j < map.length; j++){
|
||||||
|
map[0][j] = type;
|
||||||
|
}
|
||||||
|
map[i][0] = type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Person getPerson() {
|
||||||
|
return person;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createMap(){
|
||||||
|
for (int i = 0; i < map.length; i++){
|
||||||
|
for (int j = 0; j < map.length; j++){
|
||||||
|
if (map[i][j] == TypeOfCell.BLOCK){
|
||||||
|
block.add(new Block(i,j,game));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (map[i][j] == TypeOfCell.PERSON){
|
||||||
|
person = new Person(i,j,game);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Canvas extends JPanel { // class for rendering (drawing)
|
||||||
|
@Override
|
||||||
|
public void paint(Graphics g) {
|
||||||
|
super.paint(g);
|
||||||
|
Graphics2D g2D = (Graphics2D) g;
|
||||||
|
g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||||
|
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
|
for (Cell cell: block){
|
||||||
|
cell.paint(g2D);
|
||||||
|
}
|
||||||
|
person.paint(g2D);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isBusyCell(int x, int y){
|
||||||
|
for(Block cell: block){
|
||||||
|
if(cell.isInBlock(x,y))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return person.isInPerson(x,y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user