Quellcode durchsuchen

:tada: Ajout projet Maven

maxence bacquet vor 6 Jahren
Ursprung
Commit
ed7658388c
33 geänderte Dateien mit 656 neuen und 0 gelöschten Zeilen
  1. 40 0
      Client/.classpath
  2. 11 0
      Client/.gitignore
  3. 23 0
      Client/.project
  4. 6 0
      Client/.settings/org.eclipse.core.resources.prefs
  5. 6 0
      Client/.settings/org.eclipse.jdt.core.prefs
  6. 4 0
      Client/.settings/org.eclipse.m2e.core.prefs
  7. 73 0
      Client/README.md
  8. 56 0
      Client/pom.xml
  9. 34 0
      Client/src/main/java/fr/univartois/bomberman/App.java
  10. 34 0
      Client/src/main/java/fr/univartois/bomberman/model/asset/AssetManager.java
  11. 18 0
      Client/src/main/java/fr/univartois/bomberman/model/asset/Sprite.java
  12. 29 0
      Client/src/main/java/fr/univartois/bomberman/model/asset/loader/SpriteLoader.java
  13. 37 0
      Client/src/main/java/fr/univartois/bomberman/model/config/ConfigManager.java
  14. 17 0
      Client/src/main/java/fr/univartois/bomberman/model/config/Configuration.java
  15. 48 0
      Client/src/main/java/fr/univartois/bomberman/model/config/MyProperties.java
  16. 73 0
      Client/src/main/java/fr/univartois/bomberman/view/MenuView.java
  17. 28 0
      Client/src/main/java/fr/univartois/bomberman/view/View.java
  18. 45 0
      Client/src/main/java/fr/univartois/bomberman/view/Window.java
  19. 0 0
      Client/src/main/java/rsx/BomberStudentClient.java
  20. 0 0
      Client/src/main/java/rsx/BomberStudentHandler.java
  21. 0 0
      Client/src/main/java/rsx/BomberStudentRequest.java
  22. 0 0
      Client/src/main/java/rsx/tcp/TcpClient.java
  23. 0 0
      Client/src/main/java/rsx/udp/Broadcast.java
  24. 0 0
      Client/src/main/java/test/JsonTest.java
  25. 0 0
      Client/src/main/java/test/ServerHandlerTest.java
  26. 0 0
      Client/src/main/java/test/ServerTest.java
  27. 0 0
      Client/src/main/java/test/Test.java
  28. 2 0
      Client/src/main/resources/config/path.properties
  29. BIN
      Client/src/main/resources/sprite/menu_background.png
  30. 38 0
      Client/src/test/java/fr/univartois/bomberman/AppTest.java
  31. 32 0
      Client/src/test/java/fr/univartois/bomberman/model/config/ConfigManagerTest.java
  32. 2 0
      Client/src/test/resources/config/path.properties
  33. BIN
      Client/src/test/resources/sprite/menu_background.png

+ 40 - 0
Client/.classpath

@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" output="target/classes" path="src/main/java">
+		<attributes>
+			<attribute name="optional" value="true"/>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="src" output="target/test-classes" path="src/test/java">
+		<attributes>
+			<attribute name="test" value="true"/>
+			<attribute name="optional" value="true"/>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
+		<attributes>
+			<attribute name="test" value="true"/>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
+		<attributes>
+			<attribute name="module" value="true"/>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
+		<attributes>
+			<attribute name="maven.pomderived" value="true"/>
+		</attributes>
+	</classpathentry>
+	<classpathentry kind="lib" path="/home/megaman/eclipse-workspace/projet-reseaux/Client/json.jar"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

+ 11 - 0
Client/.gitignore

@@ -0,0 +1,11 @@
+target/
+pom.xml.tag
+pom.xml.releaseBackup
+pom.xml.versionsBackup
+pom.xml.next
+release.properties
+dependency-reduced-pom.xml
+buildNumber.properties
+.mvn/timing.properties
+.mvn/wrapper/maven-wrapper.jar
+

