package Base; import java.util.HashMap; import java.util.LinkedList; import Shared.* ; /** * This class should hold your grid, and also contains a method that will * start the game. * *
You need to work out this class. Do not change the signature
* of the constructor and methods below..
*
*/
public class IGrid {
INodeStatus[][] grid;
LinkedList Implement this constructor
*/
public IGrid(int N, int speed, int maxhp, int round) {
this.N = N;
this.speed = speed;
this.maxhp = maxhp;
this.round = round;
status = new IGridStatus();
// Initialize the grid
grid = new INodeStatus[N][N];
for(int x = 0; x Implement this method
*/
public int addTeam(Team t) {
if(t==null)
throw new UnsupportedOperationException() ;
// Giving each rider their RiderExecutor
for(Rider r: t.riders){
r.ra = new YourRiderExecutor(this);
}
teams.add(t);
int teamID = teams.size();
this.placeRiders(teamID, t.riders);
// Updating IGridStatus
status.numOfRemainingRiders+=t.riders.length;
status.teamNames.put(teamID, t.name);
return teams.size();
}
/**
* This will start the game. This will start all riders that participate
* in the game, and also the game-daemon.
*
* Make it so that the game can only be started once.
* In other words, calling this method once, all subsequent calls to it
* will just do nothing.
*
* Implement this method
*/
public void start() {
//for(int i = 0; i<2000; i++)
this.startRiders();
}
/**
* Will start the run methods of the placed riders
*/
private void startRiders() {
for(Team team: teams)
for(Rider r: team.riders){
Thread t = new Thread(r);
t.start();
}
}
/**
* Will place a rider of each team on an unoccupied node
* @param riders
* @param teamID
*/
private void placeRiders(int teamID, Rider[] riders) {
for(Rider r: riders)
this.placeRider(teamID, r.ra.status());
}
/**
* Will place a single rider on an unoccupied node on the grid
* @param teamID
*/
public synchronized void placeRider(int teamID, IRiderStatus status) {
// TODO: Plaatst nu nog een rider op eerst gevonden vrije node, dit aanpasssen dus
for(int x = N/3-2 /*+ (int)(Math.random()*10)*/; x