Skip to content

Commit

Permalink
Changes to fix high scores.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashgti committed May 10, 2010
1 parent 04d5a95 commit eb863c8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 39 deletions.
15 changes: 8 additions & 7 deletions src/edu/auburn/csse/comp3710/AuburnTriviaGame.java
Expand Up @@ -65,15 +65,16 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
scores[4] = settings.getInt("high5", 0);
scores[5] = new_score;

// Log.d("Game", "before" + Arrays.toString(scores));
Arrays.sort(scores);
// Log.d("Game", "before" + Arrays.toString(scores));
SharedPreferences.Editor update = settings.edit();

settings.getInt("high1", scores[5]);
settings.getInt("high2", scores[4]);
settings.getInt("high3", scores[3]);
settings.getInt("high4", scores[2]);
settings.getInt("high5", scores[1]);


update.putInt("high1", scores[5]);
update.putInt("high2", scores[4]);
update.putInt("high3", scores[3]);
update.putInt("high4", scores[2]);
update.putInt("high5", scores[1]);
update.commit();

Context context = getApplicationContext();
Expand Down
17 changes: 6 additions & 11 deletions src/edu/auburn/csse/comp3710/DataHelper.java
Expand Up @@ -11,7 +11,7 @@ public class DataHelper {
private static final String DATABASE_NAME = "AuburnTrivia.db";
private static final int DATABASE_VERSION = 8;

public enum QuestionTypes {Any, General, Sports, Eng};
public enum QuestionTypes { Any, General, Sports, Eng };

private Context context;
private SQLiteDatabase db;
Expand All @@ -25,8 +25,7 @@ public DataHelper(Context context) {
}

private void checkData() {
try
{
try {
Cursor cursor = this.db.rawQuery("select * from Questions", null);
cursor.moveToFirst();
cursor.isNull(0);
Expand All @@ -47,14 +46,12 @@ public void clearUsed() {
}
}

public String[] selectQuestion(QuestionTypes type, int difficulty)
{
public String[] selectQuestion(QuestionTypes type, int difficulty) {
Cursor question = null;

//TODO: set used bit in DB for selected question

try
{
try {
//TODO: deal with when select doesn't exist
switch (type) {
case Any:
Expand All @@ -80,8 +77,7 @@ public String[] selectQuestion(QuestionTypes type, int difficulty)
}

}
catch(Exception ex)
{
catch(Exception ex) {
Log.e("DBHelper", ex.getMessage());
}

Expand Down Expand Up @@ -114,8 +110,7 @@ private void checkUsed(int difficulty, String type) {

//TODO: have list of questions for current difficulty used in current gameplay so when all are cleared they are marked as used.

if(allUsed == 0)
{
if(allUsed == 0) {
String currentQuery;
if (type == "any") {
currentQuery = "update questions set used = 0 where difficulty = " + difficulty;
Expand Down
3 changes: 0 additions & 3 deletions src/edu/auburn/csse/comp3710/Question.java
Expand Up @@ -31,7 +31,6 @@ public String getCorrectAnswer()

public String[] getWrongAnswers()
{

return WrongAnswer;
}

Expand Down Expand Up @@ -63,8 +62,6 @@ public String executeCram()
}
else
{


while(iterator < 3)
{
if(WrongAnswer[iterator] != null)
Expand Down
27 changes: 9 additions & 18 deletions src/edu/auburn/csse/comp3710/Questions.java
Expand Up @@ -25,7 +25,7 @@ public class Questions extends Activity {
int QuestionCount = 1;
Question currentQuestion = null;

/** Called when the activity is first created. */
/* Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -68,14 +68,12 @@ public void onCreate(Bundle savedInstanceState) {

Button HintButtom = (Button)findViewById(R.id.HintButton);
HintButtom.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
TextView hintText = (TextView)findViewById(R.id.hint);
hintText.setVisibility(hintText.VISIBLE);
Button hintButton = (Button)findViewById(R.id.HintButton);
hintButton.setVisibility(hintButton.INVISIBLE);

}
});

Expand Down Expand Up @@ -118,8 +116,6 @@ public void onClick(View v) {
FiftyFiftyBtn.setVisibility(FiftyFiftyBtn.INVISIBLE);
}
});


}

public void setCurrentQuestion(int difficulty) {
Expand All @@ -128,10 +124,10 @@ public void setCurrentQuestion(int difficulty) {
//TODO: Dynamically change order so first answer is not always the correct answer
try {
TextView question = (TextView)findViewById(R.id.Question);
question.setText(currentQuestion.getQuestion());
question.setText(currentQuestion.getQuestion());

TextView hint = (TextView)findViewById(R.id.hint);
hint.setText("HINT: " + currentQuestion.getHint());
hint.setText("HINT: " + currentQuestion.getHint());
hint.setVisibility(hint.INVISIBLE);

//Always set all buttons as visible incase there has been a 50/50 call
Expand All @@ -141,9 +137,7 @@ public void setCurrentQuestion(int difficulty) {
list.add((Button)findViewById(R.id.Answer2));
list.add((Button)findViewById(R.id.Answer3));
list.add((Button)findViewById(R.id.Answer4));




Collections.shuffle(list);

Button btn = list.remove(0);
Expand Down Expand Up @@ -184,12 +178,9 @@ public void onClick(View v) {
}
});
}
catch(Exception EX)
{
Log.e("Questions", EX.getMessage());
}


catch(Exception e) {
Log.e("Questions", e.getMessage());
}
}

public void endQuestions() {
Expand All @@ -209,11 +200,11 @@ public void updateQuestions() {
public void nextQuestion()
{

if(QuestionCount < 13)
if( QuestionCount < 13)
{
difficulty = QuestionCount/3;

if(QuestionCount%3 != 0)
if (QuestionCount % 3 != 0)
{
difficulty++;
}
Expand Down

0 comments on commit eb863c8

Please sign in to comment.