package edu.oswego.wordscramble; import android.content.ClipData; import android.content.Context; import android.graphics.Color; import android.os.Build; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.DragEvent; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; import android.widget.HorizontalScrollView; import android.widget.TableLayout; import android.widget.TableRow; import android.widget.TextView; import org.w3c.dom.Text; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Random; import java.util.concurrent.atomic.AtomicInteger; public class MainActivity extends AppCompatActivity { TextView tv_info, tv_word; EditText et_guess; Button button_guess, button_new; Random r; String wordDisplayed; String [] dictionary = { "FACEBOOK", "INSTAGRAM", "SNAPCHAT", "APPLE", "MICROSOFT", "PLAYSTATION", "MONSTER", "ANDROID", "SAMSUNG", "VIZIO", "HEWLETT-PACKARD", "JORDAN", "NIKE", "ADIDAS", "REEBOK" }; @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv_info = (TextView) findViewById(R.id.tv_info); tv_word = (TextView) findViewById(R.id.tv_word); et_guess = (EditText) findViewById(R.id.et_guess); button_guess = (Button) findViewById(R.id.button_guess); button_new = (Button) findViewById(R.id.button_new); r = new Random(); newGame(); button_guess.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v){ if (et_guess.getText().toString().equalsIgnoreCase(wordDisplayed)){ tv_info.setText("YOU GOT IT RIGHT!"); button_guess.setEnabled(false); button_new.setEnabled(true); } else { tv_info.setText("YOU GOT IT WRONG...TRY AGAIN!"); } } }); button_new.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v){ newGame(); } }); } //SHUFFLE THE WORDS FROM DICTIONARY. private String shuffleTheWords(String word){ List letters = Arrays.asList(word.split("")); Collections.shuffle(letters); String shuffled = ""; for(String letter : letters){ shuffled += letter; } return shuffled; } private void newGame(){ //GET RANDOM WORDS FROM DICTIONARY FROM ABOVE wordDisplayed = dictionary[r.nextInt(dictionary.length)]; //SHOW THE SHUFFLED WORD tv_word.setText(shuffleTheWords(wordDisplayed)); et_guess.setText(""); //BUTTON SWITCH button_guess.setEnabled(true); button_new.setEnabled(false); } }