Modifs page parametre + debut recup si pion vide
This commit is contained in:
parent
e87e252360
commit
df84ff5644
@ -11,6 +11,7 @@ public class MainActivity extends Activity {
|
||||
private Button mORDI;
|
||||
private Button mSettings;
|
||||
private Button mRules;
|
||||
private boolean pionV;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -25,6 +26,9 @@ public class MainActivity extends Activity {
|
||||
public void onClick(View v) {
|
||||
Intent HotSeat = new Intent(MainActivity.this, GameActivity.class);
|
||||
HotSeat.putExtra("bot", false);
|
||||
if(pionV) {
|
||||
HotSeat.putExtra("pionVide", true);
|
||||
}
|
||||
startActivity(HotSeat);
|
||||
}
|
||||
});
|
||||
@ -33,6 +37,9 @@ public class MainActivity extends Activity {
|
||||
public void onClick(View v) {
|
||||
Intent ordi = new Intent(MainActivity.this, GameActivity.class);
|
||||
ordi.putExtra("bot", true);
|
||||
if(pionV) {
|
||||
ordi.putExtra("pionVide", true);
|
||||
}
|
||||
startActivity(ordi);
|
||||
}
|
||||
});
|
||||
@ -40,7 +47,7 @@ public class MainActivity extends Activity {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent settings = new Intent(MainActivity.this, SettingsActivity.class);
|
||||
startActivity(settings);
|
||||
startActivityForResult(settings, 1);
|
||||
}
|
||||
});
|
||||
mRules.setOnClickListener(new View.OnClickListener() {
|
||||
@ -51,4 +58,13 @@ public class MainActivity extends Activity {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if(requestCode == 1) {
|
||||
pionV = data.getBooleanExtra("pionV", false);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,33 +1,44 @@
|
||||
package com.example.mastermind;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.Switch;
|
||||
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
|
||||
public class SettingsActivity extends AppCompatActivity {
|
||||
public class SettingsActivity extends Activity {
|
||||
private Button mButton;
|
||||
private Switch mSwitch;
|
||||
private boolean pionV;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.settings_activity);
|
||||
if (savedInstanceState == null) {
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.replace(R.id.settings, new SettingsFragment())
|
||||
.commit();
|
||||
}
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SettingsFragment extends PreferenceFragmentCompat {
|
||||
mButton = findViewById(R.id.backButton);
|
||||
mSwitch = findViewById(R.id.switchPion);
|
||||
|
||||
mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
setPreferencesFromResource(R.xml.root_preferences, rootKey);
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if(isChecked) {
|
||||
pionV = true;
|
||||
} else {
|
||||
pionV = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
mButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("pionV", pionV);
|
||||
setResult(1, intent);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,10 +1,46 @@
|
||||
<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:background="@color/cardview_dark_background">
|
||||
android:background="@color/cardview_dark_background"
|
||||
android:orientation="vertical"
|
||||
tools:ignore="UseSwitchCompatOrMaterialXml">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/settings"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="@string/header"
|
||||
android:textColor="#eee"
|
||||
android:textSize="40dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/backButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="60dp"
|
||||
android:background="#aaa"
|
||||
android:padding="7dp"
|
||||
android:text="@string/back_menu"/>
|
||||
|
||||
<Switch
|
||||
android:id="@+id/switchPion"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="50dp"
|
||||
android:text="@string/pions_title"
|
||||
android:textColor="#eee"
|
||||
android:textSize="20dp"/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="40dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginRight="40dp"
|
||||
android:text="@string/summary"
|
||||
android:textColor="#eee"
|
||||
android:textSize="15dp"/>
|
||||
</LinearLayout>
|
@ -7,6 +7,7 @@
|
||||
<string name="header">Paramètres</string>
|
||||
|
||||
<!-- Sync Preferences -->
|
||||
<string name="back_menu">< Retour au menu</string>
|
||||
<string name="pions_title">Autoriser les pions vides</string>
|
||||
<string name="summary">Cette fonctionnalité augmente la difficulté du jeu pour l\'attaquant</string>
|
||||
|
||||
|
14
app/src/main/res/xml/preferences.xml
Normal file
14
app/src/main/res/xml/preferences.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<PreferenceCategory app:title="@string/header">
|
||||
<SwitchPreferenceCompat
|
||||
app:key="switchPion"
|
||||
app:title="@string/pions_title"
|
||||
app:summaryOff="@string/summary"
|
||||
app:summaryOn="@string/summary" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
Loading…
Reference in New Issue
Block a user