-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainActivity.java
172 lines (146 loc) · 5.13 KB
/
MainActivity.java
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
package com.example.android.cuarenta;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
int scoreChullas = 0;
int scoreViejos = 0;
boolean twoToChullasCaida = false;
boolean twoToViejosCaida = false;
boolean gameEnds = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/**
* Chullas section starts here
* -2 to opponent for bad dealing
*/
public void twoFromChullasBadDealing (View view){
scoreChullas = scoreChullas - 2;
displayChullas(scoreChullas);
}
/**
* +2 if you receive 3 cards of matching value
*/
public void twoToChullasRonda(View view) {
scoreChullas = scoreChullas + 2;
displayChullas(scoreChullas);
}
/**
* +2 if you snap a card that was placed on the table by your opponent
*/
public void twoToChullasLimpia(View view) {
scoreChullas = scoreChullas + 2;
displayChullas(scoreChullas);
}
/**
* +2 until you reach the number of cards you earned -start counting after 20 cards-
*/
public void pairNumberAfterTwentyCardsInStackChullas(View view) {
scoreChullas = scoreChullas + 2;
displayChullas(scoreChullas);
}
/**
* 38 points won't allow anything but to use method twoToChullasCaida
*/
public void onlyWayToFortyC(View view) {
while (scoreChullas < 38){
scoreChullas = scoreChullas + 2;
displayChullas(scoreChullas);
if ((scoreChullas == 38) && twoToChullasCaida == true){
scoreChullas = scoreChullas + 2;
displayChullas(scoreChullas);}
else {caidaToast();
return;}
}
}
/**
* Toast method
*/
public void caidaToast() {
Context context = getApplicationContext();
String text = "Only way to 40 is Caida";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
/**
* Displays the score for Team Chullas
*/
public void displayChullas(int scoreChullas) {
TextView scoreView = findViewById(R.id.chullasScore);
scoreView.setText(String.valueOf(scoreChullas));
}
/**
* Viejos section starts here
* -2 to opponent for bad dealing
*/
public void twoFromViejosBadDealing(View v) {
scoreViejos = scoreViejos - 2;
displayViejos (scoreViejos);
}
/**
* +2 if you receive 3 cards of matching value
*/
public void twoToViejosRonda (View v) {
scoreViejos = scoreViejos + 2;
displayViejos (scoreViejos);
}
/**
* +2 until you reach the number of cards you earned -start counting after 20 cards-
*/
public void twoToViejosLimpia (View v) {
scoreViejos = scoreViejos + 2;
displayViejos (scoreViejos);
}
/**
* +2 until you reach the number of cards counted -start counting after 20 cards-
*/
public void pairNumberAfterTwentyCardsInStackViejos (View v) {
scoreViejos = scoreViejos + 2;
displayViejos (scoreViejos);
}
/**
* 38 points won't allow anything but to use method twoToViejosCaida
* NOTE: pending update once Chullas method passes test
*
*/
/* public void onlyWayToFortyV(View view) {
if ((scoreViejos == 38) && twoToViejosCaida == true) {
scoreViejos = scoreViejos + 2;
displayViejos(scoreViejos);
} else {
}
}*/
/**
* Displays the score for Team Viejos
*/
public void displayViejos(int scoreViejos) {
TextView scoreView = findViewById(R.id.viejosScore);
scoreView.setText(String.valueOf(scoreViejos));
}
/**
* Should be able to reset game at any point but alwasy reset the game one 40 is reached - not tested
*/
// This is the only place you use this code. As it's attached to a button the point is to reset the scores.
// uncomment out some of the code below if that wasn't your intent.
public void reset (View v) {
scoreChullas = 0;
scoreViejos = 0;
displayChullas(scoreChullas);
displayViejos(scoreViejos);
//I would like to reset the game in this section , unless you suggest a different approach
//but I did notice I need to have the option to reset prior to reaching:
/* if (scoreViejos == 40 || scoreChullas == 40){
displayChullas(scoreChullas);
displayViejos(scoreViejos);
scoreChullas = 0;
scoreViejos = 0;*/
}
}
}