-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMultiPlayerVersion.java
63 lines (54 loc) · 1.89 KB
/
MultiPlayerVersion.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.beans.property.IntegerProperty;
import javafx.scene.Group;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Label;
import javafx.scene.control.TextInputDialog;
import javafx.scene.layout.VBox;
import javafx.util.Duration;
import java.awt.*;
import java.io.*;
import java.util.ArrayList;
import java.util.Optional;
import java.util.Stack;
public class MultiPlayerVersion implements Serializable {
protected MazeFloors originalMaze;
protected GameVersion game;
protected Scores scores;
protected Stack<Player> players;
public MultiPlayerVersion(String[] names, MazeFloors maze) throws FormatNotSupported, IOException{
players = new Stack<>();
scores = new Scores();
for (int i = names.length - 1; i >= 0; i--) players.push(new Player(names[i]));
try{
game = new SoloVersion(maze.clone(), players.pop(), scores);
originalMaze=maze;
}
catch(CloneNotSupportedException e){
}
}
public GameVersion getGame() {
return game;
}
public void save(String file) throws IOException {
File f=new File(file+".serM");
if(!f.exists()) f.createNewFile();
FileOutputStream fos = new FileOutputStream(f);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(this);
oos.close();
}
public boolean gameOver() {
return players.isEmpty();
}
public GameVersion next() throws IOException, FormatNotSupported,CloneNotSupportedException {
game = new SoloVersion(originalMaze.clone(), players.pop(), scores);
return game;
}
public Stack<Player> getPlayers() {
return players;
}
}