-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
904675b
commit 1c2d1df
Showing
10 changed files
with
298 additions
and
0 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
app/src/main/java/fr/m2ihm/a1819/shi_fu_me/models/Game.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package fr.m2ihm.a1819.shi_fu_me.models; | ||
|
||
import android.support.annotation.NonNull; | ||
|
||
/** | ||
* Représente les données d'une parties | ||
* @version 1.0.0 | ||
*/ | ||
public class Game { | ||
|
||
public enum GameType{ | ||
SINGLEPLAYER, | ||
MULTIPLAYER; | ||
} | ||
|
||
/** | ||
* Choix de l'utilisateur | ||
*/ | ||
private Choice playerChoice = Choice.UNSET; | ||
|
||
/** | ||
* Choix de l'adversaire | ||
*/ | ||
private Choice advChoice = Choice.UNSET; | ||
|
||
/** | ||
* Score du joueur | ||
*/ | ||
private int playerScore = 0; | ||
|
||
/** | ||
* Score de l'adversaire | ||
*/ | ||
private int advScore = 0; | ||
|
||
/** | ||
* Créer un jeu | ||
*/ | ||
public Game() {} | ||
|
||
/** | ||
* Met à jours les score en fonction des choix | ||
*/ | ||
public void updateScore() { | ||
if (this.playerChoice.win(this.advChoice)) | ||
this.playerScore++; | ||
else if(this.advChoice.win(this.playerChoice)) | ||
this.advScore++; | ||
} | ||
|
||
/** | ||
* Obtiens le choix du joueur | ||
* @return Choix du joueur | ||
*/ | ||
public @NonNull Choice getPlayerChoice() { | ||
return playerChoice; | ||
} | ||
|
||
/** | ||
* Définie le choix du joueur | ||
* @param playerChoice Choix du joueur | ||
*/ | ||
public void setPlayerChoice(@NonNull Choice playerChoice) { | ||
this.playerChoice = playerChoice; | ||
} | ||
|
||
/** | ||
* Obtiens le choix de l'adversaire | ||
* @return Choix de l'adversaire | ||
*/ | ||
public @NonNull Choice getAdvChoice() { | ||
return advChoice; | ||
} | ||
|
||
/** | ||
* Définie le choix du joueur | ||
* @param advChoice Choix de l'adversaire | ||
*/ | ||
public void setAdvChoice(@NonNull Choice advChoice) { | ||
this.advChoice = advChoice; | ||
} | ||
|
||
/** | ||
* Obtiens le score du joueur | ||
* @return Score du joueur | ||
*/ | ||
public int getPlayerScore() { | ||
return playerScore; | ||
} | ||
|
||
/** | ||
* Obtiens le score de l'adversaire | ||
* @return Le score de l'adversaire | ||
*/ | ||
public int getAdvScore() { | ||
return advScore; | ||
} | ||
|
||
|
||
public void resetScore() { | ||
this.playerScore = 0; | ||
this.advScore = 0; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
app/src/main/java/fr/m2ihm/a1819/shi_fu_me/p2p/ServerSideClient.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package fr.m2ihm.a1819.shi_fu_me.p2p; | ||
|
||
import android.content.Context; | ||
import android.util.Log; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.io.PrintWriter; | ||
import java.net.Socket; | ||
|
||
public class ServerSideClient extends Common{ | ||
private Socket socket; | ||
private boolean running = true; | ||
private boolean runningOnServerSide = false; | ||
|
||
ServerSideClient(Context context, Socket socket) { | ||
super(context); | ||
this.socket = socket; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
super.run(); | ||
try { | ||
this.setPrintWriter(new PrintWriter(socket.getOutputStream(), true)); | ||
this.setBufferedReader(new BufferedReader(new InputStreamReader(socket.getInputStream()))); | ||
|
||
String response; | ||
|
||
response = this.getBufferedReader().readLine(); | ||
runningOnServerSide = MessageHeader.HELLO_SERVERSIDE.checkResponse(response); | ||
Log.d("[Server]", "Hello reçut \"" + response + '"'); | ||
|
||
|
||
do { | ||
response = this.getBufferedReader().readLine(); //On recoit le choix du client | ||
if (MessageHeader.END.checkResponse(response)) {running = false; continue;} //Check si on recoit fin de connection | ||
this.getPrintWriter().println(MessageHeader.INFOS + "[opp_choice: , your_score: , opp_score: ]"); //On envoie les infos | ||
} while (running); | ||
|
||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
public Socket getSocket() { | ||
return socket; | ||
} | ||
|
||
public void setSocket(Socket socket) { | ||
this.socket = socket; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
app/src/main/java/fr/m2ihm/a1819/shi_fu_me/utils/AndroidDrawableResource.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package fr.m2ihm.a1819.shi_fu_me.utils; | ||
|
||
/** | ||
* Classe représentant des ressource drawable d'android utilisé pour être rendue par un {@link Drawer} | ||
* @version 1.0.0 | ||
*/ | ||
public class AndroidDrawableResource extends DrawableResource<Integer> { | ||
|
||
/** | ||
* Créer une ressource android | ||
* @param ressourceId Identifiant android de la ressource | ||
*/ | ||
public AndroidDrawableResource(int ressourceId) { | ||
super(ressourceId); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
app/src/main/java/fr/m2ihm/a1819/shi_fu_me/utils/AndroidImageViewDrawer.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package fr.m2ihm.a1819.shi_fu_me.utils; | ||
|
||
import android.content.Context; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.widget.AppCompatImageView; | ||
import android.util.AttributeSet; | ||
import android.widget.ImageView; | ||
|
||
/** | ||
* Classe représentant une {@link AppCompatImageView} qui peut rendre un objet de type {@link AndroidDrawableResource} | ||
* @version 1.0.0 | ||
*/ | ||
public class AndroidImageViewDrawer implements Drawer<AndroidDrawableResource> { | ||
|
||
|
||
private final AppCompatImageView imageView; | ||
|
||
public AndroidImageViewDrawer(AppCompatImageView imageView) { | ||
this.imageView = imageView; | ||
} | ||
|
||
|
||
@Override | ||
public void drawResource(AndroidDrawableResource resource) { | ||
this.imageView.setImageResource(resource.getResource()); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/fr/m2ihm/a1819/shi_fu_me/utils/ComputerOpponent.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package fr.m2ihm.a1819.shi_fu_me.utils; | ||
|
||
import fr.m2ihm.a1819.shi_fu_me.models.Choice; | ||
import fr.m2ihm.a1819.shi_fu_me.models.Game; | ||
|
||
public class ComputerOpponent implements Opponent { | ||
|
||
@Override | ||
public Choice getChoice() { | ||
return Choice.randomChoice(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
app/src/main/java/fr/m2ihm/a1819/shi_fu_me/utils/DrawableResource.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package fr.m2ihm.a1819.shi_fu_me.utils; | ||
|
||
/** | ||
* Représente une resource qui pourra être utilisé par un objet de type {@link Drawer} afin d'être rendue | ||
* @param <T> Type de ressource stocké | ||
* @version 1.0.0 | ||
*/ | ||
public abstract class DrawableResource<T> { | ||
/** | ||
* Ressource utilisé pour être rendue | ||
*/ | ||
private T resource; | ||
|
||
/** | ||
* Créer une ressource | ||
* @param resource Ressource à utiliser | ||
*/ | ||
DrawableResource(T resource) { | ||
this.resource = resource; | ||
} | ||
|
||
/** | ||
* Obtiens la ressource | ||
* @return La ressource à rendre | ||
*/ | ||
public T getResource() { | ||
return resource; | ||
} | ||
|
||
/** | ||
* Définie la ressource | ||
* @param resource La ressource à être rendue | ||
*/ | ||
public void setResource(T resource) { | ||
this.resource = resource; | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/fr/m2ihm/a1819/shi_fu_me/utils/Drawer.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package fr.m2ihm.a1819.shi_fu_me.utils; | ||
|
||
/** | ||
* Classe utilisé pour rendre un objet de type {@link DrawableResource} | ||
* @param <T> Type de {@link DrawableResource} utilisé pour être rendue | ||
*/ | ||
public interface Drawer<T extends DrawableResource> { | ||
/** | ||
* Rend la ressource | ||
* @param resource Ressource à rendre | ||
*/ | ||
public void drawResource(T resource); | ||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/fr/m2ihm/a1819/shi_fu_me/utils/Opponent.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package fr.m2ihm.a1819.shi_fu_me.utils; | ||
|
||
import fr.m2ihm.a1819.shi_fu_me.models.Choice; | ||
|
||
public interface Opponent { | ||
public Choice getChoice(); | ||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/fr/m2ihm/a1819/shi_fu_me/utils/OpponentFactory.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package fr.m2ihm.a1819.shi_fu_me.utils; | ||
|
||
import android.support.annotation.NonNull; | ||
|
||
import fr.m2ihm.a1819.shi_fu_me.models.Game; | ||
|
||
public final class OpponentFactory { | ||
public static @NonNull Opponent getOpponent(final Game.GameType gameType) { | ||
switch (gameType) { | ||
case MULTIPLAYER: return new PlayerOpponent(); | ||
case SINGLEPLAYER: default: return new ComputerOpponent(); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/fr/m2ihm/a1819/shi_fu_me/utils/PlayerOpponent.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package fr.m2ihm.a1819.shi_fu_me.utils; | ||
|
||
import fr.m2ihm.a1819.shi_fu_me.models.Choice; | ||
|
||
public class PlayerOpponent implements Opponent { | ||
@Override | ||
public Choice getChoice() { | ||
//TODO Get the player choice | ||
return null; | ||
} | ||
} |