-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStandardModeActivity.java
222 lines (194 loc) · 7.79 KB
/
StandardModeActivity.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
package com.example.drinkinggame_playstoreversion;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import static com.example.drinkinggame_playstoreversion.StandardModeInsertPlayers.standardModePlayers;
public class StandardModeActivity extends AppCompatActivity
{
int i=0;
int one=0;
int playerIndex=0;
Button previousChallengeButton, nextChallengeButton, nextChallengeDenialButton;
TextView challengeView;
StandardModeDatabase database;
Cursor cursor;
String aux;
int secondPlayerIndex ;
List<String> challenges = new ArrayList<>();
private AdView mAdView;
private InterstitialAd interstitialAd;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_standard_mode);
//Banner Ad ===============================================================================
MobileAds.initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
AdView adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId("ca-app-pub-7963930731441749/3726573279");
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
//Interstitial Ad
interstitialAd = new InterstitialAd(this);
interstitialAd.setAdUnitId("ca-app-pub-7963930731441749/8518545584");
AdRequest interstitialAdRequest = new AdRequest.Builder().build();
interstitialAd.loadAd(interstitialAdRequest);
interstitialAd.setAdListener(new AdListener(){
@Override
public void onAdClosed()
{
interstitialAd.loadAd(new AdRequest.Builder().build());
database.DropDatabase();
startActivity(new Intent(StandardModeActivity.this, StandardModeLeaderboardActivty.class));
}
});
challengeView = (TextView)findViewById(R.id.challengeView);
nextChallengeButton = (Button)findViewById(R.id.nextChallengeButton);
previousChallengeButton = (Button)findViewById(R.id.previousChallengeButton);
nextChallengeDenialButton = (Button)findViewById(R.id.nextChallengeButtonDenial);
database = new StandardModeDatabase(this);
cursor = database.getAllData();
Random random = new Random();
if(cursor.getCount() == 0)
{
database.instantiateDatabase();
cursor = database.getAllData();
}
while(cursor.moveToNext())
{
if(cursor.getString(1).startsWith("give") || cursor.getString(1).startsWith("drink")|| cursor.getString(1).startsWith("if")||
cursor.getString(1).startsWith("do")|| cursor.getString(1).startsWith("pick")
|| cursor.getString(1).startsWith("tell") || cursor.getString(1).startsWith("choose")||
cursor.getString(1).startsWith("play")|| cursor.getString(1).startsWith("make")|| cursor.getString(1).startsWith("kiss")
|| cursor.getString(1).startsWith("keep")|| cursor.getString(1).startsWith("rate")|| cursor.getString(1).startsWith("share"))
{
if(cursor.getString(1).endsWith("with") || cursor.getString(1).endsWith("kiss")|| cursor.getString(1).endsWith("against"))
{
secondPlayerIndex = random.nextInt(standardModePlayers.size());
while(secondPlayerIndex == playerIndex)
{
secondPlayerIndex = random.nextInt(standardModePlayers.size());
}
challenges.add(standardModePlayers.get(playerIndex)+ ", " + cursor.getString(1) + " " + (standardModePlayers.get(secondPlayerIndex)));
}
else
{
if(cursor.getString(1).contains("asdfe"))
{
aux = cursor.getString(1).replace("asdfe",standardModePlayers.get(secondPlayerIndex));
challenges.add(standardModePlayers.get(playerIndex) + ", " + aux);
}
else
{
challenges.add(standardModePlayers.get(playerIndex) + ", " + cursor.getString(1));
}
}
playerIndex++;
if(playerIndex == standardModePlayers.size())
{
Collections.shuffle(standardModePlayers);
playerIndex = 0;
}
}
else
{
challenges.add(cursor.getString(1));
}
}
Collections.shuffle(challenges);
if(one == 0)
{
previousChallengeButton.setVisibility(View.INVISIBLE);
}
challengeView.setText(challenges.get(i));
i++;
viewNextChallenge();
viewPreviousChallenge();
}
private void viewPreviousChallenge()
{
previousChallengeButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
i=i-2;
challengeView.setText(challenges.get(i));
previousChallengeButton.setVisibility(View.GONE);
i++;
}
});
}
private void viewNextChallenge()
{
nextChallengeButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
if(i< 25)
{
challengeView.setText(challenges.get(i));
i++;
previousChallengeButton.setVisibility(View.VISIBLE);
}
else
{
displayAds();
}
}
});
nextChallengeDenialButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
if(i< 25)
{
challengeView.setText(challenges.get(i));
i++;
previousChallengeButton.setVisibility(View.VISIBLE);
}
else
{
displayAds();
}
}
});
}
public void displayAds()
{
if(interstitialAd.isLoaded())
{
interstitialAd.show();
}
else
{
database.DropDatabase();
Toast.makeText(this, "Ad not loaded yet", Toast.LENGTH_SHORT).show();
startActivity(new Intent(this, StandardModeLeaderboardActivty.class));
}
}
}