Premier Commit

This commit is contained in:
ENSIMAG - NDR
2024-02-02 13:37:12 +01:00
commit f89b7df8d9
55 changed files with 4191 additions and 0 deletions
@@ -0,0 +1,193 @@
package com.example.boidelov3;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
//public static final List EXTRA_LIST_JOUEUR = Collections.singletonList("com.example.piccolov2.jeux.EXTRA_LISTJOUEUR");
String J1S,J2S,J3S;
private int offset;
private List<String> toutlesjoueurs;
private List<String> PhraseSansNom;
EditText J1;
EditText J2;
EditText J3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
private List<EditText> editTextList = new ArrayList<>();
public void onClickButton1(View view) {
LinearLayout namesContainer = findViewById(R.id.namesContainer); // Récupère le conteneur des noms
EditText newEditText = new EditText(this); // Crée un nouvel EditText
newEditText.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); // Définit les paramètres de mise en page
newEditText.setHint("Nom"); // Définit le texte d'indication
newEditText.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS); // Définit le type d'entrée (texte avec majuscule au début des mots)
editTextList.add(newEditText); // Ajoute l'EditText à la liste des EditText
namesContainer.addView(newEditText); // Ajoute le nouvel EditText au conteneur des noms
}
public void onClickButtonStart(View view) {
J1 = (EditText) findViewById(R.id.J1);
J1S = J1.getText().toString();
J2 = (EditText) findViewById(R.id.J2);
J2S = J2.getText().toString();
J3 = (EditText) findViewById(R.id.J3);
J3S = J3.getText().toString();
//Creation d'une liste avec tt les j et verif si elle est completé
toutlesjoueurs = new ArrayList<String>();
if (J1S.isEmpty()) {
//System.out.println("J1S A pas de valeur");
}else toutlesjoueurs.add(J1S);
if (J2S.isEmpty()) {
//System.out.println("J2S a pas de valeur");
}else toutlesjoueurs.add(J2S);
if (J3S.isEmpty()) {
//System.out.println("J3S a pas de valeur");
}else toutlesjoueurs.add(J3S);
//
int nbnom = editTextList.size();
//String test = editTextList.get(0).getText().toString();
//System.out.println(test);
System.out.println(nbnom);
for (int i = 0; i < nbnom; i++) {
String nom = editTextList.get(i).getText().toString();
System.out.println(nom);
if (nom.isEmpty()) {
System.out.println("Nom vide");
} else {
toutlesjoueurs.add(nom);
}
}
//TestListe
//System.out.println(toutlesjoueurs);
openParametres();
}
public void openParametres(){
//enregistrement des joueurs dans les shared preferences Joueurs
SharedPreferences sharedPreferences = getSharedPreferences("Joueurs", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("J1", J1S);
editor.putString("J2", J2S);
editor.putString("J3", J3S);
for (int i = 0; i < editTextList.size(); i++) {
String nom = editTextList.get(i).getText().toString();
editor.putString("J" + (i + 4), nom);
}
editor.apply();
//Lancement de l'activité (Jeux_parametres)
Intent intent = new Intent(this, JeuxParametres.class);
//Regarde si le pseudo est vide et envoie a l'activité jeux
if (toutlesjoueurs.isEmpty()){
Context context = getApplicationContext();
CharSequence text = "Merci de rentrer des joueurs";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
else {
if (toutlesjoueurs.size() >= 3) {
intent.putStringArrayListExtra("EXTRA_LIST_JOUEUR", (ArrayList<String>) toutlesjoueurs);
//intent.putStringArrayListExtra("EXTRA_LIST_DEFI_NON_JOUEUR", (ArrayList<String>) PhraseSansNom);
intent.putExtra("EXTRA_OFFSET", offset);
startActivity(intent);
} else {
Context context = getApplicationContext();
CharSequence text = "La partie ne peux pas commencer avec moins de 3 joueurs";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}}}
//Lancement de la fonction activité (Jeux)
// openJeux();
// }
//Lancement de l'activité (Jeux)
// public void openJeux(){
//
// Intent intent = new Intent(this, Jeux.class);
// //Regarde si le pseudo est vide et envoie a l'activité jeux
// if (toutlesjoueurs.isEmpty()){
// Context context = getApplicationContext();
// CharSequence text = "Merci de rentrer des joueurs";
// int duration = Toast.LENGTH_SHORT;
//
// Toast toast = Toast.makeText(context, text, duration);
// toast.show();
// }
// else{
// if(toutlesjoueurs.size() >= 3){
// intent.putStringArrayListExtra("EXTRA_LIST_JOUEUR", (ArrayList<String>) toutlesjoueurs);
// //intent.putStringArrayListExtra("EXTRA_LIST_DEFI_NON_JOUEUR", (ArrayList<String>) PhraseSansNom);
// intent.putExtra("EXTRA_OFFSET", offset);
// startActivity(intent);
// }else{
// Context context = getApplicationContext();
// CharSequence text = "La partie ne peux pas commencer avec moins de 3 joueurs";
// int duration = Toast.LENGTH_SHORT;
// Toast toast = Toast.makeText(context, text, duration);
// toast.show();
//
// }
//
//
//
// }
//
// }
//
// public void OnCheckboxClicked1(View view) {
// boolean checked = ((CheckBox) view).isChecked();
// if (checked){
// offset = 2;
// //System.out.println("OFFSET DE 2");
// }else {
// //System.out.println("DESACTIVER : OFFSET DE 2");
// offset = 0;
// }}
//
// public void OnCheckboxClicked2(View view) {
// boolean checked = ((CheckBox) view).isChecked();
// if (checked){
// offset = 4;
// //System.out.println("OFFSET DE 4");
// }else {
// //System.out.println("DESACTIVER : OFFSET DE 4");
// offset = 0;
// }}
//}