Ajout de la page Option et Seed
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package sae.chuzzle;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.Switch;
|
||||
|
||||
public class OptionsActivity extends Activity
|
||||
implements CompoundButton.OnCheckedChangeListener {
|
||||
|
||||
private SharedPreferences prefs;
|
||||
private Switch switchDaltonien;
|
||||
private Switch switchHard;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_options);
|
||||
|
||||
prefs = getSharedPreferences("chuzzle_prefs", MODE_PRIVATE);
|
||||
|
||||
switchDaltonien = findViewById(R.id.switchDaltonien);
|
||||
switchHard = findViewById(R.id.switchHard);
|
||||
|
||||
switchDaltonien.setChecked(prefs.getBoolean("daltonien", false));
|
||||
switchHard.setChecked(prefs.getBoolean("hard_mode", false));
|
||||
|
||||
switchDaltonien.setOnCheckedChangeListener(this);
|
||||
switchHard.setOnCheckedChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton bouton, boolean estCoche) {
|
||||
if (bouton == switchDaltonien) {
|
||||
prefs.edit().putBoolean("daltonien", estCoche).apply();
|
||||
} else if (bouton == switchHard) {
|
||||
prefs.edit().putBoolean("hard_mode", estCoche).apply();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package sae.chuzzle;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
||||
public class SeedActivity extends Activity implements View.OnClickListener {
|
||||
|
||||
private EditText etGraine;
|
||||
private Button btnJouer;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_seed);
|
||||
|
||||
etGraine = findViewById(R.id.etGraine);
|
||||
btnJouer = findViewById(R.id.btnJouer);
|
||||
|
||||
btnJouer.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v == btnJouer) {
|
||||
lancerPartieAvecGraine();
|
||||
}
|
||||
}
|
||||
|
||||
private void lancerPartieAvecGraine() {
|
||||
String texte = etGraine.getText().toString().trim();
|
||||
|
||||
if (texte.isEmpty()) {
|
||||
Toast.makeText(
|
||||
this,
|
||||
"Veuillez entrer une graine.",
|
||||
Toast.LENGTH_SHORT
|
||||
).show();
|
||||
return;
|
||||
}
|
||||
|
||||
long graine;
|
||||
|
||||
try {
|
||||
graine = Long.parseLong(texte);
|
||||
} catch (NumberFormatException e) {
|
||||
graine = texte.hashCode();
|
||||
}
|
||||
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
intent.putExtra("graine", graine);
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="48dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Options"
|
||||
android:textSize="32sp"
|
||||
android:textStyle="bold"
|
||||
android:gravity="center"
|
||||
android:layout_marginBottom="64dp"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_marginBottom="32dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Mode daltonien (symboles)"
|
||||
android:textSize="18sp"/>
|
||||
|
||||
<Switch
|
||||
android:id="@+id/switchDaltonien"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Hard mode (verrous)"
|
||||
android:textSize="18sp"/>
|
||||
|
||||
<Switch
|
||||
android:id="@+id/switchHard"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
android:padding="48dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Entrez une graine"
|
||||
android:textSize="24sp"
|
||||
android:gravity="center"
|
||||
android:layout_marginBottom="32dp"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etGraine"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="Ex : 12345"
|
||||
android:inputType="number"
|
||||
android:layout_marginBottom="32dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnJouer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Jouer"/>
|
||||
|
||||
</LinearLayout>
|
||||
Reference in New Issue
Block a user