Advertisement
munsking

pony java

Feb 17th, 2012
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.78 KB | None | 0 0
  1. package com.quiz.ponies;
  2.  
  3. import java.util.*;
  4. import java.text.*;
  5.  
  6. import android.app.Activity;
  7. import android.graphics.Color;
  8. import android.os.Bundle;
  9. import android.widget.*;
  10. import android.view.*;
  11. import android.view.View.*;
  12.  
  13. public class TheDailyEquiztriaActivity extends Activity implements OnClickListener {
  14. public String [][] daten = new String[6][6];
  15. public boolean fCheck = true;
  16. public Integer i;
  17. //Array anlegen-------------------------------------------------------------------------------------------------------------
  18. public Integer [] pixHappy = new Integer[10];
  19. public Integer [] pixSad = new Integer[10];
  20. public Integer rnImage;
  21. public Random r = new Random();
  22. public RadioGroup rgAnswers;
  23. public RadioButton rbA1;
  24. public RadioButton rbA2;
  25. public RadioButton rbA3;
  26. public RadioButton rbA4;
  27. public TextView tvQ;
  28. public TextView tvW;
  29. public ImageView ivR;
  30. public Button btSub;
  31. //START CUSTOM FUNCTIONS ---------------------------------------------------------------------------------------------------
  32. public void findObjects(){
  33. rgAnswers = (RadioGroup) this.findViewById(R.id.rgAnswers);
  34. rbA1 = (RadioButton) this.findViewById(R.id.rbA1);
  35. rbA2 = (RadioButton) this.findViewById(R.id.rbA2);
  36. rbA3 = (RadioButton) this.findViewById(R.id.rbA3);
  37. rbA4 = (RadioButton) this.findViewById(R.id.rbA4);
  38. tvQ = (TextView) this.findViewById(R.id.tvQuestion);
  39. tvW = (TextView) this.findViewById(R.id.tvWelcome);
  40. btSub = (Button) this.findViewById(R.id.btSubmit);
  41. ivR = (ImageView) this.findViewById(R.id.ivResult);
  42. }
  43. public void setRadio(boolean tf){
  44. rbA1.setClickable(tf);
  45. rbA2.setClickable(tf);
  46. rbA3.setClickable(tf);
  47. rbA4.setClickable(tf);
  48. }
  49. public void isCorrect(){
  50. ivR.setImageResource(pixHappy[rnImage]);
  51. btSub.setText("Next Question");
  52. setRadio(false);
  53. rbA1.setTextColor(Color.GREEN);
  54. }
  55. //END CUSTOM FUNCTIONS -----------------------------------------------------------------------------------------------------
  56. //* Called when the activity is first created. --
  57. @Override
  58. public void onCreate(Bundle savedInstanceState) {
  59. super.onCreate(savedInstanceState);
  60. setContentView(R.layout.main);
  61. //Button und TextViews einbinden----------------------------------------------------------------------------------------
  62. findObjects();
  63. btSub.setOnClickListener(this);
  64. //Datum einlesen--------------------------------------------------------------------------------------------------------
  65. Calendar calendar = Calendar.getInstance();
  66. SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM dd yyyy");
  67. tvW.setText("Question of " + dateFormat.format(calendar.getTime()));
  68. //Array Daten anlegen---------------------------------------------------------------------------------------------------
  69. daten[0][0] = "Which Pony was sent to Ponyville by Princess Celestia?";
  70. daten[0][1] = "Whats the name of Applejacks little sister?";
  71. daten[0][2] = "What type of animal is Derpy?";
  72. daten[0][3] = "What is the name of Rainbow Dash´s pet?";
  73. daten[0][4] = "Where does Pinky Pie work?";
  74. //answer 1--------------------------------------------------------------------------------------------------------------
  75. daten[1][0] = "Twilight Sparkle";
  76. daten[1][1] = "Rarity";
  77. daten[1][2] = "Crocodile";
  78. daten[1][3] = "Spike";
  79. daten[1][4] = "Carousel Boutique";
  80. //answer 2--------------------------------------------------------------------------------------------------------------
  81. daten[2][0] = "Rainbow Dash";
  82. daten[2][1] = "Big Macintosh";
  83. daten[2][2] = "Earthpony";
  84. daten[2][3] = "Mister Indestructable";
  85. daten[2][4] = "Sugarcube Corner";
  86. //answer 3--------------------------------------------------------------------------------------------------------------
  87. daten[3][0] = "Fluttershy";
  88. daten[3][1] = "Apple Bloom";
  89. daten[3][2] = "Unicorn";
  90. daten[3][3] = "Tank";
  91. daten[3][4] = "Mr. Breezy´s fan shop";
  92. //answer 4--------------------------------------------------------------------------------------------------------------
  93. daten[4][0] = "Applejack";
  94. daten[4][1] = "Scootaloo";
  95. daten[4][2] = "Pegasus";
  96. daten[4][3] = "Gummy";
  97. daten[4][4] = "The Library";
  98. //correct answer--------------------------------------------------------------------------------------------------------
  99. daten[5][0] = "Twilight Sparkle";
  100. daten[5][1] = "Apple Bloom";
  101. daten[5][2] = "Pegasus";
  102. daten[5][3] = "Tank";
  103. daten[5][4] = "Sugarcube Corner";
  104. //Array Bilder Happy anlegen--------------------------------------------------------------------------------------------
  105. pixHappy[0] = R.drawable.happy1;
  106. pixHappy[1] = R.drawable.happy2;
  107. pixHappy[2] = R.drawable.happy3;
  108. pixHappy[3] = R.drawable.happy4;
  109. pixHappy[4] = R.drawable.happy5;
  110. pixHappy[5] = R.drawable.happy6;
  111. pixHappy[6] = R.drawable.happy7;
  112. pixHappy[7] = R.drawable.happy8;
  113. pixHappy[8] = R.drawable.happy9;
  114. pixHappy[9] = R.drawable.happy10;
  115. //Array Bilder Sad anlegen----------------------------------------------------------------------------------------------
  116. pixSad[0] = R.drawable.sad1;
  117. pixSad[1] = R.drawable.sad2;
  118. pixSad[2] = R.drawable.sad3;
  119. pixSad[3] = R.drawable.sad4;
  120. pixSad[4] = R.drawable.sad5;
  121. pixSad[5] = R.drawable.sad6;
  122. pixSad[6] = R.drawable.sad7;
  123. pixSad[7] = R.drawable.sad8;
  124. pixSad[8] = R.drawable.sad9;
  125. pixSad[9] = R.drawable.sad10;
  126. //Zahl für Frage und Antworten generieren-------------------------------------------------------------------------------
  127. int rn = r.nextInt(5);
  128. i = rn;
  129. //Frage und Antworten ausgeben------------------------------------------------------------------------------------------
  130. rgAnswers.clearCheck();
  131. tvQ.setText(daten[0][i]);
  132. rbA1.setText(daten[1][i]);
  133. rbA2.setText(daten[2][i]);
  134. rbA3.setText(daten[3][i]);
  135. rbA4.setText(daten[4][i]);
  136. }
  137. public void onClick(View v) {
  138. RadioGroup rgAnswers = (RadioGroup) this.findViewById(R.id.rgAnswers);
  139. findObjects();
  140. //Zahl für Bilder generieren--------------------------------------------------------------------------------------------
  141. Random rImage = new Random();
  142. rnImage = rImage.nextInt(10);
  143. //Richtig oder Falsch bestimmen, Button ändern--------------------------------------------------------------------------
  144. if(this.fCheck) {
  145. if((rbA1.isChecked()) && (daten[1][i] == daten[5][i])){
  146. isCorrect();
  147. }
  148. else if((rbA2.isChecked()) && (daten[2][i] == daten[5][i])){
  149. isCorrect();
  150. }
  151. else if((rbA3.isChecked()) && (daten[3][i] == daten[5][i])){
  152. isCorrect();
  153. }
  154. else if((rbA4.isChecked()) && (daten[4][i] == daten[5][i])){
  155. isCorrect();
  156. }
  157. else{
  158. ivR.setImageResource(pixSad[rnImage]);
  159. btSub.setText("Next Question");
  160. rbA1.setTextColor(Color.RED);
  161. rbA2.setTextColor(Color.RED);
  162. rbA3.setTextColor(Color.RED);
  163. rbA4.setTextColor(Color.RED);
  164. if(daten[1][i] == daten[5][i])
  165. rbA1.setTextColor(Color.GREEN)
  166. ;
  167. else if(daten[2][i] == daten[5][i])
  168. rbA2.setTextColor(Color.GREEN)
  169. ;
  170. else if(daten[3][i] == daten[5][i])
  171. rbA3.setTextColor(Color.GREEN)
  172. ;
  173. else if(daten[4][i] == daten[5][i])
  174. rbA4.setTextColor(Color.GREEN)
  175. ;
  176. setRadio(false);
  177. }
  178. this.fCheck = false;
  179. }
  180. else{
  181. rgAnswers.clearCheck();
  182. btSub.setText("Answer");
  183. setRadio(true);
  184. rbA1.setTextColor(Color.WHITE);
  185. rbA2.setTextColor(Color.WHITE);
  186. rbA3.setTextColor(Color.WHITE);
  187. rbA4.setTextColor(Color.WHITE);
  188. if(i<4)
  189. i = r.nextInt(5);
  190. else
  191. i = 0;
  192. ivR.setImageResource(0);
  193. tvQ.setText(daten[0][i]);
  194. rbA1.setText(daten[1][i]);
  195. rbA2.setText(daten[2][i]);
  196. rbA3.setText(daten[3][i]);
  197. rbA4.setText(daten[4][i]);
  198. this.fCheck = true;
  199. }
  200. }
  201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement