Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.quiz.ponies;
- import java.util.*;
- import java.text.*;
- import android.app.Activity;
- import android.graphics.Color;
- import android.os.Bundle;
- import android.widget.*;
- import android.view.*;
- import android.view.View.*;
- public class TheDailyEquiztriaActivity extends Activity implements OnClickListener {
- public String [][] daten = new String[6][6];
- public boolean fCheck = true;
- public Integer i;
- //Array anlegen-------------------------------------------------------------------------------------------------------------
- public Integer [] pixHappy = new Integer[10];
- public Integer [] pixSad = new Integer[10];
- public Integer rnImage;
- public Random r = new Random();
- public RadioGroup rgAnswers;
- public RadioButton rbA1;
- public RadioButton rbA2;
- public RadioButton rbA3;
- public RadioButton rbA4;
- public TextView tvQ;
- public TextView tvW;
- public ImageView ivR;
- public Button btSub;
- //START CUSTOM FUNCTIONS ---------------------------------------------------------------------------------------------------
- public void findObjects(){
- rgAnswers = (RadioGroup) this.findViewById(R.id.rgAnswers);
- rbA1 = (RadioButton) this.findViewById(R.id.rbA1);
- rbA2 = (RadioButton) this.findViewById(R.id.rbA2);
- rbA3 = (RadioButton) this.findViewById(R.id.rbA3);
- rbA4 = (RadioButton) this.findViewById(R.id.rbA4);
- tvQ = (TextView) this.findViewById(R.id.tvQuestion);
- tvW = (TextView) this.findViewById(R.id.tvWelcome);
- btSub = (Button) this.findViewById(R.id.btSubmit);
- ivR = (ImageView) this.findViewById(R.id.ivResult);
- }
- public void setRadio(boolean tf){
- rbA1.setClickable(tf);
- rbA2.setClickable(tf);
- rbA3.setClickable(tf);
- rbA4.setClickable(tf);
- }
- public void isCorrect(){
- ivR.setImageResource(pixHappy[rnImage]);
- btSub.setText("Next Question");
- setRadio(false);
- rbA1.setTextColor(Color.GREEN);
- }
- //END CUSTOM FUNCTIONS -----------------------------------------------------------------------------------------------------
- //* Called when the activity is first created. --
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- //Button und TextViews einbinden----------------------------------------------------------------------------------------
- findObjects();
- btSub.setOnClickListener(this);
- //Datum einlesen--------------------------------------------------------------------------------------------------------
- Calendar calendar = Calendar.getInstance();
- SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM dd yyyy");
- tvW.setText("Question of " + dateFormat.format(calendar.getTime()));
- //Array Daten anlegen---------------------------------------------------------------------------------------------------
- daten[0][0] = "Which Pony was sent to Ponyville by Princess Celestia?";
- daten[0][1] = "Whats the name of Applejacks little sister?";
- daten[0][2] = "What type of animal is Derpy?";
- daten[0][3] = "What is the name of Rainbow Dash´s pet?";
- daten[0][4] = "Where does Pinky Pie work?";
- //answer 1--------------------------------------------------------------------------------------------------------------
- daten[1][0] = "Twilight Sparkle";
- daten[1][1] = "Rarity";
- daten[1][2] = "Crocodile";
- daten[1][3] = "Spike";
- daten[1][4] = "Carousel Boutique";
- //answer 2--------------------------------------------------------------------------------------------------------------
- daten[2][0] = "Rainbow Dash";
- daten[2][1] = "Big Macintosh";
- daten[2][2] = "Earthpony";
- daten[2][3] = "Mister Indestructable";
- daten[2][4] = "Sugarcube Corner";
- //answer 3--------------------------------------------------------------------------------------------------------------
- daten[3][0] = "Fluttershy";
- daten[3][1] = "Apple Bloom";
- daten[3][2] = "Unicorn";
- daten[3][3] = "Tank";
- daten[3][4] = "Mr. Breezy´s fan shop";
- //answer 4--------------------------------------------------------------------------------------------------------------
- daten[4][0] = "Applejack";
- daten[4][1] = "Scootaloo";
- daten[4][2] = "Pegasus";
- daten[4][3] = "Gummy";
- daten[4][4] = "The Library";
- //correct answer--------------------------------------------------------------------------------------------------------
- daten[5][0] = "Twilight Sparkle";
- daten[5][1] = "Apple Bloom";
- daten[5][2] = "Pegasus";
- daten[5][3] = "Tank";
- daten[5][4] = "Sugarcube Corner";
- //Array Bilder Happy anlegen--------------------------------------------------------------------------------------------
- pixHappy[0] = R.drawable.happy1;
- pixHappy[1] = R.drawable.happy2;
- pixHappy[2] = R.drawable.happy3;
- pixHappy[3] = R.drawable.happy4;
- pixHappy[4] = R.drawable.happy5;
- pixHappy[5] = R.drawable.happy6;
- pixHappy[6] = R.drawable.happy7;
- pixHappy[7] = R.drawable.happy8;
- pixHappy[8] = R.drawable.happy9;
- pixHappy[9] = R.drawable.happy10;
- //Array Bilder Sad anlegen----------------------------------------------------------------------------------------------
- pixSad[0] = R.drawable.sad1;
- pixSad[1] = R.drawable.sad2;
- pixSad[2] = R.drawable.sad3;
- pixSad[3] = R.drawable.sad4;
- pixSad[4] = R.drawable.sad5;
- pixSad[5] = R.drawable.sad6;
- pixSad[6] = R.drawable.sad7;
- pixSad[7] = R.drawable.sad8;
- pixSad[8] = R.drawable.sad9;
- pixSad[9] = R.drawable.sad10;
- //Zahl für Frage und Antworten generieren-------------------------------------------------------------------------------
- int rn = r.nextInt(5);
- i = rn;
- //Frage und Antworten ausgeben------------------------------------------------------------------------------------------
- rgAnswers.clearCheck();
- tvQ.setText(daten[0][i]);
- rbA1.setText(daten[1][i]);
- rbA2.setText(daten[2][i]);
- rbA3.setText(daten[3][i]);
- rbA4.setText(daten[4][i]);
- }
- public void onClick(View v) {
- RadioGroup rgAnswers = (RadioGroup) this.findViewById(R.id.rgAnswers);
- findObjects();
- //Zahl für Bilder generieren--------------------------------------------------------------------------------------------
- Random rImage = new Random();
- rnImage = rImage.nextInt(10);
- //Richtig oder Falsch bestimmen, Button ändern--------------------------------------------------------------------------
- if(this.fCheck) {
- if((rbA1.isChecked()) && (daten[1][i] == daten[5][i])){
- isCorrect();
- }
- else if((rbA2.isChecked()) && (daten[2][i] == daten[5][i])){
- isCorrect();
- }
- else if((rbA3.isChecked()) && (daten[3][i] == daten[5][i])){
- isCorrect();
- }
- else if((rbA4.isChecked()) && (daten[4][i] == daten[5][i])){
- isCorrect();
- }
- else{
- ivR.setImageResource(pixSad[rnImage]);
- btSub.setText("Next Question");
- rbA1.setTextColor(Color.RED);
- rbA2.setTextColor(Color.RED);
- rbA3.setTextColor(Color.RED);
- rbA4.setTextColor(Color.RED);
- if(daten[1][i] == daten[5][i])
- rbA1.setTextColor(Color.GREEN)
- ;
- else if(daten[2][i] == daten[5][i])
- rbA2.setTextColor(Color.GREEN)
- ;
- else if(daten[3][i] == daten[5][i])
- rbA3.setTextColor(Color.GREEN)
- ;
- else if(daten[4][i] == daten[5][i])
- rbA4.setTextColor(Color.GREEN)
- ;
- setRadio(false);
- }
- this.fCheck = false;
- }
- else{
- rgAnswers.clearCheck();
- btSub.setText("Answer");
- setRadio(true);
- rbA1.setTextColor(Color.WHITE);
- rbA2.setTextColor(Color.WHITE);
- rbA3.setTextColor(Color.WHITE);
- rbA4.setTextColor(Color.WHITE);
- if(i<4)
- i = r.nextInt(5);
- else
- i = 0;
- ivR.setImageResource(0);
- tvQ.setText(daten[0][i]);
- rbA1.setText(daten[1][i]);
- rbA2.setText(daten[2][i]);
- rbA3.setText(daten[3][i]);
- rbA4.setText(daten[4][i]);
- this.fCheck = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement