...
I denne oppgaven skal spillogikken og (det innkapslede) rutenettet fra tidligere spill kobles til et ferdig skrevet grafisk brukergrensesnitt (GUI). Det samme GUI-et skal kunne fungere mot mange spill og realiseringsteknikker, og den beste måten å gjøre det på er å definere spesifikke grensesnitt som brukergrensesnittet kan forutsette er implementert. De ulike grensesnittene svarer til ulik type funksjonalitet som (må) finnes i rutenettbaserte spill for å kunne kobles til et GUI.
...
GridGame- og GridOutput-grensesnittene
GridProvider og GridListener er grensesnitt som fokuserer på tilstanden til rutenettet, men ikke på hvordan tilstanden endres eller den overordned gangen i spillet, f.eks. oppstart eller brukerens kommandoer.
PlantUML Macro |
---|
interface GridGame {
public void init(String level)
public void run(GameOutput output)
public Integer doCommand(String command)
public GridProvider getGridProvider()
public String getImageFor(Object o)
public Integer gridElementSelected(int x, int y)
}
interface GameOutput {
public void info(String message)
public void warning(String message)
public void error(String message)
}
class DittRutenettspill {
}
class GridGameImpl {
}
GridGame <|-- DittRutenettspill
DittRutenettspill --> GameOutput: gridOutput
GameOutput <|-- GridGameImpl
GridGameImpl --> GridGame: gridGame |
Code Block |
---|
language | java |
---|
title | GridGame- og GameOutput-grensesnittene |
---|
collapse | true |
---|
| public interface GridGame {
/**
* Loads and initializes the game to a (new) specified level. The String can be anything, e.g. a file name or a String encoding a level.
* Note that there should be no output at this point.
* @param level the String decribing a level, e.g. path or URL
*/
public void init(String level);
/**
* Start the game (that was just initialized with init) and use the argument for all game output
* @param output the object used for providing text-based output to the user (messages, warnings and errors)
*/
public void run(GameOutput output);
/**
* Perform a command (line). This method may update the underlying grid and provide output to the user using the GameOutput object given to.
* @param command
* @return
*/
public Integer doCommand(String command);
/**
* Returns the object that encapsulates the underlying grid.
* @return the object that encapsulates the underlying grid
*/
public GridProvider getGridProvider();
/**
* Returns the location (URL or file) of the image corresponding to the provided grid element
* @param o the object
* @return the location (URL or file) of the image corresponding to the provided grid element
*/
public String getImageFor(Object o);
/**
* Perform an action corresponding to selecting a grid element. This method may update the underlying grid and provide output to the user using the GameOutput object given to.
* @param command
* @return
*/
public Integer gridElementSelected(int x, int y);
}
public interface GameOutput {
/**
* Outputs a message to user, e.g. a status update.
* @param message the message
*/
public void info(String message);
/**
* Outputs a message to user, with a style indicating it is a warning.
* @param message the warning message
*/
public void warning(String message);
/**
* Outputs a message to user, with a style indicating it is an error.
* @param message the error message
*/
public void error(String message);
} |
| Det er GUI-et som lager en instans av spillklassen og styrer oppstart og utvikling av spillet, dvs. laster inn et nytt nivå eller bra, setter spillet igang og driver det fremover ved å ta imot input fra brukeren og videreformidle det til spillet. |
...