+ 23 - 0
Client/.project

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>bomberman</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.m2e.core.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.eclipse.m2e.core.maven2Nature</nature>
+	</natures>
+</projectDescription>

+ 6 - 0
Client/.settings/org.eclipse.core.resources.prefs

@@ -0,0 +1,6 @@
+eclipse.preferences.version=1
+encoding//src/main/java=UTF-8
+encoding//src/main/resources=UTF-8
+encoding//src/test/java=UTF-8
+encoding//src/test/resources=UTF-8
+encoding/<project>=UTF-8

+ 6 - 0
Client/.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,6 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.release=disabled
+org.eclipse.jdt.core.compiler.source=1.8

+ 4 - 0
Client/.settings/org.eclipse.m2e.core.prefs

@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1

+ 73 - 0
Client/README.md

@@ -0,0 +1,73 @@
+# Client basique pour le projet Bomber Student 
+
+Ce projet n'est pas une version définitive, elle est soumise à des updates. 
+
+
+# Contenu du projet
+
+Ce projet contient un environnement de base pour un client java. 
+
+C'est un projet maven. 
+
+La classe contenant le `main` est la classe `App.java`. 
+
+# Package `model.asset`
+
+## Classe AssetManager 
+
+C'est la classe permettant de charger un nouveau sprite. C'est un singleton. Il faut donc utiliser la méthode `getInstance` pour récupérer une instance de cette classe. 
+
+C'est avec la méthode `get` que l'on vient charger un sprite (déjà chargé au préalable ou nom). On utilise pour cela son nom. Les sprite doivent être stockés dans le dossier sprite du dossier spécifique maven `resources`. 
+
+Vous pouvez renommer le dossier si vous changez le chemin dans le fichier `path.properties` du dossier config. Cependant vous devrez tout mettre quand même dans le dossier resources. 
+
+## Classe Sprite 
+
+C'est une classe très basique qui ne contient qu'une référence sur une Image. Il faudra certainement la faire évoluer ... 
+
+
+# Package model.assetLoader 
+
+## Classe SpriteLoader 
+
+C'est la classe qui permet de charger un nouveau sprite si il n'est pas présent dans la map des sprites chargés. Il utilise pour cela le chemin spécifié dans le fichier "path.properties".
+
+# Package model.config
+
+## Classe ConfigManager
+
+Comme pour l'AssetManager, c'est une classe gérant la configuration du client. C'est un singleton, il faut donc appelet la méthode `getInstance` pour récupérer une instance de cette classe. 
+
+Avec la méthode `get` vous récupérez un objet de type `Configuration`. Pour le moment les clés que vous pouvez donnez à cette méthode sont: 
+
+- path: fichier de configuration pour les chemins des sprites, des sons etc...
+- general: fichier de configuration général: activation/désactivation du son, volume, musique ... 
+- input: gestion des touches du clavier 
+
+A vous de créer les menus permettant d'éditer ces fichiers. 
+
+## Interface Configuration 
+
+- load() permet de charger le fichier de configuration 
+- save() permet de sauvegarder le fichier de configuraiton 
+- get(name) permet d'accéder à la valeur de la clé `name`
+
+
+## Classe MyProperties 
+
+Implémentation de l'interface Configuration. 
+
+
+# Package View 
+
+## Classe Abstraite View 
+
+Permet de créer une nouvelle vue du jeu (Menu, Map du jeu ...). 
+
+## Classe MenuView 
+
+Implémentation d'une view pour le menu. 
+
+## Classe Window 
+
+Classe permettant de gérer la fenêtre du jeu (taille, style...). Dans cette classe se trouve également la méthode `setView()` permettant de chagner facilement de vue.  

+ 56 - 0
Client/pom.xml

