Package student.micro.battleship
Class Game
java.lang.Object
greenfoot.World
student.micro.World
student.micro.battleship.Game
public abstract class Game
extends student.micro.World
The playing area of a "Battleship" game, consisting of two boards for
the two players.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidact()Plays one turn in the current game.abstract BattleshipStrategyCreate a strategy object representing your player strategy.abstract BattleshipStrategyCreate a strategy object representing your opponent's strategy.voidPlay one game between my strategy and the opponent's strategy, indicating which strategy won at the end.voidplayNDeviousGames(int n) Play a series of N games between my strategy and the opponent's strategy, indicating at the end how many of the games each strategy won.voidplayNStandardGames(int n) Play a series of N games between my strategy and the opponent's strategy, indicating at the end how many of the games each strategy won.voidPlay one game between my strategy and the opponent's strategy, indicating which strategy won at the end.Methods inherited from class student.micro.World
countObjects, countObjectsAt, getActSet, getOneObject, getOneObjectAt, getSpeed, hasObject, hasObjectAt, removeObject, setActOrder, setSpeed, start, stop, stop, switchDisplayedWorldToMethods inherited from class greenfoot.World
addObject, getBackground, getCellSize, getColorAt, getHeight, getObjects, getObjectsAt, getWidth, numberOfObjects, removeObjects, repaint, setBackground, setBackground, setPaintOrder, showText, started, stopped
-
Constructor Details
-
Game
public Game()Create a new game.
-
-
Method Details
-
createMyStrategy
Create a strategy object representing your player strategy.- Returns:
- The strategy I want to use in this game.
-
createOpponentsStrategy
Create a strategy object representing your opponent's strategy.- Returns:
- The strategy my opponent will use in this game.
-
playStandardGame
public void playStandardGame()Play one game between my strategy and the opponent's strategy, indicating which strategy won at the end. The game follows "standard" rules, meaning ships are only positioned once, before play starts. Note that the game is played completely unassisted--you just sit back and watch your strategy compete, and wait for the outcome. You can use Greenfoot4Sofia's speed slider to control the speed at which the game is played. This method behaves the same as pressing the "Run" button. -
playNStandardGames
public void playNStandardGames(int n) Play a series of N games between my strategy and the opponent's strategy, indicating at the end how many of the games each strategy won. The game follows "standard" rules, meaning ships are only positioned once per game, just before that game starts.- Parameters:
n- The number of games to play.
-
playDeviousGame
public void playDeviousGame()Play one game between my strategy and the opponent's strategy, indicating which strategy won at the end. The game follows "devious" rules, meaning that strategies that wish to reposition their ships will have an opportunity to do so at the start of each turn. Note that the game is played completely unassisted--you just sit back and watch your strategy compete, and wait for the outcome. You can use Greenfoot4Sofia's speed slider to control the speed at which the game is played. This method behaves the same as pressing the "Run" button. -
playNDeviousGames
public void playNDeviousGames(int n) Play a series of N games between my strategy and the opponent's strategy, indicating at the end how many of the games each strategy won. The game follows "devious" rules, meaning that strategies that wish to reposition their ships will have an opportunity to do so at the start of each turn of each game.- Parameters:
n- The number of games to play.
-
act
public void act()Plays one turn in the current game.- Overrides:
actin classgreenfoot.World
-