ÆÆÆÆ Eg er lei av å skrive
Del A er implementert sånn omtrentlig ok. Tester har blitt fikset slik at de fungerer med Intellij. Noen kommentarer har blitt fikset. En del dårlig kode har blitt fikset.
This commit is contained in:
@ -12,7 +12,7 @@ public class BlocksAndBoxes {
|
||||
|
||||
private List<Integer> order;
|
||||
|
||||
private PixelOrder(int a, int b, int c, int d) {
|
||||
PixelOrder(int a, int b, int c, int d) {
|
||||
order = Arrays.asList(a, b, c, d);
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ public class BlocksAndBoxes {
|
||||
public static final String BLOCK_REVERSE_BOTTOM_RIGHT = "▛";
|
||||
public static final String BLOCK_FULL = "█";
|
||||
|
||||
public static final String BLOCK_HALF = "▒";;
|
||||
public static final String BLOCK_HALF = "▒";
|
||||
|
||||
public static String blockAddOne(String s, PixelOrder order) {
|
||||
int i = BlocksAndBoxes.unicodeBlocksString.indexOf(s);
|
||||
|
@ -74,7 +74,7 @@ public class DemoPages {
|
||||
printer.println(" 0123456789ABCDEF 0123456789ABCDEF");
|
||||
for (int y = 0; y < 16; y++) {
|
||||
printer.print(String.format(" %X", y));
|
||||
int c = 0x00 + y * 0x010;
|
||||
int c = y * 0x010;
|
||||
for (int x = 0; x < 16; x++) {
|
||||
printer.print(c >= 0x20 ? Character.toString((char) (c + x)) : " ");
|
||||
}
|
||||
|
@ -305,8 +305,6 @@ public class TextFont {
|
||||
* @param font
|
||||
* Name of the font file. Will search for the file in the same folder
|
||||
* as the TextFont class, as well as ".." and "../fonts".
|
||||
* @param size
|
||||
* Point size of the font.
|
||||
* @param squareSize
|
||||
* The width and height of a square defining the bounds of letters
|
||||
* @param xTranslate
|
||||
@ -350,10 +348,7 @@ public class TextFont {
|
||||
* {@link #setGraphicsContext(GraphicsContext, double)} for extra on-the-fly
|
||||
* horizontal scaling, e.g. to make half-width letters ("hires" mode).
|
||||
*
|
||||
*
|
||||
* @param font
|
||||
* Name of the font file. Will search for the file in the same folder
|
||||
* as the TextFont class, as well as ".." and "../fonts".
|
||||
*
|
||||
* @param size
|
||||
* Point size of the font.
|
||||
* @param squareSize
|
||||
@ -400,10 +395,7 @@ public class TextFont {
|
||||
* {@link #setGraphicsContext(GraphicsContext, double)} for extra on-the-fly
|
||||
* horizontal scaling, e.g. to make half-width letters ("hires" mode).
|
||||
*
|
||||
*
|
||||
* @param font
|
||||
* Name of the font file. Will search for the file in the same folder
|
||||
* as the TextFont class, as well as ".." and "../fonts".
|
||||
*
|
||||
* @param size
|
||||
* Point size of the font.
|
||||
* @param squareSize
|
||||
@ -739,13 +731,13 @@ public class TextFont {
|
||||
case '0':
|
||||
return -2 * thin;
|
||||
case '2':
|
||||
ctx.setLineDashes(new double[] { 14.75, 2.5 });
|
||||
ctx.setLineDashes(14.75, 2.5);
|
||||
break;
|
||||
case '3':
|
||||
ctx.setLineDashes(new double[] { 9, 2.5 });
|
||||
ctx.setLineDashes(9, 2.5);
|
||||
break;
|
||||
case '4':
|
||||
ctx.setLineDashes(new double[] { 6.125, 2.5 });
|
||||
ctx.setLineDashes(6.125, 2.5);
|
||||
break;
|
||||
case '.':
|
||||
return 0.0;
|
||||
|
@ -55,7 +55,7 @@ public enum TextMode {
|
||||
|
||||
private int vIndex;
|
||||
|
||||
private TextMode(int w, int h, int aspect) {
|
||||
TextMode(int w, int h, int aspect) {
|
||||
this.hIndex = w;
|
||||
this.vIndex = h;
|
||||
this.aspect = aspect;
|
||||
|
@ -32,7 +32,7 @@ public enum GridDirection {
|
||||
private final int dy;
|
||||
private final int mask;
|
||||
|
||||
private GridDirection(double degrees, int dx, int dy, int mask) {
|
||||
GridDirection(double degrees, int dx, int dy, int mask) {
|
||||
this.degrees = degrees;
|
||||
this.dx = dx;
|
||||
this.dy = dy;
|
||||
|
@ -52,8 +52,8 @@ public interface IGrid<T> extends Iterable<T> {
|
||||
* // clear the grid
|
||||
* grid.setAll(null);
|
||||
* </pre>
|
||||
*
|
||||
* @param initialiser
|
||||
*
|
||||
* @param element
|
||||
*/
|
||||
void fill(T element);
|
||||
|
||||
@ -203,8 +203,6 @@ public interface IGrid<T> extends Iterable<T> {
|
||||
* y must be greater than or equal to 0 and less than getHeight(). x must be
|
||||
* greater than or equal to 0 and less than getWidth().
|
||||
*
|
||||
* @param pos
|
||||
* The (x,y) position of the grid cell to get the contents of.
|
||||
* @param element
|
||||
* The contents the cell is to have.
|
||||
* @throws IndexOutOfBoundsException
|
||||
|
@ -95,9 +95,7 @@ public class MyGrid<T> implements IGrid<T> {
|
||||
|
||||
@Override
|
||||
public IGrid<T> copy() {
|
||||
MyGrid<T> newGrid = new MyGrid<>(getWidth(), getHeight(), (l) -> get(l));
|
||||
|
||||
return newGrid;
|
||||
return new MyGrid<>(getWidth(), getHeight(), (l) -> get(l));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -80,10 +80,7 @@ public class RectArea implements IArea {
|
||||
if (x != other.getX()) {
|
||||
return false;
|
||||
}
|
||||
if (y != other.getY()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return y == other.getY();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -304,10 +301,7 @@ public class RectArea implements IArea {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("RectArea [width=").append(width).append(", height=").append(height).append(", hWrap=")
|
||||
.append(hWrap).append(", vWrap=").append(vWrap).append("]");
|
||||
return builder.toString();
|
||||
return "RectArea [width=" + width + ", height=" + height + ", hWrap=" + hWrap + ", vWrap=" + vWrap + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -12,7 +12,7 @@ import static org.junit.Assert.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
public class AreaRetting {
|
||||
private static final int N = 10000;
|
||||
|
@ -11,7 +11,7 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
public class GridRetting {
|
||||
private static final int N = 10000;
|
||||
|
@ -8,7 +8,7 @@ import javafx.scene.paint.Color;
|
||||
public class Carrot implements IItem {
|
||||
private int hp = getMaxHealth();
|
||||
|
||||
public void doTurn(IGame game) {
|
||||
public void doTurn() {
|
||||
hp = Math.min(hp + 1, getMaxHealth());
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ public class Carrot implements IItem {
|
||||
|
||||
@Override
|
||||
public int getMaxHealth() {
|
||||
return 10;
|
||||
return 23;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -74,7 +74,7 @@ public class Carrot implements IItem {
|
||||
|
||||
if (hp < 0) {
|
||||
// we're all eaten!
|
||||
hp = -1;
|
||||
hp = 0;
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
package inf101.v18.rogue101.examples;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import inf101.v18.gfx.gfxmode.ITurtle;
|
||||
import inf101.v18.grid.GridDirection;
|
||||
import inf101.v18.grid.ILocation;
|
||||
import inf101.v18.rogue101.game.IGame;
|
||||
import inf101.v18.rogue101.objects.IItem;
|
||||
import inf101.v18.rogue101.objects.INonPlayer;
|
||||
@ -16,12 +16,14 @@ public class Rabbit implements INonPlayer {
|
||||
|
||||
@Override
|
||||
public void doTurn(IGame game) {
|
||||
if (food == 0)
|
||||
if (food == 0) {
|
||||
hp--;
|
||||
else
|
||||
} else {
|
||||
food--;
|
||||
if (hp < 1)
|
||||
}
|
||||
if (hp < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (IItem item : game.getLocalItems()) {
|
||||
if (item instanceof Carrot) {
|
||||
@ -36,12 +38,18 @@ public class Rabbit implements INonPlayer {
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: prøv forskjellige varianter her
|
||||
List<GridDirection> possibleMoves = new ArrayList<>();
|
||||
for (GridDirection dir : GridDirection.FOUR_DIRECTIONS) {
|
||||
if (game.canGo(dir))
|
||||
possibleMoves.add(dir);
|
||||
|
||||
List<GridDirection> possibleMoves = game.getPossibleMoves();
|
||||
for (GridDirection dir : possibleMoves) {
|
||||
ILocation loc = game.getLocation(dir);
|
||||
for (IItem item : game.getMap().getItems(loc)) {
|
||||
if (item instanceof Carrot) {
|
||||
game.move(dir);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!possibleMoves.isEmpty()) {
|
||||
Collections.shuffle(possibleMoves);
|
||||
game.move(possibleMoves.get(0));
|
||||
@ -75,7 +83,7 @@ public class Rabbit implements INonPlayer {
|
||||
|
||||
@Override
|
||||
public int getMaxHealth() {
|
||||
return 10;
|
||||
return 30;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -148,6 +148,13 @@ public class Game implements IGame {
|
||||
beginTurn();
|
||||
}
|
||||
|
||||
if (random.nextInt(100) < 20) {
|
||||
ILocation loc = map.getLocation((int)(Math.random() * map.getWidth()), (int)(Math.random() * map.getHeight()));
|
||||
if (!map.hasActors(loc) && !map.hasItems(loc) && !map.hasWall(loc)) {
|
||||
map.add(loc, new Carrot());
|
||||
}
|
||||
}
|
||||
|
||||
// process actors one by one; for the IPlayer, we return and wait for keypresses
|
||||
// Possible TODO: for INonPlayer, we could also return early (returning
|
||||
// *false*), and then insert a little timer delay between each non-player move
|
||||
@ -231,6 +238,8 @@ public class Game implements IGame {
|
||||
}
|
||||
} else if (item instanceof IActor) {
|
||||
actors.add((IActor) item); // add other actors to the end of the list
|
||||
} else if (item instanceof Carrot) {
|
||||
((Carrot) item).doTurn();
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -356,8 +365,13 @@ public class Game implements IGame {
|
||||
|
||||
@Override
|
||||
public List<GridDirection> getPossibleMoves() {
|
||||
// TODO
|
||||
throw new UnsupportedOperationException();
|
||||
List<GridDirection> moves = new ArrayList<>();
|
||||
for (GridDirection dir : GridDirection.FOUR_DIRECTIONS) {
|
||||
if (canGo(dir)) {
|
||||
moves.add(dir);
|
||||
}
|
||||
}
|
||||
return moves;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -187,7 +187,7 @@ public interface IGame {
|
||||
double[] getFreeGraphicsAreaBounds();
|
||||
|
||||
/**
|
||||
* Get the bounds of the free texxt area.
|
||||
* Get the bounds of the free text area.
|
||||
* <p>
|
||||
* You can fill this with whatever you want, using {@link #getPrinter()} and
|
||||
* {@link #clearFreeTextArea()}.
|
||||
|
@ -2,7 +2,7 @@ package inf101.v18.rogue101.tests;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import inf101.v18.grid.ILocation;
|
||||
import inf101.v18.rogue101.map.GameMap;
|
||||
|
@ -2,7 +2,7 @@ package inf101.v18.rogue101.tests;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.Test;
|
||||
|
||||
import inf101.v18.grid.GridDirection;
|
||||
import inf101.v18.grid.ILocation;
|
||||
|
@ -82,8 +82,6 @@ public class DoubleGenerator extends AbstractGenerator<Double> {
|
||||
public Double generate(Random rng) {
|
||||
double d = rng.nextDouble();
|
||||
|
||||
double r = minValue + (d * diff);
|
||||
|
||||
return r;
|
||||
return minValue + (d * diff);
|
||||
}
|
||||
}
|
||||
|
@ -73,8 +73,6 @@ public class GridGenerator<T> extends AbstractGenerator<IGrid<T>> {
|
||||
int w = widthGenerator.generate(r);
|
||||
int h = heightGenerator.generate(r);
|
||||
|
||||
IGrid<T> grid = new MyGrid<>(w, h, (l) -> elementGenerator.generate(r));
|
||||
|
||||
return grid;
|
||||
return new MyGrid<>(w, h, (l) -> elementGenerator.generate(r));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user