@@ -0,0 +1,56 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>fr.univartois</groupId>
+  <artifactId>bomberman</artifactId>
+  <version>0.0.1-SNAPSHOT</version>
+  <packaging>jar</packaging>
+
+  <name>bomberman</name>
+  <url>http://maven.apache.org</url>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+
+
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-compiler-plugin</artifactId>
+          <version>3.8.0</version>
+          <configuration>
+            <source>1.8</source>
+            <target>1.8</target>
+          </configuration>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+
+
+  <dependencies>
+<!-- https://mvnrepository.com/artifact/junit/junit -->
+<dependency>
+    <groupId>junit</groupId>
+    <artifactId>junit</artifactId>
+    <version>4.12</version>
+    <scope>test</scope>
+</dependency>
+
+    
+    <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
+<dependency>
+    <groupId>org.apache.maven.plugins</groupId>
+    <artifactId>maven-compiler-plugin</artifactId>
+    <version>3.8.0</version>
+</dependency>
+    
+    
+    
+  </dependencies>
+</project>

+ 34 - 0
Client/src/main/java/fr/univartois/bomberman/App.java

@@ -0,0 +1,34 @@
+package fr.univartois.bomberman;
+
+import javax.swing.UIManager;
+import javax.swing.UnsupportedLookAndFeelException;
+
+import fr.univartois.bomberman.view.Window;
+
+/**
+ * Hello world!
+ *
+ */
+public class App 
+{
+	
+	public static void config() {
+		try {
+			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+		} catch (ClassNotFoundException e) {
+			e.printStackTrace();
+		} catch (InstantiationException e) {
+			e.printStackTrace();
+		} catch (IllegalAccessException e) {
+			e.printStackTrace();
+		} catch (UnsupportedLookAndFeelException e) {
+			e.printStackTrace();
+		}
+	}
+	
+    public static void main( String[] args )
+    {
+    	config();
+        new Window();
+    }
+}

+ 34 - 0
Client/src/main/java/fr/univartois/bomberman/model/asset/AssetManager.java

@@ -0,0 +1,34 @@
+/**
+ * 
+ */
+package fr.univartois.bomberman.model.asset;
+
+import java.util.Map;
+
+import fr.univartois.bomberman.model.asset.loader.SpriteLoader;
+
+/**
+ * @author thibault
+ *
+ */
+public class AssetManager {
+	private final static AssetManager instance=new AssetManager();
+	private Map<String,Sprite> sprites;
+	
+	
+	private AssetManager() {
+		//No instance for you
+	}
+	
+	
+	public static AssetManager getInstance() {
+		return instance;
+	}
+	
+	
+	public Sprite get(String name) {
+		return sprites.getOrDefault(name, SpriteLoader.load(name));
+	}
+	
+	
+}

+ 18 - 0
Client/src/main/java/fr/univartois/bomberman/model/asset/Sprite.java

@@ -0,0 +1,18 @@
+/**
+ * 
+ */
+package fr.univartois.bomberman.model.asset;
+
+import java.awt.Image;
+
+/**
+ * @author thibault
+ *
+ */
+public class Sprite {
+	private Image image; 
+	
+	public Sprite(Image image) {
+		this.image=image; 
+	}
+}

+ 29 - 0
Client/src/main/java/fr/univartois/bomberman/model/asset/loader/SpriteLoader.java

