mirror of
https://github.com/Aviortheking/Hangman.git
synced 2024-12-19 18:20:54 +00:00
Yolo
This commit is contained in:
parent
b6ad0ac8cd
commit
ba9b808769
2
.idea/modules.xml
generated
2
.idea/modules.xml
generated
@ -2,8 +2,8 @@
|
|||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectModuleManager">
|
<component name="ProjectModuleManager">
|
||||||
<modules>
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/Hangman-game.iml" filepath="$PROJECT_DIR$/Hangman-game.iml" />
|
||||||
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
|
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
|
||||||
<module fileurl="file://$PROJECT_DIR$/hangman-game.iml" filepath="$PROJECT_DIR$/hangman-game.iml" />
|
|
||||||
</modules>
|
</modules>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
@ -8,6 +8,7 @@ import android.os.Bundle;
|
|||||||
import android.support.v7.app.ActionBar;
|
import android.support.v7.app.ActionBar;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.animation.DecelerateInterpolator;
|
import android.view.animation.DecelerateInterpolator;
|
||||||
@ -27,6 +28,7 @@ public class GameActivity extends AppCompatActivity {
|
|||||||
private TextView word;
|
private TextView word;
|
||||||
static private GameUtil gameUtil;
|
static private GameUtil gameUtil;
|
||||||
private ArrayList<String> letters = new ArrayList<>();
|
private ArrayList<String> letters = new ArrayList<>();
|
||||||
|
private ArrayList<String> good = new ArrayList<>();
|
||||||
private Context context = this;
|
private Context context = this;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -54,7 +56,7 @@ public class GameActivity extends AppCompatActivity {
|
|||||||
log("Logs");
|
log("Logs");
|
||||||
|
|
||||||
gameUtil = new GameUtil();
|
gameUtil = new GameUtil();
|
||||||
word.setText(gameUtil.getUndescores().toString().replace(",", ""));
|
word.setText(TextUtils.join("", gameUtil.getUndescores()));
|
||||||
|
|
||||||
ActionBar actionBar = getSupportActionBar();
|
ActionBar actionBar = getSupportActionBar();
|
||||||
if (actionBar != null) {
|
if (actionBar != null) {
|
||||||
@ -121,16 +123,21 @@ public class GameActivity extends AppCompatActivity {
|
|||||||
break;
|
break;
|
||||||
} else { // si joueur non vainqueur
|
} else { // si joueur non vainqueur
|
||||||
letters.add(word);
|
letters.add(word);
|
||||||
((TextView) findViewById(R.id.letters)).setText(letters.toString().toLowerCase());
|
good.add(word);
|
||||||
|
((TextView) findViewById(R.id.letters)).setText(TextUtils.join(", ", letters).toLowerCase());
|
||||||
if(res) {
|
if(res) {
|
||||||
Toast.makeText(MainActivity.getInstance(), "Correct Letter!", Toast.LENGTH_LONG).show();
|
Toast.makeText(MainActivity.getInstance(), "Correct Letter!", Toast.LENGTH_LONG).show();
|
||||||
|
|
||||||
((TextView) findViewById(R.id.word)).setText(gameUtil.getUndescores().toString().replace(",", ""));
|
((TextView) findViewById(R.id.word)).setText(TextUtils.join("", gameUtil.getUndescores()));
|
||||||
new Command().execute("AFFICHER|"+gameUtil.getUndescores().toString().replace(",", ""));
|
|
||||||
|
new Command().execute("LEADING|A");
|
||||||
|
new Command().execute("LAGGING|A");
|
||||||
|
new Command().execute("COULEUR|J");
|
||||||
|
new Command().execute("AFFICHER|"+TextUtils.join("", gameUtil.getUndescores()));
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(MainActivity.getInstance(), "Incorrect letter!", Toast.LENGTH_LONG).show();
|
Toast.makeText(MainActivity.getInstance(), "Incorrect letter!", Toast.LENGTH_LONG).show();
|
||||||
//update image
|
//update image
|
||||||
if(letters.size() == 10) {
|
if(letters.size()-good.size() == 10) {
|
||||||
lost();
|
lost();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,7 +153,7 @@ public class GameActivity extends AppCompatActivity {
|
|||||||
} else {
|
} else {
|
||||||
Toast.makeText(MainActivity.getInstance(), "Incorrect word!", Toast.LENGTH_LONG).show();
|
Toast.makeText(MainActivity.getInstance(), "Incorrect word!", Toast.LENGTH_LONG).show();
|
||||||
//update image
|
//update image
|
||||||
if(letters.size() == 10) {
|
if(letters.size()-good.size() == 10) {
|
||||||
lost();
|
lost();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -258,6 +265,7 @@ public class GameActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void win() {
|
private void win() {
|
||||||
|
new Command().execute("COULEUR|F");
|
||||||
new Command().execute("AFFICHER|Tu as gagné !!!");
|
new Command().execute("AFFICHER|Tu as gagné !!!");
|
||||||
DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {
|
DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -289,6 +297,7 @@ public class GameActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void lost() {
|
private void lost() {
|
||||||
|
new Command().execute("COULEUR|B");
|
||||||
new Command().execute("AFFICHER|Tu as perdu !!!");
|
new Command().execute("AFFICHER|Tu as perdu !!!");
|
||||||
DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {
|
DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -313,7 +322,7 @@ public class GameActivity extends AppCompatActivity {
|
|||||||
};
|
};
|
||||||
|
|
||||||
new AlertDialog.Builder(context)
|
new AlertDialog.Builder(context)
|
||||||
.setMessage("Tu as perdu :( !")
|
.setMessage("Tu as perdu, le mot était : " + gameUtil.solution())
|
||||||
.setPositiveButton("Recommencer", clickListener)
|
.setPositiveButton("Recommencer", clickListener)
|
||||||
.setNegativeButton("Quitter", clickListener)
|
.setNegativeButton("Quitter", clickListener)
|
||||||
.show();
|
.show();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.DeltaWings.Android.Hangman.Util;
|
package net.DeltaWings.Android.Hangman.Util;
|
||||||
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import net.DeltaWings.Android.Hangman.MainActivity;
|
import net.DeltaWings.Android.Hangman.MainActivity;
|
||||||
|
|
||||||
@ -8,9 +9,20 @@ import java.io.DataOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class Command extends AsyncTask<String, Integer, Long> {
|
public class Command extends AsyncTask<String, Integer, Long> {
|
||||||
|
|
||||||
|
private String[][] replacements = {
|
||||||
|
{"é", "<U69>"},
|
||||||
|
{"è", "<U68>"},
|
||||||
|
{"ê", "<U6A>"},
|
||||||
|
{"î", "<U6E>"},
|
||||||
|
{"ï", "<U6F>"},
|
||||||
|
{"à", "<U60>"},
|
||||||
|
{"ç", "<U67>"}
|
||||||
|
};
|
||||||
|
|
||||||
protected Long doInBackground(String... s) {
|
protected Long doInBackground(String... s) {
|
||||||
|
|
||||||
Command c = new Command();
|
Command c = new Command();
|
||||||
@ -42,13 +54,20 @@ public class Command extends AsyncTask<String, Integer, Long> {
|
|||||||
//----------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------
|
||||||
public void envoyer_commande(String c) throws IOException {
|
public void envoyer_commande(String c) throws IOException {
|
||||||
System.out.println("\nDEBUG:\tenvoyer_commande");
|
System.out.println("\nDEBUG:\tenvoyer_commande");
|
||||||
|
//Log.v("Command.java", MainActivity.getPref("setting_ip", MainActivity.instance.getApplicationContext()));
|
||||||
Socket socket = new Socket(MainActivity.getPref("setting_ip", MainActivity.instance.getApplicationContext()), Integer.parseInt(MainActivity.getPref("setting_port", MainActivity.instance.getApplicationContext())));
|
//Log.v("Command.java", ""+Integer.parseInt(MainActivity.getPref("setting_port", MainActivity.instance.getApplicationContext())));
|
||||||
|
Socket socket = new Socket("192.168.1.2", 53000);
|
||||||
|
|
||||||
DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
|
DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
|
||||||
|
|
||||||
|
for(String[] replacement: replacements) {
|
||||||
|
Log.v("Command.java", Arrays.toString(replacement));
|
||||||
|
c = c.replace(replacement[0], replacement[1]);
|
||||||
|
}
|
||||||
|
|
||||||
System.out.println("\nDEBUG:\tConnexion ok");
|
System.out.println("\nDEBUG:\tConnexion ok");
|
||||||
System.out.println("\nDEBUG:\tdebut envoi");
|
System.out.println("\nDEBUG:\tdebut envoi");
|
||||||
|
Log.v("Command.java", "Sended String "+c);
|
||||||
dataOutputStream.writeBytes(c);
|
dataOutputStream.writeBytes(c);
|
||||||
System.out.println("\nDEBUG:\tfinenvoi");
|
System.out.println("\nDEBUG:\tfinenvoi");
|
||||||
|
|
||||||
|
@ -25,11 +25,6 @@ public class GameUtil {
|
|||||||
public GameUtil() {
|
public GameUtil() {
|
||||||
//Generate Word
|
//Generate Word
|
||||||
|
|
||||||
JSONObject obj = null;
|
|
||||||
|
|
||||||
|
|
||||||
String r = "";
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
ArrayList<String> list = new ArrayList<>();
|
ArrayList<String> list = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@ -39,11 +34,8 @@ public class GameUtil {
|
|||||||
|
|
||||||
while (line != null) {
|
while (line != null) {
|
||||||
list.add(line);
|
list.add(line);
|
||||||
sb.append(line);
|
|
||||||
sb.append(System.lineSeparator());
|
|
||||||
line = br.readLine();
|
line = br.readLine();
|
||||||
}
|
}
|
||||||
r = sb.toString();
|
|
||||||
br.close();
|
br.close();
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -82,7 +74,7 @@ public class GameUtil {
|
|||||||
if(this.word.contains(letter)) {
|
if(this.word.contains(letter)) {
|
||||||
Log.v(tag, "Letter Found !");
|
Log.v(tag, "Letter Found !");
|
||||||
for (int i = 0; i < this.word.length(); i++) {
|
for (int i = 0; i < this.word.length(); i++) {
|
||||||
if(Objects.equals(String.valueOf(this.word.charAt(i)), letter)) {
|
if(String.valueOf(this.word.charAt(i)).equals(letter)) {
|
||||||
res.set(i, letter);
|
res.set(i, letter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,7 +84,7 @@ public class GameUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkWord(String word) {
|
public boolean checkWord(String word) {
|
||||||
if(Objects.equals(word, this.word)) {
|
if(word.equals(this.word)) {
|
||||||
for (int i = 0; i < word.length(); i++) {
|
for (int i = 0; i < word.length(); i++) {
|
||||||
res.set(i, word.split("")[i]);
|
res.set(i, word.split("")[i]);
|
||||||
}
|
}
|
||||||
@ -114,4 +106,8 @@ public class GameUtil {
|
|||||||
public ArrayList<String> getUndescores() {
|
public ArrayList<String> getUndescores() {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String solution() {
|
||||||
|
return word;
|
||||||
|
}
|
||||||
}
|
}
|
@ -13,8 +13,8 @@
|
|||||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||||
# org.gradle.parallel=true
|
# org.gradle.parallel=true
|
||||||
#Mon Feb 05 13:35:24 CET 2018
|
#Mon Feb 05 13:35:24 CET 2018
|
||||||
#systemProp.https.proxyPort=8080
|
systemProp.https.proxyPort=8080
|
||||||
#systemProp.http.proxyHost=10.16.0.6
|
systemProp.http.proxyHost=10.16.0.6
|
||||||
org.gradle.jvmargs=-Xmx1536m
|
org.gradle.jvmargs=-Xmx1536m
|
||||||
#systemProp.https.proxyHost=10.16.0.6
|
systemProp.https.proxyHost=10.16.0.6
|
||||||
#systemProp.http.proxyPort=8080
|
systemProp.http.proxyPort=8080
|
||||||
|
Loading…
x
Reference in New Issue
Block a user