Added documentation for Game Listener and Controller.

This commit is contained in:
Alexei KADIR 2024-04-04 20:39:08 +02:00
parent 52266dc517
commit b0e2050d92
2 changed files with 113 additions and 24 deletions

View File

@ -5,39 +5,75 @@ import android.view.View;
import android.widget.Button;
import android.widget.TextView;
/**
* {@code GameController} is a class that controls the game by recieving events
* from the {@code GameView} and updating the {@code GameModel}.
*
* @autor Alexeï Kadir, Lyanis Souidi, Hugo Dimitrijevic
* @version 1.0
*/
public class GameController implements GameListener, View.OnClickListener {
/**
* The {@code Activity} that contains the game.
*/
private final Activity activity;
/**
* The {@code GameView} that displays the game.
*/
private final GameView view;
/**
* The {@code GameModel} that represents the game.
*/
private final GameModel model;
/**
* The {@code Button} that resets the game when clicked.
*/
private final Button reset;
/**
* The {@code TextView} that displays the score during the game.
*/
private final TextView score;
/**
* The {@code TextView} that displays the number of moves possible during the
* game.
*/
private final TextView moves;
/**
* The {@code View} that contains the end of the game menu.
*/
private final View end;
/**
* The {@code TextView} that displays the score at the end of the game.
*/
private final TextView endScore;
/**
* The {@code Button} that closes the end of the game menu when clicked, and
* returns to the main menu.
*/
private final Button back;
/**
* The {@code Button} that closes the end of the game menu when clicked, and
* allows the player to watch the game.
*/
private final Button watch;
/**
* Constructs a new {@code GameController} with the specified {@code Activity},
* {@code GameView} and {@code GameModel}.
*
* @param activity The {@code Activity} that contains the game.
* @param view The {@code GameView} that displays the game.
* @param model The {@code GameModel} that represents the game.
*/
public GameController(Activity activity, GameView view, GameModel model) {
this.activity = activity;
this.view = view;
@ -61,7 +97,10 @@ public class GameController implements GameListener, View.OnClickListener {
this.update();
}
/**
* Updates the game state by updating the score and the number of moves
* possible, and displaying the end of the game menu if the game is finished.
*/
public void update() {
this.score.setText(this.activity.getString(R.string.score, this.model.getScore()));
this.moves.setText(this.activity.getString(R.string.moves, this.model.getValidLineCount()));
@ -72,23 +111,35 @@ public class GameController implements GameListener, View.OnClickListener {
}
}
/**
* Hides the end of the game menu, and allows the player to watch the game.
*/
public void watch() {
this.end.setVisibility(View.INVISIBLE);
}
/**
* Closes the game and returns to the main menu.
*/
public void back() {
this.activity.finish();
}
/**
* Resets the view offset to (0, 0).
*/
public void reset() {
this.view.setOffset(0, 0);
this.view.invalidate();
}
/**
* Called when the player starts drawing a {@code Line}. The {@code Line}
* initially starts and ends at the specified {@code Cell}.
*
* @param view The {@code GameView} that sent the event.
* @param start The {@code Cell} where the line starts.
*/
@Override
public void onLineStarted(GameView view, Cell start) {
if (this.view != view)
@ -100,7 +151,13 @@ public class GameController implements GameListener, View.OnClickListener {
this.view.invalidate();
}
/**
* Called when the player moves the end of the {@code Line} being drawn. The end
* of the {@code Line} is moved to the specified {@code Cell}.
*
* @param view The {@code GameView} that sent the event.
* @param end The {@code Cell} where the line ends.
*/
@Override
public void onLineEndMoved(GameView view, Cell end) {
if (this.view != view)
@ -112,7 +169,13 @@ public class GameController implements GameListener, View.OnClickListener {
this.view.invalidate();
}
/**
* Called when the player ends drawing a {@code Line}. The {@code Line} ends at
* the specified {@code Cell}.
*
* @param view The {@code GameView} that sent the event.
* @param end The {@code Cell} where the line ends.
*/
@Override
public void onLineEnded(GameView view, Cell end) {
if (this.view != view)
@ -126,7 +189,12 @@ public class GameController implements GameListener, View.OnClickListener {
this.update();
}
/**
* Called when the player clicks on a {@code View}. The {@code GameController}
* handles the click event by calling the appropriate method.
*
* @param view The {@code View} that was clicked.
*/
@Override
public void onClick(View view) {
if (this.reset == view)

View File

@ -2,14 +2,35 @@ package fr.iutfbleau.sae;
import android.graphics.Point;
/**
* {@code GameListener} is an interface that listens to events from the
* {@code GameView}.
*
* @autor Alexeï Kadir, Lyanis Souidi, Hugo Dimitrijevic
* @version 1.0
*/
public interface GameListener {
/**
* Called when the user starts drawing a line.
*
* @param view The {@code GameView} that displays the game.
* @param start The {@code Cell} where the line starts.
*/
void onLineStarted(GameView view, Cell start);
/**
* Called when the user moves the end of the line being drawn.
*
* @param view The {@code GameView} that displays the game.
* @param end The {@code Cell} where the line ends.
*/
void onLineEndMoved(GameView view, Cell end);
/**
* Called when the user ends drawing a line.
*
* @param view The {@code GameView} that displays the game.
* @param end The {@code Cell} where the line ends.
*/
void onLineEnded(GameView view, Cell end);
}