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 teams; int N; int speed; int maxhp; int round; IGridStatus status; /** * Just a trivial constructor that will not do any initialization. */ public IGrid() { } /** * This is your main constructor for creating a grid. Parameters that you need to * support are listed below. * * @param N Specify the grid's dimension (NxN). * * @param speed Specify the rider's speed. This is an integer in the range of 0..10, * with 0 being the slowest and 10 the fastest. Low speed is useful for testing. * * @param maxhp Specify the riders' initial hit points. All riders have the same number * of initial hit points. * * @param round Specify the maximum number of scanning-rounds. The game ends when * this number is reached. * *

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(); teams = new LinkedList(); } /** * This is used to add a team to the grid. The team is assumed to already * contain all the riders belonging to the team. For each rider in the team * this method should assign to it a fresh instance of IRiderExecutor. Every * rider will have an attribute to hold a pointer to such an executor. * * @param t The team to add. * @return The team-number. This number is assigned your game engine. * *

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