Merge branch 'master' of https://github.com/jsmaniac/2011-m1s2-ter
Conflicts: code/serveur/README
This commit is contained in:
commit
e1b0ac4220
|
@ -14,7 +14,7 @@
|
|||
<activity android:name=".games.BaseGame" android:screenOrientation="portrait"></activity>
|
||||
<activity android:label="Information" android:name=".Information" android:screenOrientation="portrait"></activity>
|
||||
<activity android:name=".Score" android:label="Score" android:screenOrientation="portrait"></activity>
|
||||
<activity android:name=".FrontPage" android:screenOrientation="portrait"></activity>
|
||||
<activity android:name="FrontPage" android:screenOrientation="portrait"></activity>
|
||||
</application>
|
||||
|
||||
|
||||
|
|
BIN
code/PtiClic/res/drawable-hdpi/corbeille.png
Executable file
BIN
code/PtiClic/res/drawable-hdpi/corbeille.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 6.6 KiB |
BIN
code/PtiClic/res/drawable-ldpi/corbeille.png
Executable file
BIN
code/PtiClic/res/drawable-ldpi/corbeille.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
BIN
code/PtiClic/res/drawable-mdpi/corbeille.png
Executable file
BIN
code/PtiClic/res/drawable-mdpi/corbeille.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 3.6 KiB |
|
@ -8,19 +8,15 @@
|
|||
android:layout_weight="2">
|
||||
|
||||
<LinearLayout android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" android:paddingTop="10px"
|
||||
android:orientation="horizontal">
|
||||
android:layout_height="wrap_content" android:orientation="horizontal" android:paddingTop="10dip">
|
||||
|
||||
<TextView android:id="@+id/wordRemaining" android:text="0/10"
|
||||
android:textStyle="bold" android:paddingTop="10px"
|
||||
android:paddingLeft="20px" android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content" android:paddingRight="5px">
|
||||
android:textStyle="bold" android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content" android:paddingRight="5dip" android:paddingTop="10dip" android:paddingLeft="13dip">
|
||||
</TextView>
|
||||
|
||||
<TextView android:id="@+id/mainWord" android:text="mainWord"
|
||||
android:textStyle="bold" android:textSize="30dip"
|
||||
android:layout_weight="1" android:paddingTop="10px" android:layout_height="fill_parent"
|
||||
android:layout_width="fill_parent" android:gravity="center_vertical|center_horizontal">
|
||||
<TextView android:id="@+id/mainWord" android:textStyle="bold" android:textSize="30dip"
|
||||
android:layout_weight="1" android:layout_width="fill_parent" android:paddingBottom="10dip" android:layout_height="90dip" android:gravity="top|center_vertical|center_horizontal" android:text="Un truc super long">
|
||||
</TextView>
|
||||
|
||||
<ImageView android:src="@drawable/aide" android:id="@+id/aideBaseGame"
|
||||
|
@ -37,8 +33,7 @@
|
|||
</LinearLayout>
|
||||
|
||||
<LinearLayout android:layout_height="fill_parent"
|
||||
android:layout_width="fill_parent" android:layout_weight="10"
|
||||
android:orientation="horizontal" android:id="@+id/menuLayout">
|
||||
android:layout_width="fill_parent" android:orientation="horizontal" android:id="@+id/menuLayout" android:layout_weight="8">
|
||||
|
||||
<LinearLayout android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent" android:orientation="horizontal"
|
||||
|
@ -104,22 +99,6 @@
|
|||
</TextView>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent" android:orientation="horizontal"
|
||||
android:id="@+id/trashLayout" android:layout_weight="1"
|
||||
android:layout_gravity="center">
|
||||
|
||||
<ImageView android:id="@+id/trash" android:src="@android:drawable/ic_menu_delete"
|
||||
android:layout_weight="1" android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content" android:layout_gravity="center">
|
||||
</ImageView>
|
||||
<TextView android:id="@+id/trashName" android:layout_width="wrap_content"
|
||||
android:text="poubelle" android:textStyle="bold" android:textSize="15dip"
|
||||
android:layout_height="wrap_content" android:layout_weight="3"
|
||||
android:layout_gravity="center_vertical" android:visibility="gone">
|
||||
</TextView>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -3,38 +3,14 @@
|
|||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_height="fill_parent" android:orientation="vertical"
|
||||
android:layout_width="fill_parent" android:id="@+id/LinearLayout01">
|
||||
|
||||
|
||||
<TextView android:text="@+id/corrects" android:id="@+id/correct" android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" android:textSize="20px"></TextView>
|
||||
|
||||
<TextView android:text="@+id/manquants" android:id="@+id/missing" android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" android:textSize="20px"></TextView>
|
||||
|
||||
<TextView android:text="@+id/mauvais" android:id="@+id/bad" android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" android:textSize="20px"></TextView>
|
||||
|
||||
<TextView android:text="@+id/total" android:id="@+id/total" android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" android:textSize="25px"></TextView>
|
||||
|
||||
<TextView android:text="@+id/joueravec" android:id="@+id/playedWith" android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" android:textSize="20px"></TextView>
|
||||
|
||||
<Button android:text="J'ai vu !" android:id="@+id/saw" android:layout_width="100px"
|
||||
android:layout_height="40px" android:layout_gravity="center_vertical|center_horizontal|center"></Button>
|
||||
|
||||
<TextView android:text="@+id/category1" android:id="@+id/category1" android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" android:textSize="20px"></TextView>
|
||||
|
||||
<TextView android:text="@+id/category1words" android:id="@+id/category1words" android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"></TextView>
|
||||
|
||||
<TextView android:text="@+id/category2" android:id="@+id/category2" android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" android:textSize="20px"></TextView>
|
||||
|
||||
<TextView android:text="@+id/category2words" android:id="@+id/category2words" android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"></TextView>
|
||||
android:id="@+id/LinearLayout01" android:layout_gravity="center" android:layout_width="150dip">
|
||||
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/linearLayout2" android:orientation="vertical" android:layout_weight="2">
|
||||
<TextView android:layout_width="fill_parent" android:id="@+id/textView1" android:layout_height="wrap_content" android:text="Votre score est de :" android:gravity="center" android:layout_weight="1"></TextView>
|
||||
<TextView android:layout_width="fill_parent" android:id="@+id/total" android:layout_height="wrap_content" android:text="@+id/total" android:textStyle="bold" android:textSize="25px" android:layout_weight="1" android:gravity="center|top"></TextView>
|
||||
</LinearLayout>
|
||||
<LinearLayout android:layout_width="fill_parent" android:id="@+id/linearLayout1" android:layout_weight="1" android:layout_height="wrap_content">
|
||||
<Button android:id="@+id/saw" android:text="J'ai vu !" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_gravity="top"></Button>
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -1,17 +1,21 @@
|
|||
package org.pticlic;
|
||||
|
||||
import org.pticlic.exception.PtiClicException;
|
||||
import org.pticlic.model.Constant;
|
||||
import org.pticlic.model.Match;
|
||||
import org.pticlic.model.Network;
|
||||
import org.pticlic.model.Network.Mode;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* @author John CHARRON
|
||||
|
@ -20,7 +24,7 @@ import android.widget.Button;
|
|||
*/
|
||||
public class Score extends Activity implements OnClickListener{
|
||||
|
||||
private Match gamePlayed;
|
||||
private Match gamePlayed;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -28,7 +32,7 @@ public class Score extends Activity implements OnClickListener{
|
|||
setContentView(R.layout.score);
|
||||
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
String serverURL = sp.getString(Constant.SERVER_URL, "http://dumbs.fr/~bbrun/pticlic.json"); // TODO : Mettre comme valeur par defaut l'adresse reel du serveur
|
||||
String serverURL = sp.getString(Constant.SERVER_URL, "http://dumbs.fr/~bbrun/pticlic/pticlic.php"); // TODO : Mettre comme valeur par defaut l'adresse reel du serveur
|
||||
String id = sp.getString(Constant.USER_ID, "joueur");
|
||||
String passwd = sp.getString(Constant.USER_PASSWD, "");
|
||||
Mode mode = null;
|
||||
|
@ -42,7 +46,25 @@ public class Score extends Activity implements OnClickListener{
|
|||
Network network = new Network(serverURL, mode, id, passwd);
|
||||
|
||||
// FIXME : Pour l'instant ne marche pas, attend de savoir comment est formater le score que l'on recois.
|
||||
//DownloadedScore score = network.sendGame(gamePlayed);
|
||||
try {
|
||||
Double score = network.sendGame(gamePlayed);
|
||||
((TextView)findViewById(R.id.total)).setText(String.valueOf(score.floatValue()));
|
||||
sp.edit().putString(Constant.NEW_BASE_GAME, network.getNewGame()).commit();
|
||||
} catch (PtiClicException e) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(getString(R.string.app_name))
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setMessage(e.getMessage())
|
||||
.setCancelable(false)
|
||||
.setNegativeButton("Ok", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
finish();
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
|
||||
((Button)findViewById(R.id.saw)).setOnClickListener(this);
|
||||
|
||||
|
|
51
code/PtiClic/src/org/pticlic/exception/PtiClicException.java
Normal file
51
code/PtiClic/src/org/pticlic/exception/PtiClicException.java
Normal file
|
@ -0,0 +1,51 @@
|
|||
package org.pticlic.exception;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class PtiClicException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Error error;
|
||||
|
||||
public static class Error implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private int num;
|
||||
private String msg;
|
||||
|
||||
public Error() {}
|
||||
|
||||
public Error(int num, String msg) {
|
||||
this.num = num;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public int getNum() {
|
||||
return num;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
public PtiClicException(Error error) {
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
public PtiClicException(int num, String msg) {
|
||||
this.error = new Error(num, msg);
|
||||
}
|
||||
|
||||
public PtiClicException(String json) {
|
||||
Gson gson = new Gson();
|
||||
error = gson.fromJson(json, Error.class);
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return "Erreur numero: " + error.getNum() + "\n" + error.getMsg();
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,7 @@ package org.pticlic.games;
|
|||
|
||||
import org.pticlic.R;
|
||||
import org.pticlic.Score;
|
||||
import org.pticlic.exception.PtiClicException;
|
||||
import org.pticlic.model.Constant;
|
||||
import org.pticlic.model.DownloadedBaseGame;
|
||||
import org.pticlic.model.Match;
|
||||
|
@ -10,6 +11,8 @@ import org.pticlic.model.Network.Mode;
|
|||
import org.pticlic.model.Relation;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
|
@ -26,6 +29,8 @@ import android.widget.LinearLayout;
|
|||
import android.widget.LinearLayout.LayoutParams;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
* @author Bertrand BRUN et Georges DUPÉRON
|
||||
*
|
||||
|
@ -50,6 +55,7 @@ public class BaseGame extends Activity implements OnClickListener {
|
|||
private Match match;
|
||||
private Network network;
|
||||
private boolean help = false;
|
||||
private String gameJson;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
|
@ -59,9 +65,10 @@ public class BaseGame extends Activity implements OnClickListener {
|
|||
|
||||
// On recupere du PreferenceManager les differentes information dont on a besoin
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
String serverURL = sp.getString(Constant.SERVER_URL, "http://dumbs.fr/~bbrun/pticlic.json"); // TODO : Mettre comme valeur par defaut l'adresse reel du serveur
|
||||
String serverURL = sp.getString(Constant.SERVER_URL, Constant.SERVER); // TODO : Mettre comme valeur par defaut l'adresse reel du serveur
|
||||
String id = sp.getString(Constant.USER_ID, "joueur");
|
||||
String passwd = sp.getString(Constant.USER_PASSWD, "");
|
||||
gameJson = sp.getString(Constant.NEW_BASE_GAME, null);
|
||||
|
||||
// On initialise la classe permettant la communication avec le serveur.
|
||||
network = new Network(serverURL, Mode.SIMPLE_GAME, id, passwd);
|
||||
|
@ -75,19 +82,36 @@ public class BaseGame extends Activity implements OnClickListener {
|
|||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
try {
|
||||
Gson gson = new Gson();
|
||||
if (gameJson == null) game = (DownloadedBaseGame)network.getGames(1);
|
||||
else game = gson.fromJson(gameJson, DownloadedBaseGame.class);
|
||||
runMatch();
|
||||
start();
|
||||
} catch (PtiClicException e) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(getString(R.string.app_name))
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setMessage(e.getMessage())
|
||||
.setCancelable(false)
|
||||
.setNegativeButton("Ok", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
finish();
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
|
||||
game = (DownloadedBaseGame)network.getGames(1);
|
||||
runMatch();
|
||||
start();
|
||||
}
|
||||
|
||||
private void runMatch() {
|
||||
int nbrel = game.getNbRelation();
|
||||
nbWord = game.getNbWord();
|
||||
|
||||
|
||||
wordRemaining = (TextView)findViewById(R.id.wordRemaining);
|
||||
wordRemaining.setText((currentWord + 1) + "/" + nbWord);
|
||||
|
||||
|
||||
// On initialise la partie.
|
||||
match = new Match();
|
||||
match.setGame(game);
|
||||
|
@ -105,75 +129,49 @@ public class BaseGame extends Activity implements OnClickListener {
|
|||
TextView rn3 = ((TextView)findViewById(R.id.relation3Name));
|
||||
TextView rn4 = ((TextView)findViewById(R.id.relation4Name));
|
||||
|
||||
// Layout des relations
|
||||
LinearLayout rl1 = ((LinearLayout)findViewById(R.id.relation1Layout));
|
||||
LinearLayout rl2 = ((LinearLayout)findViewById(R.id.relation2Layout));
|
||||
LinearLayout rl3 = ((LinearLayout)findViewById(R.id.relation3Layout));
|
||||
LinearLayout rl4 = ((LinearLayout)findViewById(R.id.relation4Layout));
|
||||
|
||||
// Bouton d'aide
|
||||
ImageView aide = ((ImageView)findViewById(R.id.aideBaseGame));
|
||||
aide.setOnClickListener(this);
|
||||
|
||||
Relation r = Relation.getInstance();
|
||||
|
||||
ImageView trash = ((ImageView)findViewById(R.id.trash));
|
||||
trash.setOnClickListener(this);
|
||||
trash.setImageResource(android.R.drawable.ic_menu_delete);
|
||||
|
||||
// Écoute des clics sur les relations
|
||||
if (nbrel > 0) {
|
||||
// TODO : A enlever lorsque l'on aura toutes les images des relations.
|
||||
try {
|
||||
r1.setOnClickListener(this);
|
||||
rn1.setText(r.getRelationName(game.getCat1()));
|
||||
r1.setImageResource(r.getRelationImage(game.getCat1()));
|
||||
} catch (Exception e) {
|
||||
r1.setImageResource(R.drawable.icon);
|
||||
}
|
||||
} else {
|
||||
rl1.setVisibility(View.GONE);
|
||||
// TODO : A enlever lorsque l'on aura toutes les images des relations.
|
||||
try {
|
||||
r1.setOnClickListener(this);
|
||||
rn1.setText(r.getRelationName(game.getCat1()));
|
||||
r1.setImageResource(r.getRelationImage(game.getCat1()));
|
||||
} catch (Exception e) {
|
||||
r1.setImageResource(R.drawable.icon);
|
||||
}
|
||||
if (nbrel > 1) {
|
||||
// TODO : A enlever lorsque l'on aura toutes les images des relations.
|
||||
try {
|
||||
r2.setOnClickListener(this);
|
||||
rn2.setText(r.getRelationName(game.getCat2()));
|
||||
r2.setImageResource(r.getRelationImage(game.getCat2()));
|
||||
} catch (Exception e) {
|
||||
r2.setImageResource(R.drawable.icon);
|
||||
}
|
||||
} else {
|
||||
rl2.setVisibility(View.GONE);
|
||||
// TODO : A enlever lorsque l'on aura toutes les images des relations.
|
||||
try {
|
||||
r2.setOnClickListener(this);
|
||||
rn2.setText(r.getRelationName(game.getCat2()));
|
||||
r2.setImageResource(r.getRelationImage(game.getCat2()));
|
||||
} catch (Exception e) {
|
||||
r2.setImageResource(R.drawable.icon);
|
||||
}
|
||||
if (nbrel > 2) {
|
||||
// TODO : A enlever lorsque l'on aura toutes les images des relations.
|
||||
try {
|
||||
r3.setOnClickListener(this);
|
||||
rn3.setText(r.getRelationName(game.getCat3()));
|
||||
r3.setImageResource(r.getRelationImage(game.getCat3()));
|
||||
} catch (Exception e) {
|
||||
r3.setImageResource(R.drawable.icon);
|
||||
}
|
||||
} else {
|
||||
rl3.setVisibility(View.GONE);
|
||||
// TODO : A enlever lorsque l'on aura toutes les images des relations.
|
||||
try {
|
||||
r3.setOnClickListener(this);
|
||||
rn3.setText(r.getRelationName(game.getCat3()));
|
||||
r3.setImageResource(r.getRelationImage(game.getCat3()));
|
||||
} catch (Exception e) {
|
||||
r3.setImageResource(R.drawable.icon);
|
||||
}
|
||||
// TODO : A enlever lorsque l'on aura toutes les images des relations.
|
||||
try {
|
||||
r4.setOnClickListener(this);
|
||||
rn4.setText(r.getRelationName(game.getCat4()));
|
||||
r4.setImageResource(r.getRelationImage(game.getCat4()));
|
||||
} catch (Exception e) {
|
||||
r4.setImageResource(R.drawable.icon);
|
||||
}
|
||||
if (nbrel > 3) {
|
||||
// TODO : A enlever lorsque l'on aura toutes les images des relations.
|
||||
try {
|
||||
r4.setOnClickListener(this);
|
||||
rn4.setText(r.getRelationName(game.getCat4()));
|
||||
r4.setImageResource(r.getRelationImage(game.getCat4()));
|
||||
} catch (Exception e) {
|
||||
r4.setImageResource(R.drawable.icon);
|
||||
}
|
||||
} else {
|
||||
rl4.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
((TextView)findViewById(R.id.mainWord)).setText(DownloadedBaseGame.getName(game.getCentre()));
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.app.Activity#onActivityResult(int, int, android.content.Intent)
|
||||
*/
|
||||
|
@ -202,9 +200,9 @@ public class BaseGame extends Activity implements OnClickListener {
|
|||
|
||||
TranslateAnimation translate;
|
||||
if (isInHelpMode())
|
||||
translate = new TranslateAnimation(mainWord.getScrollX() / 2, mainWord.getScrollX() / 2, mainWord.getScrollY() / 2, width / 4);
|
||||
translate = new TranslateAnimation(mainWord.getScrollX() / 2, mainWord.getScrollX() / 2, mainWord.getScrollY() / 2, width / 8);
|
||||
else
|
||||
translate = new TranslateAnimation(mainWord.getScrollX() / 2, mainWord.getScrollX() / 2, mainWord.getScrollY() / 2, width / 2);
|
||||
translate = new TranslateAnimation(mainWord.getScrollX() / 2, mainWord.getScrollX() / 2, mainWord.getScrollY() / 2, width / 4);
|
||||
translate.setDuration(500);
|
||||
set.addAnimation(translate);
|
||||
|
||||
|
@ -293,13 +291,6 @@ public class BaseGame extends Activity implements OnClickListener {
|
|||
relationName = ((TextView)findViewById(R.id.relation4Name));
|
||||
relationName.setVisibility(View.VISIBLE);
|
||||
|
||||
//trash
|
||||
relationLayout = ((LinearLayout)findViewById(R.id.trashLayout));
|
||||
relationLayout.setGravity(Gravity.LEFT);
|
||||
|
||||
relationName = ((TextView)findViewById(R.id.trashName));
|
||||
relationName.setVisibility(View.VISIBLE);
|
||||
|
||||
|
||||
// On met le mot courant au bon endroit dans la fenetre
|
||||
// On recupere la largueur de l'ecran.
|
||||
|
@ -310,7 +301,7 @@ public class BaseGame extends Activity implements OnClickListener {
|
|||
TextView mainWord = (TextView)findViewById(R.id.mainWord);
|
||||
currentWordTextView = (TextView)findViewById(R.id.currentWord);
|
||||
|
||||
TranslateAnimation translate = new TranslateAnimation(mainWord.getScrollX() / 2, mainWord.getScrollX() / 2, mainWord.getScrollY() / 2, width / 4);
|
||||
TranslateAnimation translate = new TranslateAnimation(mainWord.getScrollX() / 2, mainWord.getScrollX() / 2, mainWord.getScrollY() / 2, width / 8);
|
||||
translate.setDuration(0);
|
||||
translate.setFillAfter(true);
|
||||
|
||||
|
@ -355,13 +346,6 @@ public class BaseGame extends Activity implements OnClickListener {
|
|||
relationName = ((TextView)findViewById(R.id.relation4Name));
|
||||
relationName.setVisibility(View.GONE);
|
||||
|
||||
//trash
|
||||
relationLayout = ((LinearLayout)findViewById(R.id.trashLayout));
|
||||
relationLayout.setGravity(Gravity.CENTER);
|
||||
|
||||
relationName = ((TextView)findViewById(R.id.trashName));
|
||||
relationName.setVisibility(View.GONE);
|
||||
|
||||
// On met le mot courant au bon endroit dans la fenetre
|
||||
// On recupere la largueur de l'ecran.
|
||||
Display display = getWindowManager().getDefaultDisplay();
|
||||
|
@ -371,7 +355,7 @@ public class BaseGame extends Activity implements OnClickListener {
|
|||
TextView mainWord = (TextView)findViewById(R.id.mainWord);
|
||||
currentWordTextView = (TextView)findViewById(R.id.currentWord);
|
||||
|
||||
TranslateAnimation translate = new TranslateAnimation(mainWord.getScrollX() / 2, mainWord.getScrollX() / 2, mainWord.getScrollY() / 2, width / 2);
|
||||
TranslateAnimation translate = new TranslateAnimation(mainWord.getScrollX() / 2, mainWord.getScrollX() / 2, mainWord.getScrollY() / 2, width / 4);
|
||||
translate.setDuration(0);
|
||||
translate.setFillAfter(true);
|
||||
|
||||
|
@ -393,13 +377,11 @@ public class BaseGame extends Activity implements OnClickListener {
|
|||
*/
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int currentWord = game.getWordInCloud(this.currentWord).getId();
|
||||
switch (v.getId()) {
|
||||
case (R.id.relation1) : match.add(1, currentWord); next(); break;
|
||||
case (R.id.relation2) : match.add(2, currentWord); next(); break;
|
||||
case (R.id.relation3) : match.add(3, currentWord); next(); break;
|
||||
case (R.id.relation4) : match.add(4, currentWord); next(); break;
|
||||
case (R.id.trash) : match.add(0, currentWord); next(); break;
|
||||
case (R.id.aideBaseGame) : helpMode(); break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,8 +2,11 @@ package org.pticlic.model;
|
|||
|
||||
public class Constant {
|
||||
public static final String SERVER_URL = "server";
|
||||
|
||||
public static final String SERVER_AUTH = "SERVER_AUTH";
|
||||
public static final String SERVER = "http://dumbs.fr/~bbrun/pticlic";
|
||||
|
||||
// Constant pour les parties en cache
|
||||
public static final String NEW_BASE_GAME = "NEW_BASE_GAME";
|
||||
|
||||
// Constant pour les information de l'utilisateur.
|
||||
public static final String USER_ID = "login";
|
||||
|
|
|
@ -64,30 +64,6 @@ public class DownloadedBaseGame extends DownloadedGame {
|
|||
this.center = center;
|
||||
this.cloud = cloud;
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet de recupere le nombre de relation que l'on va utiliser.
|
||||
*
|
||||
* @return le nombre de relation
|
||||
*/
|
||||
public int getNbRelation() {
|
||||
int res = 0;
|
||||
|
||||
if (cat1 != -1) {
|
||||
res++;
|
||||
}
|
||||
if (cat2 != -1) {
|
||||
res++;
|
||||
}
|
||||
if (cat3 != -1) {
|
||||
res++;
|
||||
}
|
||||
if (cat4 != -1) {
|
||||
res++;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public static String getName(Word word) {
|
||||
return word.getName();
|
||||
|
|
|
@ -18,7 +18,6 @@ public class Match implements Serializable {
|
|||
private ArrayList<Integer> relation2;
|
||||
private ArrayList<Integer> relation3;
|
||||
private ArrayList<Integer> relation4;
|
||||
private ArrayList<Integer> trash;
|
||||
private DownloadedGame game;
|
||||
|
||||
public Match() {
|
||||
|
@ -26,7 +25,6 @@ public class Match implements Serializable {
|
|||
relation2 = new ArrayList<Integer>();
|
||||
relation3 = new ArrayList<Integer>();
|
||||
relation4 = new ArrayList<Integer>();
|
||||
trash = new ArrayList<Integer>();
|
||||
}
|
||||
|
||||
public void setGame(DownloadedGame game) {
|
||||
|
@ -43,7 +41,6 @@ public class Match implements Serializable {
|
|||
case 2: relation2.add(word); break;
|
||||
case 3: relation3.add(word); break;
|
||||
case 4: relation4.add(word); break;
|
||||
default: trash.add(word); break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,12 +71,4 @@ public class Match implements Serializable {
|
|||
public ArrayList<Integer> getRelation4() {
|
||||
return relation4;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the trash
|
||||
*/
|
||||
public ArrayList<Integer> getTrash() {
|
||||
return trash;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
package org.pticlic.model;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
import org.pticlic.exception.PtiClicException;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
|
@ -11,6 +16,7 @@ import android.net.ConnectivityManager;
|
|||
import com.google.gson.Gson;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
|
||||
|
||||
/**
|
||||
* @author Bertrand BRUN
|
||||
*
|
||||
|
@ -20,7 +26,9 @@ import com.google.gson.stream.JsonReader;
|
|||
* puisse insérer la contribution de l'utilisateur, mais aussi pouvoir calculer le score de celui-ci.
|
||||
*/
|
||||
public class Network {
|
||||
|
||||
|
||||
String newGameJson = null;
|
||||
|
||||
public enum Action {
|
||||
GET_GAMES(0),
|
||||
SEND_GAME(1);
|
||||
|
@ -123,7 +131,7 @@ public class Network {
|
|||
* @param nbGames Le nombre de parties que l'on veut récupérer.
|
||||
* @return
|
||||
*/
|
||||
public DownloadedGame getGames(int nbGames) {
|
||||
public DownloadedGame getGames(int nbGames) throws PtiClicException {
|
||||
switch (mode) {
|
||||
case SIMPLE_GAME:
|
||||
return DownloadBaseGame(nbGames);
|
||||
|
@ -132,8 +140,12 @@ public class Network {
|
|||
}
|
||||
}
|
||||
|
||||
private DownloadedBaseGame DownloadBaseGame(int nbGames) {
|
||||
private DownloadedBaseGame DownloadBaseGame(int nbGames) throws PtiClicException {
|
||||
DownloadedBaseGame game = null;
|
||||
URL url = null;
|
||||
Gson gson = null;
|
||||
BufferedReader reader = null;
|
||||
String json = null;
|
||||
try {
|
||||
// TODO : ne restera le temps que les requete du serveur passe du GET au POST
|
||||
String urlS = this.serverURL+"/pticlic.php?"
|
||||
|
@ -143,7 +155,7 @@ public class Network {
|
|||
+ "&nb=" + String.valueOf(nbGames)
|
||||
+ "&mode="+mode.value();
|
||||
|
||||
URL url = new URL(urlS);
|
||||
url = new URL(urlS);
|
||||
|
||||
// URLConnection connection = url.openConnection();
|
||||
// connection.addRequestProperty("action", Action.GET_GAMES.value());
|
||||
|
@ -151,22 +163,27 @@ public class Network {
|
|||
// connection.addRequestProperty("passwd", this.passwd);
|
||||
// connection.addRequestProperty("nb", String.valueOf(nbGames));
|
||||
// connection.addRequestProperty("mode", mode.value());
|
||||
|
||||
Gson gson = new Gson();
|
||||
reader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
|
||||
json = reader.readLine();
|
||||
|
||||
gson = new Gson();
|
||||
//JsonReader reader = new JsonReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
|
||||
JsonReader reader = new JsonReader(new InputStreamReader(url.openStream(), "UTF-8"));
|
||||
InputStream in = new ByteArrayInputStream(json.getBytes("UTF-8"));
|
||||
JsonReader jsonReader = new JsonReader(new InputStreamReader(in));
|
||||
|
||||
// FIXME : Attention lorsque l'on pourra vraiment recupere plusieur partie, il faudra changer ce qui suit.
|
||||
reader.beginArray();
|
||||
while (reader.hasNext()) {
|
||||
game = makeBaseGame(reader, gson);
|
||||
jsonReader.beginArray();
|
||||
while (jsonReader.hasNext()) {
|
||||
game = makeBaseGame(jsonReader, gson);
|
||||
}
|
||||
reader.endArray();
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
return null;
|
||||
jsonReader.endArray();
|
||||
jsonReader.close();
|
||||
} catch (UnsupportedEncodingException e1) {
|
||||
throw new PtiClicException(0, "Impossible de recuperer l'erreur, nous avons pris note de cette erreur.\n Merci");
|
||||
} catch (IOException e1) {
|
||||
throw new PtiClicException(0, "Impossible de recuperer l'erreur, nous avons pris note de cette erreur.\n Merci");
|
||||
} catch (Exception e) {
|
||||
throw new PtiClicException(json);
|
||||
}
|
||||
|
||||
return game;
|
||||
|
@ -219,58 +236,111 @@ public class Network {
|
|||
reader.endObject();
|
||||
return new DownloadedBaseGame(id, gid, pgid, cat1, cat2, cat3, cat4, center, cloud);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Cette méthode permet d'envoyer les parties au serveur pour qu'il puisse les
|
||||
* rajouter à la base de données, et calculer le score.
|
||||
* @param game La partie jouee par l'utilisateur
|
||||
* @return Le score sous forme JSON.
|
||||
*/
|
||||
public TotalScore sendGame(Match game) {
|
||||
TotalScore score = null;
|
||||
try {
|
||||
URL url = new URL(this.serverURL);
|
||||
URLConnection connection = url.openConnection();
|
||||
connection.addRequestProperty("action", Action.SEND_GAME.value());
|
||||
connection.addRequestProperty("user", this.id);
|
||||
connection.addRequestProperty("passwd", this.passwd);
|
||||
connection.addRequestProperty("mode", mode.value());
|
||||
connection.addRequestProperty("pgid", String.valueOf(game.getGame().getId()));
|
||||
|
||||
if (((DownloadedBaseGame)game.getGame()).getCat1() != -1) {
|
||||
for (Integer i : game.getRelation1()) {
|
||||
connection.addRequestProperty("cat1[]", i.toString());
|
||||
}
|
||||
}
|
||||
if (((DownloadedBaseGame)game.getGame()).getCat2() != -1) {
|
||||
for (Integer i : game.getRelation2()) {
|
||||
connection.addRequestProperty("cat2[]", i.toString());
|
||||
}
|
||||
}
|
||||
if (((DownloadedBaseGame)game.getGame()).getCat3() != -1) {
|
||||
for (Integer i : game.getRelation3()) {
|
||||
connection.addRequestProperty("cat3[]", i.toString());
|
||||
}
|
||||
}
|
||||
if (((DownloadedBaseGame)game.getGame()).getCat4() != -1) {
|
||||
for (Integer i : game.getRelation4()) {
|
||||
connection.addRequestProperty("cat4[]", i.toString());
|
||||
}
|
||||
}
|
||||
for (Integer i : game.getTrash()) {
|
||||
connection.addRequestProperty("trash[]", i.toString());
|
||||
}
|
||||
|
||||
Gson gson = new Gson();
|
||||
JsonReader reader = new JsonReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
|
||||
|
||||
score = gson.fromJson(reader, TotalScore.class);
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
return score;
|
||||
public double sendGame(Match game) throws PtiClicException {
|
||||
switch (mode) {
|
||||
case SIMPLE_GAME:
|
||||
return sendBaseGame(game);
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public double sendBaseGame(Match game) throws PtiClicException {
|
||||
double score = -1;
|
||||
URL url = null;
|
||||
Gson gson = null;
|
||||
BufferedReader reader = null;
|
||||
String json = null;
|
||||
try {
|
||||
|
||||
// TODO : ne restera le temps que les requete du serveur passe du GET au POST
|
||||
String urlS = this.serverURL+"/pticlic.php?"
|
||||
+ "action=" + Action.SEND_GAME.value()
|
||||
+ "&user=" + this.id
|
||||
+ "&passwd=" + this.passwd
|
||||
+ "&pgid=" + game.getGame().getPgid()
|
||||
+ "&gid=" + game.getGame().getGid()
|
||||
+ "&mode="+mode.value();
|
||||
|
||||
// TODO : faut gere le mode
|
||||
for (Integer i : game.getRelation1()) {
|
||||
urlS += "&" + i + "=" + ((DownloadedBaseGame)game.getGame()).getCat1() ;
|
||||
}
|
||||
for (Integer i : game.getRelation2()) {
|
||||
urlS += "&" + i + "=" + ((DownloadedBaseGame)game.getGame()).getCat2();
|
||||
}
|
||||
for (Integer i : game.getRelation3()) {
|
||||
urlS += "&" + i + "=" + ((DownloadedBaseGame)game.getGame()).getCat3();
|
||||
}
|
||||
for (Integer i : game.getRelation4()) {
|
||||
urlS += "&" + i + "=" + ((DownloadedBaseGame)game.getGame()).getCat4();
|
||||
}
|
||||
|
||||
url = new URL(urlS);
|
||||
|
||||
// URL url = new URL(this.serverURL);
|
||||
// URLConnection connection = url.openConnection();
|
||||
// connection.addRequestProperty("action", Action.SEND_GAME.value());
|
||||
// connection.addRequestProperty("user", this.id);
|
||||
// connection.addRequestProperty("passwd", this.passwd);
|
||||
// connection.addRequestProperty("mode", mode.value());
|
||||
// connection.addRequestProperty("pgid", String.valueOf(game.getGame().getId()));
|
||||
|
||||
reader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
|
||||
json = reader.readLine();
|
||||
|
||||
gson = new Gson();
|
||||
//JsonReader reader = new JsonReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
|
||||
InputStream in = new ByteArrayInputStream(json.getBytes("UTF-8"));
|
||||
JsonReader jsonReader = new JsonReader(new InputStreamReader(in));
|
||||
|
||||
// Comme gson ne renvoie pas une erreur si l'objet qui recupere ne correspond pas a la classe qu'il attends.
|
||||
// On creer tout d'abord une objet error et si celui-ci est vide on creer l'objet score, sinon on lance
|
||||
// une exception.
|
||||
PtiClicException.Error error = gson.fromJson(json, PtiClicException.Error.class);
|
||||
if (error.getMsg() == null) {
|
||||
score = getScore(jsonReader, gson);
|
||||
} else {
|
||||
throw new PtiClicException(error);
|
||||
}
|
||||
|
||||
} catch (UnsupportedEncodingException e1) {
|
||||
throw new PtiClicException(0, "Impossible de recuperer l'erreur, nous avons pris note de cette erreur.\n Merci");
|
||||
} catch (IOException e1) {
|
||||
throw new PtiClicException(0, "Impossible de recuperer l'erreur, nous avons pris note de cette erreur.\n Merci");
|
||||
}
|
||||
|
||||
return score;
|
||||
}
|
||||
|
||||
private double getScore(JsonReader reader, Gson gson) throws IOException {
|
||||
double score = -1;
|
||||
|
||||
reader.beginObject();
|
||||
while (reader.hasNext()) {
|
||||
String name = reader.nextName();
|
||||
if (name.equals("score")) {
|
||||
score = reader.nextDouble();
|
||||
} else if (name.equals("newGame")) {
|
||||
DownloadedBaseGame newGame = gson.fromJson(reader, DownloadedBaseGame.class);
|
||||
newGameJson = gson.toJson(newGame);
|
||||
} else {
|
||||
reader.skipValue();
|
||||
}
|
||||
}
|
||||
reader.endObject();
|
||||
return score;
|
||||
}
|
||||
|
||||
public String getNewGame() {
|
||||
return this.newGameJson;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,13 +20,15 @@ public class Relation {
|
|||
|
||||
private Relation() {
|
||||
imageRelations = new HashMap<Integer, Integer>();
|
||||
imageRelations.put(-1, R.drawable.corbeille);
|
||||
imageRelations.put(0, R.drawable.rapport);
|
||||
imageRelations.put(5, R.drawable.synonyme);
|
||||
imageRelations.put(7, R.drawable.contraire);
|
||||
imageRelations.put(9, R.drawable.contenu);
|
||||
imageRelations.put(10, R.drawable.contenant);
|
||||
|
||||
stringRelations = new HashMap<Integer, String>();
|
||||
stringRelations.put(-1, "");
|
||||
stringRelations.put(-1, "poubelle");
|
||||
stringRelations.put(0, "idée");
|
||||
stringRelations.put(1, "raffinement sémantique");
|
||||
stringRelations.put(2, "raffinement morphologique");
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
rm php/db
|
||||
cat dump.url
|
||||
# Aller à cette adresse, et télécharger le dernier dump
|
||||
./dump2sqlite.sh 01232011-LEXICALNET-JEUXDEMOTS-FR-NOHTML.txt > sql
|
||||
pv sql | sqlite3 php/db
|
||||
sudo chown -R user.www-data php
|
||||
chmod 664 php/db
|
23
code/serveur/README.sh
Executable file
23
code/serveur/README.sh
Executable file
|
@ -0,0 +1,23 @@
|
|||
#!/bin/sh
|
||||
|
||||
# cat dump.url
|
||||
# Aller à cette adresse, et télécharger le dernier dump
|
||||
echo
|
||||
echo "Étape 1/3 : Téléchargement"
|
||||
echo "=========================="
|
||||
latest="$(wget 'http://www.lirmm.fr/~lafourcade/JDM-LEXICALNET-FR/?C=M;O=D' -O- | grep '\-LEXICALNET\-JEUXDEMOTS\-FR\-\(NOHTML\)\?\.txt' | head -n 1 | sed -E -e 's/^.*<a href="([0-9]*-LEXICALNET-JEUXDEMOTS-FR-(NOHTML)?\.txt)">.*$/\1/')"
|
||||
wget -c 'http://www.lirmm.fr/~lafourcade/JDM-LEXICALNET-FR/'"$latest"
|
||||
|
||||
echo
|
||||
echo "Étape 2/3 : Conversion vers sql"
|
||||
echo "==============================="
|
||||
./dump2sqlite.sh "$latest" > sql
|
||||
|
||||
echo
|
||||
echo "Étape 3/3 : Insertion dans la bdd"
|
||||
echo "================================="
|
||||
mv php/db php/db.old
|
||||
pv sql | sqlite3 php/db
|
||||
|
||||
sudo chgrp -R www-data php || sudo chgrp -R www php
|
||||
chmod 664 php/db
|
|
@ -1 +1 @@
|
|||
http://www.lirmm.fr/~lafourcade/JDM-LEXICALNET-FR/
|
||||
http://www.lirmm.fr/~lafourcade/JDM-LEXICALNET-FR/?C=M;O=D
|
||||
|
|
|
@ -1,13 +1,23 @@
|
|||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
# TODO : sed -E sur certaines machines, sed -r sur d'autres.
|
||||
|
||||
user="foo"
|
||||
passwd="bar"
|
||||
|
||||
if ! [ -e "$1" ]; then
|
||||
echo "Le fichier $1 n'existe pas !"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo " dump2sql.sh : conversion des dumps de JeuxDeMots vers du sql (sqlite3)." >&2
|
||||
echo " La progression est affichée avec pv. Si vous n'avez pas pv, supprimez la ligne correspondante dans ce script." >&2
|
||||
echo " Et c'est parti !" >&2
|
||||
echo >&2
|
||||
|
||||
# Played_game(type) : 0 => partie de référence, 1 => joueur
|
||||
# Note : l'index i_played_game_all sert à la vérification lors du set_partie.
|
||||
# Note : le echo | dd | md5 permet de ne pas avoir le \n, y compris sur les versions de sh sous mac boguées qui ne supportent pas «echo -n»
|
||||
|
||||
cat <<EOF
|
||||
begin transaction;
|
||||
|
@ -18,9 +28,17 @@ create table type_relation(name, num, extended_name, info);
|
|||
create table user(login primary key, mail, hash_passwd, score);
|
||||
create table game(gid integer primary key autoincrement, eid_central_word, relation_1, relation_2, difficulty);
|
||||
create table game_cloud(gid, num, difficulty, eid_word, totalWeight, probaR1, probaR2, probaR0, probaTrash);
|
||||
create table played_game(pgid integer primary key autoincrement, gid, login, played);
|
||||
create table played_game(pgid integer primary key autoincrement, gid, login, timestamp);
|
||||
create table played_game_cloud(pgid, gid, type, num, relation, weight, score);
|
||||
insert into user(login, mail, hash_passwd, score) values('foo', 'foo@isp.com', '$(echo -n 'bar' | md5sum | cut -d ' ' -f 1)', 0);
|
||||
|
||||
insert into user(login, mail, hash_passwd, score) values('$(echo "$user" | sed -e "s/'/''/g")', 'foo@isp.com', '$(echo "$passwd" | dd bs=1 count="${#passwd}" | (if which md5sum; then md5sum; else md5; fi) | cut -d ' ' -f 1)', 0);
|
||||
|
||||
create index i_relation_start on relation(start);
|
||||
create index i_relation_end on relation(end);
|
||||
create index i_relation_type on relation(type);
|
||||
create index i_relation_start_type on relation(start,type);
|
||||
create index i_relation_end_type on relation(end,type);
|
||||
create index i_played_game_all on played_game(pgid, gid, login, timestamp);
|
||||
EOF
|
||||
|
||||
# tr : pour virer le CRLF qui traîne
|
||||
|
@ -29,20 +47,13 @@ cat "$1" \
|
|||
| iconv -f iso-8859-1 -t utf-8 \
|
||||
| tr '\r' ' ' \
|
||||
| sed -e 's/X/XX/g' | sed -e 's/A/Xa/g' | tr '\n' 'A' | sed -e 's/A")/")/g' | tr 'A' '\n' | sed -e 's/Xa/A/g' | sed -e 's/XX/X/g' \
|
||||
| pv -s $(wc -c < "$1") \
|
||||
| pv -s "$(wc -c "$1" | sed -E -e 's/^ *([0-9]*) .*$/\1/')" \
|
||||
| sed -E -e "s#'#''#g" \
|
||||
-e 's#^/?// [0-9]+ occurrences of relations ([a-z_]+) \(t=([0-9]+) nom_etendu="([^"]+)" info="([^"]+)"\)$#insert into type_relation(name, num, extended_name, info) values('\''\1'\'', \2, '\''\3'\'', '\''\4'\'');#' \
|
||||
-e 's#^/?// [0-9]+ occurrences of nodes ([a-z_]+) \(t=([0-9]+)\)$#insert into type_node(name, num) values('\''\1'\'', \2);#' \
|
||||
-e 's#^eid=([0-9]+):n="(.*)":t=([0-9]+):w=(-?[0-9]+)$#insert into node(eid, name, type, weight) values(\1, '\''\2'\'', '\''\3'\'', '\''\4'\'');#' \
|
||||
-e 's#^eid=([0-9]+):n="(.*)":t=([0-9]+):w=(-?[0-9]+)$#insert into node(eid, name, type, weight) values(\1, '\''\2'\'', \3, \4);#' \
|
||||
-e 's#^rid=([0-9]+):n1=([0-9]+):n2=([0-9]+):t=([0-9]+):w=(-?[0-9]+)#insert into relation(rid, start, end, type, weight) values(\1,\2,\3,\4,\5);#' \
|
||||
| grep -v '^//' \
|
||||
| grep -v '^$'
|
||||
|
||||
cat <<EOF
|
||||
create index i_relation_start on relation(start);
|
||||
create index i_relation_end on relation(end);
|
||||
create index i_relation_type on relation(type);
|
||||
create index i_relation_start_type on relation(start,type);
|
||||
create index i_relation_end_type on relation(end,type);
|
||||
commit;
|
||||
EOF
|
||||
echo "commit;"
|
||||
|
|
|
@ -1,33 +1,57 @@
|
|||
<?php
|
||||
// Requête : http://serveur/pticlic.php?action=getparties&nb=2&mode=normal&user=foo&passwd=bar
|
||||
|
||||
$do_initdb = false;
|
||||
ob_start();
|
||||
date_default_timezone_set('Europe/Paris');
|
||||
$email_admin = ''; // Adresse e-mail Administrateur.
|
||||
|
||||
$SQL_DBNAME = (dirname(__FILE__) . "/db");
|
||||
|
||||
|
||||
/** Enregistre une erreur et quitte le programme.
|
||||
* @param err : Numéro de l'erreur.
|
||||
* @param msg : Description de l'erreur.
|
||||
*/
|
||||
function mDie($err,$msg)
|
||||
{
|
||||
echo "{ error:".json_encode("".$err).", msg:".json_encode("".$msg)."}";
|
||||
global $db;
|
||||
|
||||
ob_end_clean();
|
||||
echo "{\"error\":".$err.",\"msg\":".json_encode("".$msg)."}";
|
||||
|
||||
log_error($err,$msg, date("c"));
|
||||
|
||||
$db->close();
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
/** Ecrit un rapport d'erreur dans un fichier.
|
||||
* @param errNum : Numéro de l'erreur.
|
||||
* @param msg : Description de l'erreur.
|
||||
* @param [other] : (Optionnel) Complément d'information.
|
||||
*/
|
||||
function log_error($errNum, $msg, $other="")
|
||||
{
|
||||
$file = fopen("./log.txt","a+");
|
||||
|
||||
// Met en forme la chaine contenant les paramètres de la requête.
|
||||
$dump_parameters = str_replace("(\n","",print_r($_GET,true));
|
||||
$dump_parameters = str_replace(")\n","",$dump_parameters);
|
||||
|
||||
fwrite($file,"\nErreur n° ".$errNum);
|
||||
fwrite($file," : ".$msg);
|
||||
if(!empty($other))
|
||||
fwrite($file,"\n ".$other);
|
||||
fwrite($file,"\n ".$dump_parameters);
|
||||
|
||||
fclose($file);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!$db = new SQlite3($SQL_DBNAME))
|
||||
mDie(1,"Erreur lors de l'ouverture de la base de données SQLite3");
|
||||
|
||||
|
||||
/** Initialise la base de données avec un nom d'utilisateur et un mot de passe
|
||||
*/
|
||||
function initdb()
|
||||
{
|
||||
global $db;
|
||||
|
||||
$db->exec("insert into user(login, mail, hash_passwd, score) values('foo', 'foo@isp.com', '".md5('bar')."', 0);");
|
||||
}
|
||||
|
||||
if ($do_initdb)
|
||||
initdb();
|
||||
|
||||
if(!isset($_GET['action']) || !isset($_GET['user']) || !isset($_GET['passwd']))
|
||||
mDie(2,"La requête est incomplète");
|
||||
|
||||
|
@ -36,9 +60,18 @@ $action = $_GET['action'];
|
|||
$user = SQLite3::escapeString($_GET['user']);
|
||||
$hash_passwd = md5($_GET['passwd']);
|
||||
|
||||
if ($hash_passwd !== $db->querySingle("SELECT hash_passwd FROM user WHERE login='$user';"))
|
||||
$login_is_ok = ($hash_passwd == $db->querySingle("SELECT hash_passwd FROM user WHERE login='$user';"));
|
||||
if ($action != "check_login" && (!$login_is_ok)) {
|
||||
mDie(3,"Utilisateur non enregistré ou mauvais mot de passe");
|
||||
|
||||
}
|
||||
if ($action = "check_login") {
|
||||
if ($login_is_ok) {
|
||||
echo '{"login_ok":true}';
|
||||
} else {
|
||||
echo '{"login_ok":false}';
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
/** Selectionne aléatoirement un noeud.
|
||||
*/
|
||||
|
@ -50,7 +83,7 @@ function random_node()
|
|||
}
|
||||
|
||||
|
||||
// TODO : Yoann : peut-être faire une classe create_game avec les fonctions ci-dessous comme méthodes ?
|
||||
// TODO : Yoann : peut-être faire une classe GameCreator avec les fonctions ci-dessous comme méthodes ?
|
||||
|
||||
/**
|
||||
* @param cloudSize : Taille du nuage.
|
||||
|
@ -74,23 +107,23 @@ function cg_build_result_sets($cloudSize, $centerEid, $r1, $r2)
|
|||
// Voisins 1 saut via r_associated (0), donc qu'on voudrait spécifier si possible.
|
||||
array('w'=>40, 'd'=>2, 's'=>"select end as eid, 0.25 as r1, 0.25 as r2, 0.5 as r0, 0 as trash from relation where start = $centerEid and type = 0 order by random();"),
|
||||
// Voisins 1 saut via les autres relations
|
||||
// TODO ! certains de ces select pourraient renvoyer des mots de types systèmes (4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001), il faut les éliminer.
|
||||
array('w'=>20, 'd'=>3, 's'=>"select end as eid, 0.1 as r1, 0.1 as r2, 0.8 as r0, 0 as trash from relation where start = $centerEid and type not in (0, $r1, $r2) order by random();"),
|
||||
array('w'=>20, 'd'=>3, 's'=>"select end as eid, 0.1 as r1, 0.1 as r2, 0.8 as r0, 0 as trash from relation where start = $centerEid and type not in (0, $r1, $r2, 4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001) order by random();"),
|
||||
// Voisins 2 sauts, avec un mix de R1 et R2 pour les liens. Par ex [ A -R1-> B -R2-> C ] ou bien [ A -R2-> B -R2-> C ]
|
||||
// Version optimisée de : "select end as eid from relation where $typer1r2 and start in oneHopWithType order by random();"
|
||||
array('w'=>30, 'd'=>3, 's'=>"select B.end as eid, ((A.type = $r1) + (B.type = $r1)) / 3 as r1, ((A.type = $r2) + (B.type = $r2)) / 3 as r2, 1/6 as r0, 1/6 as trash from relation as A, relation as B where A.start = $centerEid and A.$typer1r2 and B.start = A.end and B.$typer1r2 order by random();"),
|
||||
// Voisins 1 saut r1/r2 + 1 saut synonyme
|
||||
// Version optimisée de : "select end as eid from relation where start in oneHopWithType and type = 5 order by random();"
|
||||
// Version optimisée de : "select end as eid from relation where start in oneHopWithType and type = 5 order by random()";
|
||||
array('w'=>20, 'd'=>5, 's'=>"select B.end as eid, (A.type = $r1) * 0.75 as r1, (A.type = $r2) * 0.75 as r2, 0.25 as r0, 0 as trash from relation as A, relation as B where A.start = $centerEid and A.$typer1r2 and B.start = A.end and B.type = 5 order by random();"),
|
||||
// Version optimisée de : "select end as eid from relation where start in (select end from relation where start = $centerEid and type = 5) and $typer1r2 order by random();"
|
||||
array('w'=>20, 'd'=>6, 's'=>"select B.end as eid, (B.type = $r1) * 0.75 as r1, (B.type = $r2) * 0.75 as r2, 0.25 as r0, 0 as trash from relation as A, relation as B where A.start = $centerEid and A.type = 5 and B.start = A.end and B.$typer1r2 order by random();"),
|
||||
// Voisins 2 sauts (tous)
|
||||
array('w'=>10, 'd'=>7, 's'=>"select end as eid, 0.1 as r1, 0.1 as r2, 0.3 as r0, 0.5 as trash from relation where start in (select end from relation where start = $centerEid) order by random();"),
|
||||
// Version optimisée de : "select end as eid, 0.1 as r1, 0.1 as r2, 0.3 as r0, 0.5 as trash from relation where start in (select end from relation where start = $centerEid and type not in (4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001)) and type not in (4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001) order by random();"
|
||||
array('w'=>10, 'd'=>8, 's'=>"select x as eid, 0.1 as r1, 0.1 as r2, 0.3 as r0, 0.5 as trash from (select x from (select X.eid + Y.dumb as x from (select B.end as eid from relation as A, relation as B where A.type not in (4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001) and A.start = $centerEid and B.type not in (4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001) and B.start = A.end limit ".($cloudSize*4).") as X, (select 0 as dumb) as Y)) order by random();"),
|
||||
// Centre pointe vers X, M pointe vers X aussi, on prend M.
|
||||
// Version optimisée de : "select start as eid from relation where end in (select end from relation where start = $centerEid) and type not in (4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001) order by random();"
|
||||
// Ce n'est toujours pas ça… : "select eid from (select B.start as eid from relation as A, relation as B where A.type not in (4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001) and A.start = $centerEid and B.type not in (4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001) and B.end = A.end limit 1) order by random();"
|
||||
// Tordu, mais ça marche \o/ . En fait il faut empêcher l'optimiseur de ramener le random avant le limit (et l'optimiseur est malin… :)
|
||||
array('w'=>10, 'd'=>8, 's'=>"select x as eid, 0.1 as r1, 0.1 as r2, 0.2 as r0, 0.6 as trash from (select x from (select X.eid + Y.dumb as x from (select B.start as eid from relation as A, relation as B where A.type not in (4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001) and A.start = 74860 and B.type not in (4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001) and B.end = A.end limit $cloudSize) as X, (select 0 as dumb) as Y)) order by random();"),
|
||||
array('w'=>10, 'd'=>8, 's'=>"select x as eid, 0.1 as r1, 0.1 as r2, 0.2 as r0, 0.6 as trash from (select x from (select X.eid + Y.dumb as x from (select B.start as eid from relation as A, relation as B where A.type not in (4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001) and A.start = $centerEid and B.type not in (4, 12, 36, 18, 29, 45, 46, 47, 48, 1000, 1001) and B.end = A.end limit ".($cloudSize*4).") as X, (select 0 as dumb) as Y)) order by random();"),
|
||||
'rand' => array('w'=>5, 'd'=>10, 's'=>false) // random. Le r1 et r2 de random sont juste en-dessous
|
||||
);
|
||||
|
||||
|
@ -135,7 +168,7 @@ function cg_build_result_sets($cloudSize, $centerEid, $r1, $r2)
|
|||
*/
|
||||
function cg_choose_relations()
|
||||
{
|
||||
$relations = array(5, 7, 9, 10, /* Pas d'icônes pour celles-ci. */ 13, 14, 22);
|
||||
$relations = array(5, 7, 9, 10);// /* Pas d'icônes pour celles-ci. */ 13, 14, 22);
|
||||
$r1 = rand(0,count($relations)-1);
|
||||
$r2 = rand(0,count($relations)-2);
|
||||
|
||||
|
@ -162,13 +195,16 @@ function cg_build_cloud($cloudSize, $sources, $sumWeights)
|
|||
$i = 0;
|
||||
$totalDifficulty = 0;
|
||||
|
||||
while ($i < $cloudSize && $nbFailed < 5*$cloudSize)
|
||||
while ($i < $cloudSize && $nbFailed < 10*$cloudSize)
|
||||
{
|
||||
// On choisit une source aléatoire en tennant compte des poids.
|
||||
$rands = rand(1,$sumWeights);
|
||||
$sumw = 0;
|
||||
if (!isset($sources['rand'])) {
|
||||
break;
|
||||
}
|
||||
$src = $sources['rand'];
|
||||
$srck = null;
|
||||
$srck = 'rand';
|
||||
|
||||
// Sélection d'une source aléatoire
|
||||
foreach ($sources as $k => $x)
|
||||
|
@ -188,26 +224,25 @@ function cg_build_cloud($cloudSize, $sources, $sumWeights)
|
|||
{
|
||||
$nbFailed++;
|
||||
|
||||
if ($srck !== null)
|
||||
{
|
||||
$sumWeights -= $src['w'];
|
||||
unset($sources[$srck]);
|
||||
}
|
||||
$sumWeights -= $src['w'];
|
||||
unset($sources[$srck]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// On récupère un résultat de cette source.
|
||||
// TODO : vérifier que $src['rsPos']++ fait ce que l'on veut
|
||||
$res = $src['resultSet'][$src['rsPos']++];
|
||||
$res = $src['resultSet'][$src['rsPos']];
|
||||
$sources[$srck]['rsPos']++;
|
||||
|
||||
// TODO (FAIT) : vérifier si $res['eid'] est présent dans un des $cloud[*]['eid'], car la condition qui suit est fausse.
|
||||
foreach ($c in $cloud) {
|
||||
// On vérifie si le mot n'a pas déjà été sélectionné.
|
||||
$rejected = false;
|
||||
foreach ($cloud as $c) {
|
||||
if ($c['eid'] == $res['eid']) {
|
||||
$nbFailed++;
|
||||
continue;
|
||||
$rejected = true;
|
||||
}
|
||||
}
|
||||
if ($rejected) { continue; }
|
||||
|
||||
// position dans le nuage, difficulté, eid, probaR1, probaR2
|
||||
$totalDifficulty += $src['d'];
|
||||
|
@ -242,54 +277,67 @@ function cg_insert($centerEid, $cloud, $r1, $r2, $totalDifficulty)
|
|||
$db->exec("INSERT INTO game(gid, eid_central_word, relation_1, relation_2, difficulty)
|
||||
VALUES (null, $centerEid, $r1, $r2, $totalDifficulty);");
|
||||
$gid = $db->lastInsertRowID();
|
||||
|
||||
$t = time();
|
||||
$db->exec("INSERT INTO played_game(pgid, gid, login, timestamp)
|
||||
VALUES (null, $gid, null, $t);");
|
||||
$pgid1 = $db->lastInsertRowID();
|
||||
$db->exec("INSERT INTO played_game(pgid, gid, login, timestamp)
|
||||
VALUES (null, $gid, null, $t);");
|
||||
$pgid2 = $db->lastInsertRowID();
|
||||
$db->exec("INSERT INTO played_game(pgid, gid, login, timestamp)
|
||||
VALUES (null, $gid, null, $t);");
|
||||
$pgid0 = $db->lastInsertRowID();
|
||||
$db->exec("INSERT INTO played_game(pgid, gid, login, timestamp)
|
||||
VALUES (null, $gid, null, $t);");
|
||||
$pgidT = $db->lastInsertRowID();
|
||||
|
||||
$db->exec("INSERT INTO played_game(pgid, gid, login, played)
|
||||
VALUES (null, $gid, null, 1);");
|
||||
$pgid = $db->lastInsertRowID();
|
||||
|
||||
// TODO : R0 et Trash + corrections
|
||||
foreach ($cloud as $c)
|
||||
{
|
||||
$db->exec("INSERT INTO game_cloud(gid, num, difficulty, eid_word, totalWeight, probaR1, probaR2, probaR0, probaTrash)
|
||||
VALUES ($gid, ".$c['pos'].", ".$c['d'].", ".$c['eid'].", 2, ".$c['probaR1'].", ".$c['probaR2'].", ".$c['probaR0'].", ".$c['probaTrash'].");");
|
||||
|
||||
$db->exec("INSERT INTO played_game_cloud(pgid, gid, type, num, relation, weight, score)
|
||||
VALUES ($pgid, $gid, 0, ".$c['pos'].", $r1, ".$c['probaR1'].", 0);");
|
||||
VALUES ($pgid1, $gid, 0, ".$c['pos'].", $r1, ".$c['probaR1'].", 0);");
|
||||
|
||||
$db->exec("INSERT INTO played_game_cloud(pgid, gid, type, num, relation, weight, score)
|
||||
VALUES ($pgid, $gid, 0, ".$c['pos'].", $r1, ".$c['probaR1'].", 0);");
|
||||
VALUES ($pgid2, $gid, 0, ".$c['pos'].", $r2, ".$c['probaR2'].", 0);");
|
||||
|
||||
$db->exec("INSERT INTO played_game_cloud(pgid, gid, type, num, relation, weight, score)
|
||||
VALUES ($pgid0, $gid, 0, ".$c['pos'].", 0, ".$c['probaR0'].", 0);");
|
||||
|
||||
$db->exec("INSERT INTO played_game_cloud(pgid, gid, type, num, relation, weight, score)
|
||||
VALUES ($pgidT, $gid, 0, ".$c['pos'].", -1, ".$c['probaTrash'].", 0);");
|
||||
}
|
||||
|
||||
$db->exec("commit;");
|
||||
}
|
||||
|
||||
|
||||
/** Génère une partie pour une certaine taille de nuage.
|
||||
* @param cloudSize : Taille du nuage.
|
||||
*/
|
||||
function create_game($cloudSize)
|
||||
{
|
||||
global $db;
|
||||
|
||||
// select random node
|
||||
$centerEid = random_node();
|
||||
|
||||
$r1 = cg_choose_relations(); $r2 = $r1[1]; $r1 = $r1[0];
|
||||
$sources = cg_build_result_sets($cloudSize, $centerEid, $r1, $r2); $sumWeights = $sources[1]; $sources = $sources[0];
|
||||
$cloud = cg_build_cloud($cloudSize, $sources, $sumWeights); $totalDifficulty = $cloud[1]; $cloud = $cloud[0];
|
||||
cg_insert($centerEid, $cloud, $r1, $r2, $totalDifficulty);
|
||||
}
|
||||
|
||||
|
||||
/** Retourne un identifiant de partie aléatoire de la liste de parties jouables
|
||||
* @return gid : Identifiant de partie.
|
||||
*/
|
||||
function random_game()
|
||||
{
|
||||
function randomGameCore() {
|
||||
global $db;
|
||||
|
||||
return $db->querySingle("select gid from game where gid = (abs(random()) % (select max(gid) from game))+1 or gid = (select max(gid) from game where gid > 0) order by gid limit 1;");
|
||||
}
|
||||
|
||||
function randomGame()
|
||||
{
|
||||
$gid = randomGameCore();
|
||||
if ($gid === null) {
|
||||
// TODO : séparer ces créations de parties dans une fonction qui détecte le mode toussa.
|
||||
for ($i = 0; $i < 100; $i++) {
|
||||
createGameCore(10);
|
||||
}
|
||||
$gid = randomGameCore();
|
||||
if ($gid === null) {
|
||||
mDie(6, "Erreur lors de la récupération de la partie. Vérifiez qu'il y a au moins une partie.");
|
||||
}
|
||||
}
|
||||
return $gid;
|
||||
}
|
||||
|
||||
|
||||
/** Formate une partie en JSON en l'imprimant.
|
||||
* @param game_id : L'identifiant d'une partie.
|
||||
|
@ -299,7 +347,7 @@ function game2json($game_id)
|
|||
global $db, $user;
|
||||
|
||||
// TODO : planter si la requête suivante échoue pour quelque raison que ce soit.
|
||||
$db->exec("INSERT INTO played_game(pgid, gid, login, played) VALUES (null, $game_id, '$user', 0);");
|
||||
$db->exec("INSERT INTO played_game(pgid, gid, login, timestamp) VALUES (null, $game_id, '$user', -1);");
|
||||
$pgid = $db->lastInsertRowID();
|
||||
|
||||
// TODO Yoann : faire des tests d'erreur pour ces select ?
|
||||
|
@ -331,15 +379,34 @@ function game2json($game_id)
|
|||
*/
|
||||
function createGame()
|
||||
{
|
||||
if(!isset($_GET['nb']) || !isset($_GET['mode']))
|
||||
if (!isset($_GET['nb']) || !isset($_GET['mode']))
|
||||
mDie(2,"La requête est incomplète");
|
||||
|
||||
$nbParties = intval($_GET['nb']);
|
||||
|
||||
for ($i = 0; $i < $nbParties; $i++)
|
||||
create_game(10);
|
||||
createGameCore(10);
|
||||
|
||||
echo '{"success":1}';
|
||||
}
|
||||
|
||||
/** Génère une partie (mode normal pour l'instant) pour une certaine taille de nuage.
|
||||
* @param cloudSize : Taille du nuage.
|
||||
*
|
||||
* Est appelée par randomGame(), donc il faudra adapter quand on aura plusieurs modes, par exemple en ayant une fonction intermédiaire qui puisse être appelée par createGame et randomGame.
|
||||
*/
|
||||
function createGameCore($cloudSize)
|
||||
{
|
||||
global $db;
|
||||
|
||||
// select random node
|
||||
$centerEid = random_node();
|
||||
|
||||
$r1 = cg_choose_relations(); $r2 = $r1[1]; $r1 = $r1[0];
|
||||
$sources = cg_build_result_sets($cloudSize, $centerEid, $r1, $r2); $sumWeights = $sources[1]; $sources = $sources[0];
|
||||
$cloud = cg_build_cloud($cloudSize, $sources, $sumWeights); $totalDifficulty = $cloud[1]; $cloud = $cloud[0];
|
||||
cg_insert($centerEid, $cloud, $r1, $r2, $totalDifficulty);
|
||||
}
|
||||
|
||||
/** Récupération d'une partie.
|
||||
*/
|
||||
|
@ -354,7 +421,7 @@ function getGame()
|
|||
|
||||
for ($i=0; $i < $nbGames; $i)
|
||||
{
|
||||
game2json(random_game());
|
||||
game2json(randomGame());
|
||||
|
||||
if ((++$i) < $nbGames)
|
||||
echo ",";
|
||||
|
@ -376,14 +443,14 @@ function setGame()
|
|||
$pgid = intval($_GET['pgid']);
|
||||
$gid = intval($_GET['gid']);
|
||||
|
||||
if ('t' !== $db->querySingle("SELECT 't' FROM played_game WHERE pgid = $pgid and $gid = $gid and played = 0 and login = '$user';"))
|
||||
if ('ok' !== $db->querySingle("SELECT 'ok' FROM played_game WHERE pgid = $pgid and $gid = $gid and login = '$user' and timestamp = -1;"))
|
||||
mDie(4,"Cette partie n'est associée à votre nom d'utilisateur, ou bien vous l'avez déjà jouée.");
|
||||
|
||||
$userReputation = $db->querySingle("SELECT score FROM user WHERE login='$user';");
|
||||
$userReputation = ($userReputation > 0) ? log($userReputation) : 0;
|
||||
|
||||
$db->exec("begin transaction;");
|
||||
$db->exec("update played_game set played = 1 where pgid = $pgid;");
|
||||
$db->exec("update played_game set timestamp = ".time()." where pgid = $pgid;");
|
||||
|
||||
$r0 = 0;
|
||||
$trash = -1;
|
||||
|
@ -396,7 +463,7 @@ function setGame()
|
|||
{
|
||||
$num = $row['num'];
|
||||
if (!isset($_GET[$num])) {
|
||||
mDie(5,"Pas de réponse pour le mot $num de cette partie.");
|
||||
mDie(5,"Cette requête set_partie ne donne pas de réponse (une relation) pour le mot numéro $num de la partie.");
|
||||
}
|
||||
$relanswer = intval($_GET[$num]);
|
||||
|
||||
|
@ -429,7 +496,9 @@ function setGame()
|
|||
|
||||
$db->exec("commit;");
|
||||
// On renvoie une nouvelle partie pour garder le client toujours bien alimenté.
|
||||
game2json(random_game());
|
||||
echo "{\"score\":$score,\"newGame\":";
|
||||
game2json(randomGame());
|
||||
echo "}";
|
||||
}
|
||||
|
||||
/** La fonction principale.
|
||||
|
@ -456,4 +525,6 @@ function main($action)
|
|||
|
||||
main($action);
|
||||
|
||||
ob_end_flush();
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue
Block a user