Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void getWordString() {
- int row1 = 0;
- int col1 = 0;
- int length1 = 0, length2 = 0;
- String word_last = "";
- boolean isCanceled = false;
- ArrayList<String> newWords = new ArrayList<>();
- for (GridLetter gridLetter : gridLettersTemp) {
- int row = gridLetter.getRow();
- StringBuilder word;
- for (int a = 0; a < gridLetter.getRow(); a++) {
- int position = row * 15 + gridLetter.getCol() - a;
- TextView txtLetter = scrabble.getChildAt(position)
- .findViewById(R.id.gridLetter);
- if (txtLetter.getText().toString().equals("")) {
- col1 = (int) scrabble.getChildAt(position)
- .getTag(R.string.col) + 1;
- break;
- }
- }
- word = new StringBuilder();
- for (int a = 0; a < 15 - col1; a++) {
- int position = row * 15 + col1 + a;
- TextView txtLetter = scrabble.getChildAt(position)
- .findViewById(R.id.gridLetter);
- word.append(txtLetter.getText().toString());
- if (txtLetter.getText().toString().equals("")) {
- length1 = word.length();
- if (word.length() > 1 && !word.toString().equals(word_last)) {
- word_last = word.toString();
- if (!words.contains(word_last)) {
- newWords.add(word_last);
- } else {
- isCanceled = true;
- break;
- }
- }
- break;
- }
- }
- word = new StringBuilder();
- int col = gridLetter.getCol();
- for (int a = 0; a < gridLetter.getRow(); a++) {
- int position = row * 15 + col - 15 * a;
- TextView txtLetter = scrabble.getChildAt(position)
- .findViewById(R.id.gridLetter);
- if (txtLetter.getText().toString().equals("")) {
- row1 = (int) scrabble.getChildAt(position)
- .getTag(R.string.row) + 1;
- break;
- }
- }
- for (int a = 0; a < 15 - row1; a++) {
- int position = row1 * 15 + col + 15 * a;
- TextView txtLetter = scrabble.getChildAt(position)
- .findViewById(R.id.gridLetter);
- word.append(txtLetter.getText().toString());
- if (txtLetter.getText().toString().equals("")) {
- length2 = word.length();
- if (word.length() > 1 && !word.toString().equals(word_last)) {
- word_last = word.toString();
- if (!words.contains(word_last)) {
- newWords.add(word_last);
- } else {
- isCanceled = true;
- break;
- }
- }
- break;
- }
- }
- }
- if (isCanceled) {
- cancelMove();
- } else {
- if (length1 == 1 && length2 == 1) {
- cancelMove();
- } else {
- if (newWords.size() > 0) {
- boolean canceled = false;
- Set<String> words_final = new HashSet<>(newWords);
- for (String word : words_final) {
- if (!dictionary.contains(word.toLowerCase())) {
- canceled = true;
- break;
- }
- }
- if (!canceled) {
- alertDialog.show();
- boolean cross = false;
- if (!isFirstMove) {
- for (GridLetter gridLetter : gridLettersTemp) {
- for (GridLetter gridLetter1 : gridLetters) {
- if ((gridLetter.getRow() - 1 == gridLetter1.getRow()
- || gridLetter.getRow() + 1 == gridLetter1.getRow())
- && (gridLetter.getCol() - 1 == gridLetter1.getCol()
- || gridLetter.getCol() + 1 == gridLetter1.getCol())) {
- cross = true;
- break;
- }
- }
- }
- } else {
- cross = true;
- }
- if (cross) {
- setLetters();
- gridLetters.addAll(gridLettersTemp);
- if (isFirstMove) isFirstMove = false;
- int score = 0;
- for (String word : newWords) {
- mDatabase.child("sessions").child(sessionId).child("words").push().setValue(word);
- for (int i = 0; i < word.length(); i++) {
- score += scores[letters.indexOf(word.charAt(i))];
- }
- }
- for (GridLetter gridLetter : gridLettersTemp) {
- mDatabase.child("sessions").child(sessionId).child("letters").push().setValue(gridLetter);
- }
- gridLettersTemp.clear();
- mDatabase.child("sessions").child(sessionId).child("users").child(String.valueOf(userId))
- .child("score").setValue(currentUser.getScore() + score);
- clearPasses();
- } else {
- alertDialog.dismiss();
- cancelMove();
- }
- } else {
- alertDialog.dismiss();
- cancelMove();
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment