Merge branch 'master' of https://github.com/bokrosbalint/cicaprojekt
1
.gitignore
vendored
@ -28,3 +28,4 @@ local.properties
|
||||
.buildpath
|
||||
.idea
|
||||
out/*
|
||||
Test.java
|
BIN
BlueStargate.png
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
GreenStargate.png
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
ONeill.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
RedStargate.png
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
Replicator.png
Normal file
After Width: | Height: | Size: 20 KiB |
BIN
SpecialWall.png
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
YellowStargate.png
Normal file
After Width: | Height: | Size: 22 KiB |
@ -1,5 +0,0 @@
|
||||
4x3
|
||||
|
||||
W W W W
|
||||
W O Z W
|
||||
W W W W
|
65
cicaprojekt/ApplicationFrame.java
Normal file
@ -0,0 +1,65 @@
|
||||
package cicaprojekt;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.File;
|
||||
|
||||
public class ApplicationFrame implements Runnable
|
||||
{
|
||||
private Game game;
|
||||
|
||||
private JFrame jframe;
|
||||
|
||||
private JPanel mapselectorpanel;
|
||||
private JPanel gamepanel;
|
||||
|
||||
private JList<File> filelist;
|
||||
|
||||
|
||||
public ApplicationFrame(Game game){
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
private class ListMouseHandler extends MouseAdapter{
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
JOptionPane.showMessageDialog(null, ((JList<File>)e.getComponent()).getSelectedValue().toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void init(){
|
||||
jframe = new JFrame();
|
||||
jframe.setMinimumSize(new Dimension(600, 400));
|
||||
|
||||
mapselectorpanel = new JPanel();
|
||||
|
||||
DefaultListModel<File> dungeonslist = new DefaultListModel<>();
|
||||
File dir = new File(System.getProperty("user.dir"));
|
||||
FileNameExtensionFilter filter = new FileNameExtensionFilter("N/A", "dungeon");
|
||||
|
||||
for (File f : dir.listFiles()) {
|
||||
if (filter.accept(f) && f.isFile()){
|
||||
dungeonslist.addElement(f);
|
||||
}
|
||||
}
|
||||
|
||||
filelist = new JList<>(dungeonslist);
|
||||
filelist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
filelist.setLayoutOrientation(JList.HORIZONTAL_WRAP);
|
||||
filelist.addMouseListener(new ListMouseHandler());
|
||||
|
||||
mapselectorpanel.add(filelist);
|
||||
|
||||
jframe.add(mapselectorpanel);
|
||||
|
||||
//TODO rewrite demo ListMouseHandler and do Game stuff...
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
jframe.setVisible(true);
|
||||
}
|
||||
}
|
63
cicaprojekt/Control.java
Normal file
@ -0,0 +1,63 @@
|
||||
package cicaprojekt;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
public class Control {
|
||||
private Game game;
|
||||
|
||||
public class KeyHandler extends KeyAdapter{
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
char c = e.getKeyChar();
|
||||
c = Character.toUpperCase(c);
|
||||
switch(c) {
|
||||
case 'W' :
|
||||
game.moveONeill(Direction.NORTH);
|
||||
break;
|
||||
case 'A' :
|
||||
game.moveONeill(Direction.WEST);
|
||||
break;
|
||||
case 'S' :
|
||||
game.moveONeill(Direction.SOUTH);
|
||||
break;
|
||||
case 'D' :
|
||||
game.moveONeill(Direction.EAST);
|
||||
break;
|
||||
case 'I' :
|
||||
game.moveJaffa(Direction.NORTH);
|
||||
break;
|
||||
case 'J' :
|
||||
game.moveJaffa(Direction.WEST);
|
||||
break;
|
||||
case 'K' :
|
||||
game.moveJaffa(Direction.SOUTH);
|
||||
break;
|
||||
case 'L' :
|
||||
game.moveJaffa(Direction.EAST);
|
||||
break;
|
||||
case 'Q' :
|
||||
game.boxONeill();
|
||||
break;
|
||||
case 'U' :
|
||||
game.boxJaffa();
|
||||
break;
|
||||
case 'E' :
|
||||
game.shootStargate(Color.YELLOW);
|
||||
break;
|
||||
case 'R' :
|
||||
game.shootStargate(Color.BLUE);
|
||||
break;
|
||||
case 'O' :
|
||||
game.shootStargate(Color.RED);
|
||||
break;
|
||||
case 'P' :
|
||||
game.shootStargate(Color.GREEN);
|
||||
break;
|
||||
}
|
||||
game.updateDisplay();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
22
cicaprojekt/Display.java
Normal file
@ -0,0 +1,22 @@
|
||||
package cicaprojekt;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Display {
|
||||
private List<Drawer> visuals;
|
||||
|
||||
public Display() {
|
||||
visuals = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addVisual(Drawer visual) {
|
||||
visuals.add(visual);
|
||||
}
|
||||
|
||||
public void drawVisuals() throws IOException {
|
||||
for(Drawer visual : visuals)
|
||||
visual.draw();
|
||||
}
|
||||
}
|
10
cicaprojekt/Drawer.java
Normal file
@ -0,0 +1,10 @@
|
||||
package cicaprojekt;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface Drawer {
|
||||
|
||||
public void draw() throws IOException;
|
||||
public int getTileX();
|
||||
public int getTileY();
|
||||
}
|
@ -31,7 +31,7 @@ public class Dungeon {
|
||||
* S: Scale
|
||||
* X: Gap
|
||||
* R: Replicator */
|
||||
Map<String, Tile> buildDungeon(File input) throws IOException
|
||||
Map<String, Tile> buildDungeon(File input, Display display) throws IOException
|
||||
{
|
||||
Tile defaultTile = new Field();
|
||||
defaultTile.setX(-666);
|
||||
@ -63,29 +63,35 @@ public class Dungeon {
|
||||
{
|
||||
case 'W':
|
||||
tile = new Wall();
|
||||
display.addVisual(new WallDrawer((Wall) tile));
|
||||
break;
|
||||
|
||||
case 'F':
|
||||
tile = new Field();
|
||||
display.addVisual(new FieldDrawer((Field) tile));
|
||||
break;
|
||||
|
||||
case 'Z':
|
||||
tile = new Field();
|
||||
display.addVisual(new FieldDrawer((Field) tile));
|
||||
tile.setZPMOnTile(new ZPM());
|
||||
break;
|
||||
|
||||
case 'B':
|
||||
tile = new Field();
|
||||
display.addVisual(new FieldDrawer((Field) tile));
|
||||
tile.putABox(new Box());
|
||||
break;
|
||||
|
||||
case 'O':
|
||||
tile = new Field();
|
||||
display.addVisual(new FieldDrawer((Field) tile));
|
||||
oneilllocation = tile;
|
||||
break;
|
||||
|
||||
case 'J':
|
||||
tile = new Field();
|
||||
display.addVisual(new FieldDrawer((Field) tile));
|
||||
jaffalocation = tile;
|
||||
break;
|
||||
|
||||
@ -100,10 +106,12 @@ public class Dungeon {
|
||||
|
||||
case 'X':
|
||||
tile = new Gap();
|
||||
display.addVisual(new GapDrawer((Gap) tile));
|
||||
break;
|
||||
|
||||
case 'R':
|
||||
tile = new Field();
|
||||
display.addVisual(new FieldDrawer((Field) tile));
|
||||
replicatorlocation = tile;
|
||||
break;
|
||||
}
|
||||
@ -125,13 +133,16 @@ public class Dungeon {
|
||||
int triggerweight = Integer.parseInt(scaledata[4]);
|
||||
|
||||
Gate gate = new Gate();
|
||||
display.addVisual(new GateDrawer(gate));
|
||||
gate.setY(gy);
|
||||
gate.setX(gx);
|
||||
|
||||
Scale scale = new Scale(gate, triggerweight);
|
||||
display.addVisual(new ScaleDrawer(scale));
|
||||
scale.setY(sy);
|
||||
scale.setX(sx);
|
||||
|
||||
dungeon[gy][gx] = gate;
|
||||
dungeon[sy][sx] = scale;
|
||||
}
|
||||
|
||||
|
37
cicaprojekt/FieldDrawer.java
Normal file
@ -0,0 +1,37 @@
|
||||
package cicaprojekt;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class FieldDrawer extends ImagePanel implements Drawer {
|
||||
|
||||
Field field;
|
||||
|
||||
public FieldDrawer(Field f) throws IOException {
|
||||
super("Field.png");
|
||||
field = f;
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() throws IOException {
|
||||
if(field.hasBox())
|
||||
changeImage("Box.png");
|
||||
else if(field.hasZPM())
|
||||
changeImage("ZPM.png");
|
||||
else
|
||||
changeImage("Field.png");
|
||||
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTileX() {
|
||||
return field.getX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTileY() {
|
||||
return field.getY();
|
||||
}
|
||||
|
||||
}
|
@ -6,8 +6,18 @@ import java.util.TimerTask;
|
||||
public class FlowOfTime extends Timer {
|
||||
private TimerTask timeup;
|
||||
private long gametime;
|
||||
private Game game;
|
||||
|
||||
|
||||
public void start() {
|
||||
private class GameOver extends TimerTask {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
game.stopGame(GameoverCause.TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
public void start(long delay) {
|
||||
schedule(new GameOver(), delay);
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,81 @@
|
||||
package cicaprojekt;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class Game {
|
||||
private Player oneill;
|
||||
private Player jaffa;
|
||||
|
||||
private PlayerBase replicator;
|
||||
|
||||
private Dungeon dungeon;
|
||||
private Random random;
|
||||
private FlowOfTime flowoftime;
|
||||
|
||||
public static void main(String[] args) {
|
||||
private Display display;
|
||||
|
||||
public Game() {
|
||||
dungeon = new Dungeon();
|
||||
random = new Random();
|
||||
flowoftime = new FlowOfTime();
|
||||
display = new Display();
|
||||
}
|
||||
|
||||
public void allZPMsCollected() {
|
||||
this.stopGame();
|
||||
public void allZPMsCollected(GameoverCause cause) {
|
||||
this.stopGame(cause);
|
||||
}
|
||||
|
||||
public void startGame() {
|
||||
public void startGame(File dungeonFile) throws IOException {
|
||||
Stargate.init();
|
||||
|
||||
Map<String, Tile> players = dungeon.buildDungeon(dungeonFile, display);
|
||||
oneill = new Player("O'Neill", players.get("oneill"), getRandomDirection());
|
||||
jaffa = new Player("Jaffa", players.get("jaffa"), getRandomDirection());
|
||||
replicator = new PlayerBase("Replicator", players.get("replicator"), getRandomDirection());
|
||||
|
||||
flowoftime.start(420*420);
|
||||
}
|
||||
|
||||
public void stopGame() {
|
||||
private Direction getRandomDirection() {
|
||||
return Direction.values()[random.nextInt(Direction.values().length)];
|
||||
}
|
||||
|
||||
public void stopGame(GameoverCause cause) {
|
||||
}
|
||||
|
||||
public void moveONeill(Direction direction) {
|
||||
oneill.move(direction);
|
||||
}
|
||||
|
||||
public void moveJaffa(Direction direction) {
|
||||
jaffa.move(direction);
|
||||
}
|
||||
|
||||
public void boxONeill() {
|
||||
if(oneill.hasBox())
|
||||
oneill.boxDrop();
|
||||
else
|
||||
oneill.boxLift();
|
||||
}
|
||||
|
||||
public void boxJaffa() {
|
||||
if(jaffa.hasBox())
|
||||
jaffa.boxDrop();
|
||||
else
|
||||
jaffa.boxLift();
|
||||
}
|
||||
|
||||
public void shootStargate(Color color) {
|
||||
if(color == Color.YELLOW || color == Color.BLUE)
|
||||
oneill.shootStargate(Stargate.get(color));
|
||||
else
|
||||
jaffa.shootStargate(Stargate.get(color));
|
||||
}
|
||||
|
||||
public void updateDisplay() {
|
||||
}
|
||||
}
|
||||
|
5
cicaprojekt/GameoverCause.java
Normal file
@ -0,0 +1,5 @@
|
||||
package cicaprojekt;
|
||||
|
||||
public enum GameoverCause {
|
||||
TIMEOUT, ONEILLWON, JAFFAWON;
|
||||
}
|
30
cicaprojekt/GapDrawer.java
Normal file
@ -0,0 +1,30 @@
|
||||
package cicaprojekt;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class GapDrawer extends ImagePanel implements Drawer{
|
||||
|
||||
private Gap gap;
|
||||
|
||||
public GapDrawer(Gap g) throws IOException {
|
||||
super("Gap.png");
|
||||
gap = g;
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTileX() {
|
||||
return gap.getX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTileY() {
|
||||
return gap.getY();
|
||||
}
|
||||
|
||||
}
|
35
cicaprojekt/GateDrawer.java
Normal file
@ -0,0 +1,35 @@
|
||||
package cicaprojekt;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class GateDrawer extends ImagePanel implements Drawer{
|
||||
|
||||
Gate gate;
|
||||
|
||||
public GateDrawer(Gate g) throws IOException {
|
||||
super("ClosedGate.png");
|
||||
gate = g;
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() throws IOException {
|
||||
if(gate.isOpen())
|
||||
changeImage("Field.png"); //TODO picture for open gate.
|
||||
else
|
||||
changeImage("ClosedGate.png");
|
||||
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTileX() {
|
||||
return gate.getX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTileY() {
|
||||
return gate.getY();
|
||||
}
|
||||
|
||||
}
|
29
cicaprojekt/ImagePanel.java
Normal file
@ -0,0 +1,29 @@
|
||||
package cicaprojekt;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class ImagePanel extends JPanel{
|
||||
|
||||
private BufferedImage image;
|
||||
|
||||
public ImagePanel(String path) throws IOException {
|
||||
image = ImageIO.read(new File(path));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
g.drawImage(image, 0, 0, null); // see javadoc for more info on the parameters
|
||||
}
|
||||
|
||||
public void changeImage(String path) throws IOException {
|
||||
image = ImageIO.read(new File(path));
|
||||
repaint();
|
||||
}
|
||||
}
|
@ -1,65 +1,8 @@
|
||||
package cicaprojekt;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.Console;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class Menu {
|
||||
public static void main(String[] args) throws IOException, InvocationTargetException, IllegalAccessException {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Continuously Integrated Cica Projekt - Proto");
|
||||
System.out.println("Üdvözöllek a Babylon Simulator 2000 játékban! Kérlek válassz egy menüpontot!");
|
||||
|
||||
Tester tester = new Tester();
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||
|
||||
boolean isExiting = false;
|
||||
while (!isExiting) {
|
||||
try {
|
||||
String[] input = br.readLine().split(" ");
|
||||
switch (input[0]) {
|
||||
case "loadMap":
|
||||
tester.loadMap(input[1]);
|
||||
break;
|
||||
case "listPlayers":
|
||||
System.out.println(tester.listPlayers());
|
||||
break;
|
||||
case "move":
|
||||
tester.move(input[1]);
|
||||
break;
|
||||
case "boxLift":
|
||||
System.out.println(tester.boxLift(input[1]));
|
||||
break;
|
||||
case "boxDrop":
|
||||
System.out.println(tester.boxDrop(input[1]));
|
||||
break;
|
||||
case "shootONeillsGun":
|
||||
tester.shootONeillsGun(input[1]);
|
||||
break;
|
||||
case "rotate":
|
||||
tester.rotate(input[1], input[2]);
|
||||
break;
|
||||
case "listStargates":
|
||||
System.out.println(tester.listStargates());
|
||||
break;
|
||||
case "runAllTests":
|
||||
boolean testresult = tester.runAllTests();
|
||||
if (testresult)
|
||||
System.out.println("All tests successful!");
|
||||
else
|
||||
System.out.println("Tests failed!");
|
||||
break;
|
||||
case "exit":
|
||||
isExiting = true;
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
//TODO not so granular error handling
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,10 @@ public class Player extends PlayerBase {
|
||||
zpmContainer = new ArrayList<>();
|
||||
}
|
||||
|
||||
public boolean hasBox() {
|
||||
return (boxLifted != null);
|
||||
}
|
||||
|
||||
public void boxLift() {
|
||||
boxLifted = (Box) currentTile.getAdjacentTile(facingDirection).getABox();
|
||||
}
|
||||
|
49
cicaprojekt/PlayerBaseDrawer.java
Normal file
@ -0,0 +1,49 @@
|
||||
package cicaprojekt;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class PlayerBaseDrawer extends ImagePanel implements Drawer {
|
||||
PlayerBase playerbase;
|
||||
|
||||
public PlayerBaseDrawer(PlayerBase pb) throws IOException {
|
||||
super("Replicator.png");
|
||||
playerbase = pb;
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() throws IOException {
|
||||
|
||||
//TODO Pictures for different facing directions.
|
||||
switch(playerbase.name){
|
||||
case "Replicator":
|
||||
switch(playerbase.facingDirection){
|
||||
case NORTH:
|
||||
changeImage("ONeill.png");
|
||||
break;
|
||||
case EAST:
|
||||
changeImage("ONeill.png");
|
||||
break;
|
||||
case SOUTH:
|
||||
changeImage("ONeill.png");
|
||||
break;
|
||||
default:
|
||||
changeImage("ONeill.png");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTileX() {
|
||||
return playerbase.currentTile.getX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTileY() {
|
||||
return playerbase.currentTile.getY();
|
||||
}
|
||||
|
||||
}
|
67
cicaprojekt/PlayerDrawer.java
Normal file
@ -0,0 +1,67 @@
|
||||
package cicaprojekt;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class PlayerDrawer extends ImagePanel implements Drawer {
|
||||
Player player;
|
||||
|
||||
public PlayerDrawer(Player p) throws IOException {
|
||||
super("ONeill.png");
|
||||
player = p;
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() throws IOException {
|
||||
|
||||
//TODO Pictures for different facing directions.
|
||||
switch(player.name){
|
||||
case "O'Neill":
|
||||
switch(player.facingDirection){
|
||||
case NORTH:
|
||||
changeImage("ONeill.png");
|
||||
break;
|
||||
case EAST:
|
||||
changeImage("ONeill.png");
|
||||
break;
|
||||
case SOUTH:
|
||||
changeImage("ONeill.png");
|
||||
break;
|
||||
default:
|
||||
changeImage("ONeill.png");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
switch(player.facingDirection){
|
||||
case NORTH:
|
||||
changeImage("Jaffa.png");
|
||||
break;
|
||||
case EAST:
|
||||
changeImage("Jaffa.png");
|
||||
break;
|
||||
case SOUTH:
|
||||
changeImage("Jaffa.png");
|
||||
break;
|
||||
default:
|
||||
changeImage("Jaffa.png");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTileX() {
|
||||
return player.getCurrentTile().getX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTileY() {
|
||||
return player.getCurrentTile().getY();
|
||||
}
|
||||
|
||||
}
|
35
cicaprojekt/ScaleDrawer.java
Normal file
@ -0,0 +1,35 @@
|
||||
package cicaprojekt;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ScaleDrawer extends ImagePanel implements Drawer {
|
||||
|
||||
Scale scale;
|
||||
|
||||
public ScaleDrawer(Scale s) throws IOException {
|
||||
super("Scale.png");
|
||||
scale = s;
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() throws IOException {
|
||||
if(scale.hasBox())
|
||||
changeImage("Box.png"); //TODO Picture for Scale with box.
|
||||
else
|
||||
changeImage("Scale.png");
|
||||
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTileX() {
|
||||
return scale.getX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTileY() {
|
||||
return scale.getY();
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,9 @@
|
||||
package cicaprojekt;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Stargate {
|
||||
public static final Stargate yellowStargate = new Stargate("Yellow Stargate");
|
||||
public static final Stargate blueStargate = new Stargate("Blue Stargate");
|
||||
@ -10,6 +14,8 @@ public class Stargate {
|
||||
private Wall currentWall;
|
||||
private String name;
|
||||
|
||||
private static Map<Color, Stargate> stargates = new HashMap<>();
|
||||
|
||||
|
||||
private Stargate(String name) {
|
||||
isSpawned = false;
|
||||
@ -21,6 +27,15 @@ public class Stargate {
|
||||
blueStargate.other = yellowStargate;
|
||||
redStargate.other = greenStargate;
|
||||
greenStargate.other = redStargate;
|
||||
|
||||
stargates.put(Color.YELLOW, yellowStargate);
|
||||
stargates.put(Color.BLUE, blueStargate);
|
||||
stargates.put(Color.RED, redStargate);
|
||||
stargates.put(Color.GREEN, greenStargate);
|
||||
}
|
||||
|
||||
public static Stargate get(Color color) {
|
||||
return stargates.get(color);
|
||||
}
|
||||
|
||||
public Wall getCurrentWall() {
|
||||
@ -62,4 +77,8 @@ public class Stargate {
|
||||
return String.format("%s: %s", name, currentWall);
|
||||
else return String.format("%s: not spawned", name, currentWall);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
@ -1,286 +0,0 @@
|
||||
package cicaprojekt;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
public class Tester {
|
||||
private Player oneill;
|
||||
private Player jaffa;
|
||||
private PlayerBase replicator;
|
||||
|
||||
|
||||
Dungeon loadMap(String param) throws IOException{
|
||||
Dungeon dungeon = new Dungeon();
|
||||
Map playerLocations = dungeon.buildDungeon(new File(param));
|
||||
oneill = new Player("ONeill", (Tile) playerLocations.get("oneill"), Direction.NORTH);
|
||||
jaffa = new Player("Jaffa", (Tile) playerLocations.get("jaffa"), Direction.NORTH);
|
||||
replicator = new PlayerBase("Replicator", (Tile) playerLocations.get("replicator"), Direction.NORTH);
|
||||
return dungeon;
|
||||
}
|
||||
|
||||
String listPlayers() {
|
||||
return oneill.toString() + " " + jaffa.toString() + " " + replicator.toString();
|
||||
}
|
||||
|
||||
void move(String param) {
|
||||
switch (param) {
|
||||
case "O" :
|
||||
oneill.move(oneill.getFacingDirection());
|
||||
break;
|
||||
case "J" :
|
||||
jaffa.move(jaffa.getFacingDirection());
|
||||
break;
|
||||
default:
|
||||
//TODO error handling
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
String boxLift(String param) {
|
||||
switch (param) {
|
||||
case "O" :
|
||||
oneill.boxLift();
|
||||
break;
|
||||
case "J" :
|
||||
jaffa.boxLift();
|
||||
break;
|
||||
}
|
||||
return "box lifted";
|
||||
}
|
||||
|
||||
String boxDrop(String param) {
|
||||
switch (param) {
|
||||
case "O" :
|
||||
oneill.boxDrop();
|
||||
break;
|
||||
case "J" :
|
||||
jaffa.boxDrop();
|
||||
break;
|
||||
}
|
||||
return "box dropped";
|
||||
}
|
||||
|
||||
void shootONeillsGun(String param) {
|
||||
switch (param) {
|
||||
case "B" :
|
||||
oneill.shootStargate(Stargate.blueStargate);
|
||||
break;
|
||||
case "Y" :
|
||||
oneill.shootStargate(Stargate.yellowStargate);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
String rotate(String playerParam, String directionParam) {
|
||||
switch (playerParam) {
|
||||
case "O" :
|
||||
switch (directionParam) {
|
||||
case "L" :
|
||||
oneill.rotateLeft();
|
||||
return oneill.getFacingDirection().toString();
|
||||
case "R" :
|
||||
oneill.rotateRight();
|
||||
return oneill.getFacingDirection().toString();
|
||||
default: return "Hiba, nem fordult!";
|
||||
}
|
||||
case "J" :
|
||||
switch (directionParam) {
|
||||
case "L" :
|
||||
jaffa.rotateLeft();
|
||||
return jaffa.getFacingDirection().toString();
|
||||
case "R" :
|
||||
jaffa.rotateRight();
|
||||
return jaffa.getFacingDirection().toString();
|
||||
default: return "Hiba, nem fordult!";
|
||||
}
|
||||
default: return "Hiba, nem létező játékos!";
|
||||
}
|
||||
}
|
||||
|
||||
String listStargates() {
|
||||
String blue = Stargate.blueStargate.toString();
|
||||
String yellow = Stargate.yellowStargate.toString();
|
||||
String red = Stargate.redStargate.toString();
|
||||
String green = Stargate.greenStargate.toString();
|
||||
|
||||
return blue + " " + yellow + " " + red + " " + green;
|
||||
}
|
||||
|
||||
String getConnectedGateOpen(Scale s){
|
||||
if(s.getGateConnected().isOpen())
|
||||
return "gate open";
|
||||
else return "gate closed";
|
||||
}
|
||||
|
||||
/* custom Test annotation */
|
||||
@Target(ElementType.METHOD) // it's for methods
|
||||
@Retention(RetentionPolicy.RUNTIME) // we want to retain annotations in runtime
|
||||
private @interface Test {}
|
||||
|
||||
/* run all methods annotated with @Test */
|
||||
public boolean runAllTests() throws InvocationTargetException, IllegalAccessException
|
||||
{
|
||||
boolean testspassed = true;
|
||||
|
||||
for (Method m : this.getClass().getMethods()) // iterate over all methods of this
|
||||
{
|
||||
if (m.isAnnotationPresent(Test.class)) // if its annotated with @Test...
|
||||
{
|
||||
Boolean testresult = (Boolean) m.invoke(null); // call it!
|
||||
if (!testresult)
|
||||
{
|
||||
testspassed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return testspassed;
|
||||
}
|
||||
|
||||
@Test
|
||||
boolean moveTest() throws IOException{
|
||||
boolean success = true;
|
||||
|
||||
loadMap("moveTest.dungeon");
|
||||
|
||||
String listOfPlayers = listPlayers();
|
||||
if(!listOfPlayers.equals("ONeill: 1, 1 Jaffa: -666, -666 Replicator: -666, -666"))
|
||||
success = false;
|
||||
|
||||
move("O");
|
||||
|
||||
listOfPlayers = listPlayers();
|
||||
if(!listOfPlayers.equals("ONeill: 1, 2 Jaffa: -666, -666 Replicator: -666, -666"))
|
||||
success = false;
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
@Test
|
||||
boolean testStargates() throws IOException{
|
||||
boolean success = true;
|
||||
|
||||
loadMap("testStargates.dungeon");
|
||||
shootONeillsGun("B");
|
||||
rotate("O", "L");
|
||||
shootONeillsGun("Y");
|
||||
|
||||
String listOfStargates = listStargates();
|
||||
if(!listOfStargates.equals("BlueStargate: 5, 10 YellowStargate: 10, 5 RedStargate: not spawned GreenStargate: not spawned"))
|
||||
success = false;
|
||||
|
||||
move("O");
|
||||
move("O");
|
||||
move("O");
|
||||
|
||||
String listOfPlayers = listPlayers();
|
||||
if(!listOfPlayers.equals("ONeill: 5, 9 Jaffa: -666, -666 Replicator: -666, -666"))
|
||||
success = false;
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
@Test
|
||||
boolean testScalesAndGates() throws IOException {
|
||||
boolean success = true;
|
||||
|
||||
loadMap("testScalesAndGates.dungeon");
|
||||
boxLift("O");
|
||||
rotate("O", "L");
|
||||
boxDrop("O");
|
||||
|
||||
String gateOpen = getConnectedGateOpen((Scale)oneill.getCurrentTile().getAdjacentTile(oneill.facingDirection));
|
||||
|
||||
if(!gateOpen.equals("gate open"))
|
||||
success = false;
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
@Test
|
||||
boolean gapTest() throws IOException{
|
||||
|
||||
loadMap("gapTest.dungeon");
|
||||
move("O");
|
||||
|
||||
boolean success = oneill.isDestroyed();
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
@Test
|
||||
boolean ZPMTest() throws IOException{
|
||||
boolean success = true;
|
||||
|
||||
loadMap("ZPMTest.dungeon");
|
||||
move("O");
|
||||
|
||||
if(oneill.getZPMCount() != 1)
|
||||
success = false;
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
@Test
|
||||
boolean testReplicatorPosition(){
|
||||
String[] commands = {"loadMap testReplicatorPosition\n",
|
||||
"move O\n"};
|
||||
|
||||
String[] expectedOutputs = {};
|
||||
|
||||
boolean results = testOnSequenceOfCommands(commands, expectedOutputs);
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@Test
|
||||
boolean timeUpTest(){
|
||||
String[] commands = {"loadMap timeUpTest\n"};
|
||||
|
||||
String[] expectedOutputs = {};
|
||||
boolean results = testOnSequenceOfCommands(commands, expectedOutputs);
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
boolean rotationTest() throws IOException {
|
||||
boolean success = true;
|
||||
|
||||
loadMap("rotationTest.dungeon");
|
||||
|
||||
if(!rotate("O", "L").equals("WEST"))
|
||||
success = false;
|
||||
|
||||
if(!rotate("O", "R").equals("NORTH"))
|
||||
success = false;
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
@Test
|
||||
boolean testBoxes() throws IOException{
|
||||
boolean success = true;
|
||||
|
||||
loadMap("testBoxes.dungeon");
|
||||
|
||||
if(!boxLift("O").equals("box lifted"))
|
||||
success = false;
|
||||
|
||||
if(!boxDrop("O").equals("box dropped"))
|
||||
success = false;
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
private boolean testOnSequenceOfCommands(String[] commands, String[] expectedOutputs) {
|
||||
return true;
|
||||
}
|
||||
}
|
@ -71,4 +71,15 @@ public abstract class Tile {
|
||||
public String toString() {
|
||||
return String.format("%d, %d", x, y);
|
||||
}
|
||||
|
||||
public boolean hasZPM() {
|
||||
if(zpmOnTile == null)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hasBox() {
|
||||
return !boxStack.isEmpty();
|
||||
}
|
||||
}
|
||||
|
@ -36,4 +36,8 @@ public class Wall extends Tile {
|
||||
public void onExit(PlayerBase playerBase) throws IllegalStateException {
|
||||
throw new IllegalStateException("Hiba! Te hogy kerültél a falba?");
|
||||
}
|
||||
|
||||
public Stargate getStargate() {
|
||||
return sg;
|
||||
}
|
||||
}
|
||||
|
52
cicaprojekt/WallDrawer.java
Normal file
@ -0,0 +1,52 @@
|
||||
package cicaprojekt;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class WallDrawer extends ImagePanel implements Drawer {
|
||||
|
||||
Wall wall;
|
||||
|
||||
public WallDrawer(Wall w) throws IOException {
|
||||
super("Wall.png");
|
||||
wall = w;
|
||||
setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() throws IOException {
|
||||
if(wall.getStargate() == null)
|
||||
changeImage("Wall.png");
|
||||
else{
|
||||
switch(wall.getStargate().getName()){
|
||||
case "Blue Stargate":
|
||||
changeImage("BlueStargate.png");
|
||||
break;
|
||||
case "Yellow Stargate":
|
||||
changeImage("YellowStargate.png");
|
||||
break;
|
||||
case "Red Stargate":
|
||||
changeImage("RedStargate.png");
|
||||
break;
|
||||
case "Green Stargate":
|
||||
changeImage("GreenStargate.png");
|
||||
break;
|
||||
default:
|
||||
changeImage("Wall.png");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTileX() {
|
||||
return wall.getX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTileY() {
|
||||
return wall.getY();
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
4x3
|
||||
|
||||
W W W W
|
||||
W O X W
|
||||
W W W W
|
||||
|
@ -1,8 +0,0 @@
|
||||
5x5
|
||||
|
||||
W W W W W
|
||||
W O F F W
|
||||
W F F F W
|
||||
W F F F W
|
||||
W W W W W
|
||||
|
@ -1,5 +0,0 @@
|
||||
3x3
|
||||
|
||||
W W W
|
||||
W O W
|
||||
W W W
|
@ -1,6 +0,0 @@
|
||||
4x4
|
||||
|
||||
W W W W
|
||||
W O B W
|
||||
W F F W
|
||||
W W W W
|
@ -1,5 +0,0 @@
|
||||
4x3
|
||||
|
||||
W W W W
|
||||
W O X W
|
||||
W W W W
|
@ -1,6 +0,0 @@
|
||||
4x4
|
||||
|
||||
W W W W
|
||||
W R O W
|
||||
W S B W
|
||||
W W W W
|
@ -1,8 +0,0 @@
|
||||
5x4
|
||||
|
||||
W W W W W
|
||||
W O F F G
|
||||
W F S B W
|
||||
W W W W W
|
||||
|
||||
2-2-1-4-1
|
@ -1,6 +0,0 @@
|
||||
5x4
|
||||
|
||||
W W W W W
|
||||
W O F F W
|
||||
W F F F W
|
||||
W W W W W
|
@ -1,5 +0,0 @@
|
||||
4x3
|
||||
|
||||
X X X X
|
||||
X O X Z
|
||||
X X X X
|