Created
April 16, 2016 21:08
-
-
Save maudmcok/1511b994fec2a2779b853de54cd430f2 to your computer and use it in GitHub Desktop.
game socket testestestestestest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="CompilerConfiguration"> | |
<resourceExtensions /> | |
<wildcardResourcePatterns> | |
<entry name="!?*.java" /> | |
<entry name="!?*.form" /> | |
<entry name="!?*.class" /> | |
<entry name="!?*.groovy" /> | |
<entry name="!?*.scala" /> | |
<entry name="!?*.flex" /> | |
<entry name="!?*.kt" /> | |
<entry name="!?*.clj" /> | |
<entry name="!?*.aj" /> | |
</wildcardResourcePatterns> | |
<annotationProcessing> | |
<profile default="true" name="Default" enabled="false"> | |
<processorPath useClasspath="true" /> | |
</profile> | |
</annotationProcessing> | |
</component> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<component name="CopyrightManager"> | |
<settings default="" /> | |
</component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="EntryPointsManager"> | |
<entry_points version="2.0" /> | |
</component> | |
<component name="MavenImportPreferences"> | |
<option name="generalSettings"> | |
<MavenGeneralSettings> | |
<option name="mavenHome" value="Bundled (Maven 3)" /> | |
</MavenGeneralSettings> | |
</option> | |
</component> | |
<component name="ProjectLevelVcsManager" settingsEditedManually="false"> | |
<OptionsSetting value="true" id="Add" /> | |
<OptionsSetting value="true" id="Remove" /> | |
<OptionsSetting value="true" id="Checkout" /> | |
<OptionsSetting value="true" id="Update" /> | |
<OptionsSetting value="true" id="Status" /> | |
<OptionsSetting value="true" id="Edit" /> | |
<ConfirmationsSetting value="0" id="Add" /> | |
<ConfirmationsSetting value="0" id="Remove" /> | |
</component> | |
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> | |
<output url="file://$PROJECT_DIR$/out" /> | |
</component> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project version="4"> | |
<component name="ProjectModuleManager"> | |
<modules> | |
<module fileurl="file://$PROJECT_DIR$/socketserver.iml" filepath="$PROJECT_DIR$/socketserver.iml" /> | |
</modules> | |
</component> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project name="module_socketserver" default="compile.module.socketserver"> | |
<dirname property="module.socketserver.basedir" file="${ant.file.module_socketserver}"/> | |
<property name="module.jdk.home.socketserver" value="${project.jdk.home}"/> | |
<property name="module.jdk.bin.socketserver" value="${project.jdk.bin}"/> | |
<property name="module.jdk.classpath.socketserver" value="${project.jdk.classpath}"/> | |
<property name="compiler.args.socketserver" value="-encoding UTF-8 -source 8 -target 8 ${compiler.args}"/> | |
<property name="socketserver.output.dir" value="${module.socketserver.basedir}/out/production/socketserver"/> | |
<property name="socketserver.testoutput.dir" value="${module.socketserver.basedir}/out/test/socketserver"/> | |
<path id="socketserver.module.bootclasspath"> | |
<!-- Paths to be included in compilation bootclasspath --> | |
</path> | |
<path id="socketserver.module.production.classpath"> | |
<path refid="${module.jdk.classpath.socketserver}"/> | |
</path> | |
<path id="socketserver.runtime.production.module.classpath"> | |
<pathelement location="${socketserver.output.dir}"/> | |
</path> | |
<path id="socketserver.module.classpath"> | |
<path refid="${module.jdk.classpath.socketserver}"/> | |
<pathelement location="${socketserver.output.dir}"/> | |
</path> | |
<path id="socketserver.runtime.module.classpath"> | |
<pathelement location="${socketserver.testoutput.dir}"/> | |
<pathelement location="${socketserver.output.dir}"/> | |
</path> | |
<patternset id="excluded.from.module.socketserver"> | |
<patternset refid="ignored.files"/> | |
</patternset> | |
<patternset id="excluded.from.compilation.socketserver"> | |
<patternset refid="excluded.from.module.socketserver"/> | |
</patternset> | |
<path id="socketserver.module.sourcepath"> | |
<dirset dir="${module.socketserver.basedir}"> | |
<include name="src"/> | |
</dirset> | |
</path> | |
<target name="compile.module.socketserver" depends="compile.module.socketserver.production,compile.module.socketserver.tests" description="Compile module socketserver"/> | |
<target name="compile.module.socketserver.production" depends="register.custom.compilers" description="Compile module socketserver; production classes"> | |
<mkdir dir="${socketserver.output.dir}"/> | |
<javac2 destdir="${socketserver.output.dir}" debug="${compiler.debug}" nowarn="${compiler.generate.no.warnings}" memorymaximumsize="${compiler.max.memory}" fork="true" executable="${module.jdk.bin.socketserver}/javac"> | |
<compilerarg line="${compiler.args.socketserver}"/> | |
<bootclasspath refid="socketserver.module.bootclasspath"/> | |
<classpath refid="socketserver.module.production.classpath"/> | |
<src refid="socketserver.module.sourcepath"/> | |
<patternset refid="excluded.from.compilation.socketserver"/> | |
</javac2> | |
<copy todir="${socketserver.output.dir}"> | |
<fileset dir="${module.socketserver.basedir}/src"> | |
<patternset refid="compiler.resources"/> | |
<type type="file"/> | |
</fileset> | |
</copy> | |
</target> | |
<target name="compile.module.socketserver.tests" depends="register.custom.compilers,compile.module.socketserver.production" description="compile module socketserver; test classes" unless="skip.tests"/> | |
<target name="clean.module.socketserver" description="cleanup module"> | |
<delete dir="${socketserver.output.dir}"/> | |
<delete dir="${socketserver.testoutput.dir}"/> | |
</target> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<module type="JAVA_MODULE" version="4"> | |
<component name="NewModuleRootManager" inherit-compiler-output="true"> | |
<exclude-output /> | |
<content url="file://$MODULE_DIR$"> | |
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | |
</content> | |
<orderEntry type="inheritedJdk" /> | |
<orderEntry type="sourceFolder" forTests="false" /> | |
</component> | |
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
path.variable.kotlin_bundled=C\:\\Program Files (x86)\\JetBrains\\IntelliJ IDEA Community Edition 2016.1.1\\plugins\\Kotlin\\kotlinc | |
path.variable.maven_repository=C\:\\Users\\Maudmcok\\.m2\\repository | |
jdk.home.1.8=C\:/Program Files/Java/jdk1.8.0_77 | |
javac2.instrumentation.includeJavaRuntime=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project name="socketserver" default="all"> | |
<property file="socketserver.properties"/> | |
<!-- Uncomment the following property if no tests compilation is needed --> | |
<!-- | |
<property name="skip.tests" value="true"/> | |
--> | |
<!-- Compiler options --> | |
<property name="compiler.debug" value="on"/> | |
<property name="compiler.generate.no.warnings" value="off"/> | |
<property name="compiler.args" value=""/> | |
<property name="compiler.max.memory" value="700m"/> | |
<patternset id="ignored.files"> | |
<exclude name="**/*.hprof/**"/> | |
<exclude name="**/*.pyc/**"/> | |
<exclude name="**/*.pyo/**"/> | |
<exclude name="**/*.rbc/**"/> | |
<exclude name="**/*.yarb/**"/> | |
<exclude name="**/*~/**"/> | |
<exclude name="**/.DS_Store/**"/> | |
<exclude name="**/.git/**"/> | |
<exclude name="**/.hg/**"/> | |
<exclude name="**/.svn/**"/> | |
<exclude name="**/CVS/**"/> | |
<exclude name="**/RCS/**"/> | |
<exclude name="**/SCCS/**"/> | |
<exclude name="**/__pycache__/**"/> | |
<exclude name="**/_svn/**"/> | |
<exclude name="**/rcs/**"/> | |
<exclude name="**/vssver.scc/**"/> | |
<exclude name="**/vssver2.scc/**"/> | |
</patternset> | |
<patternset id="library.patterns"> | |
<include name="*.war"/> | |
<include name="*.swc"/> | |
<include name="*.apk"/> | |
<include name="*.zip"/> | |
<include name="*.ear"/> | |
<include name="*.egg"/> | |
<include name="*.ane"/> | |
<include name="*.jar"/> | |
</patternset> | |
<patternset id="compiler.resources"> | |
<exclude name="**/?*.java"/> | |
<exclude name="**/?*.form"/> | |
<exclude name="**/?*.class"/> | |
<exclude name="**/?*.groovy"/> | |
<exclude name="**/?*.scala"/> | |
<exclude name="**/?*.flex"/> | |
<exclude name="**/?*.kt"/> | |
<exclude name="**/?*.clj"/> | |
<exclude name="**/?*.aj"/> | |
</patternset> | |
<!-- JDK definitions --> | |
<property name="jdk.bin.1.8" value="${jdk.home.1.8}/bin"/> | |
<path id="jdk.classpath.1.8"> | |
<fileset dir="${jdk.home.1.8}"> | |
<include name="jre/lib/charsets.jar"/> | |
<include name="jre/lib/deploy.jar"/> | |
<include name="jre/lib/ext/access-bridge-64.jar"/> | |
<include name="jre/lib/ext/cldrdata.jar"/> | |
<include name="jre/lib/ext/dnsns.jar"/> | |
<include name="jre/lib/ext/jaccess.jar"/> | |
<include name="jre/lib/ext/jfxrt.jar"/> | |
<include name="jre/lib/ext/localedata.jar"/> | |
<include name="jre/lib/ext/nashorn.jar"/> | |
<include name="jre/lib/ext/sunec.jar"/> | |
<include name="jre/lib/ext/sunjce_provider.jar"/> | |
<include name="jre/lib/ext/sunmscapi.jar"/> | |
<include name="jre/lib/ext/sunpkcs11.jar"/> | |
<include name="jre/lib/ext/zipfs.jar"/> | |
<include name="jre/lib/javaws.jar"/> | |
<include name="jre/lib/jce.jar"/> | |
<include name="jre/lib/jfr.jar"/> | |
<include name="jre/lib/jfxswt.jar"/> | |
<include name="jre/lib/jsse.jar"/> | |
<include name="jre/lib/management-agent.jar"/> | |
<include name="jre/lib/plugin.jar"/> | |
<include name="jre/lib/resources.jar"/> | |
<include name="jre/lib/rt.jar"/> | |
</fileset> | |
</path> | |
<property name="project.jdk.home" value="${jdk.home.1.8}"/> | |
<property name="project.jdk.bin" value="${jdk.bin.1.8}"/> | |
<property name="project.jdk.classpath" value="jdk.classpath.1.8"/> | |
<!-- Register Custom Compiler Taskdefs --> | |
<property name="javac2.home" value="${idea.home}/lib"/> | |
<path id="javac2.classpath"> | |
<pathelement location="${javac2.home}/javac2.jar"/> | |
<pathelement location="${javac2.home}/jdom.jar"/> | |
<pathelement location="${javac2.home}/asm-all.jar"/> | |
<pathelement location="${javac2.home}/jgoodies-forms.jar"/> | |
</path> | |
<target name="register.custom.compilers"> | |
<taskdef name="javac2" classname="com.intellij.ant.Javac2" classpathref="javac2.classpath"/> | |
<taskdef name="instrumentIdeaExtensions" classname="com.intellij.ant.InstrumentIdeaExtensions" classpathref="javac2.classpath"/> | |
</target> | |
<!-- Modules --> | |
<import file="${basedir}/module_socketserver.xml"/> | |
<target name="init" description="Build initialization"> | |
<!-- Perform any build initialization in this target --> | |
</target> | |
<target name="clean" depends="clean.module.socketserver" description="cleanup all"/> | |
<target name="build.modules" depends="init, clean, compile.module.socketserver" description="build all modules"/> | |
<target name="all" depends="build.modules" description="build all"/> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.net.ServerSocket; | |
import java.net.Socket; | |
/** | |
* Created by Maudmcok on 05/04/2016. | |
*/ | |
public class Accepter_connexion implements Runnable{ | |
private ServerSocket socketserver = null; | |
private Socket socket = null; | |
private String pass = null; | |
public Thread t1; | |
public Accepter_connexion(ServerSocket ss,String st){ | |
socketserver = ss; | |
pass = st; | |
} | |
public void run() { | |
try { | |
while(true){ | |
socket = socketserver.accept(); | |
System.out.println("Un Joueur veux se connecter "); | |
t1 = new Thread( new Authentification(socket,pass)); | |
t1.start(); | |
} | |
} catch (IOException e) { | |
System.err.println("Erreur serveur"); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Maudmcok on 05/04/2016. | |
*/ | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.io.PrintWriter; | |
import java.net.Socket; | |
import java.util.Objects; | |
public class Authentification implements Runnable { | |
private Socket socket; | |
private PrintWriter out = null; | |
private BufferedReader in = null; | |
protected String cpass,pass = null; | |
public boolean authentifier = false; | |
public Thread t2; | |
public Authentification(Socket s,String st){ | |
socket = s; | |
cpass = st; | |
} | |
public void run() { | |
try { | |
in = new BufferedReader(new InputStreamReader(socket.getInputStream())); | |
out = new PrintWriter(socket.getOutputStream()); | |
while(!authentifier){ | |
/* | |
out.println("Entrez votre login :"); | |
out.flush(); | |
login = in.readLine();*/ | |
out.println("Entrez Le mot de passe :"); | |
out.flush(); | |
pass = in.readLine(); | |
// if(isValid(login, pass)){ | |
if(isValid(pass,cpass)){ | |
out.println("connecte"); | |
System.out.println("Un joueur vient de se connecter "); | |
out.flush(); | |
authentifier = true; | |
} | |
else {out.println("erreur"); out.flush();} | |
} | |
t2 = new Thread(new Shootconsole(socket)); | |
t2.start(); | |
} catch (IOException e) { | |
System.err.println(" ne répond pas !"); | |
} | |
} | |
// private static boolean isValid(String login, String pass) { | |
private static boolean isValid( String pass,String cp) { | |
boolean connexion = false; | |
// if (Objects.equals(login, "maud") && Objects.equals(pass, "mcok")) { | |
if (Objects.equals(pass, cp)) { | |
connexion = true; | |
} | |
/* try { | |
Scanner sc = new Scanner(new File("zero.txt")); | |
while(sc.hasNext()){ | |
if(sc.nextLine().equals(login+" "+pass)){ | |
connexion=true; | |
break; | |
} | |
} | |
} catch (FileNotFoundException e) { | |
System.err.println("Le fichier n'existe pas !"); | |
}*/ | |
return connexion; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Maudmcok on 05/04/2016. | |
*/ | |
import java.io.*; | |
import java.net.*; | |
public class Client { | |
public static Socket socket = null; | |
public static Thread t1; | |
public static String adrss = null; | |
public Client(String s){ | |
adrss = s; | |
} | |
public static void main() { | |
try { | |
System.out.println("Demande de connexion"); | |
socket = new Socket(adrss,3000); | |
System.out.println("Connexion établie avec le serveur, authentification :"); // Si le message s'affiche c'est que je suis connecté | |
t1 = new Thread( new Connexion(socket)); | |
t1.start(); | |
} catch (UnknownHostException e) { | |
System.err.println("Impossible de se connecter à l'adresse "+socket.getLocalAddress()); | |
} catch (IOException e) { | |
System.err.println("Aucun serveur à l'écoute du port "+socket.getLocalPort()); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Maudmcok on 05/04/2016. | |
*/ | |
import java.net.*; | |
import java.util.Scanner; | |
import java.io.*; | |
public class Connexion implements Runnable { | |
private Socket socket = null; | |
public static Thread t2; | |
public static String login = null, pass = null, message1 = null, message2 = null, message3 = null; | |
private PrintWriter out = null; | |
private BufferedReader in = null; | |
private Scanner sc = null; | |
private boolean connect = false; | |
public Connexion(Socket s){ | |
socket = s; | |
} | |
public void run() { | |
try { | |
out = new PrintWriter(socket.getOutputStream()); | |
in = new BufferedReader(new InputStreamReader(socket.getInputStream())); | |
sc = new Scanner(System.in); | |
while(!connect ){ | |
/*System.out.println(in.readLine()); | |
login = sc.nextLine(); | |
out.println(login); | |
out.flush();*/ | |
System.out.println(in.readLine()); | |
pass = sc.nextLine(); | |
out.println(pass); | |
out.flush(); | |
if(in.readLine().equals("connecte")){ | |
System.out.println("Je suis connecté "); | |
connect = true; | |
} | |
else { | |
System.err.println("Vos informations sont incorrectes "); | |
} | |
} | |
t2 = new Thread(new Shootconsole(socket)); | |
t2.start(); | |
} catch (IOException e) { | |
System.err.println("Le serveur ne répond plus "); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Constants { | |
public final static int BULLETS = 2; | |
public final static int LIFE = 3; | |
public final static int ATTACK = 1; | |
public final static int DODGE = 2; | |
public final static int RELOAD = 3; | |
public final static int NONE = 7; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Maudmcok on 04/04/2016. | |
*/ | |
import java.net.*; | |
import java.io.*; | |
import java.util.*; | |
public class Main { | |
public static Thread t7; | |
static Scanner sc; | |
public static String choix; | |
/* | |
public static String lireString() { | |
String ligne = null; | |
try { | |
InputStreamReader lect = new InputStreamReader(System.in); | |
BufferedReader entree = new BufferedReader(lect); | |
ligne = entree.readLine(); | |
return ligne; | |
} catch (IOException e) { | |
return ligne; | |
} | |
} | |
}*/ | |
/* | |
class UnClient { | |
String ligne; | |
BufferedReader fluxEntree = null; | |
PrintStream fluxSortie = null; | |
UnClient(String sxr){ | |
try { | |
InetAddress adrloc = InetAddress.getLocalHost(); | |
System.out.println("Adresse local = " + adrloc.getHostAddress()); | |
System.out.println("Nom netBios = " + adrloc.getHostName()); | |
InetAddress Adresse = InetAddress.getByName(sxr); | |
// System.out.println("Autre = " + Adresse.getHostName()); | |
Socket socket = new Socket(Adresse, 3000); | |
fluxEntree = new BufferedReader(new InputStreamReader(socket.getInputStream())); | |
fluxSortie = new PrintStream(socket.getOutputStream()); | |
}catch (IOException e){ | |
System.out.println("Probleme de connexion"); | |
} | |
}; | |
void envoyer (){ | |
try { | |
System.out.println("Saisi une ligne de texte "); | |
ligne = Main.lireString(); | |
while (!ligne.equals("")){ | |
fluxSortie.println(ligne); | |
ligne = fluxEntree.readLine(); | |
System.out.println("Saisire une ligne de texte"); | |
ligne = Main.lireString(); | |
} | |
}catch (Exception e){}; | |
}; | |
*/ | |
public static void main(String mx) throws IOException { | |
//Client[] tabClient = new Client[]{}; | |
choix = mx; | |
String adrssr;do{ | |
FindS finds = new FindS(); | |
adrssr = finds.serveurok(mx); | |
}while (adrssr == "nope"); | |
Client clt = new Client(adrssr); | |
clt.main(); | |
// UnClient client = new UnClient(adrssr); | |
// while (0==0)client.envoyer(); | |
}; | |
}; | |
class FindS { | |
protected InetAddress address; | |
protected int port; | |
protected DatagramPacket dpaquet=null; | |
protected DatagramSocket dsocket=null; | |
protected DatagramPacket dpaquet0=null; | |
protected DatagramSocket dsocket0=null; | |
FindS(){ | |
try { | |
address = InetAddress.getByName("255.255.255.255"); | |
port = 3000; | |
}catch (UnknownHostException e){} | |
} | |
String validation = null; | |
// boolean serveurok() throws IOException { | |
String serveurok(String mz) { | |
DatagramSocket socket; | |
try { | |
DatagramSocket qsocket = null; | |
byte[] sendData = "SHOOTING_BAKA".getBytes(); | |
try { | |
dpaquet = new DatagramPacket(sendData, sendData.length, address,port); | |
qsocket = new DatagramSocket(); | |
}catch (Exception ew){} | |
try { | |
qsocket.send(dpaquet); | |
}catch (IOException e){} | |
//System.out.println("lolo"); | |
// System.out.println(getClass().getName() + ">>>> Request send to 255.255.255.255"); | |
// }catch (Exception e){} | |
Enumeration interfaces = NetworkInterface.getNetworkInterfaces(); | |
while (interfaces.hasMoreElements()) { | |
NetworkInterface networkInterface = (NetworkInterface) interfaces.nextElement(); | |
if (networkInterface.isLoopback() || !networkInterface.isUp()) { | |
continue; // Don't want to broadcast to the loopback interface | |
} | |
for (InterfaceAddress interfaceAddress : networkInterface.getInterfaceAddresses()) { | |
InetAddress broadcast = interfaceAddress.getBroadcast(); | |
if (broadcast == null) { | |
continue; | |
} | |
// Send the broadcast package! | |
try { | |
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, broadcast, 3000); | |
qsocket.send(sendPacket); | |
} catch (Exception e) { | |
} | |
//System.out.println(getClass().getName() + ">>> Request packet sent to: " + broadcast.getHostAddress() + "; Interface: " + networkInterface.getDisplayName()); | |
} | |
} | |
System.out.println(getClass().getName() + ">>> Done looping over all network interfaces. Now waiting for a reply! Wait Game client 212"); | |
//Wait for a response | |
byte[] recvBuf = new byte[15000]; | |
DatagramPacket receivePacket = new DatagramPacket(recvBuf, recvBuf.length); | |
qsocket.receive(receivePacket); | |
//We have a response | |
System.out.println(getClass().getName() + ">>> Partie found from server: " + receivePacket.getAddress().getHostName()); | |
//Check if the message is correct | |
String message = new String(receivePacket.getData()).trim(); | |
System.out.println(getClass().getName() + ">>> Partie Mane found : " + message + " or you put =" + mz); | |
if (message == mz ) { | |
//DO SOMETHING WITH THE SERVER'S IP (for example, store it in your controller) | |
// Controller_Base.setServerIp(receivePacket.getAddress()); | |
validation = receivePacket.getAddress().getHostAddress(); | |
System.out.println(getClass().getName() + " >>> confirmation "); | |
DatagramSocket qsocket0 = null; | |
byte[] sendData0 = "OK".getBytes(); | |
try { | |
dpaquet0 = new DatagramPacket(sendData0, sendData0.length, InetAddress.getByName(receivePacket.getAddress().getHostAddress()),port); | |
// qsocket0 = new DatagramSocket(); | |
}catch (Exception ew){} | |
try { | |
qsocket0.send(dpaquet0); | |
}catch (IOException e){} | |
qsocket.close(); | |
dsocket.close(); | |
} else { | |
System.out.println("Le nom departy ne corespond pas "); | |
validation = "nope"; | |
DatagramSocket qsocket0 = null; | |
byte[] sendData0 = "NOK".getBytes(); | |
try { | |
dpaquet0 = new DatagramPacket(sendData0, sendData0.length, InetAddress.getByName(receivePacket.getAddress().getHostAddress()),port); | |
// qsocket0 = new DatagramSocket(); | |
}catch (Exception ew){} | |
try { | |
qsocket0.send(dpaquet0); | |
}catch (IOException e){} | |
new Main();} | |
}catch (Exception e){} | |
//Close the port! | |
//dsocket.close(); | |
return validation; | |
}; | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Player { | |
// Life of player | |
int life; | |
// Bullet of player | |
int bullet; | |
// Action of player | |
int action; | |
/** | |
* Player constructor | |
*/ | |
public Player(){ | |
life = Constants.LIFE; | |
bullet = Constants.BULLETS; | |
action = Constants.NONE; | |
} | |
/** | |
* Apply damage to oppenent | |
* @param player oppenent | |
*/ | |
public void setDamage(Player player){ | |
player.getDamage(); | |
removeBullet(); | |
} | |
public int getLife(){ | |
return this.life; | |
} | |
/** | |
* Apply damage to player | |
*/ | |
public void getDamage(){ | |
if(life > 0){ | |
life--; | |
} | |
} | |
/** | |
* Increment player's bullets | |
*/ | |
public void addBullet(){ | |
bullet++; | |
} | |
/** | |
* Decrement player's bullets | |
*/ | |
public void removeBullet(){ | |
if(bullet > 0){ | |
bullet--; | |
} | |
} | |
/** | |
* Apply action to player | |
* @param a action | |
*/ | |
public void setAction(int a){ | |
action = a; | |
} | |
/** | |
* Get action of player | |
* @return action | |
*/ | |
public int getAction(){ | |
return this.action; | |
} | |
/** | |
* Attack opponent | |
* @param player opponent | |
*/ | |
public void attack(Player player){ | |
if(hasBullet()){ | |
setDamage(player); | |
}else player.setAction(7); | |
} | |
/** | |
* Check if player has bullets | |
* @return True if player has bullets. False otherwise | |
*/ | |
public boolean hasBullet(){ | |
return bullet > 0 ? true : false; | |
} | |
/** | |
* Get bullets | |
* @return number of bullets | |
*/ | |
public int getBullets(){ | |
return this.bullet; | |
} | |
/** | |
* Run selected action (to opponent eventually) | |
* @param player opponent | |
*/ | |
/** | |
* Check if player is dead | |
* @return True if player is dead. False otherwise | |
*/ | |
public boolean isDead(){ | |
return life > 0 ? false : true ; | |
} | |
public void runAction(Player player){ | |
switch(justsu(player)){ | |
case 11:{ | |
if (hasBullet()){player.life--;bullet--;}; | |
if (player.hasBullet()){life--;bullet--;} | |
}break; | |
case 12:{ | |
if (hasBullet()){bullet--;} | |
}break; | |
case 13:{ | |
if (hasBullet()){ bullet--; player.life--;}; | |
player.bullet++; | |
}break; | |
case 21:{ | |
if (player.hasBullet()){player.bullet--; } | |
}break; | |
case 22:{}break; | |
case 23:{ | |
player.bullet++; | |
}break; | |
case 31:{ | |
bullet++; | |
if (player.hasBullet()){player.bullet--;life--;} | |
}break; | |
case 32:{ | |
bullet++; | |
}break; | |
case 33:{ | |
bullet++; | |
bullet++; | |
}break; | |
case 14:{ | |
if (hasBullet()){bullet--; | |
player.life--;} | |
}break; | |
case 24:{}break; | |
case 34:{ | |
bullet++; | |
}break; | |
case 44:{}break; | |
case 43:{ | |
player.bullet++; | |
}break; | |
case 42:{}break; | |
case 41:{ | |
if (player.hasBullet()){ player.bullet--; | |
life--;} | |
}break; | |
}; | |
} | |
/** | |
* Check if player is attacked | |
* @param player opponent | |
* @return True if player is attacked . False otherwise | |
*/ | |
public boolean isAttackedBy(Player player){ | |
return player.getAction() == Constants.ATTACK ? true : false; | |
} | |
public int justsu(Player p) {return (action*10 + p.action) ;} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.io.PrintStream; | |
import java.net.*; | |
/** | |
* Created by Maudmcok on 04/04/2016. | |
*/ | |
class Serverkk { | |
BufferedReader entree; | |
PrintStream sortie; | |
DatagramSocket socket; | |
Serverkk() {}; | |
boolean finds(String my){ | |
try { | |
//Keep a socket open to listen to all the UDP trafic that is destined for this port | |
socket = new DatagramSocket(3000, InetAddress.getByName("0.0.0.0")); | |
socket.setBroadcast(true); | |
while (true) { | |
System.out.println(getClass().getName() + ">>>Ready to receive broadcast packets!"); | |
//Receive a packet | |
byte[] recvBuf = new byte[15000]; | |
DatagramPacket packet = new DatagramPacket(recvBuf, recvBuf.length); | |
socket.receive(packet); | |
//Packet received | |
System.out.println(getClass().getName() + ">>>Discovery packet received from: " + packet.getAddress().getHostAddress()); | |
System.out.println(getClass().getName() + ">>>Packet received; data: " + new String(packet.getData())); | |
//See if the packet holds the right command (message) | |
String message = new String(packet.getData()).trim(); | |
System.out.println(getClass().getName() + ">>>Packet received; MANE : " + message); | |
if (message.equals("SHOOTING_BAKA")) { | |
byte[] sendData = my.getBytes(); | |
//Send a response | |
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, packet.getAddress(), packet.getPort()); | |
socket.send(sendPacket); | |
System.out.println(getClass().getName() + ">>>Sent packet to: " + sendPacket.getAddress().getHostAddress()); | |
String message0 = new String(sendPacket.getData()).trim(); | |
System.out.println(getClass().getName() + ">>>Whit message: " + message0); | |
// reponce of game found | |
byte[] recvBuf0 = new byte[15000]; | |
DatagramPacket packet0 = new DatagramPacket(recvBuf0, recvBuf0.length); | |
socket.receive(packet0); | |
//Packet received | |
System.out.println(getClass().getName() + ">>> Discovery lolo received Party: " + packet0.getAddress().getHostAddress()); | |
System.out.println(getClass().getName() + ">>> Packet lolo; data: " + new String(packet0.getData())); | |
//See if the packet holds the right command (message) | |
String message1 = new String(packet0.getData()).trim(); | |
if (message1 == "OK") return true; | |
else return false; | |
}else return false; | |
} | |
} catch (IOException ex) { | |
return false; | |
} | |
}; | |
/* | |
void connecter(){ | |
try { | |
InetAddress adrloc = InetAddress.getLocalHost(); | |
System.out.println("Adresse local = " + adrloc.getHostAddress()); | |
System.out.println("Nom netBios = " + adrloc.getHostName()); | |
InetAddress adrServeur = InetAddress.getByName("www.aviso.ci"); | |
System.out.println("Adresse aviso = " + adrServeur.getHostAddress()); | |
ServerSocket server = new ServerSocket(3000); | |
System.out.println("Serveur en attente de client "); | |
Socket socket = server.accept(); | |
System.out.println("Connexion sur le socket " + socket); | |
entree = new BufferedReader( new InputStreamReader(socket.getInputStream())); | |
sortie = new PrintStream(socket.getOutputStream()); | |
String ligne = entree.readLine(); | |
if(ligne != null) { | |
System.out.println("la ligne lue est : " + ligne); | |
}; | |
server.close(); | |
}catch (IOException e ){ | |
System.out.println(e); | |
}; | |
};*/ | |
public static void main(String mx){ | |
boolean respond_gameCliebt = false; | |
do { | |
Serverkk serveur = new Serverkk(); | |
respond_gameCliebt = serveur.finds(mx); | |
if (respond_gameCliebt) System.out.println(" find !"); | |
}while (!respond_gameCliebt); | |
Serveur serveur1 = new Serveur(); | |
serveur1.main(); | |
};}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Maudmcok on 05/04/2016. | |
*/ | |
import java.io.IOException; | |
import java.net.ServerSocket; | |
import java.util.Scanner; | |
public class Serveur { | |
public static ServerSocket ss = null; | |
public static Thread t; | |
public static Scanner sc = null; | |
public static void main() { | |
try { | |
ss = new ServerSocket(3000); | |
System.out.println("Le serveur est à l'écoute du port "+ss.getLocalPort()); | |
sc = new Scanner(System.in); | |
System.out.println("Entrez le pass de la partie "); | |
String pass = sc.nextLine(); | |
t = new Thread(new Accepter_connexion(ss,pass)); | |
t.start(); | |
} catch (IOException e) { | |
System.err.println("Le port "+ss.getLocalPort()+" est déjà utilisé !"); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
import java.io.*; | |
import java.net.*; | |
import java.util.Scanner; | |
/** | |
* | |
* @author Maudmcok & AgnamC | |
*/ | |
public class Shootconsole implements Runnable { | |
/** | |
* @param args the command line arguments | |
*/ | |
// player 2 for test multiplayer reseau socket | |
static Scanner sc; | |
static int action; | |
static Player player1; | |
static Player player2; | |
// connexion | |
static Socket socket; | |
static PrintWriter out = null; | |
static BufferedReader in = null; | |
static Thread t3, t4; | |
static int aux; | |
static boolean synchoneg = false; | |
public Shootconsole(Socket s){ | |
socket = s; | |
} | |
@SuppressWarnings("empty-statement") | |
@Override | |
public void run() { | |
boolean agains =false; | |
do { | |
try { | |
out = new PrintWriter(socket.getOutputStream()); | |
in = new BufferedReader(new InputStreamReader(socket.getInputStream())); | |
sc = new Scanner(System.in); | |
player1 = new Player(); | |
player2 = new Player(); | |
do { | |
System.out.println("\nStatus"); | |
System.out.println("You | bullets : " + player1.getBullets() + " | life : " + player1.getLife()); | |
System.out.println("Freind E | bullets : " + player2.getBullets() + " | life : " + player2.getLife()); | |
// ATTACK : 4 , DODGE : 5 , RELOAD : 6 | |
System.out.println("\nChoose action ATTACK : 1 , DODGE : 2 , RELOAD : 3"); | |
System.out.print("You ... "); | |
player1.setAction(sc.nextInt()); | |
/*System.out.print("Player 2 ... "); | |
player2.setAction(sc.nextInt());*/ | |
out.println(player1.action); | |
out.flush(); | |
try { | |
aux = Integer.valueOf(in.readLine()).intValue(); | |
player2.setAction(aux); | |
synchoneg = true; | |
} catch (IOException e) { | |
System.out.println("\n impossible de contacter l autre joueur "); | |
e.printStackTrace(); | |
} | |
if (synchoneg) { | |
conbaat(player1,player2); | |
synchoneg = false; | |
} else System.out.println("\n impossible de contacter l autre joueur "); | |
} | |
while (!player1.isDead() && !player2.isDead()); | |
System.out.println("\nStatus"); | |
System.out.println("You | bullets : " + player1.getBullets() + " | life : " + player1.getLife()); | |
System.out.println("Freind E | bullets : " + player2.getBullets() + " | life : " + player2.getLife()); | |
if (!player1.isDead() && player2.isDead()) { | |
System.out.println("\n You win"); | |
} | |
if (player1.isDead() && !player2.isDead()) { | |
System.out.println("\n Player 2 win"); | |
System.out.println("\n You Lose"); | |
} | |
if (player1.isDead() && player2.isDead()) { | |
System.out.println("\nDraw game"); | |
} | |
System.out.println("\n Pour une nouvelle parie taper Y"); | |
if (sc.nextLine().equals("Y")){ | |
out.println("Y"); | |
out.flush();agains=true; | |
}else {agains = false ; | |
out.println("N"); | |
out.flush(); | |
} | |
try { | |
String auxs = in.readLine(); | |
if (auxs.equals("Y")) { | |
System.out.println("\n nouvelle parie "); | |
agains = true ; | |
}else System.out.println("\n Votre ami refuse de rejouer lol "); | |
} catch (IOException e) { | |
System.out.println("\n impossible de contacter l autre joueur "); | |
e.printStackTrace(); } | |
} catch (IOException e) { | |
System.err.println("freind déconnecté !"); | |
} | |
}while(agains); | |
} | |
public void conbaat(Player p1,Player p2){ | |
int mx = justsu(p1,p2); | |
System.out.println("\n PS : GOOD GAME @NGNL ="+mx); | |
switch(mx){ | |
case 11:{ | |
System.out.println("\n PS : GOOD GAME @NGNL lolo ="+mx); | |
if (p1.hasBullet()){p2.life--;p1.bullet--;} | |
if (p2.hasBullet()){p1.life--;p2.bullet--;} | |
}break; | |
case 12:{ | |
if (p1.hasBullet()){p1.bullet--;} | |
}break; | |
case 13:{ | |
if (p1.hasBullet()){ p1.bullet--; p2.life--;}; | |
p2.bullet++; | |
}break; | |
case 21:{ | |
if (p2.hasBullet()){p2.bullet--; } | |
}break; | |
case 22:{}break; | |
case 23:{ | |
p2.bullet++; | |
}break; | |
case 31:{ | |
p1.bullet++; | |
if (p2.hasBullet()){p2.bullet--;p1.life--;} | |
}break; | |
case 32:{ | |
p1.bullet++; | |
}break; | |
case 33:{ | |
p1.bullet++; | |
p1.bullet++; | |
}break; | |
case 14:{ | |
if (p1.hasBullet()){p1.bullet--; | |
p2.life--;} | |
}break; | |
case 24:{}break; | |
case 34:{ | |
p1.bullet++; | |
}break; | |
case 44:{}break; | |
case 43:{ | |
p2.bullet++; | |
}break; | |
case 42:{}break; | |
case 41:{ | |
if (p2.hasBullet()){ p2.bullet--; | |
p1.life--;} | |
}break; | |
}; | |
} | |
public int justsu(Player p,Player p0) { | |
int aux = (p.action*10 + p0.action) ; | |
System.out.println("\n PS : GOOD GAME @NGNL ="+aux); | |
return aux ; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javafx.application.Application; | |
import javafx.stage.Stage; | |
import java.io.IOException; | |
import java.util.Scanner; | |
/** | |
* Created by Maudmcok on 06/04/2016. | |
*/ | |
public class StartGame extends Application { | |
static Scanner sc; | |
static String choix; | |
public static void main() { | |
sc = new Scanner(System.in); | |
System.out.println("\n Salut bien venue dans le shooting baka "); | |
System.out.println("\n pour jouer avec votre amie un doit cree"); | |
System.out.println("\n La parti et l autre s y connectrera !"); | |
System.out.println("\n PS: Vous devez etre sur le meme reseau Wifi ."); | |
System.out.println("\n PS : GOOD GAME @NGNL"); | |
System.out.println("\n Pour Cree uine partie entrez Y"); | |
choix = sc.nextLine(); | |
if (choix.equals("Y") || choix.equals("y")) { | |
Serverkk serveurfind = new Serverkk(); | |
System.out.println("\n Donner un nom a votre server"); | |
choix = sc.nextLine(); | |
serveurfind.main(choix); | |
} else { | |
System.out.println("\n Si votre ami(e) cree la partie verifier si la partie est cree"); | |
System.out.println("\n Puis tapez Y"); | |
choix = sc.nextLine(); | |
if (choix.equals("Y") || choix.equals("y")) { | |
Serverkk serveurfind = new Serverkk(); | |
Main maing = new Main(); | |
try { | |
System.out.println("\n Donner le nom du server de votre ami(e) :3"); | |
choix = sc.nextLine(); | |
maing.main(choix); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
System.out.println("\n Impossible de demarer le client"); | |
} | |
} | |
} | |
} | |
@Override | |
public void start(Stage primaryStage) throws Exception { | |
main(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment