Commit f7824f4e authored by Rominho15's avatar Rominho15
Browse files

Version 6 :

- Fin de jeu (Défaite / Victoire)
- Gestion des scores
- Sauvegarde des scores sur Parse.com
- Gestion des High-Scores (10 max), suppression des plus récents
- Nouvelles activités
parent 0fa1f506
Pipeline #1237 skipped
......@@ -23,4 +23,6 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.parse:parse-android:1.+'
}
......@@ -3,6 +3,7 @@
package="com.example.rleger.cassebrique">
<application
android:name=".Screen.ApplicationClass"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
......@@ -20,7 +21,18 @@
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar" />
<activity android:name=".Screen.BetweenLevelActivity"></activity>
<activity android:name=".Screen.BetweenLevelActivity" />
<activity android:name=".Screen.EndActivity"></activity>
<meta-data
android:name="com.parse.APPLICATION_ID"
android:value="QC4nJLSPp2R4CpJm6YbMWy1d6ONhjpHtzhXMPpZL" />
<meta-data
android:name="com.parse.CLIENT_KEY"
android:value="3AZNZ3bMsodgCDq2j7eRGZ4gTblecPsFAAwFrqgC" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
......@@ -13,10 +13,11 @@ import com.example.rleger.cassebrique.Model.Brick;
import com.example.rleger.cassebrique.Model.BrickGroup;
import com.example.rleger.cassebrique.Model.GameModel;
import com.example.rleger.cassebrique.Screen.BetweenLevelActivity;
import com.example.rleger.cassebrique.Screen.EndActivity;
import com.example.rleger.cassebrique.View.GameView;
/**
* Created by Utilisateur on 04/12/2015.
* Created by rleger on 04/12/2015.
*/
public class GameController {
private static GameView gameView;
......@@ -25,11 +26,12 @@ public class GameController {
private Context context;
private int niveau;
public GameController(GameView gv, Context c, int n, int m) {
public GameController(GameView gv, Context c, int n, int s) {
gameView = gv;
gameView.setGameControlleur(this);
context = c;
gameModel = new GameModel();
gameModel.getEvents().setScore(s);
niveau = n;
init();
}
......@@ -111,6 +113,7 @@ public class GameController {
else
vx*=-1;
brickGroup.destroyBrick(b);
gameModel.getEvents().addScore();
if(gameModel.getNbBricks() == 0) {
this.endGame(true);
}
......@@ -131,17 +134,29 @@ public class GameController {
public void endGame(boolean gagne) {
gameThread.toStop();
Intent i;
if(gagne) {
if(niveau == 1) {
Log.e("Niveau ","gagné !");
Intent i = new Intent(context,BetweenLevelActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
//Log.e("Niveau ","gagné !");
i = new Intent(context,BetweenLevelActivity.class);
i.putExtra("method",this.gameView.getMethode());
} else {
Log.e("Partie ", "gagnée !");
//Log.e("Partie ", "gagnée !");
i = new Intent(context,EndActivity.class);
i.putExtra("win",true);
}
i.putExtra("val_score",gameModel.getEvents().getScore());
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
} else {
Log.e("Partie ","perdue !");
//Log.e("Partie ","perdue !");
i = new Intent(context,EndActivity.class);
i.putExtra("val_score", gameModel.getEvents().getScore());
i.putExtra("win",false);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
......
package com.example.rleger.cassebrique.Model;
/**
* Created by Utilisateur on 30/12/2015.
*/
public class Evenements {
private int score = 0;
private int bonus = 0;
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public int getBonus() {
return bonus;
}
public void setBonus(int bonus) {
this.bonus = bonus;
}
public void addScore() {
this.score += 10;
}
public void addBonus() {
this.bonus++;
}
}
......@@ -13,10 +13,12 @@ public class GameModel{
private Ball ball;
private Ground ground;
private ArrayList<BrickGroup> brickGroups;
private Evenements events;
public GameModel() {
bat = new Bat(50,50);
ball = new Ball(15,15);
events = new Evenements();
brickGroups = new ArrayList<>();
}
......@@ -56,6 +58,14 @@ public class GameModel{
this.brickGroups = brickGroups;
}
public Evenements getEvents() {
return events;
}
public void setEvents(Evenements events) {
this.events = events;
}
public int getBrickGroupsSize() {
return brickGroups.size();
}
......
package com.example.rleger.cassebrique.Screen;
import android.app.Application;
import com.parse.Parse;
/**
* Created by Utilisateur on 31/12/2015.
*/
public class ApplicationClass extends Application {
@Override
public void onCreate() {
super.onCreate();
Parse.initialize(this);
}
}
......@@ -4,20 +4,34 @@ import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.example.rleger.cassebrique.R;
public class BetweenLevelActivity extends AppCompatActivity {
private int score;
private int methode;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_between_level);
// Récupération du score
Bundle extras = getIntent().getExtras();
score = extras.getInt("val_score");
methode = extras.getInt("method");
// Affichage score
TextView TVscore = (TextView) findViewById(R.id.score);
TVscore.setText(TVscore.getText() + " " + score);
}
public void createLevel(View v) {
Intent i = new Intent(this,GameActivity.class);
i.putExtra("level",2);
i.putExtra("score",score);
i.putExtra("method",methode);
startActivity(i);
}
}
package com.example.rleger.cassebrique.Screen;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
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.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.example.rleger.cassebrique.R;
import com.parse.CountCallback;
import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import java.util.List;
public class EndActivity extends AppCompatActivity {
private int score;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_end);
// Récupération du score
Bundle extras = getIntent().getExtras();
score = extras.getInt("val_score");
if(!extras.getBoolean("win")) {
TextView TVwin = (TextView) findViewById(R.id.messageWin);
TVwin.setText(R.string.Failed);
}
// Affichage score
TextView TVscore = (TextView) findViewById(R.id.scoreEnd);
TVscore.setText(TVscore.getText() + " " + score);
}
public void toParse(View v){
Button b = (Button) v;
b.setEnabled(false);
EditText ETpseudo = (EditText) findViewById(R.id.pseudo);
String pseudo = ETpseudo.getText().toString();
if(isOnline()) {
ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");
// number
int numberLines = 0;
try {
numberLines = query.count();
} catch (ParseException e) {
e.printStackTrace();
}
// si High-score est plein
if(numberLines < 10) {
// PARSE
ParseObject gameScore = new ParseObject("GameScore");
// Sauvegarde
gameScore.put("score", score);
gameScore.put("playerName", pseudo);
gameScore.saveInBackground();
Log.e("saved", "ok");
Toast.makeText(this, R.string.EnterHS, Toast.LENGTH_SHORT).show();
} else {
// On prend le score le plus bas, et le score le plus récent
query.orderByDescending("score");
query.addAscendingOrder("updatedAt");
try {
List<ParseObject> results = query.find();
ParseObject last = results.get(results.size()-1);
// Si le dernier score est dépassé, on le remplace
if(last.getInt("score") < this.score) {
last.put("score", score);
last.put("playerName", pseudo);
last.saveInBackground();
Toast.makeText(this, R.string.EnterHS, Toast.LENGTH_SHORT).show();
}
else {
// Score non battu
Toast.makeText(this, R.string.NoHS, Toast.LENGTH_SHORT).show();
}
} catch (ParseException e) {
e.printStackTrace();
}
}
} else {
Toast.makeText(this, R.string.Internet, Toast.LENGTH_SHORT).show();
}
}
public boolean isOnline() {
ConnectivityManager cm =
(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
return netInfo != null && netInfo.isConnectedOrConnecting();
}
public void toRetry(View v) {
Intent i = new Intent(this,MainActivity.class);
i.putExtra("ini",true);
startActivity(i);
}
}
......@@ -18,12 +18,18 @@ public class GameActivity extends AppCompatActivity {
Bundle extras = getIntent().getExtras();
int niveau = extras.getInt("level");
int methode = extras.getInt("method");
initGame(niveau,methode);
int score = 0;
if(niveau > 1)
score = extras.getInt("score");
initGame(niveau,methode,score);
}
public void initGame(int niveau, int methode){
public void initGame(int niveau, int methode, int score){
GameView gameView = (GameView)findViewById(R.id.gameview);
GameController gameController = new GameController(gameView,this.getApplicationContext(),niveau,methode);
GameController gameController = new GameController(gameView,this.getApplicationContext(),niveau,score);
gameController.startGame();
gameView.setMethode(methode);
}
......
......@@ -7,8 +7,10 @@ import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.RadioGroup;
import android.widget.Toast;
import com.example.rleger.cassebrique.R;
import com.parse.Parse;
public class MainActivity extends AppCompatActivity {
......
......@@ -236,4 +236,8 @@ public class GameView extends View {
}
return true;
}
public int getMethode() {
return methode;
}
}
......@@ -7,8 +7,15 @@
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="com.example.rleger.cassebrique.Screen.BetweenLevelActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Score"
android:id="@+id/score"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context="com.example.rleger.cassebrique.Screen.EndActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Congratulations"
android:id="@+id/messageWin"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/LongScore"
android:id="@+id/scoreEnd"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Name"/>
<EditText
android:id="@+id/pseudo"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/Submit"
android:id="@+id/submit"
android:onClick="toParse"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/newGame"
android:id="@+id/newGameEnd"
android:onClick="toRetry"/>
</LinearLayout>
......@@ -7,4 +7,13 @@
<string name="Cursor">Curseur</string>
<string name="DirectionalArrows">Flèches directionnelles</string>
<string name="DeviceRotation">Rotation</string>
<string name="Score">Score :</string>
<string name="Congratulations">Félicitations ! Vous avez fini le jeu :)</string>
<string name="LongScore">Score Final :</string>
<string name="Failed">Vous avez perdu :(</string>
<string name="Submit">Envoyer</string>
<string name="EnterHS">Vous entrez dans les High-Scores !</string>
<string name="NoHS">Désolé, allez recommencez !</string>
<string name="Internet">Vous n\'avez pas de connexion Internet</string>
<string name="Name">Nom</string>
</resources>
\ No newline at end of file
......@@ -6,4 +6,13 @@
<string name="Cursor">Cursor</string>
<string name="DirectionalArrows">Directional Arrows</string>
<string name="DeviceRotation">Device Rotation</string>
<string name="Score">Score :</string>
<string name="Congratulations">Congratulations ! You finished the game :)</string>
<string name="LongScore">Final Score :</string>
<string name="Failed">You failed :(</string>
<string name="Submit">Submit</string>
<string name="EnterHS">You enter in the High-Scores !</string>
<string name="NoHS">Sorry, try again !</string>
<string name="Internet">You don\'t have any Internet access</string>
<string name="Name">Name</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