Getneightbourhood without edge detection.

This commit is contained in:
2018-03-07 21:40:06 +01:00
parent ea0a2695cc
commit 29ae17d535
11 changed files with 365 additions and 79 deletions

View File

@@ -18,17 +18,13 @@ import inf101.v18.grid.IGrid;
import inf101.v18.grid.ILocation;
import inf101.v18.rogue101.Main;
import inf101.v18.rogue101.examples.Carrot;
import inf101.v18.rogue101.items.Manga;
import inf101.v18.rogue101.examples.Rabbit;
import inf101.v18.rogue101.map.GameMap;
import inf101.v18.rogue101.map.IGameMap;
import inf101.v18.rogue101.map.IMapView;
import inf101.v18.rogue101.map.MapReader;
import inf101.v18.rogue101.objects.Dust;
import inf101.v18.rogue101.objects.IActor;
import inf101.v18.rogue101.objects.IItem;
import inf101.v18.rogue101.objects.INonPlayer;
import inf101.v18.rogue101.objects.IPlayer;
import inf101.v18.rogue101.objects.Wall;
import inf101.v18.rogue101.objects.*;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.input.KeyCode;
import javafx.scene.paint.Color;
@@ -63,9 +59,7 @@ public class Game implements IGame {
this.painter = painter;
this.printer = printer;
// TODO: (*very* optional) for advanced factory technique, use
// something like "itemFactories.put("R", () -> new Rabbit());"
// must be done *before* you read the map
addFactory();
// NOTE: in a more realistic situation, we will have multiple levels (one map
// per level), and (at least for a Roguelike game) the levels should be
@@ -90,8 +84,13 @@ public class Game implements IGame {
}
public Game(String mapString) {
printer = new Printer(1280, 720);
painter = new TurtlePainter(1280, 720, null);
//printer = new Printer(1280, 720);
//painter = new TurtlePainter(1280, 720, null);
printer = null;
painter = null;
addFactory();
IGrid<String> inputGrid = MapReader.readString(mapString);
this.map = new GameMap(inputGrid.getArea());
for (ILocation loc : inputGrid.locations()) {
@@ -149,7 +148,7 @@ public class Game implements IGame {
}
if (random.nextInt(100) < 20) {
ILocation loc = map.getLocation((int)(Math.random() * map.getWidth()), (int)(Math.random() * map.getHeight()));
ILocation loc = map.getLocation(random.nextInt(map.getWidth()), random.nextInt(map.getHeight()));
if (!map.hasActors(loc) && !map.hasItems(loc) && !map.hasWall(loc)) {
map.add(loc, new Carrot());
}
@@ -250,20 +249,18 @@ public class Game implements IGame {
return map.canGo(currentLocation, dir);
}
private void addFactory() {
itemFactories.put("#", Wall::new);
itemFactories.put("@", Player::new);
itemFactories.put("C", Carrot::new);
itemFactories.put("R", Rabbit::new);
itemFactories.put("M", Manga::new);
itemFactories.put(".", Dust::new);
}
@Override
public IItem createItem(String sym) {
switch (sym) {
case "#":
return new Wall();
case ".":
// TODO: add Dust
return null;
case "R":
return new Rabbit();
case "C":
return new Carrot();
case "@":
// TODO: add Player
case " ":
return null;
default: