Premier commit - Introduction au système git
This commit is contained in:
commit
3897fafc01
15
.gitignore
vendored
Normal file
15
.gitignore
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# Ignore Gradle project-specific cache directory
|
||||||
|
.gradle/
|
||||||
|
gradlew
|
||||||
|
gradlew.bat
|
||||||
|
gradle/
|
||||||
|
|
||||||
|
|
||||||
|
# Ignore Gradle build output directory
|
||||||
|
build/
|
||||||
|
bin/
|
||||||
|
|
||||||
|
# Eclipse files
|
||||||
|
.classpath
|
||||||
|
.settings
|
||||||
|
.project
|
||||||
33
build.gradle
Normal file
33
build.gradle
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* This file was generated by the Gradle 'init' task.
|
||||||
|
*
|
||||||
|
* This generated file contains a sample Java Library project to get you started.
|
||||||
|
* For more details take a look at the Java Libraries chapter in the Gradle
|
||||||
|
* User Manual available at https://docs.gradle.org/6.0/userguide/java_library_plugin.html
|
||||||
|
*/
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
// Apply the java-library plugin to add support for Java Library
|
||||||
|
id 'java-library'
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
// Use jcenter for resolving dependencies.
|
||||||
|
// You can declare any Maven/Ivy/file repository here.
|
||||||
|
jcenter()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
|
||||||
|
compile 'com.amihaiemil.web:eo-yaml:4.3.3'
|
||||||
|
|
||||||
|
// This dependency is exported to consumers, that is to say found on their compile classpath.
|
||||||
|
api 'org.apache.commons:commons-math3:3.6.1'
|
||||||
|
|
||||||
|
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
|
||||||
|
implementation 'com.google.guava:guava:28.0-jre'
|
||||||
|
|
||||||
|
// Use JUnit test framework
|
||||||
|
testImplementation 'junit:junit:4.12'
|
||||||
|
}
|
||||||
10
settings.gradle
Normal file
10
settings.gradle
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
/*
|
||||||
|
* This file was generated by the Gradle 'init' task.
|
||||||
|
*
|
||||||
|
* The settings file is used to specify which projects to include in your build.
|
||||||
|
*
|
||||||
|
* Detailed information about configuring a multi-project build in Gradle can be found
|
||||||
|
* in the user manual at https://docs.gradle.org/6.0/userguide/multi_project_builds.html
|
||||||
|
*/
|
||||||
|
|
||||||
|
rootProject.name = 'Murderator'
|
||||||
21
src/main/java/com/bernard/murder/Murderator.java
Normal file
21
src/main/java/com/bernard/murder/Murderator.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package com.bernard.murder;
|
||||||
|
|
||||||
|
import com.bernard.murder.view.MurderatorMainFrame;
|
||||||
|
|
||||||
|
public class Murderator {
|
||||||
|
|
||||||
|
static MurderatorMainFrame mainFrame;
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
mainFrame = new MurderatorMainFrame();
|
||||||
|
/*File f = new File("/home/mysaa/Documents/eclipse-workspace/Murderator/uneMurder.bernard.tmurder");
|
||||||
|
try {
|
||||||
|
System.out.println(GameCreator.genFromFile(f));
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}*/
|
||||||
|
mainFrame.startFrame();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
74
src/main/java/com/bernard/murder/ParseUtils.java
Normal file
74
src/main/java/com/bernard/murder/ParseUtils.java
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package com.bernard.murder;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.Spliterator;
|
||||||
|
import java.util.Spliterators;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
import java.util.stream.StreamSupport;
|
||||||
|
|
||||||
|
import com.amihaiemil.eoyaml.Yaml;
|
||||||
|
import com.amihaiemil.eoyaml.YamlMapping;
|
||||||
|
import com.amihaiemil.eoyaml.YamlNode;
|
||||||
|
import com.amihaiemil.eoyaml.YamlSequence;
|
||||||
|
|
||||||
|
public class ParseUtils {
|
||||||
|
|
||||||
|
static Pattern timeLengthPattern = Pattern.compile("^(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s?)?$");
|
||||||
|
|
||||||
|
public static long parseTimeLength(String tl) {
|
||||||
|
Matcher mtch = timeLengthPattern.matcher(tl);
|
||||||
|
if(!mtch.matches())throw new IllegalArgumentException("La chaine de caractères «"+tl+"» ne décrit pas un intervalle de temps normalisé");
|
||||||
|
int h = mtch.group(2)==null?0:Integer.parseInt(mtch.group(2));
|
||||||
|
int m = mtch.group(4)==null?0:Integer.parseInt(mtch.group(4));
|
||||||
|
int s = mtch.group(6)==null?0:Integer.parseInt(mtch.group(6));
|
||||||
|
return h*3600+m*60+s;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Set<T> union(Collection<T> c1, Collection<T> c2){
|
||||||
|
Set<T> out = c1.stream().collect(Collectors.toSet());
|
||||||
|
out.addAll(c2);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Set<String> mappingKeys(YamlMapping mapping) throws IOException{
|
||||||
|
return mapping.keys().stream().map(n ->{
|
||||||
|
try {
|
||||||
|
return Yaml.createYamlInput(n.toString()).readYamlSequence().string(0);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}).collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
public static Stream<YamlNode> sequenceStream(YamlSequence sequence){
|
||||||
|
return StreamSupport.stream(Spliterators.spliteratorUnknownSize(sequence.iterator(),Spliterator.ORDERED),false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String node(YamlNode n){
|
||||||
|
try {
|
||||||
|
return Yaml.createYamlInput(n.toString()).readYamlSequence().string(0);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Function<YamlNode,T> wetherMapping(Function<YamlNode,T> fnot,Function<YamlMapping,T> fyes){
|
||||||
|
return n -> (n instanceof YamlMapping)?fyes.apply((YamlMapping)n):fnot.apply(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Color randColor() {
|
||||||
|
return Color.getHSBColor((float) Math.random(), 1.0f, 1.0f);
|
||||||
|
}
|
||||||
|
public static Color getContrastColor(Color color) {
|
||||||
|
double y = (299 * color.getRed() + 587 * color.getGreen() + 114 * color.getBlue()) / 1000;
|
||||||
|
return y >= 128 ? Color.black : Color.white;
|
||||||
|
}
|
||||||
|
}
|
||||||
149
src/main/java/com/bernard/murder/game/GameCreator.java
Normal file
149
src/main/java/com/bernard/murder/game/GameCreator.java
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
package com.bernard.murder.game;
|
||||||
|
|
||||||
|
import static com.bernard.murder.ParseUtils.mappingKeys;
|
||||||
|
import static com.bernard.murder.ParseUtils.node;
|
||||||
|
import static com.bernard.murder.ParseUtils.parseTimeLength;
|
||||||
|
import static com.bernard.murder.ParseUtils.sequenceStream;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.Spliterator;
|
||||||
|
import java.util.Spliterators;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
import java.util.stream.StreamSupport;
|
||||||
|
|
||||||
|
import com.amihaiemil.eoyaml.Yaml;
|
||||||
|
import com.amihaiemil.eoyaml.YamlInput;
|
||||||
|
import com.amihaiemil.eoyaml.YamlMapping;
|
||||||
|
import com.amihaiemil.eoyaml.YamlNode;
|
||||||
|
import com.amihaiemil.eoyaml.YamlSequence;
|
||||||
|
import com.bernard.murder.ParseUtils;
|
||||||
|
import com.bernard.murder.model.Action;
|
||||||
|
import com.bernard.murder.model.Objet;
|
||||||
|
import com.bernard.murder.model.Partie;
|
||||||
|
import com.bernard.murder.model.Personnage;
|
||||||
|
import com.bernard.murder.model.Piece;
|
||||||
|
import com.bernard.murder.model.Status;
|
||||||
|
|
||||||
|
public class GameCreator {
|
||||||
|
|
||||||
|
public static Partie genFromFile(File toread) throws IOException{
|
||||||
|
|
||||||
|
YamlInput input = Yaml.createYamlInput(toread);
|
||||||
|
YamlMapping globalMap = input.readYamlMapping();
|
||||||
|
|
||||||
|
YamlMapping yjoueurs = globalMap.yamlMapping("joueurs");
|
||||||
|
System.out.println(yjoueurs);
|
||||||
|
|
||||||
|
// Pour pouvoir créer les objets et les espaces personnels
|
||||||
|
Set<String> playerNames = mappingKeys(yjoueurs).stream().map(n -> n.toString()).collect(Collectors.toSet());
|
||||||
|
|
||||||
|
|
||||||
|
YamlMapping yactions = globalMap.yamlMapping("actions");
|
||||||
|
Set<Action> actions = yactions.keys()
|
||||||
|
.stream()
|
||||||
|
.map(n -> new Action(node(n), parseTimeLength(yactions.string(n))))
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
Map<String,Set<Action>> persActions = playerNames.stream()
|
||||||
|
.collect(Collectors.toMap(Function.identity(), s -> actions.stream().map(Action::clone).collect(Collectors.toSet())));
|
||||||
|
YamlSequence yinventory = globalMap.yamlSequence("inventaire");
|
||||||
|
Set<String> objets = StreamSupport.stream(Spliterators.spliteratorUnknownSize(yinventory.iterator(),Spliterator.ORDERED),false)
|
||||||
|
.map(n ->ParseUtils.node(n))
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
Map<String,Set<Objet>> persObjets = playerNames.stream()
|
||||||
|
.collect(Collectors.toMap(Function.identity(),p -> objets.stream().map(o ->new Objet(String.format(o,p))).collect(Collectors.toSet())));
|
||||||
|
|
||||||
|
YamlSequence ystatus = globalMap.yamlSequence("status");
|
||||||
|
Set<Status> status = sequenceStream(ystatus).map(n -> new Status(node(n))).collect(Collectors.toSet());
|
||||||
|
|
||||||
|
YamlMapping yespaces = globalMap.yamlMapping("espaces");
|
||||||
|
|
||||||
|
Map<String, Map<Objet, Integer>> objetsDansEspaces = yespaces.keys().stream().collect(Collectors.toMap(
|
||||||
|
n -> node(n),
|
||||||
|
n-> parseHiddenObjects(yespaces.yamlSequence(n))
|
||||||
|
));
|
||||||
|
Set<Piece> espaceObjets = yespaces.keys().stream()
|
||||||
|
.map(n -> new Piece(node(n), objetsDansEspaces.get(node(n))))
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
YamlMapping yespacesPersos = globalMap.yamlMapping("espacesPersos");
|
||||||
|
|
||||||
|
Map<String,Set<Piece>> persespacesPersos = playerNames.stream().collect(Collectors.toMap(
|
||||||
|
Function.identity(),
|
||||||
|
p -> yespacesPersos.keys().stream()
|
||||||
|
.map(e -> new Piece(
|
||||||
|
String.format(node(e), p),
|
||||||
|
parseHiddenObjects(yespacesPersos.yamlSequence(e),p)
|
||||||
|
))
|
||||||
|
.collect(Collectors.toSet())
|
||||||
|
));
|
||||||
|
|
||||||
|
//Per perso settings
|
||||||
|
for(YamlNode pn : yjoueurs.keys()) {
|
||||||
|
String pname = node(pn);
|
||||||
|
System.out.println(pn);
|
||||||
|
System.out.println(yjoueurs.yamlMapping(pn));
|
||||||
|
persActions.get(pname).addAll(
|
||||||
|
yjoueurs.yamlMapping(pn).yamlMapping("actions").keys()
|
||||||
|
.stream()
|
||||||
|
.map(n -> new Action(node(n), parseTimeLength(yjoueurs.yamlMapping(pn).yamlMapping("actions").string(n))))
|
||||||
|
.collect(Collectors.toSet())
|
||||||
|
);
|
||||||
|
persObjets.get(pname).addAll(
|
||||||
|
StreamSupport.stream(Spliterators.spliteratorUnknownSize(yjoueurs.yamlMapping(pn).yamlSequence("inventaire").iterator(),Spliterator.ORDERED),false)
|
||||||
|
.map(n ->ParseUtils.node(n))
|
||||||
|
.map(o ->new Objet(o))
|
||||||
|
.collect(Collectors.toSet())
|
||||||
|
);
|
||||||
|
if(yjoueurs.yamlMapping(pn).yamlMapping("espacePerso")!= null)
|
||||||
|
// Plusieurs espaces
|
||||||
|
yjoueurs.yamlMapping(pn).yamlMapping("espacePerso").keys().forEach(n ->
|
||||||
|
persespacesPersos.get(pname)
|
||||||
|
.stream()
|
||||||
|
.filter(p -> p.getNom().contentEquals(node(n)))
|
||||||
|
.findAny()
|
||||||
|
.orElseGet(() -> new Piece(node(n)))
|
||||||
|
.insertObjects(parseHiddenObjects(yjoueurs.yamlMapping(pn).yamlMapping("espacePerso").yamlSequence(n)))
|
||||||
|
|
||||||
|
);
|
||||||
|
else
|
||||||
|
((persespacesPersos.get(pname).isEmpty())?
|
||||||
|
Stream.of(new Piece(String.format("Espace de %s",pname))):persespacesPersos.get(pname).stream())
|
||||||
|
.forEach(p -> p.insertObjects(parseHiddenObjects(yjoueurs.yamlMapping(pn).yamlSequence("espacePerso"))));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Set<Personnage> personnages = playerNames.stream().map(p -> new Personnage(
|
||||||
|
p,
|
||||||
|
persObjets.get(p),
|
||||||
|
persActions.get(p),
|
||||||
|
status.stream().filter(st -> sequenceStream(ystatus)
|
||||||
|
.filter(n -> n instanceof YamlMapping)
|
||||||
|
.filter(n -> ((YamlMapping)n).string(st.getName())!=null)
|
||||||
|
.filter(n -> ((YamlMapping)((YamlMapping)n).yamlMapping(st.getName())).string("onStart").contentEquals("true"))
|
||||||
|
.findAny().isPresent())
|
||||||
|
.collect(Collectors.toSet()),
|
||||||
|
persespacesPersos.get(p)
|
||||||
|
)).collect(Collectors.toSet());
|
||||||
|
|
||||||
|
return new Partie(personnages, status, espaceObjets);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map<Objet,Integer> parseHiddenObjects(YamlSequence sequence,Object... nameFormat){
|
||||||
|
return sequenceStream(sequence).collect(Collectors.toMap(
|
||||||
|
on -> new Objet(String.format((on instanceof YamlMapping)?(((YamlMapping)on).keys().stream().map(nn -> node(nn)).findAny().get()):node(on),nameFormat)),
|
||||||
|
on -> ((on instanceof YamlMapping)?(((YamlMapping)on).integer(((YamlMapping)on).keys().stream().findAny().get())):-1)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
private static Map<Objet,Integer> parseHiddenObjects(YamlSequence sequence){
|
||||||
|
return parseHiddenObjects(sequence, new Object[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
13
src/main/java/com/bernard/murder/game/GameManager.java
Normal file
13
src/main/java/com/bernard/murder/game/GameManager.java
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package com.bernard.murder.game;
|
||||||
|
|
||||||
|
import com.bernard.murder.model.Partie;
|
||||||
|
|
||||||
|
public class GameManager {
|
||||||
|
|
||||||
|
Partie partie;
|
||||||
|
|
||||||
|
public GameManager(Partie partie) {
|
||||||
|
this.partie = partie;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
29
src/main/java/com/bernard/murder/model/Action.java
Normal file
29
src/main/java/com/bernard/murder/model/Action.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package com.bernard.murder.model;
|
||||||
|
|
||||||
|
public class Action implements Cloneable{
|
||||||
|
|
||||||
|
String action;
|
||||||
|
long basetime;
|
||||||
|
long triggertime;
|
||||||
|
|
||||||
|
public Action(String action, long basetime) {
|
||||||
|
this.action = action;
|
||||||
|
this.basetime = basetime;
|
||||||
|
this.triggertime = Long.MIN_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Action clone() {
|
||||||
|
Action actions = new Action(action, basetime);
|
||||||
|
actions.triggertime = triggertime;
|
||||||
|
return actions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Action [action=" + action + ", basetime=" + basetime + ", triggertime=" + triggertime + ", transient id=" + System.identityHashCode(this) + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
9
src/main/java/com/bernard/murder/model/Inventaire.java
Normal file
9
src/main/java/com/bernard/murder/model/Inventaire.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package com.bernard.murder.model;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public interface Inventaire {
|
||||||
|
|
||||||
|
Set<Objet> getObjects();
|
||||||
|
|
||||||
|
}
|
||||||
22
src/main/java/com/bernard/murder/model/Objet.java
Normal file
22
src/main/java/com/bernard/murder/model/Objet.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package com.bernard.murder.model;
|
||||||
|
|
||||||
|
public class Objet {
|
||||||
|
|
||||||
|
String nom;
|
||||||
|
|
||||||
|
public Objet(String nom) {
|
||||||
|
this.nom = nom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNom() {
|
||||||
|
return nom;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Objet [nom=" + nom + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
39
src/main/java/com/bernard/murder/model/Partie.java
Normal file
39
src/main/java/com/bernard/murder/model/Partie.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package com.bernard.murder.model;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
public class Partie {
|
||||||
|
|
||||||
|
Set<Personnage> personnages;
|
||||||
|
Set<Status> statuz;
|
||||||
|
Set<Piece> piece;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public Partie(Set<Personnage> personnages, Set<Status> statuz, Set<Piece> piece) {
|
||||||
|
this.personnages = personnages;
|
||||||
|
this.statuz = statuz;
|
||||||
|
this.piece = piece;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int persoCount() {
|
||||||
|
return personnages.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Stream<Personnage> personnagesStream() {
|
||||||
|
return personnages.stream();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Stream<Piece> piecesStream() {
|
||||||
|
return piece.stream();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Partie [personnages=" + personnages + ", statuz=" + statuz + ", piece=" + piece + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
59
src/main/java/com/bernard/murder/model/Personnage.java
Normal file
59
src/main/java/com/bernard/murder/model/Personnage.java
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
package com.bernard.murder.model;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
public class Personnage implements Inventaire{
|
||||||
|
|
||||||
|
String nom;
|
||||||
|
Set<Objet> inventaire;
|
||||||
|
Set<Action> actions;
|
||||||
|
Set<Status> status;
|
||||||
|
Set<Piece> espacesPersos;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public Personnage(String nom, Set<Objet> inventaire, Set<Action> actions, Set<Status> status,
|
||||||
|
Set<Piece> espacesPersos) {
|
||||||
|
super();
|
||||||
|
this.nom = nom;
|
||||||
|
this.inventaire = inventaire;
|
||||||
|
this.actions = actions;
|
||||||
|
this.status = status;
|
||||||
|
this.espacesPersos = espacesPersos;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public String getNom() {
|
||||||
|
return nom;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Set<Objet> getInventaire() {
|
||||||
|
return inventaire;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Stream<Piece> streamEspacesPersos(){
|
||||||
|
return espacesPersos.stream();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Personnage [nom=" + nom + ", inventaire=" + inventaire + ", actions=" + actions + ", status=" + status
|
||||||
|
+ ", espacesPersos=" + espacesPersos + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<Objet> getObjects() {
|
||||||
|
return inventaire;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
43
src/main/java/com/bernard/murder/model/Piece.java
Normal file
43
src/main/java/com/bernard/murder/model/Piece.java
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package com.bernard.murder.model;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class Piece implements Inventaire{
|
||||||
|
|
||||||
|
String nom;
|
||||||
|
|
||||||
|
Map<Objet,Integer> contenu;
|
||||||
|
|
||||||
|
public Piece(String nom) {
|
||||||
|
this(nom, new HashMap<Objet, Integer>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Piece(String nom, Map<Objet, Integer> contenu) {
|
||||||
|
this.nom = nom;
|
||||||
|
this.contenu = contenu;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Piece [nom=" + nom + ", contenu=" + contenu + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNom() {
|
||||||
|
return nom;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<Objet> getObjects() {
|
||||||
|
return contenu.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void insertObjects(Map<Objet, Integer> objs) {
|
||||||
|
contenu.putAll(objs);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
21
src/main/java/com/bernard/murder/model/Status.java
Normal file
21
src/main/java/com/bernard/murder/model/Status.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package com.bernard.murder.model;
|
||||||
|
|
||||||
|
public class Status {
|
||||||
|
String name;
|
||||||
|
|
||||||
|
public Status(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Status [name=" + name + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
6
src/main/java/com/bernard/murder/module-info.java
Normal file
6
src/main/java/com/bernard/murder/module-info.java
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
module murder{
|
||||||
|
|
||||||
|
requires com.amihaiemil.eoyaml;
|
||||||
|
requires java.desktop;
|
||||||
|
|
||||||
|
}
|
||||||
60
src/main/java/com/bernard/murder/view/GlobalUIManager.java
Normal file
60
src/main/java/com/bernard/murder/view/GlobalUIManager.java
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
package com.bernard.murder.view;
|
||||||
|
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseListener;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
import com.bernard.murder.model.Inventaire;
|
||||||
|
import com.bernard.murder.model.Objet;
|
||||||
|
|
||||||
|
public class GlobalUIManager implements MouseListener{
|
||||||
|
|
||||||
|
public GlobalUIManager(JPanel globalPan) {
|
||||||
|
globalPan.addMouseListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<Objet> currentUIselection = new HashSet<Objet>();
|
||||||
|
Map<JPanel,Inventaire> inventaire = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
System.out.println(e.getSource());
|
||||||
|
System.out.println(e.getComponent());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent e) {
|
||||||
|
|
||||||
|
|
||||||
|
if(e.getButton()==MouseEvent.NOBUTTON) {
|
||||||
|
currentUIselection.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(MouseEvent e) {
|
||||||
|
if(e.getButton()==MouseEvent.NOBUTTON) {
|
||||||
|
// Le clic a peut être été laché à l'exterieur
|
||||||
|
currentUIselection.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
49
src/main/java/com/bernard/murder/view/MinelsCreator.java
Normal file
49
src/main/java/com/bernard/murder/view/MinelsCreator.java
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package com.bernard.murder.view;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import com.bernard.murder.game.GameManager;
|
||||||
|
import com.bernard.murder.model.Partie;
|
||||||
|
import com.bernard.murder.model.Personnage;
|
||||||
|
import com.bernard.murder.view.minel.InventaireMinel;
|
||||||
|
import com.bernard.murder.view.minel.Minel;
|
||||||
|
import com.bernard.murder.view.minel.TextPanMinel;
|
||||||
|
|
||||||
|
public class MinelsCreator {
|
||||||
|
|
||||||
|
public static Map<String, List<Minel>> genSupMinels(Partie partie, GameManager manager) {
|
||||||
|
Map<String, List<Minel>> outPute = new HashMap<String, List<Minel>>();
|
||||||
|
|
||||||
|
List<Minel> generalMinels = new ArrayList<Minel>();
|
||||||
|
|
||||||
|
partie.piecesStream().map(p -> new InventaireMinel(manager, p)).forEach(m -> generalMinels.add(m));
|
||||||
|
|
||||||
|
generalMinels.add(new TextPanMinel(manager));
|
||||||
|
|
||||||
|
outPute.put("Général", generalMinels);
|
||||||
|
return outPute;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<Personnage, List<Minel>> genMinels(Partie partie, GameManager manager) {
|
||||||
|
return partie.personnagesStream().collect(Collectors.toMap(Function.identity(), p -> genMinelsForPerso(partie,manager,p)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<Minel> genMinelsForPerso(Partie partie, GameManager manager, Personnage personnage){
|
||||||
|
List<Minel> minels = new ArrayList<Minel>();
|
||||||
|
|
||||||
|
minels.add(new InventaireMinel(manager, personnage));
|
||||||
|
personnage.streamEspacesPersos().map(p -> new InventaireMinel(manager, p)).forEach(m -> minels.add(m));
|
||||||
|
|
||||||
|
minels.add(new TextPanMinel(manager));
|
||||||
|
|
||||||
|
|
||||||
|
return minels;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
128
src/main/java/com/bernard/murder/view/MurderatorMainFrame.java
Normal file
128
src/main/java/com/bernard/murder/view/MurderatorMainFrame.java
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
package com.bernard.murder.view;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.CardLayout;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.GridLayout;
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
|
||||||
|
import com.bernard.murder.game.GameCreator;
|
||||||
|
import com.bernard.murder.game.GameManager;
|
||||||
|
import com.bernard.murder.model.Partie;
|
||||||
|
import com.bernard.murder.model.Personnage;
|
||||||
|
import com.bernard.murder.view.minel.Minel;
|
||||||
|
|
||||||
|
public class MurderatorMainFrame extends JFrame{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -4512350072325470066L;
|
||||||
|
|
||||||
|
|
||||||
|
public MurderatorMainFrame() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startFrame() {
|
||||||
|
this.setSize(700, 500);
|
||||||
|
this.setMinimumSize(new Dimension(575, 200));
|
||||||
|
this.setLocationRelativeTo(null);
|
||||||
|
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
|
this.setTitle("En attente d'un fichier");
|
||||||
|
|
||||||
|
this.setContentPane(genFirstPanel());
|
||||||
|
this.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JPanel genFirstPanel() {
|
||||||
|
JPanel globalPanel = new JPanel();
|
||||||
|
globalPanel.setLayout(new BoxLayout(globalPanel, BoxLayout.PAGE_AXIS));
|
||||||
|
JPanel semiPan = new JPanel();
|
||||||
|
semiPan.setLayout(new BoxLayout(semiPan, BoxLayout.LINE_AXIS));
|
||||||
|
JButton loadFile = new JButton("Ouvrir un fichier");
|
||||||
|
|
||||||
|
loadFile.addActionListener(e -> {
|
||||||
|
this.setEnabled(false);
|
||||||
|
JFileChooser chooser = new JFileChooser();
|
||||||
|
int returnState = chooser.showOpenDialog(this);
|
||||||
|
if(returnState==JFileChooser.APPROVE_OPTION) {
|
||||||
|
File toread = chooser.getSelectedFile();
|
||||||
|
try {
|
||||||
|
Partie partie = GameCreator.genFromFile(toread);
|
||||||
|
GameManager manager = new GameManager(partie);
|
||||||
|
Map<String,List<Minel>> minelsSup = MinelsCreator.genSupMinels(partie,manager);
|
||||||
|
Map<Personnage,List<Minel>> minels = MinelsCreator.genMinels(partie,manager);
|
||||||
|
|
||||||
|
|
||||||
|
this.setContentPane(genGamePane(partie,manager,minelsSup,minels));
|
||||||
|
this.getContentPane().repaint(20);
|
||||||
|
}catch(Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
JOptionPane.showMessageDialog(this, ex.getLocalizedMessage(), "Impossible de lire le fichier", JOptionPane.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.setEnabled(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
semiPan.add(loadFile);
|
||||||
|
globalPanel.add(semiPan);
|
||||||
|
return globalPanel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JPanel genGamePane(Partie partie,GameManager manager,Map<String,List<Minel>> minelsSup,Map<Personnage,List<Minel>> minels) {
|
||||||
|
|
||||||
|
JPanel globalPan = new JPanel(new BorderLayout());
|
||||||
|
GlobalUIManager guim = new GlobalUIManager(globalPan);
|
||||||
|
|
||||||
|
//Center Panel
|
||||||
|
CardLayout centerLayout = new CardLayout();
|
||||||
|
JPanel centerPan = new JPanel(centerLayout);
|
||||||
|
|
||||||
|
for(String s : minelsSup.keySet()) {
|
||||||
|
JPanel centralLocalBpanPan = new JPanel(new GridLayout(2,(minelsSup.get(s).size()+1)/2));
|
||||||
|
minelsSup.get(s).stream().map(m -> m.genContentPane(guim)).forEach(mpan -> centralLocalBpanPan.add(mpan));
|
||||||
|
JScrollPane centralLocalPan = new JScrollPane(centralLocalBpanPan);
|
||||||
|
centerPan.add(centralLocalPan, s);
|
||||||
|
}
|
||||||
|
for(Personnage p : minels.keySet()) {
|
||||||
|
JPanel centralLocalBpanPan = new JPanel(new GridLayout(2, (minels.get(p).size()+1)/2));
|
||||||
|
minels.get(p).stream().map(m -> m.genContentPane(guim)).forEach(mpan -> centralLocalBpanPan.add(mpan));
|
||||||
|
JScrollPane centralLocalPan = new JScrollPane(centralLocalBpanPan);
|
||||||
|
centerPan.add(centralLocalPan, personnageIdentifier(p));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Left Panel
|
||||||
|
JPanel leftPan = new JPanel(new GridLayout(minels.size() + minelsSup.size(), 1));
|
||||||
|
|
||||||
|
for(String s : minelsSup.keySet()) {
|
||||||
|
JButton localButton = new JButton(s);
|
||||||
|
localButton.addActionListener(e -> centerLayout.show(centerPan, s));
|
||||||
|
leftPan.add(localButton);
|
||||||
|
}
|
||||||
|
for(Personnage p : minels.keySet()) {
|
||||||
|
JButton localButton = new JButton(p.getNom());
|
||||||
|
localButton.addActionListener(e -> centerLayout.show(centerPan, personnageIdentifier(p)));
|
||||||
|
leftPan.add(localButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
globalPan.add(leftPan, BorderLayout.WEST);
|
||||||
|
globalPan.add(centerPan, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
return globalPan;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String personnageIdentifier(Personnage personnage) {
|
||||||
|
return String.format("%08X",System.identityHashCode(personnage))+personnage.getNom();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,58 @@
|
|||||||
|
package com.bernard.murder.view.minel;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JList;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
import com.bernard.murder.ParseUtils;
|
||||||
|
import com.bernard.murder.game.GameManager;
|
||||||
|
import com.bernard.murder.model.Inventaire;
|
||||||
|
import com.bernard.murder.model.Objet;
|
||||||
|
import com.bernard.murder.view.GlobalUIManager;
|
||||||
|
|
||||||
|
public class InventaireMinel extends Minel {
|
||||||
|
|
||||||
|
public InventaireMinel(GameManager manager, Inventaire inv) {
|
||||||
|
super(manager);
|
||||||
|
this.inv = inv;
|
||||||
|
}
|
||||||
|
|
||||||
|
JList<Objet> objets;
|
||||||
|
Inventaire inv;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JPanel genContentPane(GlobalUIManager guim) {
|
||||||
|
JPanel globalpan = new JPanel(new BorderLayout());
|
||||||
|
|
||||||
|
globalpan.setBackground(ParseUtils.randColor());
|
||||||
|
|
||||||
|
JPanel inventaire = new JPanel();
|
||||||
|
inventaire.setBackground(ParseUtils.randColor());
|
||||||
|
|
||||||
|
JButton voler = new JButton("RandomItem");
|
||||||
|
voler.addActionListener(e -> {
|
||||||
|
objets.setSelectedIndex((int) (Math.random() * objets.getModel().getSize()));
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO dragndrop multiple items
|
||||||
|
objets = new JList<Objet>();
|
||||||
|
objets.addMouseListener(guim);
|
||||||
|
updateObjets();
|
||||||
|
|
||||||
|
inventaire.add(objets);
|
||||||
|
|
||||||
|
globalpan.add(voler, BorderLayout.SOUTH);
|
||||||
|
globalpan.add(inventaire, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
return globalpan;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateObjets() {
|
||||||
|
Objet[] objz = new Objet[inv.getObjects().size()];
|
||||||
|
objz = inv.getObjects().toArray(objz);
|
||||||
|
objets.setListData(objz);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
21
src/main/java/com/bernard/murder/view/minel/Minel.java
Normal file
21
src/main/java/com/bernard/murder/view/minel/Minel.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package com.bernard.murder.view.minel;
|
||||||
|
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
import com.bernard.murder.game.GameManager;
|
||||||
|
import com.bernard.murder.view.GlobalUIManager;
|
||||||
|
|
||||||
|
public abstract class Minel{
|
||||||
|
|
||||||
|
GameManager manager;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public Minel(GameManager manager) {
|
||||||
|
this.manager = manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract JPanel genContentPane(GlobalUIManager guim);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
package com.bernard.murder.view.minel;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Color;
|
||||||
|
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.JTextArea;
|
||||||
|
import javax.swing.border.EmptyBorder;
|
||||||
|
|
||||||
|
import com.bernard.murder.ParseUtils;
|
||||||
|
import com.bernard.murder.game.GameManager;
|
||||||
|
import com.bernard.murder.view.GlobalUIManager;
|
||||||
|
|
||||||
|
public class TextPanMinel extends Minel {
|
||||||
|
|
||||||
|
|
||||||
|
public TextPanMinel(GameManager manager) {
|
||||||
|
super(manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JPanel genContentPane(GlobalUIManager guim) {
|
||||||
|
JPanel globalPan = new JPanel(new BorderLayout());
|
||||||
|
globalPan.setBackground(ParseUtils.randColor());
|
||||||
|
JTextArea textArea = new JTextArea();
|
||||||
|
textArea.setBorder(new EmptyBorder(23,23,23,23));
|
||||||
|
|
||||||
|
Color col = ParseUtils.randColor();
|
||||||
|
textArea.setBackground(col);
|
||||||
|
textArea.setForeground(ParseUtils.getContrastColor(col));
|
||||||
|
|
||||||
|
globalPan.add(new JScrollPane(textArea),BorderLayout.CENTER);
|
||||||
|
return globalPan;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
BIN
src/main/resources/notepad.png
Normal file
BIN
src/main/resources/notepad.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 52 KiB |
46
src/test/resources/uneMurder.bernard.tmurder
Normal file
46
src/test/resources/uneMurder.bernard.tmurder
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
actions:
|
||||||
|
Doudou: 23s
|
||||||
|
Chanter: 42s
|
||||||
|
|
||||||
|
status:
|
||||||
|
- Mort
|
||||||
|
- Paralysie
|
||||||
|
- NoKill:
|
||||||
|
onStart: true
|
||||||
|
|
||||||
|
inventaire:
|
||||||
|
# Tout le monde en a un au départ, sera nommé Portefeuille_Bernard, Portefeuille_Jach
|
||||||
|
-"Portefeuille de %s"
|
||||||
|
|
||||||
|
espaces:
|
||||||
|
"Cabine du capitaine":
|
||||||
|
- "Clés du bateau": 12
|
||||||
|
- "Carte grise"
|
||||||
|
|
||||||
|
espacesPersos:
|
||||||
|
# Un espace chacun, appelé Chambre_Jach, Chambre_Bernard
|
||||||
|
"Chambre de %s":
|
||||||
|
- "Manteau de %s"
|
||||||
|
|
||||||
|
|
||||||
|
joueurs:
|
||||||
|
Bernard:
|
||||||
|
actions:
|
||||||
|
DominerLeMonde: 42s
|
||||||
|
inventaire:
|
||||||
|
- "JuL'IA"
|
||||||
|
- "MasterKey"
|
||||||
|
espacePerso:
|
||||||
|
"Chambre de Bernard":
|
||||||
|
- "Pipi"
|
||||||
|
|
||||||
|
Jach:
|
||||||
|
actions:
|
||||||
|
Python: 2h15m
|
||||||
|
status:
|
||||||
|
- "Rage du normalien"
|
||||||
|
inventaire:
|
||||||
|
- "PB ENS"
|
||||||
|
espacePerso:
|
||||||
|
- "Guide Richard"
|
||||||
|
# Par défaut, se place dans le seul espace personnel (Si il y en a deux, pas bon)
|
||||||
Loading…
x
Reference in New Issue
Block a user