mirror of
https://github.com/Aviortheking/Hangman.git
synced 2024-12-19 18:20:54 +00:00
Continuing dev
This commit is contained in:
parent
2156de4939
commit
2fb83c57b0
@ -4,7 +4,7 @@ android {
|
||||
buildToolsVersion "27.0.3"
|
||||
defaultConfig {
|
||||
applicationId "net.DeltaWings.Android.Hangman"
|
||||
minSdkVersion 21
|
||||
minSdkVersion 26
|
||||
targetSdkVersion 27
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:fullBackupContent="@xml/backup_descriptor"
|
||||
@ -32,7 +33,7 @@
|
||||
<activity
|
||||
android:name=".settings.SettingActivity"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/DeltaWings.Dark">
|
||||
android:theme="@style/DeltaWings.Color">
|
||||
</activity>
|
||||
<activity android:name=".AboutActivity"
|
||||
android:screenOrientation="portrait"
|
||||
|
@ -5,6 +5,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.StrictMode;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.Menu;
|
||||
@ -50,6 +51,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
instance = this;
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
|
||||
StrictMode.setThreadPolicy(policy);
|
||||
|
||||
setTheme(this);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
|
@ -1,24 +1,38 @@
|
||||
package net.DeltaWings.Android.Hangman.Util;
|
||||
|
||||
import android.os.Environment;
|
||||
import android.text.TextUtils;
|
||||
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.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.File;
|
||||
import java.io.FileReader;
|
||||
import java.net.URL;
|
||||
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.HashMap;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.Scanner;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
public class GameUtil {
|
||||
|
||||
private String word = "example";
|
||||
@ -35,26 +49,20 @@ public class GameUtil {
|
||||
String s = "https://raw.githubusercontent.com/dwyl/english-words/master/words_dictionary.json";
|
||||
|
||||
|
||||
try{
|
||||
URL url = new URL(s);
|
||||
try {
|
||||
|
||||
// read from the URL
|
||||
Scanner scan = new Scanner(url.openStream());
|
||||
StringBuilder str = new StringBuilder();
|
||||
|
||||
while (scan.hasNext()) str.append(scan.nextLine());
|
||||
scan.close();
|
||||
|
||||
obj = new JSONObject(str.toString());
|
||||
int pageName = obj.getJSONObject("pageInfo").length();
|
||||
Log.v("NTM", pageName +"");
|
||||
Toast.makeText(MainActivity.getInstance(), pageName, Toast.LENGTH_LONG).show();
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
byte[] encoded = Files.readAllBytes(Paths.get("/sdcard/list.txt"));
|
||||
String[] strings = new String(encoded, Charset.defaultCharset()).split("\r");
|
||||
Log.v(tag, strings[randInt(0, strings.length-1)]);
|
||||
word = strings[randInt(0, strings.length-1)];
|
||||
} catch (Exception e) {
|
||||
//ntm
|
||||
}
|
||||
|
||||
|
||||
word = generateRandomWords();
|
||||
|
||||
|
||||
|
||||
for (int i = 0; i < word.length(); i++) {
|
||||
res.add("_");
|
||||
}
|
||||
@ -112,6 +120,12 @@ public class GameUtil {
|
||||
|
||||
return randomStrings;
|
||||
}
|
||||
|
||||
public static int randInt(int min, int max) {
|
||||
Random rand = new Random();
|
||||
int randomNum = rand.nextInt((max - min) + 1) + min;
|
||||
return randomNum;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user