diff --git a/src/main/java/sae/chuzzle/OptionsActivity.java b/src/main/java/sae/chuzzle/OptionsActivity.java new file mode 100644 index 0000000..8d082cc --- /dev/null +++ b/src/main/java/sae/chuzzle/OptionsActivity.java @@ -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(); + } + } +} \ No newline at end of file diff --git a/src/main/java/sae/chuzzle/SeedActivity.java b/src/main/java/sae/chuzzle/SeedActivity.java new file mode 100644 index 0000000..50534b3 --- /dev/null +++ b/src/main/java/sae/chuzzle/SeedActivity.java @@ -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); + } +} \ No newline at end of file diff --git a/src/main/res/layout/activity_options.xml b/src/main/res/layout/activity_options.xml new file mode 100644 index 0000000..6b59046 --- /dev/null +++ b/src/main/res/layout/activity_options.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/res/layout/activity_seed.xml b/src/main/res/layout/activity_seed.xml new file mode 100644 index 0000000..4ed8a38 --- /dev/null +++ b/src/main/res/layout/activity_seed.xml @@ -0,0 +1,31 @@ + + + + + + + +