mirror of
https://github.com/Aviortheking/Hangman.git
synced 2024-12-19 18:20:54 +00:00
Nearly done
This commit is contained in:
parent
2fb83c57b0
commit
343b8016bd
@ -20,11 +20,11 @@ android {
|
|||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.android.support:support-v4:27.0.2'
|
implementation 'com.android.support:support-v4:27.0.2'
|
||||||
compile fileTree(include: ['*.jar'], dir: 'libs')
|
api fileTree(include: ['*.jar'], dir: 'libs')
|
||||||
compile 'com.android.support:appcompat-v7:27.0.2'
|
api 'com.android.support:appcompat-v7:27.0.2'
|
||||||
compile 'com.android.support.constraint:constraint-layout:1.0.2'
|
api 'com.android.support.constraint:constraint-layout:1.0.2'
|
||||||
compile 'com.android.support:design:27.0.2'
|
api 'com.android.support:design:27.0.2'
|
||||||
compile 'com.android.support:support-vector-drawable:27.0.2'
|
api 'com.android.support:support-vector-drawable:27.0.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
@ -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.util.Log;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.animation.DecelerateInterpolator;
|
import android.view.animation.DecelerateInterpolator;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
@ -16,20 +17,16 @@ import android.widget.TextView;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import net.DeltaWings.Android.Hangman.Util.Command;
|
import net.DeltaWings.Android.Hangman.Util.Command;
|
||||||
import net.DeltaWings.Android.Hangman.Util.ConnectionUtil;
|
import net.DeltaWings.Android.Hangman.Util.GameUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class GameActivity extends AppCompatActivity {
|
public class GameActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private AlertDialog.Builder builder;
|
private AlertDialog.Builder builder;
|
||||||
private ConnectionUtil co;
|
|
||||||
private TextView word;
|
private TextView word;
|
||||||
private List<String> letters = new ArrayList<>();
|
static private GameUtil gameUtil;
|
||||||
|
private ArrayList<String> letters = new ArrayList<>();
|
||||||
private Context context = this;
|
private Context context = this;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -50,13 +47,14 @@ public class GameActivity extends AppCompatActivity {
|
|||||||
MainActivity.setTheme(this);
|
MainActivity.setTheme(this);
|
||||||
setContentView(R.layout.game_activity);
|
setContentView(R.layout.game_activity);
|
||||||
|
|
||||||
word = findViewById(R.id.letters);
|
word = findViewById(R.id.word);
|
||||||
ProgressBar progressBar = findViewById(R.id.progressBar);
|
ProgressBar progressBar = findViewById(R.id.progressBar);
|
||||||
EditText input = findViewById(R.id.input);
|
EditText input = findViewById(R.id.input);
|
||||||
|
|
||||||
log("Logs");
|
log("Logs");
|
||||||
log("Connecting...");
|
|
||||||
co = new ConnectionUtil();
|
gameUtil = new GameUtil();
|
||||||
|
word.setText(gameUtil.getUndescores().toString().replace(",", ""));
|
||||||
|
|
||||||
ActionBar actionBar = getSupportActionBar();
|
ActionBar actionBar = getSupportActionBar();
|
||||||
if (actionBar != null) {
|
if (actionBar != null) {
|
||||||
@ -76,10 +74,6 @@ public class GameActivity extends AppCompatActivity {
|
|||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
switch (which){
|
switch (which){
|
||||||
case DialogInterface.BUTTON_POSITIVE:
|
case DialogInterface.BUTTON_POSITIVE:
|
||||||
//Close Connection
|
|
||||||
log("Closing connection");
|
|
||||||
co.closeConnection();
|
|
||||||
|
|
||||||
//send to main menu
|
//send to main menu
|
||||||
finish();
|
finish();
|
||||||
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
|
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
|
||||||
@ -88,6 +82,14 @@ public class GameActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//Return Builder
|
||||||
|
builder = new AlertDialog.Builder(context);
|
||||||
|
|
||||||
|
builder.setMessage("Do you really want to quit the game ?")
|
||||||
|
.setPositiveButton("Yes", dialogClickListener)
|
||||||
|
.setNegativeButton("No", dialogClickListener);
|
||||||
|
//Return Builder
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -97,11 +99,58 @@ public class GameActivity extends AppCompatActivity {
|
|||||||
input.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
input.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||||
EditText txt = ((EditText) v);
|
EditText editText = ((EditText) v);
|
||||||
String text = txt.getText().toString().toLowerCase();
|
String word = editText.getText().toString().toLowerCase();
|
||||||
|
|
||||||
|
switch (word.length()) {
|
||||||
|
case 0:
|
||||||
|
Toast.makeText(MainActivity.getInstance(), "Please type something!", Toast.LENGTH_LONG).show();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
if(letters.contains(word)) { // Check si lettre déjà noté
|
||||||
|
Toast.makeText(MainActivity.getInstance(), "letter already used!", Toast.LENGTH_LONG).show();
|
||||||
|
editText.setText("");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Boolean res = gameUtil.checkLetter(word);
|
||||||
|
if(res && gameUtil.hasWon()) { // check si joueur vainqueur
|
||||||
|
|
||||||
|
win();
|
||||||
|
break;
|
||||||
|
} else { // si joueur non vainqueur
|
||||||
|
letters.add(word);
|
||||||
|
((TextView) findViewById(R.id.letters)).setText(letters.toString().toLowerCase());
|
||||||
|
if(res) {
|
||||||
|
Toast.makeText(MainActivity.getInstance(), "Correct Letter!", Toast.LENGTH_LONG).show();
|
||||||
|
|
||||||
|
((TextView) findViewById(R.id.word)).setText(gameUtil.getUndescores().toString().replace(",", ""));
|
||||||
|
new Command().execute("AFFICHER|"+gameUtil.getUndescores().toString().replace(",", ""));
|
||||||
|
} else {
|
||||||
|
Toast.makeText(MainActivity.getInstance(), "Incorrect letter!", Toast.LENGTH_LONG).show();
|
||||||
|
//update image
|
||||||
|
}
|
||||||
|
editText.setText("");
|
||||||
|
|
||||||
|
log("You used : " + word);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
if(gameUtil.checkWord(word)) {
|
||||||
|
win();
|
||||||
|
} else {
|
||||||
|
Toast.makeText(MainActivity.getInstance(), "Incorrect word!", Toast.LENGTH_LONG).show();
|
||||||
|
//update image
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if(text.length() == 1) { //is letter
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
if(word.length() == 1) { //is letter
|
||||||
if(letters.contains(text)) {
|
if(letters.contains(text)) {
|
||||||
log("Letter : " + text + "Already in");
|
log("Letter : " + text + "Already in");
|
||||||
} else {
|
} else {
|
||||||
@ -154,7 +203,7 @@ public class GameActivity extends AppCompatActivity {
|
|||||||
log(letters.toString());
|
log(letters.toString());
|
||||||
}
|
}
|
||||||
//Send Letter
|
//Send Letter
|
||||||
txt.setText("", TextView.BufferType.EDITABLE);
|
editText.setText("", TextView.BufferType.EDITABLE);
|
||||||
}
|
}
|
||||||
} else if(text.length() > 1) {
|
} else if(text.length() > 1) {
|
||||||
log("Word : " + text);
|
log("Word : " + text);
|
||||||
@ -163,9 +212,9 @@ public class GameActivity extends AppCompatActivity {
|
|||||||
temp.put("letter", text);
|
temp.put("letter", text);
|
||||||
co.sendData(temp);
|
co.sendData(temp);
|
||||||
|
|
||||||
txt.setText("", TextView.BufferType.EDITABLE);
|
editText.setText("", TextView.BufferType.EDITABLE);
|
||||||
|
|
||||||
}
|
}*/
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -176,13 +225,7 @@ public class GameActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Return Builder
|
|
||||||
builder = new AlertDialog.Builder(context);
|
|
||||||
|
|
||||||
builder.setMessage("Do you really want to quit your game ?")
|
|
||||||
.setPositiveButton("Yes", dialogClickListener)
|
|
||||||
.setNegativeButton("No", dialogClickListener);
|
|
||||||
//Return Builder
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -202,7 +245,39 @@ public class GameActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void log(String message) {
|
private void log(String message) {
|
||||||
|
Log.v("GameActivity", message);
|
||||||
TextView logs = findViewById(R.id.logs);
|
TextView logs = findViewById(R.id.logs);
|
||||||
logs.setText(logs.getText().toString() + "\n" + message);
|
logs.setText(logs.getText().toString() + "\n" + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void win() {
|
||||||
|
new Command().execute("AFFICHER|You won !!!");
|
||||||
|
DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
switch (which){
|
||||||
|
case DialogInterface.BUTTON_POSITIVE:
|
||||||
|
//Close Connection
|
||||||
|
Intent intent = getIntent();
|
||||||
|
overridePendingTransition(0, 0);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
|
||||||
|
finish();
|
||||||
|
|
||||||
|
overridePendingTransition(0, 0);
|
||||||
|
startActivity(intent);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
finish();
|
||||||
|
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
new AlertDialog.Builder(context)
|
||||||
|
.setMessage("You won!")
|
||||||
|
.setPositiveButton("Restart", clickListener)
|
||||||
|
.setNegativeButton("Quit", clickListener)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,22 +5,17 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.StrictMode;
|
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.animation.Animation;
|
|
||||||
import android.view.animation.AnimationUtils;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import net.DeltaWings.Android.Hangman.Util.Command;
|
import net.DeltaWings.Android.Hangman.Util.Command;
|
||||||
import net.DeltaWings.Android.Hangman.settings.SettingActivity;
|
import net.DeltaWings.Android.Hangman.settings.SettingActivity;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
public static MainActivity instance;
|
public static MainActivity instance;
|
||||||
@ -51,16 +46,12 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
instance = this;
|
instance = this;
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
|
|
||||||
StrictMode.setThreadPolicy(policy);
|
|
||||||
|
|
||||||
setTheme(this);
|
setTheme(this);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
|
||||||
|
|
||||||
//Multiplayer button
|
//Multiplayer button
|
||||||
findViewById(R.id.multiplayerButton).setOnClickListener(new View.OnClickListener() {
|
findViewById(R.id.singleplayerButton).setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
startActivity(new Intent(instance, GameActivity.class));
|
startActivity(new Intent(instance, GameActivity.class));
|
||||||
@ -68,7 +59,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
findViewById(R.id.singleplayerButton).setOnClickListener(new View.OnClickListener() {
|
findViewById(R.id.testsButton).setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
new Command().execute("AFFICHER|test");
|
new Command().execute("AFFICHER|test");
|
||||||
@ -104,7 +95,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void putPref(String key, String value, Context context) {
|
public static void setPref(String key, String value, Context context) {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
SharedPreferences.Editor editor = prefs.edit();
|
SharedPreferences.Editor editor = prefs.edit();
|
||||||
editor.putString(key, value);
|
editor.putString(key, value);
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
package net.DeltaWings.Android.Hangman.Util;
|
package net.DeltaWings.Android.Hangman.Util;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.Socket;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.Socket;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
public class Command extends AsyncTask<String, Integer, Long> {
|
public class Command extends AsyncTask<String, Integer, Long> {
|
||||||
|
|
||||||
@ -46,24 +45,18 @@ public class Command extends AsyncTask<String, Integer, Long> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------
|
||||||
public void envoyer_commande( String c ) throws IOException, ClassNotFoundException, InterruptedException {
|
public void envoyer_commande(String c) throws IOException, ClassNotFoundException, InterruptedException {
|
||||||
System.out.println("\nDEBUG:\tenvoyer_commande");
|
System.out.println("\nDEBUG:\tenvoyer_commande");
|
||||||
|
|
||||||
String message_recu;
|
|
||||||
byte[] ipAddr = new byte[]{(byte)192,(byte)168,(byte)1,(byte)103};
|
|
||||||
InetAddress host = InetAddress.getByAddress(ipAddr);
|
|
||||||
int port = Integer.parseInt("53000");
|
|
||||||
|
|
||||||
Socket socket = null;
|
Socket socket = null;
|
||||||
DataOutputStream dataOutputStream = null;
|
DataOutputStream dataOutputStream = null;
|
||||||
DataInputStream dataInputStream = null;
|
DataInputStream dataInputStream = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//establish socket connection to server
|
//establish socket connection to server
|
||||||
socket = new Socket("192.168.1.2", 53000);
|
socket = new Socket("192.168.0.2", 53000);
|
||||||
|
|
||||||
dataOutputStream = new DataOutputStream(socket.getOutputStream());
|
dataOutputStream = new DataOutputStream(socket.getOutputStream());
|
||||||
//dataInputStream = new DataInputStream(socket.getInputStream());
|
|
||||||
|
|
||||||
System.out.println("\nDEBUG:\tConnexion ok");
|
System.out.println("\nDEBUG:\tConnexion ok");
|
||||||
System.out.println("\nDEBUG:\tdebut envoi");
|
System.out.println("\nDEBUG:\tdebut envoi");
|
||||||
@ -71,8 +64,6 @@ public class Command extends AsyncTask<String, Integer, Long> {
|
|||||||
System.out.println("\nDEBUG:\tfinenvoi");
|
System.out.println("\nDEBUG:\tfinenvoi");
|
||||||
|
|
||||||
System.out.println("\nDEBUG:\tdebut reception");
|
System.out.println("\nDEBUG:\tdebut reception");
|
||||||
//message_recu = dataInputStream.readLine();
|
|
||||||
//System.out.println("\nDEBUG:\tmessage recu = " + message_recu);
|
|
||||||
System.out.println("\nDEBUG:\tfin réception");
|
System.out.println("\nDEBUG:\tfin réception");
|
||||||
}
|
}
|
||||||
catch (UnknownHostException e) {
|
catch (UnknownHostException e) {
|
||||||
|
@ -1,59 +0,0 @@
|
|||||||
package net.DeltaWings.Android.Hangman.Util;
|
|
||||||
|
|
||||||
import net.DeltaWings.Android.Hangman.MainActivity;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class ConnectionUtil {
|
|
||||||
|
|
||||||
static public ConnectionUtil connection;
|
|
||||||
|
|
||||||
private String ip = null;
|
|
||||||
private String userID = null;
|
|
||||||
private String jsp = "jsp";
|
|
||||||
public int percent = 0;
|
|
||||||
private boolean single = MainActivity.getInstance().single;
|
|
||||||
private GameUtil gameUtil = null;
|
|
||||||
|
|
||||||
public ConnectionUtil() {
|
|
||||||
//check gamemode
|
|
||||||
if(single) {
|
|
||||||
gameUtil = new GameUtil();
|
|
||||||
} else {
|
|
||||||
//init connection
|
|
||||||
//send user name, generated userID
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void closeConnection() {
|
|
||||||
if(single) {
|
|
||||||
gameUtil = null;
|
|
||||||
} else {
|
|
||||||
//send null username and null userID
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean sendData(HashMap<String, String> query) {
|
|
||||||
if(single) {
|
|
||||||
System.out.println(query);
|
|
||||||
return gameUtil.datasReader(query);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
System.out.println(query);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<String, String> getDatas() {
|
|
||||||
if(single) {
|
|
||||||
return gameUtil.datasSender();
|
|
||||||
} else {
|
|
||||||
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,37 +1,17 @@
|
|||||||
package net.DeltaWings.Android.Hangman.Util;
|
package net.DeltaWings.Android.Hangman.Util;
|
||||||
|
|
||||||
import android.os.Environment;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Xml;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import net.DeltaWings.Android.Hangman.MainActivity;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.w3c.dom.Element;
|
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
|
||||||
import org.xml.sax.InputSource;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.net.URL;
|
import java.io.IOException;
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
|
||||||
|
|
||||||
public class GameUtil {
|
public class GameUtil {
|
||||||
|
|
||||||
@ -48,16 +28,43 @@ public class GameUtil {
|
|||||||
|
|
||||||
String s = "https://raw.githubusercontent.com/dwyl/english-words/master/words_dictionary.json";
|
String s = "https://raw.githubusercontent.com/dwyl/english-words/master/words_dictionary.json";
|
||||||
|
|
||||||
|
String r = "";
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
ArrayList<String> list = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
|
BufferedReader br = new BufferedReader(new FileReader("/sdcard/list.txt"));
|
||||||
|
|
||||||
|
String line = br.readLine();
|
||||||
|
|
||||||
|
while (line != null) {
|
||||||
|
list.add(line);
|
||||||
|
sb.append(line);
|
||||||
|
sb.append(System.lineSeparator());
|
||||||
|
line = br.readLine();
|
||||||
|
}
|
||||||
|
r = sb.toString();
|
||||||
|
br.close();
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Log.v(tag, list.toString());
|
||||||
|
word = list.get(randInt(0, list.size()-1));
|
||||||
|
Log.v(tag, word);
|
||||||
|
|
||||||
|
/*try {
|
||||||
|
URI uri = new URI("/sdcard/list.txt");
|
||||||
|
|
||||||
byte[] encoded = Files.readAllBytes(Paths.get("/sdcard/list.txt"));
|
byte[] encoded = Files.readAllBytes(Paths.get("/sdcard/list.txt"));
|
||||||
|
Files.readAllLines(Paths.get(uri));
|
||||||
String[] strings = new String(encoded, Charset.defaultCharset()).split("\r");
|
String[] strings = new String(encoded, Charset.defaultCharset()).split("\r");
|
||||||
Log.v(tag, strings[randInt(0, strings.length-1)]);
|
Log.v(tag, strings[randInt(0, strings.length-1)]);
|
||||||
word = strings[randInt(0, strings.length-1)];
|
word = strings[randInt(0, strings.length-1)];
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//ntm
|
//ntm
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -70,55 +77,31 @@ public class GameUtil {
|
|||||||
Log.v(tag, res.toString());
|
Log.v(tag, res.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean datasReader(HashMap<String, String> datas) {
|
public boolean checkLetter(String letter) {
|
||||||
returning.clear();
|
if(this.word.contains(letter)) {
|
||||||
String query = datas.get("query");
|
Log.v(tag, "Letter Found !");
|
||||||
if(Objects.equals(query, "letter")) {
|
for (int i = 0; i < this.word.length(); i++) {
|
||||||
String letter = datas.get("letter");
|
if(Objects.equals(String.valueOf(this.word.charAt(i)), letter)) {
|
||||||
if(word.contains(letter)) {
|
res.set(i, letter);
|
||||||
Log.v(tag, "2");
|
|
||||||
for (int i = 0; i < word.length(); i++) {
|
|
||||||
if(Objects.equals(String.valueOf(word.charAt(i)), letter)) {
|
|
||||||
res.set(i, letter);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(!res.contains("_")) {
|
|
||||||
//winner
|
|
||||||
returning.put("status", "won");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
|
|
||||||
}
|
|
||||||
letters.add(letter);
|
|
||||||
returning.put("newWord", TextUtils.join("", res));
|
|
||||||
returning.put("lettersUsed", TextUtils.join(",", letters));
|
|
||||||
} else if (Objects.equals(query, "word")) {
|
|
||||||
if(Objects.equals(datas.get("word"), word)) {
|
|
||||||
returning.put("status", "won");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
Log.v(tag, returning.toString());
|
return false;
|
||||||
//Toast.makeText(MainActivity.getInstance(), returning.get("newWord"), Toast.LENGTH_SHORT).show();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<String, String> datasSender() {
|
public boolean checkWord(String word) {
|
||||||
return returning;
|
if(Objects.equals(word, this.word)) {
|
||||||
|
for (int i = 0; i < word.length(); i++) {
|
||||||
|
res.set(i, word.split("")[i]);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String generateRandomWords()
|
public boolean hasWon() {
|
||||||
{
|
return !res.contains("_");
|
||||||
String randomStrings;
|
|
||||||
Random random = new Random();
|
|
||||||
char[] word = new char[random.nextInt(8)+3]; // words of length 3 through 10. (1 and 2 letter words are boring.)
|
|
||||||
for(int j = 0; j < word.length; j++)
|
|
||||||
{
|
|
||||||
word[j] = (char)('a' + random.nextInt(26));
|
|
||||||
}
|
|
||||||
randomStrings = new String(word);
|
|
||||||
|
|
||||||
return randomStrings;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int randInt(int min, int max) {
|
public static int randInt(int min, int max) {
|
||||||
@ -126,18 +109,8 @@ public class GameUtil {
|
|||||||
int randomNum = rand.nextInt((max - min) + 1) + min;
|
int randomNum = rand.nextInt((max - min) + 1) + min;
|
||||||
return randomNum;
|
return randomNum;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
public ArrayList<String> getUndescores() {
|
||||||
Trames sended to app :
|
return res;
|
||||||
status = status de la game (won, Integer of tries left, lost)
|
}
|
||||||
lettersUsed = String of letters used (,)
|
}
|
||||||
newWord = _________
|
|
||||||
|
|
||||||
|
|
||||||
Trames sended from app:
|
|
||||||
word = word || letter = letter
|
|
||||||
userId = userId
|
|
||||||
username = username
|
|
||||||
ip = ip
|
|
||||||
*/
|
|
@ -49,7 +49,7 @@
|
|||||||
tools:layout_editor_absoluteX="142dp"/>
|
tools:layout_editor_absoluteX="142dp"/>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/multiplayerButton"
|
android:id="@+id/testsButton"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_below="@+id/singleplayerButton"
|
android:layout_below="@+id/singleplayerButton"
|
||||||
@ -58,7 +58,7 @@
|
|||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:background="@drawable/button"
|
android:background="@drawable/button"
|
||||||
android:textColor="?android:textColorPrimaryInverse"
|
android:textColor="?android:textColorPrimaryInverse"
|
||||||
android:text="@string/multiplayer"
|
android:text="Tests"
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat"
|
android:textAppearance="@style/TextAppearance.AppCompat"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/singleplayerButton"
|
app:layout_constraintTop_toBottomOf="@+id/singleplayerButton"
|
||||||
tools:layout_editor_absoluteX="146dp"/>
|
tools:layout_editor_absoluteX="146dp"/>
|
||||||
|
@ -51,7 +51,7 @@
|
|||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/lettersTextView"
|
android:id="@+id/letters"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="172dp"
|
android:layout_height="172dp"
|
||||||
android:layout_weight=".50"
|
android:layout_weight=".50"
|
||||||
@ -69,11 +69,11 @@
|
|||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/letters"
|
android:id="@+id/word"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:fontFamily="sans-serif-condensed"
|
android:fontFamily="sans-serif-condensed"
|
||||||
android:text="________________"
|
android:text="null"
|
||||||
android:textAlignment="center"
|
android:textAlignment="center"
|
||||||
android:textSize="36sp"
|
android:textSize="36sp"
|
||||||
android:textStyle="bold"/>
|
android:textStyle="bold"/>
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
<string name="setting_general_desc">General Configuration</string>
|
<string name="setting_general_desc">General Configuration</string>
|
||||||
|
|
||||||
<string name="setting_general_theme">Theme</string>
|
<string name="setting_general_theme">Theme</string>
|
||||||
|
<string name="setting_general_ip">Select the server IP</string>
|
||||||
|
|
||||||
<string name="setting_single_title">Singleplayer</string>
|
<string name="setting_single_title">Singleplayer</string>
|
||||||
<string name="setting_single_desc">Singleplayer Configuration</string>
|
<string name="setting_single_desc">Singleplayer Configuration</string>
|
||||||
|
@ -6,4 +6,10 @@
|
|||||||
android:entryValues="@array/theme"
|
android:entryValues="@array/theme"
|
||||||
android:key="setting_theme"
|
android:key="setting_theme"
|
||||||
android:title="@string/setting_general_theme"/>
|
android:title="@string/setting_general_theme"/>
|
||||||
|
<EditTextPreference
|
||||||
|
android:defaultValue="192.168.0.2"
|
||||||
|
android:key="setting_ip"
|
||||||
|
android:selectAllOnFocus="true"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:title="@string/setting_general_ip"/>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
@ -3,9 +3,10 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.0.1'
|
classpath 'com.android.tools.build:gradle:3.1.1'
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
@ -15,6 +16,7 @@ buildscript {
|
|||||||
allprojects {
|
allprojects {
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
|
jcenter()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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