-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainActivity.java
More file actions
73 lines (61 loc) · 2.46 KB
/
MainActivity.java
File metadata and controls
73 lines (61 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.example.jianingsun.portandstarboard;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Arrays;
import java.util.Collections;
public class MainActivity extends AppCompatActivity {
private static final String TAG1="Color";
private static final String TAG2="Correction";
private Game leftOrRight= new Game();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupNameButton(R.id.btnLeft, "Port(left) is red ");
setupNameButton(R.id.btnRight, "Starboard(right) is green.");
setupMeaningButton(R.id.btnMeansLeft, Game.Side.PORT);
setupMeaningButton(R.id.btnMeansRight,Game.Side.STARBOARD);
UpdateUI();
}
private void setupNameButton(int buttonId, final String direction){
Button button=(Button)findViewById(buttonId);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i(TAG1,direction);
Toast.makeText(getApplicationContext(),direction,Toast.LENGTH_SHORT)
.show();
}
});
}
private void setupMeaningButton(int buttonId, final Game.Side side){
Button btn=(Button)findViewById(buttonId);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(leftOrRight.checkIfCorrect(side)){
Log.i(TAG2,"User guess of "+leftOrRight.getChosenSideName()+" was Correct!");
Toast.makeText(getApplicationContext(),"Correct!",Toast.LENGTH_SHORT)
.show();
UpdateUI();
}
else{
Log.i(TAG2,"User guess of "+leftOrRight.getChosenSideName()+" was Incorrect.");
Toast.makeText(getApplicationContext(),"Incorrect. :(",Toast.LENGTH_SHORT)
.show();
UpdateUI();
}
}
});
}
private void UpdateUI(){
leftOrRight = new Game();
TextView text = (TextView) findViewById(R.id.txt);
text.setText(leftOrRight.getChosenSideName());
}
}