-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainActivity.java
More file actions
183 lines (152 loc) · 5.56 KB
/
MainActivity.java
File metadata and controls
183 lines (152 loc) · 5.56 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package com.example.android.blackjack;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
int playerOneScore = 0;
int playerTwoScore = 0;
String win = " ";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void TwoPointsP1(View v) {
playerOneScore = playerOneScore + 2;
displayPlayerOneScore(playerOneScore);
}
public void TwoPointsP2(View v) {
playerTwoScore = playerTwoScore + 2;
displayPlayerTwoScore(playerTwoScore);
}
public void ThreePointsP1(View v) {
playerOneScore = playerOneScore + 3;
displayPlayerOneScore(playerOneScore);
}
public void ThreePointsP2(View v) {
playerTwoScore = playerTwoScore + 3;
displayPlayerTwoScore(playerTwoScore);
}
public void FourPointsP1(View v) {
playerOneScore = playerOneScore + 4;
displayPlayerOneScore(playerOneScore);
}
public void FourPointsP2(View v) {
playerTwoScore = playerTwoScore + 4;
displayPlayerTwoScore(playerTwoScore);
}
public void FivePointsP1(View v) {
playerOneScore = playerOneScore + 5;
displayPlayerOneScore(playerOneScore);
}
public void FivePointsP2(View v) {
playerTwoScore = playerTwoScore + 5;
displayPlayerTwoScore(playerTwoScore);
}
public void SixPointsP1(View v) {
playerOneScore = playerOneScore + 6;
displayPlayerOneScore(playerOneScore);
}
public void SixPointsP2(View v) {
playerTwoScore = playerTwoScore + 6;
displayPlayerTwoScore(playerTwoScore);
}
public void SevenPointsP1(View v) {
playerOneScore = playerOneScore + 7;
displayPlayerOneScore(playerOneScore);
}
public void SevenPointsP2(View v) {
playerTwoScore = playerTwoScore + 7;
displayPlayerTwoScore(playerTwoScore);
}
public void EightPointsP1(View v) {
playerOneScore = playerOneScore + 8;
displayPlayerOneScore(playerOneScore);
}
public void EightPointsP2(View v) {
playerTwoScore = playerTwoScore + 8;
displayPlayerTwoScore(playerTwoScore);
}
public void NinePointsP1(View v) {
playerOneScore = playerOneScore + 9;
displayPlayerOneScore(playerOneScore);
}
public void NinePointsP2(View v) {
playerTwoScore = playerTwoScore + 9;
displayPlayerTwoScore(playerTwoScore);
}
public void TenPointsP1(View v) {
playerOneScore = playerOneScore + 10;
displayPlayerOneScore(playerOneScore);
}
public void TenPointsP2(View v) {
playerTwoScore = playerTwoScore + 10;
displayPlayerTwoScore(playerTwoScore);
}
public void OnePointP1(View v) {
playerOneScore = playerOneScore + 1;
displayPlayerOneScore(playerOneScore);
}
public void OnePointP2(View v) {
playerTwoScore = playerTwoScore + 1;
displayPlayerTwoScore(playerTwoScore);
}
public void ElevenPointsP1(View v) {
playerOneScore = playerOneScore + 11;
displayPlayerOneScore(playerOneScore);
}
public void ElevenPointsP2(View v) {
playerTwoScore = playerTwoScore + 11;
displayPlayerTwoScore(playerTwoScore);
}
public void resetButton(View v) {
playerOneScore = 0;
playerTwoScore = 0;
win = "";
displayPlayerOneScore(playerOneScore);
displayPlayerTwoScore(playerTwoScore);
}
public void displayPlayerOneScore(int number) {
TextView scoreView = (TextView) findViewById(R.id.player_one_score);
scoreView.setText(String.valueOf(number));
if (number == 21) {
win = "Player One BLACK JACK!";
TextView blackJackView = (TextView) findViewById(R.id.gameResult);
blackJackView.setText(String.valueOf(win));
} else if (number > 21) {
win = "PLAYER ONE LOSES";
TextView blackJackView = (TextView) findViewById(R.id.gameResult);
blackJackView.setText(String.valueOf(win));
} else if (number == 0) {
win = " ";
TextView blackJackView = (TextView) findViewById(R.id.gameResult);
blackJackView.setText(String.valueOf(win));
} else {
win = "HIT?";
TextView blackJackView = (TextView) findViewById(R.id.gameResult);
blackJackView.setText(String.valueOf(win));
}
}
public void displayPlayerTwoScore(int number) {
TextView scoreView = (TextView) findViewById(R.id.player_two_score);
scoreView.setText(String.valueOf(number));
if (number == 21) {
win = "Player Two BLACK JACK!";
TextView blackJackView = (TextView) findViewById(R.id.gameResult);
blackJackView.setText(String.valueOf(win));
} else if (number > 21) {
win = "PLAYER TWO LOSES";
TextView blackJackView = (TextView) findViewById(R.id.gameResult);
blackJackView.setText(String.valueOf(win));
} else if (number == 0) {
win = " ";
TextView blackJackView = (TextView) findViewById(R.id.gameResult);
blackJackView.setText(String.valueOf(win));
} else {
win = "HIT?";
TextView blackJackView = (TextView) findViewById(R.id.gameResult);
blackJackView.setText(String.valueOf(win));
}
}
}