diff --git a/app/src/main/java/fr/iutfbleau/sae/GameActivity.java b/app/src/main/java/fr/iutfbleau/sae/GameActivity.java new file mode 100644 index 0000000..40e11d2 --- /dev/null +++ b/app/src/main/java/fr/iutfbleau/sae/GameActivity.java @@ -0,0 +1,88 @@ +package fr.iutfbleau.sae; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.graphics.Point; +import android.os.Bundle; +import android.widget.Button; +import android.widget.TextView; + +import java.util.HashSet; +import java.util.Set; + + +public class GameActivity extends AppCompatActivity { + + public static final String SIZE_KEY = "SIZE"; + + + public static final int DEFAULT_SIZE = 10; + + + public static final String HARD_MODE_KEY = "HARD_MODE"; + + + public static final boolean DEFAULT_HARD_MODE = false; + + + private static final String LINES_KEY = "LINES"; + + + private static final String OFFSET_X_KEY = "OFFSET_X"; + + + private static final String OFFSET_Y_KEY = "OFFSET_Y"; + + + private GameView view; + + + private GameModel model; + + + private GameController controller; + + + @Override + protected void onCreate(Bundle savedState) { + super.onCreate(savedState); + this.setContentView(R.layout.activity_game); + + Intent intent = this.getIntent(); + + this.view = (GameView) this.findViewById(R.id.game); + + this.model = new GameModel(intent.getIntExtra(SIZE_KEY, DEFAULT_SIZE), + intent.getBooleanExtra(HARD_MODE_KEY, DEFAULT_HARD_MODE)); + this.view.setModel(this.model); + + this.controller = new GameController(this, this.view, this.model); + } + + + @Override + protected void onSaveInstanceState(@NonNull Bundle state) { + super.onSaveInstanceState(state); + + state.putSerializable(LINES_KEY, new HashSet(this.model.getLines())); + + Point offset = this.view.getOffset(); + + state.putInt(OFFSET_X_KEY, offset.x); + state.putInt(OFFSET_Y_KEY, offset.y); + } + + + @Override + protected void onRestoreInstanceState(@NonNull Bundle savedState) { + super.onSaveInstanceState(savedState); + + Intent intent = this.getIntent(); + + this.model.reset(intent.getIntExtra(SIZE_KEY, DEFAULT_SIZE), (Set) savedState.getSerializable(LINES_KEY)); + this.controller.update(); + this.view.setOffset(savedState.getInt(OFFSET_X_KEY, 0), savedState.getInt(OFFSET_Y_KEY, 0)); + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_game.xml b/app/src/main/res/layout/activity_game.xml new file mode 100644 index 0000000..fc75840 --- /dev/null +++ b/app/src/main/res/layout/activity_game.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + +