85 lines
2.5 KiB
Java
85 lines
2.5 KiB
Java
package ruscz.game.gameOfProd.Cells;
|
|
|
|
import ruscz.game.gameOfProd.Dialog.Dialog;
|
|
import ruscz.game.gameOfProd.Image.ImageCell;
|
|
import ruscz.game.gameOfProd.Image.ImageDialog;
|
|
import ruscz.game.gameOfProd.Map.Map;
|
|
import ruscz.game.gameOfProd.Windows.WindowOfFreeMove;
|
|
|
|
import java.awt.*;
|
|
import java.io.File;
|
|
import java.io.FileNotFoundException;
|
|
import java.util.Scanner;
|
|
|
|
public class InteractionCell extends Cell {
|
|
private String message;
|
|
private ruscz.game.gameOfProd.Dialog.Dialog dialog;
|
|
private Scanner scanner;
|
|
private ImageCell imageCell;
|
|
|
|
public InteractionCell(int x, int y, String message, Dialog dialog, ImageCell imageCell) {
|
|
super(x, y, WindowOfFreeMove.CELL_SIZE, Color.ORANGE);
|
|
this.message = message;
|
|
this.dialog = dialog;
|
|
this.imageCell = imageCell;
|
|
}
|
|
|
|
public void startEvent() {
|
|
WindowOfFreeMove.setCanPersonMove(false);
|
|
if (message != null)
|
|
readDialogFile(message);
|
|
}
|
|
|
|
public void readDialogFile(String name) {
|
|
try {
|
|
File dialogFile = new File("src/main/resources/" + name + ".txt");
|
|
scanner = new Scanner(dialogFile);
|
|
readNextLine();
|
|
} catch (FileNotFoundException e) {
|
|
System.out.println("An error occurred.");
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
public void readNextLine() {
|
|
if (scanner.hasNextLine() && !dialog.getTimerIsRunning()) {
|
|
String data = scanner.nextLine();
|
|
if (data.equals("<end>"))
|
|
endEvent();
|
|
else if (data.contains("<image>")) {
|
|
String[] imageName = data.split(" ");
|
|
dialog.setImageDialog(new ImageDialog(imageName[1]));
|
|
readNextLine();
|
|
}
|
|
else {
|
|
dialog.hideText();
|
|
dialog.setText(data);
|
|
dialog.showText();
|
|
}
|
|
}
|
|
else {
|
|
dialog.skipShowText();
|
|
}
|
|
}
|
|
|
|
public void endEvent() {
|
|
if (dialog != null) {
|
|
dialog.hideText();
|
|
dialog.setImageDialog(null);
|
|
}
|
|
WindowOfFreeMove.setCanPersonMove(true);
|
|
Person.setInEvent(false);
|
|
}
|
|
|
|
@Override
|
|
public void paint(Graphics2D g) {
|
|
super.paint(g);
|
|
g.drawImage(imageCell.getImagesOfTiles().get(334), getX() * WindowOfFreeMove.CELL_SIZE,
|
|
getY() * WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, WindowOfFreeMove.CELL_SIZE, null);
|
|
}
|
|
|
|
public ImageCell getImageCell() {
|
|
return imageCell;
|
|
}
|
|
}
|