Structure
This commit is contained in:
parent
0c16b87dd1
commit
59c444d162
@ -1,3 +1,6 @@
|
|||||||
|
import ruscz.game.gameOfProd.Map.MapManager;
|
||||||
|
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
||||||
|
|
||||||
public class Game {
|
public class Game {
|
||||||
private MapManager mm;
|
private MapManager mm;
|
||||||
|
|
||||||
|
|||||||
@ -1,14 +0,0 @@
|
|||||||
import java.util.LinkedList;
|
|
||||||
|
|
||||||
public class MapManager {
|
|
||||||
WindowOfFreeMove window;
|
|
||||||
LinkedList<Map> maps;
|
|
||||||
Map actualMap;
|
|
||||||
|
|
||||||
MapManager(WindowOfFreeMove window){
|
|
||||||
this.window = window;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,3 +1,8 @@
|
|||||||
|
package ruscz.game.gameOfProd.Cells;
|
||||||
|
|
||||||
|
import ruscz.game.gameOfProd.Image.ImageCell;
|
||||||
|
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class Block extends Cell {
|
public class Block extends Cell {
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
package ruscz.game.gameOfProd.Cells;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class Cell {
|
public class Cell {
|
||||||
@ -1,3 +1,9 @@
|
|||||||
|
package ruscz.game.gameOfProd.Cells;
|
||||||
|
|
||||||
|
import ruscz.game.gameOfProd.Cells.Cell;
|
||||||
|
import ruscz.game.gameOfProd.Map.Map;
|
||||||
|
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class EventMoveToCell extends Cell {
|
public class EventMoveToCell extends Cell {
|
||||||
@ -35,7 +41,7 @@ public class EventMoveToCell extends Cell {
|
|||||||
public int getDirectionOut() { return directionOut; }
|
public int getDirectionOut() { return directionOut; }
|
||||||
|
|
||||||
public void moveToMap() {
|
public void moveToMap() {
|
||||||
window.getMap().getPerson().stopPerson();
|
//window.getMap().getPerson().stopPerson();
|
||||||
window.getMap().setIdExit(id);
|
window.getMap().setIdExit(id);
|
||||||
window.setMap(this.map);
|
window.setMap(this.map);
|
||||||
window.getMap().setIdExit(id);
|
window.getMap().setIdExit(id);
|
||||||
@ -1,3 +1,11 @@
|
|||||||
|
package ruscz.game.gameOfProd.Cells;
|
||||||
|
|
||||||
|
import ruscz.game.gameOfProd.Cells.Cell;
|
||||||
|
import ruscz.game.gameOfProd.Dialog.Dialog;
|
||||||
|
import ruscz.game.gameOfProd.Image.ImageCell;
|
||||||
|
import ruscz.game.gameOfProd.Image.ImageDialog;
|
||||||
|
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
@ -5,11 +13,11 @@ import java.util.Scanner;
|
|||||||
|
|
||||||
public class InteractionCell extends Cell {
|
public class InteractionCell extends Cell {
|
||||||
private String message;
|
private String message;
|
||||||
private Dialog dialog;
|
private ruscz.game.gameOfProd.Dialog.Dialog dialog;
|
||||||
private Scanner scanner;
|
private Scanner scanner;
|
||||||
private ImageCell imageCell;
|
private ImageCell imageCell;
|
||||||
|
|
||||||
InteractionCell(int x, int y, String message, Dialog dialog, ImageCell imageCell) {
|
public InteractionCell(int x, int y, String message, Dialog dialog, ImageCell imageCell) {
|
||||||
super(x, y, WindowOfFreeMove.CELL_SIZE, Color.ORANGE);
|
super(x, y, WindowOfFreeMove.CELL_SIZE, Color.ORANGE);
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.dialog = dialog;
|
this.dialog = dialog;
|
||||||
@ -1,4 +1,9 @@
|
|||||||
import javax.swing.*;
|
package ruscz.game.gameOfProd.Cells;
|
||||||
|
|
||||||
|
import ruscz.game.gameOfProd.Image.ImagePerson;
|
||||||
|
import ruscz.game.gameOfProd.Map.Map;
|
||||||
|
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
public class Person extends Cell {
|
public class Person extends Cell {
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
package ruscz.game.gameOfProd.Cells;
|
||||||
|
|
||||||
public enum TypeOfCell {
|
public enum TypeOfCell {
|
||||||
BLOCK, EMPTY, MOVETO, EVENT, SPAWNPOINT;
|
BLOCK, EMPTY, MOVETO, EVENT, SPAWNPOINT;
|
||||||
}
|
}
|
||||||
@ -1,3 +1,7 @@
|
|||||||
|
package ruscz.game.gameOfProd.Dialog;
|
||||||
|
|
||||||
|
import ruscz.game.gameOfProd.Image.ImageDialog;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
@ -27,7 +31,7 @@ public class Dialog {
|
|||||||
charNumber = 0;
|
charNumber = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Dialog(DialogBar dialogBar) {
|
public Dialog(DialogBar dialogBar) {
|
||||||
this.dialogBar = dialogBar;
|
this.dialogBar = dialogBar;
|
||||||
charNumber = 0;
|
charNumber = 0;
|
||||||
}
|
}
|
||||||
@ -1,3 +1,7 @@
|
|||||||
|
package ruscz.game.gameOfProd.Dialog;
|
||||||
|
|
||||||
|
import ruscz.game.gameOfProd.Image.ImageDialog;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
@ -1,3 +1,7 @@
|
|||||||
|
package ruscz.game.gameOfProd.Image;
|
||||||
|
|
||||||
|
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.print.DocFlavor;
|
import javax.print.DocFlavor;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@ -42,7 +46,7 @@ public class ImageCell {
|
|||||||
|
|
||||||
private void ImageTileset(String[] mapInfo) {
|
private void ImageTileset(String[] mapInfo) {
|
||||||
try {
|
try {
|
||||||
image = ImageIO.read(getClass().getResource(mapInfo[1]));
|
image = ImageIO.read(new File("src/main/resources/" + mapInfo[1]));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
package ruscz.game.gameOfProd.Image;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -10,7 +12,7 @@ public class ImageDialog {
|
|||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageDialog(String name){
|
public ImageDialog(String name){
|
||||||
this.name = name;
|
this.name = name;
|
||||||
parseImage();
|
parseImage();
|
||||||
}
|
}
|
||||||
@ -1,7 +1,10 @@
|
|||||||
|
package ruscz.game.gameOfProd.Image;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.image.*;
|
import java.awt.image.*;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class ImagePerson {
|
public class ImagePerson {
|
||||||
@ -21,7 +24,7 @@ public class ImagePerson {
|
|||||||
|
|
||||||
public ImagePerson(String name, Rectangle[] rectangles) {
|
public ImagePerson(String name, Rectangle[] rectangles) {
|
||||||
try {
|
try {
|
||||||
image = ImageIO.read(getClass().getResource(name));
|
image = ImageIO.read(new File("src/main/resources/" + name));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -1,11 +1,10 @@
|
|||||||
import javax.imageio.ImageIO;
|
package ruscz.game.gameOfProd.Map;
|
||||||
import java.awt.*;
|
|
||||||
import java.awt.image.BufferedImage;
|
import ruscz.game.gameOfProd.Cells.*;
|
||||||
import java.io.FileNotFoundException;
|
import ruscz.game.gameOfProd.Image.ImageCell;
|
||||||
import java.io.IOException;
|
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.io.File;
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class Map {
|
public class Map {
|
||||||
private String name;
|
private String name;
|
||||||
@ -46,7 +45,7 @@ public class Map {
|
|||||||
person = new Person(this);
|
person = new Person(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map(int height, int width, Boolean isBlocked) {
|
public Map(int height, int width, Boolean isBlocked) {
|
||||||
name = "Spawn";
|
name = "Spawn";
|
||||||
idExit = 0;
|
idExit = 0;
|
||||||
moveToCells = new LinkedList<EventMoveToCell>();
|
moveToCells = new LinkedList<EventMoveToCell>();
|
||||||
@ -183,7 +182,7 @@ public class Map {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isBusyCell(int x, int y) {
|
public boolean isBusyCell(int x, int y) {
|
||||||
for (Block cell : block) {
|
for (Block cell : block) {
|
||||||
if (cell.isInBlock(x, y))
|
if (cell.isInBlock(x, y))
|
||||||
return true;
|
return true;
|
||||||
@ -191,28 +190,28 @@ public class Map {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isCellMoveTo(int x, int y) {
|
public boolean isCellMoveTo(int x, int y) {
|
||||||
for (EventMoveToCell cell : moveToCells)
|
for (EventMoveToCell cell : moveToCells)
|
||||||
if (x == cell.getX() && y == cell.getY() && cell.getClass().getName().equals("EventMoveToCell"))
|
if (x == cell.getX() && y == cell.getY() && cell.getClass().getName().equals("ruscz.game.gameOfProd.Cells.EventMoveToCell"))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isCellEvent(int x, int y) {
|
public boolean isCellEvent(int x, int y) {
|
||||||
for (InteractionCell cell : eventCells)
|
for (InteractionCell cell : eventCells)
|
||||||
if (x == cell.getX() && y == cell.getY() && cell.getClass().getName().equals("InteractionCell"))
|
if (x == cell.getX() && y == cell.getY() && cell.getClass().getName().equals("ruscz.game.gameOfProd.Cells.InteractionCell"))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
EventMoveToCell findEventByXY(int x, int y) {
|
public EventMoveToCell findEventByXY(int x, int y) {
|
||||||
for (EventMoveToCell cell : moveToCells)
|
for (EventMoveToCell cell : moveToCells)
|
||||||
if (x == cell.getX() && y == cell.getY())
|
if (x == cell.getX() && y == cell.getY())
|
||||||
return cell;
|
return cell;
|
||||||
return moveToCells.getFirst();
|
return moveToCells.getFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
InteractionCell findInteractionByXY(int x, int y, int directionSight) {
|
public InteractionCell findInteractionByXY(int x, int y, int directionSight) {
|
||||||
switch (directionSight) {
|
switch (directionSight) {
|
||||||
case 1:
|
case 1:
|
||||||
x--;
|
x--;
|
||||||
19
src/main/java/ruscz/game/gameOfProd/Map/MapManager.java
Normal file
19
src/main/java/ruscz/game/gameOfProd/Map/MapManager.java
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package ruscz.game.gameOfProd.Map;
|
||||||
|
|
||||||
|
import ruscz.game.gameOfProd.Map.Map;
|
||||||
|
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
public class MapManager {
|
||||||
|
WindowOfFreeMove window;
|
||||||
|
LinkedList<Map> maps;
|
||||||
|
Map actualMap;
|
||||||
|
|
||||||
|
public MapManager(WindowOfFreeMove window){
|
||||||
|
this.window = window;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,3 +1,11 @@
|
|||||||
|
package ruscz.game.gameOfProd.Windows;
|
||||||
|
import ruscz.game.gameOfProd.Cells.Cell;
|
||||||
|
import ruscz.game.gameOfProd.Cells.EventMoveToCell;
|
||||||
|
import ruscz.game.gameOfProd.Cells.InteractionCell;
|
||||||
|
import ruscz.game.gameOfProd.Dialog.Dialog;
|
||||||
|
import ruscz.game.gameOfProd.Dialog.DialogBar;
|
||||||
|
import ruscz.game.gameOfProd.Map.Map;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
@ -6,19 +14,19 @@ import java.awt.event.KeyAdapter;
|
|||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
|
|
||||||
public class WindowOfFreeMove extends JFrame {
|
public class WindowOfFreeMove extends JFrame {
|
||||||
static final int CELL_SIZE = 40;
|
public static final int CELL_SIZE = 40;
|
||||||
static final int CANVAS_WIDTH = 10;
|
public static final int CANVAS_WIDTH = 25;
|
||||||
static final int CANVAS_HEIGHT = 10;
|
public static final int CANVAS_HEIGHT = 25;
|
||||||
|
|
||||||
private static boolean canPersonMove;
|
private static boolean canPersonMove;
|
||||||
private static int nextMove;
|
private static int nextMove;
|
||||||
private static boolean isReadyToPaint;
|
private static boolean isReadyToPaint;
|
||||||
|
|
||||||
static final int KEY_LEFT = 37;
|
public static final int KEY_LEFT = 37;
|
||||||
static final int KEY_UP = 38;
|
public static final int KEY_UP = 38;
|
||||||
static final int KEY_RIGHT = 39;
|
public static final int KEY_RIGHT = 39;
|
||||||
static final int KEY_DOWN = 40;
|
public static final int KEY_DOWN = 40;
|
||||||
static final int KEY_EVENT = 69;
|
public static final int KEY_EVENT = 69;
|
||||||
|
|
||||||
private Canvas canvas;
|
private Canvas canvas;
|
||||||
private DialogBar dialogBar;
|
private DialogBar dialogBar;
|
||||||
@ -164,36 +172,12 @@ public class WindowOfFreeMove extends JFrame {
|
|||||||
map.createMap();
|
map.createMap();
|
||||||
isReadyToPaint = true;
|
isReadyToPaint = true;
|
||||||
canvas.repaint();
|
canvas.repaint();
|
||||||
//
|
|
||||||
// lp.remove(dialogBar);
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// JPanel jf = new JPanel() {
|
|
||||||
// Font f = new Font("Times New Roman", Font.ITALIC, 50);
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void paint(Graphics g) {
|
|
||||||
// super.paint(g);
|
|
||||||
// g.setColor(Color.green);
|
|
||||||
// g.setFont(f);
|
|
||||||
// g.drawString("> Test", 10, 50);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// jf.setBounds(0, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.CANVAS_HEIGHT * 3 / 4, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.CANVAS_WIDTH, WindowOfFreeMove.CELL_SIZE * WindowOfFreeMove.CANVAS_HEIGHT / 4);
|
|
||||||
// jf.setBackground(Color.BLACK);
|
|
||||||
// jf.setVisible(false);
|
|
||||||
//
|
|
||||||
// setDialogBar(jf);
|
|
||||||
// dialogBar.setVisible(true);
|
|
||||||
//setCanPersonMove(false);
|
|
||||||
// lp.add(jf, JLayeredPane.POPUP_LAYER);
|
|
||||||
|
|
||||||
timer = new Timer(10, new ActionListener() {
|
timer = new Timer(10, new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent actionEvent) {
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
map.getPerson().move();
|
map.getPerson().move();
|
||||||
canvas.repaint(new Rectangle(CELL_SIZE, CELL_SIZE, CELL_SIZE * 8, CELL_SIZE * 8));
|
canvas.repaint();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
timer.start();
|
timer.start();
|
||||||
Loading…
x
Reference in New Issue
Block a user