parent
91593fca60
commit
9da930e512
@ -1,11 +1,53 @@
|
|||||||
package projet.iut.jeu_de_la_vie.view.fragment;
|
package projet.iut.jeu_de_la_vie.view.fragment;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.text.Editable;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
import projet.iut.jeu_de_la_vie.R;
|
import projet.iut.jeu_de_la_vie.R;
|
||||||
|
import projet.iut.jeu_de_la_vie.model.cellule.Cellule;
|
||||||
|
import projet.iut.jeu_de_la_vie.view.LauncherActivity;
|
||||||
|
|
||||||
public class MenuFragment extends Fragment {
|
public class MenuFragment extends Fragment {
|
||||||
public MenuFragment() {
|
public MenuFragment() {
|
||||||
super(R.layout.menu_principal);
|
super(R.layout.menu_principal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
view.findViewById(R.id.startButton).setOnClickListener(l->{startGame(view);});
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getNbColumnsFromView(View v) throws NumberFormatException{
|
||||||
|
EditText editText = v.findViewById(R.id.nbColone);
|
||||||
|
Editable text = editText.getText();
|
||||||
|
return Integer.parseInt(text.toString());
|
||||||
|
}
|
||||||
|
private int getNbLignesFromView(View v) throws NumberFormatException{
|
||||||
|
EditText editText = v.findViewById(R.id.nbLignes);
|
||||||
|
Editable text = editText.getText();
|
||||||
|
return Integer.parseInt(text.toString());
|
||||||
|
}
|
||||||
|
public void startGame(View view){
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
int colones;
|
||||||
|
int lignes;
|
||||||
|
try {
|
||||||
|
lignes = getNbLignesFromView(view);
|
||||||
|
colones = getNbColumnsFromView(view);
|
||||||
|
}catch (NumberFormatException e){
|
||||||
|
lignes=10;
|
||||||
|
colones=10;
|
||||||
|
}
|
||||||
|
bundle.putInt("lignes", lignes);
|
||||||
|
bundle.putInt("colones", colones);
|
||||||
|
((LauncherActivity)getActivity()).startGame(bundle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue