Commit 4bd6ccf8 authored by Rominho15's avatar Rominho15
Browse files

Version 8 : Affichage des Hi-Scores en fin de partie

parent 546b8478
......@@ -2,6 +2,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.rleger.cassebrique">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:name=".Screen.ApplicationClass"
android:allowBackup="true"
......@@ -22,7 +25,7 @@
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar" />
<activity android:name=".Screen.BetweenLevelActivity" />
<activity android:name=".Screen.EndActivity"></activity>
<activity android:name=".Screen.EndActivity" />
<meta-data
android:name="com.parse.APPLICATION_ID"
......@@ -31,8 +34,7 @@
android:name="com.parse.CLIENT_KEY"
android:value="3AZNZ3bMsodgCDq2j7eRGZ4gTblecPsFAAwFrqgC" />
<activity android:name=".Screen.ScoreActivity"></activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
......@@ -13,6 +13,7 @@ public class BetweenLevelActivity extends AppCompatActivity {
private int score;
private int methode;
private int player;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......
......@@ -53,6 +53,7 @@ public class EndActivity extends AppCompatActivity {
String pseudo = ETpseudo.getText().toString();
if(isOnline()) {
Toast.makeText(this, R.string.Wait, Toast.LENGTH_SHORT).show();
ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");
// number
......@@ -115,4 +116,14 @@ public class EndActivity extends AppCompatActivity {
this.finish();
}
public void toSeeScores (View v) {
if(isOnline()) {
Toast.makeText(this, R.string.Wait, Toast.LENGTH_SHORT).show();
Intent i = new Intent(this, ScoreActivity.class);
startActivity(i);
} else {
Toast.makeText(this, R.string.Internet, Toast.LENGTH_SHORT).show();
}
}
}
package com.example.rleger.cassebrique.Screen;
import android.content.ClipData;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.example.rleger.cassebrique.R;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ScoreActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_score);
toPrintScore();
}
public void toPrintScore() {
int score;
String player;
String[] allStringScores = new String[10];
ListView scoresList = (ListView) findViewById(R.id.scoreListView);
ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");
query.orderByDescending("score");
query.addAscendingOrder("updatedAt");
try {
List<ParseObject> results = query.find();
for (int i = 0; i < results.size() ; i++) {
ParseObject currentLine = results.get(i);
score = currentLine.getInt("score");
player = currentLine.getString("playerName");
int place = i+1;
String date = android.text.format.DateFormat.format("dd/MM/yyyy HH:mm", currentLine.getUpdatedAt()).toString();
allStringScores[i] = place + ". " + player + ", " + date + ", " + score + " points";
}
} catch (ParseException e) {
e.printStackTrace();
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, allStringScores);
scoresList.setAdapter(adapter);
}
public void toReturn(View v) {
onBackPressed();
}
}
......@@ -46,6 +46,13 @@
android:id="@+id/submit"
android:onClick="toParse"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/SeeScores"
android:id="@+id/highScores"
android:onClick="toSeeScores"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.rleger.cassebrique.Screen.ScoreActivity">
<ListView
android:id="@+id/scoreListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#CCCCCC"
android:dividerHeight="1dp">
</ListView>
</RelativeLayout>
......@@ -18,4 +18,7 @@
<string name="Name">Nom</string>
<string name="Multiplayer">Multijoueurs</string>
<string name="Tplayers">2 joueurs</string>
<string name="SeeScores">Meilleurs scores</string>
<string name="Return">Retour</string>
<string name="Wait">Traitement ...</string>
</resources>
\ No newline at end of file
......@@ -17,4 +17,7 @@
<string name="Name">Name</string>
<string name="Multiplayer">Multiplayer</string>
<string name="Tplayers">2 players</string>
<string name="SeeScores">See High-Scores</string>
<string name="Return">Return</string>
<string name="Wait">Please wait ...</string>
</resources>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment