Skip to content

Commit 06f8277

Browse files
committed
Added scoreboard
1 parent e8f8866 commit 06f8277

File tree

17 files changed

+390
-35
lines changed

17 files changed

+390
-35
lines changed

.idea/compiler.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 25 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ButtonGame.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</configuration>
99
</facet>
1010
</component>
11-
<component name="NewModuleRootManager" inherit-compiler-output="true">
11+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
1212
<exclude-output />
1313
<content url="file://$MODULE_DIR$">
1414
<excludeFolder url="file://$MODULE_DIR$/.gradle" />

app/app.iml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
1313
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
1414
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
15-
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
1615
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
1716
<option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
18-
<option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugAndroidTestSources" />
17+
<afterSyncTasks>
18+
<task>generateDebugAndroidTestSources</task>
19+
<task>generateDebugSources</task>
20+
</afterSyncTasks>
1921
<option name="ALLOW_USER_CONFIGURATION" value="false" />
2022
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
2123
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
@@ -24,7 +26,7 @@
2426
</configuration>
2527
</facet>
2628
</component>
27-
<component name="NewModuleRootManager" inherit-compiler-output="false">
29+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
2830
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
2931
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
3032
<exclude-output />

app/src/main/AndroidManifest.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616
<category android:name="android.intent.category.LAUNCHER" />
1717
</intent-filter>
1818
</activity>
19+
<activity
20+
android:name=".ScoreSubmit"
21+
android:label="@string/title_activity_score_submit" >
22+
</activity>
23+
<activity
24+
android:name=".ScoreView"
25+
android:label="@string/title_activity_score_view" >
26+
</activity>
1927
</application>
2028

2129
</manifest>

app/src/main/java/com/buttongame/ellak/buttongame/Game.java

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package com.buttongame.ellak.buttongame;
22

33
import android.app.Activity;
4+
import android.content.Intent;
45
import android.os.Handler;
56
import android.os.Message;
6-
import android.support.v7.app.ActionBarActivity;
77
import android.os.Bundle;
8-
import android.view.Menu;
9-
import android.view.MenuItem;
108
import android.view.View;
119
import android.widget.Button;
1210
import android.widget.TextView;
@@ -27,6 +25,8 @@ public class Game extends Activity implements View.OnClickListener {
2725
int lcounter =0;
2826
int tmp = 0;
2927
Button[] buttons = new Button[9];
28+
Button exit;
29+
Button scshow;
3030
@Override
3131
protected void onCreate(Bundle savedInstanceState) {
3232
super.onCreate(savedInstanceState);
@@ -40,6 +40,10 @@ protected void onCreate(Bundle savedInstanceState) {
4040
buttons[6]= (Button) findViewById(R.id.button7);
4141
buttons[7]= (Button) findViewById(R.id.button8);
4242
buttons[8]= (Button) findViewById(R.id.button9);
43+
exit = (Button) findViewById(R.id.exitbt);
44+
scshow = (Button) findViewById(R.id.scorebt);
45+
exit.setOnClickListener(this);
46+
scshow.setOnClickListener(this);
4347
tv = (TextView) findViewById(R.id.tv);
4448
tv.setText("hits: "+String.valueOf(counter));
4549
tv2 = (TextView) findViewById(R.id.tv2);
@@ -59,7 +63,7 @@ public void run() {
5963
if (timer == null) {
6064
timer = new Timer();
6165
}
62-
timer.schedule(task,1000,1000);
66+
timer.schedule(task,2000,1000);
6367
task = new TimerTask() {
6468
@Override
6569
public void run() {
@@ -97,26 +101,53 @@ public void run() {
97101
buttons[rand].setVisibility(View.INVISIBLE);
98102
lcounter++;
99103
tv2.setText("lost hits: " + String.valueOf(lcounter));
104+
if(lcounter==20){
105+
submitScore();
106+
}
100107
}
101108
}
102109
};
103110

104-
public void DoHandlerInvis(){
105-
Timer tim = new Timer();
106-
TimerTask tsk = new TimerTask() {
107-
@Override
108-
public void run() {
109-
myHandler.post(myRun);
110-
}
111-
};
112-
tim.schedule(tsk,500,1000);
113-
}
111+
114112

115113
@Override
116114
public void onClick(View v) {
117-
tmp = counter;
118-
counter++;
119-
tv.setText("hits: "+String.valueOf(counter));
120-
v.setVisibility(View.INVISIBLE);
115+
if(v == scshow){
116+
Intent inte = new Intent(this,ScoreView.class);
117+
startActivity(inte);
118+
}
119+
else if(v == exit){
120+
timer.cancel();
121+
timer.purge();
122+
finish();
123+
}
124+
else{
125+
tmp = counter;
126+
counter++;
127+
tv.setText("hits: " + String.valueOf(counter));
128+
v.setVisibility(View.INVISIBLE);
129+
}
130+
131+
}
132+
133+
public void submitScore(){
134+
Intent intent = new Intent(this,ScoreSubmit.class);
135+
Bundle bu = new Bundle();
136+
bu.putInt("score",counter);
137+
intent.putExtras(bu);
138+
startActivity(intent);
121139
}
140+
141+
@Override
142+
protected void onRestart(){
143+
lcounter = 0;
144+
counter = 0;
145+
tv.setText("hits: "+counter);
146+
tv2.setText("lost hits: "+lcounter);
147+
super.onRestart();
148+
}
149+
150+
122151
}
152+
153+
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.buttongame.ellak.buttongame;
2+
3+
import android.app.Activity;
4+
import android.content.ContentValues;
5+
import android.database.SQLException;
6+
import android.database.sqlite.SQLiteDatabase;
7+
import android.os.Bundle;
8+
import android.view.View;
9+
import android.widget.Button;
10+
import android.widget.EditText;
11+
import android.widget.Toast;
12+
13+
public class ScoreSubmit extends Activity {
14+
15+
Button insert;
16+
EditText nametext;
17+
SQLiteDatabase db;
18+
int hits;
19+
20+
@Override
21+
protected void onCreate(Bundle savedInstanceState) {
22+
super.onCreate(savedInstanceState);
23+
setContentView(R.layout.activity_score_submit);
24+
25+
insert = (Button) findViewById(R.id.insert);
26+
nametext = (EditText) findViewById(R.id.name);
27+
hits = getIntent().getExtras().getInt("score");
28+
try {
29+
db = openOrCreateDatabase("Score", SQLiteDatabase.CREATE_IF_NECESSARY, null);
30+
db.execSQL("create table if not exists scores(hits integer,name text)");
31+
} catch (SQLException e) {}
32+
insert.setOnClickListener(new View.OnClickListener() {
33+
@Override
34+
public void onClick(View view) {
35+
ContentValues values = new ContentValues();
36+
values.put("hits", hits);
37+
values.put("name", nametext.getText().toString());
38+
if (db.insert("scores", null, values) != -1) {
39+
Toast.makeText(ScoreSubmit.this, "Success", Toast.LENGTH_LONG).show();
40+
} else {
41+
Toast.makeText(ScoreSubmit.this, "Failed", Toast.LENGTH_LONG).show();
42+
}
43+
finish();
44+
45+
}
46+
});
47+
48+
}
49+
50+
@Override
51+
protected void onStop() {
52+
db.close();
53+
super.onStop();
54+
55+
}
56+
57+
}

0 commit comments

Comments
 (0)