@@ -0,0 +1,29 @@
+/**
+ * 
+ */
+package fr.univartois.bomberman.model.asset.loader;
+
+import java.awt.Image;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+
+import fr.univartois.bomberman.model.asset.Sprite;
+
+/**
+ * @author thibault
+ *
+ */
+public class SpriteLoader {
+	
+	
+	public static Sprite load(String name) {
+		try {
+			Image image=ImageIO.read(SpriteLoader.class.getResourceAsStream(name));
+			return new Sprite(image);
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+}

+ 37 - 0
Client/src/main/java/fr/univartois/bomberman/model/config/ConfigManager.java

@@ -0,0 +1,37 @@
+/**
+ * 
+ */
+package fr.univartois.bomberman.model.config;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author thibault
+ *
+ */
+public class ConfigManager {
+	private final static ConfigManager config=new ConfigManager();
+	
+	private static Map<String,Configuration> configuration=new HashMap<>();
+	static {
+	    configuration.put("path",new MyProperties("path.properties"));
+	    configuration.put("general",new MyProperties("general.properties"));
+	    configuration.put("input",new MyProperties("input.properties"));
+	    
+	}
+	private ConfigManager() {
+		//No instance for you
+	}
+	
+	
+	public static ConfigManager getInstance() {
+		return config;
+	}
+	
+	public Configuration get(String key) {
+		return configuration.get(key);
+	}
+	
+	
+}

+ 17 - 0
Client/src/main/java/fr/univartois/bomberman/model/config/Configuration.java

@@ -0,0 +1,17 @@
+/**
+ * 
+ */
+package fr.univartois.bomberman.model.config;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+/**
+ * @author thibault
+ *
+ */
+public interface Configuration {
+	public void load() throws FileNotFoundException, IOException;
+	public void save() throws FileNotFoundException, IOException;
+	public String get(String name);
+}

+ 48 - 0
Client/src/main/java/fr/univartois/bomberman/model/config/MyProperties.java

@@ -0,0 +1,48 @@
+/**
+ * 
+ */
+package fr.univartois.bomberman.model.config;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+/**
+ * @author thibault
+ *
+ */
+public class MyProperties implements Configuration{
+	protected Properties prop=new Properties();
+	public final static String PATH_CONFIG="/config/";
+	
+	
+	private String path;
+
+	
+	public MyProperties(String path) {
+		this.path=path;
+		try {
+			load();
+		} catch (FileNotFoundException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+	
+	public void load() throws FileNotFoundException, IOException {
+		prop.load(MyProperties.class.getResourceAsStream("/config/"+path));
+	}
+
+	public void save() throws FileNotFoundException, IOException {
+		prop.store(new FileOutputStream(PATH_CONFIG+path),null);
+		
+	}
+
+	public String get(String key) {
+		return prop.getProperty(key);
+	}
+	
+}

+ 73 - 0
Client/src/main/java/fr/univartois/bomberman/view/MenuView.java

@@ -0,0 +1,73 @@
+/**
+ * 
+ */
+package fr.univartois.bomberman.view;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.GridLayout;
+import java.awt.Image;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+import javax.swing.JButton;
+import javax.swing.JPanel;
+
+/**
+ * @author thibault
+ *
+ */
+public class MenuView extends View {
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 8242388999005805846L;
+	
+	private Image background;
+	
+	private JButton[] jbutton=new JButton[4];
+	
+	private String[] texts= {"Créer ou rejoindre une partie","Configuration générale","Configuration des touches","Quitter"};
+	
+	public MenuView(Window w) {
+		super(w);
+		
+		this.setLayout(new BorderLayout());
+		
+		try {
+			background=ImageIO.read(MenuView.class.getResourceAsStream("/sprite/menu_background.png"));
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		
+		GridLayout layout=new GridLayout(4,1);
+		JPanel panel=new JPanel(layout);
+		for(int i=0;i<jbutton.length;i++) {
+			jbutton[i]=new JButton(texts[i]);
+			Dimension d=new Dimension(190, 49);
+			jbutton[i].setSize(d);
+			jbutton[i].setMinimumSize(d);
+			jbutton[i].setMaximumSize(d);
+			jbutton[i].setPreferredSize(d);
+			panel.add(jbutton[i]);
+		}
+		
+		this.add(panel,BorderLayout.CENTER);
+		
+		
+	}
+	/* (non-Javadoc)
+	 * @see javax.swing.JComponent#paint(java.awt.Graphics)
+	 */
+	@Override
+	public void paint(Graphics arg0) {
+		
+		arg0.drawImage(background, 0, 0, this);
+		super.paint(arg0);
+		
+	}
+	
+	
+
+}

+ 28 - 0
Client/src/main/java/fr/univartois/bomberman/view/View.java

@@ -0,0 +1,28 @@
+/**
+ * 
+ */
+package fr.univartois.bomberman.view;
+
+import javax.swing.JPanel;
+
+/**
+ * @author thibault
+ *
+ */
+public abstract class View extends JPanel{
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = -4269527495039353633L;
+	/**
+	 * 
+	 */
+	protected Window window;
+	/**
+	 * Abstract of View
+	 * @param w The window 
+	 */
+	public View(Window w) {
+		window=w;
+	}
+}

+ 45 - 0
Client/src/main/java/fr/univartois/bomberman/view/Window.java

@@ -0,0 +1,45 @@
+/**
+ * 
+ */
+package fr.univartois.bomberman.view;
+
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+import javax.swing.WindowConstants;
+
+/**
+ * @class Window 
+ * @author thibault
+ * 
+ */
+public class Window extends JFrame {
+	
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1459275138805807700L;
+	
+	public final static int WIDTH = 1450;  
+	public final static int HEIGHT =  820; 
+	
+	public Window() {
+		super("BomberStudent");
+		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+		
+		setSize(WIDTH, HEIGHT);
+		setPanel(new MenuView(this));
+		setVisible(true);
+	}
+	/**
+	 * Change the current view
+	 * @param view 
+	 */
+	public void setPanel(JComponent view) {
+		setContentPane(view);
+		view.setRequestFocusEnabled(true);
+		view.setFocusable(true);
+		view.requestFocus(true);
+		revalidate();
+		repaint();
+	}
+}

+ 0 - 0
Client/rsx/BomberStudentClient.java → Client/src/main/java/rsx/BomberStudentClient.java


+ 0 - 0
Client/rsx/BomberStudentHandler.java → Client/src/main/java/rsx/BomberStudentHandler.java


+ 0 - 0
Client/rsx/BomberStudentRequest.java → Client/src/main/java/rsx/BomberStudentRequest.java


+ 0 - 0
Client/rsx/tcp/TcpClient.java → Client/src/main/java/rsx/tcp/TcpClient.java


+ 0 - 0
Client/rsx/udp/Broadcast.java → Client/src/main/java/rsx/udp/Broadcast.java


+ 0 - 0
Client/test/JsonTest.java → Client/src/main/java/test/JsonTest.java


+ 0 - 0
Client/test/ServerHandlerTest.java → Client/src/main/java/test/ServerHandlerTest.java


+ 0 - 0
Client/test/ServerTest.java → Client/src/main/java/test/ServerTest.java


+ 0 - 0
Client/test/Test.java → Client/src/main/java/test/Test.java


+ 2 - 0
Client/src/main/resources/config/path.properties

@@ -0,0 +1,2 @@
+sprite="/sprite/"
+sound="/sound/"

BIN
Client/src/main/resources/sprite/menu_background.png


+ 38 - 0
Client/src/test/java/fr/univartois/bomberman/AppTest.java

@@ -0,0 +1,38 @@
+package fr.univartois.bomberman;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest 
+    extends TestCase
+{
+    /**
+     * Create the test case
+     *
+     * @param testName name of the test case
+     */
+    public AppTest( String testName )
+    {
+        super( testName );
+    }
+
+    /**
+     * @return the suite of tests being tested
+     */
+    public static Test suite()
+    {
+        return new TestSuite( AppTest.class );
+    }
+
+    /**
+     * Rigourous Test :-)
+     */
+    public void testApp()
+    {
+        assertTrue( true );
+    }
+}

+ 32 - 0
Client/src/test/java/fr/univartois/bomberman/model/config/ConfigManagerTest.java

@@ -0,0 +1,32 @@
+/**
+ * 
+ */
+package fr.univartois.bomberman.model.config;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+import fr.univartois.bomberman.view.MenuView;
+
+/**
+ * @author thibault
+ *
+ */
+public class ConfigManagerTest {
+	
+	
+	@Test
+	public void testInstance() {
+		assertNotNull(ConfigManager.getInstance());
+	}
+	
+	@Test
+	public void testGet() {
+		assertNotNull(MyProperties.class.getResourceAsStream("/config/path.properties"));
+		assertNotNull(ConfigManager.getInstance().get("path"));
+		assertNotNull(ConfigManager.getInstance().get("general"));
+		assertNotNull(ConfigManager.getInstance().get("input"));
+	}
+
+}

+ 2 - 0
Client/src/test/resources/config/path.properties

@@ -0,0 +1,2 @@
+sprite="/sprite/"
+sound="/sound/"

BIN
Client/src/test/resources/sprite/menu_background.png