## Major creative work Your major creative work is worth 60% of your unit total and is made up of four components: * Milestone 1: 8% * Milestone 2: 10% * __Milestone 3: 12%__ * Viva Exam: 30% ##...

1 answer below »
Need help with some coding assigment


## Major creative work Your major creative work is worth 60% of your unit total and is made up of four components: * Milestone 1: 8% * Milestone 2: 10% * __Milestone 3: 12%__ * Viva Exam: 30% ## Milestone 3 ### Note: due date is Monday 25th of October 2021, at 10:00am (Week 12) ### Note: some edits to provide clarity ### Milestone 2 solution ### Milestone 3 preparation You will need to start from the code published in the ["milestone3" branch of the github repository](https://github.com/mq-soft-tech/COMP2000_2021/tree/milestone3/). **Do not** use the code that you submit for milestone2. Your game has gone out for testing and the unanimous response from testers was that the turn-taking was frustrating. The testers have suggested the following alternative model for turn-taking: * An Actor can make a move up to once every two seconds. * Once the Actor moves, their colour gradually changes to a different hue to indicate how long until their next move. * If you are unable to implement a gradual colour change, you can choose to change the colour in a single step but you will receive less marks. * Blue Actors change to green immediately after moving, and transition to blue. * Red Actors change to yellow immediately after moving, and transition to red. * In the following two seconds, all the other characters make their moves "in parallel". Actors still have a variable number of moves, those moves are made in the time available (i.e. faster if there are more moves to be made). * One that two seconds is up, the Actor is able to move again and their colour changes back to normal * The game waits for the (human) player to make their move. **Note**: the key points that you will be assessed on with the new gameplay are that you've used Threads for your Actors, that your code is thread-safe, and that the colour transitions are graduated. Of course, nothing really runs in parallel in a computer, you will need to use multithreading of some variety to make this work. How hard this is to implement will depend almost entirely on the design you choose so we recommend you spend a significant amount of time investigating possible designs. For this reason, 25% of the marks available are set aside for the quality of your discussion. Note, bad designs with good discussions will still get high marks, full marks are reserved for those who discuss not only their actual solution but at least one other possible design as well. In addition to the above, your starting code includes new actor type Rogue provided in a jar file (hence no source code), there seems to be a randomly occurring bug with this code that causes the whole game to freeze. ## Tasks * Make a change so that the game no longer randomly freezes whenever a Rogue moves. * You will need to explicitly choose concurrency patterns in order to implement the new style of game play. * 25% of the available marks are set aside for your explanation of which concurrency pattern you have used, why you have chosen it, and how it works in context (global lock, latch, pool, monitor, fork/join, read/write lock, re-entrant lock, atomics, etc). ## Marking * (10 marks) `Bug.md` which contains your explanations of what causes the `Rogue` bug. * (10 marks) Implement a fix for the `Rogue` bug. * (10 marks) `Rogue.md` which contains a description of your solution to the `Rogue` bug. * (25 marks) Implement the new game play functionality using whatever approach you think is best. * (25 marks) `Threading.md` which contains an explanation of your solution. Your explanation should include; why you chose that solution, and any problems you encountered in your solution. * (20 marks) The remaining marks are for improving the game in some creative way. Implement your changes and write a report explaining all the interesting things you implemented. Include this report in a file called `Improvements.md`. **Note:** all the `.md` files should include a description of where in the source files you have made changes, additions, corrections, or deletions so that your marker can find your implementation changes easily. Failure to include this information will incur a penalty for each relevant marking item. ## Submission You must submit a zipped VSCode project. Your marker will download your zip file, open it in VSCode and run it from there. Please don't submit unnecessary temporary files (such as class files) in your zip file. (note that rar files will not be accepted). Your submission file should be named with your student number **only**, and *strictly* follow the following structure (in this example, substitute your student number in place of 43215678): ``` 43215678 | Bug.md | Rogue.md | Threading.md | Improvements.md +-- data | | stage1.rvb | | stage2.rvb | | ... | | stage4.rvb | +-- doc | | milestone3.md | | ... | | style.md | +-- src | Actor.java | Cell.java | ... | Water.java ``` Your zip file should not contain any `.class` files, `.git` directories, `.vscode` directories, or anything else apart from `.java`, `.md`, and`.rvb` files, and any resource *required* to compile and run your program (eg. `rogue.jar` and `full_pack_2025.ttf`). Failure to follow these requirements may result in your submission not being accepted. **Note:** some zip utilities, such as the Microsoft Windows desktop will refuse to add some file types such as fonts and executables into a zip file. If that happens don't worry, your marker will put a copy of the relevant file into place when marking your submission.
Answered 4 days AfterOct 19, 2021

Answer To: ## Major creative work Your major creative work is worth 60% of your unit total and is made up of...

Swapnil answered on Oct 24 2021
119 Votes
94461/Code/Actor.java
94461/Code/Actor.java
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Polygon;
import java.util.List;
import java.util.function.Predicate;
abstract class Actor 
{
  protected Cell location;
  protected float rdns;
  protected int iTrns;
  protected int tr;
  protected int m;
  protected int r;
  protected MoveStrategy s;
  protected List d;
  protected Predicate filter;
  protected ColorMixer color;
  public Actor(Cell inLocation, float inrdns, int inTurns, int inMoves, int inRange) 
  {
    setLocation(inLocation);
    rdns = inrdns;
    iTrns = inTurns;
    tr = iTrns;
    m = inMoves;
    r = inRange;
    s = new RandomMove();
    color = new ColorMixer();
    color.setHue((1.0f - rdns) * ColorMixer.BLUE);
  }
  void paint(Graphics g) 
  {
    for (Polygon p : d) 
    {
      g.setColor(color.mix(rdns));
      g.fillPolygon(p);
      g.setColor(Color.GRAY);
      g.drawPolygon(p);
    }
  }
  protected abstract void setPoly();
  boolean isTeamRed() 
  {
    return rdns >= 0.5;
  }
  void setLocation(Cell inLocation) 
  {
    location = inLocation;
    setPoly();
  }
  void makeRedder(float amt) 
  {
    rdns = rdns + amt;
    if (rdns > 1.0f) 
    {
      rdns = 1.0f;
    }
  }
  public Cell location() 
  {
    return location;
  }
  public MoveStrategy strategy() 
  {
    return s;
  }
  public float getrdns() 
  {
    return rdns;
  }
  public int turnsLeft() 
  {
    return tr;
  }
  public int maxTurns() 
  {
    return iTrns;
  }
  public void resetTurns() 
  {
    tr = iTrns;
  }
  public void turnTaken() 
  {
    tr--;
  }
  public int getMoves() 
  {
    return m;
  }
  public int getRange() 
  {
    return r;
  }
  public String toString() 
  {
    return this.getClass().getName().toString();
  }
}
94461/Code/ActorInfo.java
94461/Code/ActorInfo.java
import java.awt.Graphics;
import java.awt.Point;
public class ActorInfo extends InfoPanel 
{
  Stage stg;
  public 
ActorInfo(Stage stg) 
  {
    this.stg = stg;
  }
  @Override
  public void paint(Graphics g, int yloc, Point mouseLoc) 
  {
    final int lIndent = mrgn + hTab;
    final int mvIndent = mrgn + 3 * blockVtab;
    yloc = yloc + 2 * blockVtab;
    for (int i = 0; i < stg.actors.size(); i++) 
    {
      Actor a = stg.actors.get(i);
      yloc = yloc + 2 * blockVtab;
      g.drawString(a.toString(), mrgn, yloc);
      g.drawString("location:", lIndent, yloc + vTab);
      String crdnt = Character.toString(a.location().col) + Integer.toString(a.location().row);
      g.drawString(crdnt, mvIndent, yloc + vTab);
      g.drawString("redness:", lIndent, yloc + 2 * vTab);
      g.drawString(String.format("%.1f", a.getRedness()), mvIndent, yloc + 2 * vTab);
    }
  }
}
94461/Code/AnimationBeat.java
94461/Code/AnimationBeat.java
public class AnimationBeat 
{
  private long strtd;
  private long pA; 
  private long pB; 
  private long pC; 
  private static AnimationBeat instnc;
  private AnimationBeat() 
  {
    strtd = System.cTmMillis();
    pA = 5000;
    pB = 500;
    pC = 500;
  }
  static AnimationBeat getInstance() 
  {
    if (instnc == null) 
    {
      instnc = new AnimationBeat();
    }
    return instnc;
  }
  char inPhase() 
  {
    long cTime = System.cTmMillis();
    long rem = (cTime - strtd) % (pA + pB + pC);
    if (rem > pA + pB) 
    {
      return 'c';
    } 
    else if (rem > pA) 
    {
      return 'b';
    } 
    else 
    {
      return 'a';
    }
  }
  long phaseCompletion() 
  { 
    long cTime = System.cTmMillis();
    long rem = (cTime - strtd) % (pA + pB + pC);
    if (rem > pA + pB) 
    {
      return ((rem - pA - pB) * 100) / pC;
    } 
    else if (rem > pA) 
    {
      return ((rem - pA) * 100) / pB;
    } 
    else 
    {
      return rem * 100 / pA;
    }
  }
}
94461/Code/Boat.java
94461/Code/Boat.java
import java.awt.Polygon;
import java.util.ArrayList;
class Boat extends Actor 
{
  public Boat(Cell inLoc, float inRdns) 
  {
    super(inLoc, inRdns, 3, 1, 4);
    fltr = (Cell c) -> 
    { 
      return ! Water.class.isInstance(c); 
    };
    setPoly();
  }
  protected void setPoly() 
  {
    dsply = new ArrayList();
    Polygon lSail = new Polygon();
    lSail.adPoint(lctn().x + 16, lctn().y + 11);
    lSail.adPoint(lctn().x + 11, lctn().y + 24);
    lSail.adPoint(lctn().x + 16, lctn().y + 24);
    Polygon rSail = new Polygon();
    rSail.adPoint(lctn().x + 18, lctn().y + 7);
    rSail.adPoint(lctn().x + 24, lctn().y + 24);
    rSail.adPoint(lctn().x + 18, lctn().y + 24);
    Polygon body = new Polygon();
    body.adPoint(lctn().x + 6, lctn().y + 24);
    body.adPoint(lctn().x + 29, lctn().y + 24);
    body.adPoint(lctn().x + 24, lctn().y + 29);
    body.adPoint(lctn().x + 11, lctn().y + 29);
    dsply.add(lSail);
    dsply.add(rSail);
    dsply.add(body);
  }
}
94461/Code/Building.java
94461/Code/Building.java
import java.awt.Color;
class Building extends Cell 
{
  public Building(char col, int r, int a, int b) 
  {
    super(col, r, a, b);
    d = "Building";
    clr = new Color(96, 64, 32);
  }
}
94461/Code/Car.java
94461/Code/Car.java
import java.awt.Polygon;
import java.util.ArrayList;
class Car extends Actor 
{
  public Car(Cell inLoc, float inRdns) 
  {
    super(inLoc, inRdns, 1, 1, 3);
    filter = (Cell c) -> { return ! Road.class.isInstance(c); };
    setPoly();
  }
  protected void setPoly() 
  {
    dsply = new ArrayList();
    int sides = 20;
    int angl;
    double cX;
    double cY;
    Polygon rWheel = new Polygon();
    Polygon fWheel = new Polygon();
    angl = 360 / sides;
    for (int s = 0; s <= sides; s++) 
    {
      cX = (4.0 * Math.sin(Math.toRadians(s * angl)));
      cY = (4.0 * Math.cos(Math.toRadians(s * angl)));
      rWheel.adPoint(lctn().x + 11 + (int) cX, lctn().y + 25 + (int) cY);
      fWheel.adPoint(lctn().x + 24 + (int) cX, lctn().y + 25 + (int) cY);
    }
    Polygon body = new Polygon();
    body.adPoint(lctn().x + 6, lctn().y + 14);
    body.adPoint(lctn().x + 29, lctn().y + 14);
    body.adPoint(lctn().x + 29, lctn().y + 20);
    body.adPoint(lctn().x + 6, lctn().y + 20);
    Polygon top = new Polygon();
    top.adPoint(lctn().x + 11, lctn().y + 7);
    top.adPoint(lctn().x + 20, lctn().y + 7);
    top.adPoint(lctn().x + 24, lctn().y + 14);
    top.adPoint(lctn().x + 11, lctn().y + 14);
    dsply.add(rWheel);
    dsply.add(fWheel);
    dsply.add(body);
    dsply.add(top);
  }
}
94461/Code/Cell.java
94461/Code/Cell.java
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
class Cell extends Rectangle 
{
  private static int s = 35;
  protected char c;
  protected int r;
  protected Color c;
  protected String dsptn;
  public Cell(char inC, int inR, int inX, int inY) 
  {
    super(inX, inY, s, s);
    c = inC;
    r = inR;
  }
  void paint(Graphics g, Point mousePos) 
  {
    if (contains(mousePos)) 
    {
      g.setColor(Color.GRAY);
    } 
    else 
    {
      g.setColor(c);
    }
    g.fillRect(x, y, s, s);
    g.setColor(Color.BLACK);
    g.drawRect(x, y, s, s);
  }
  @Override
  public boolean contains(Point p) 
  {
    if (p != null) 
    {
      return (super.contains(p));
    } 
    else 
    {
      return false;
    }
  }
  public int leftOfComparison(Cell c) 
  {
    return Character.compare(c, c.c);
  }
  public int aboveComparison(Cell c) 
  {
    return Integer.compare(r, c.r);
  }
  public String toString() 
  {
    return Character.toString(c) + Integer.toString(r) + ":" + dsptn;
  }
}
94461/Code/CellIterator.java
94461/Code/CellIterator.java
import java.util.Iterator;
public class CellIterator implements Iterator 
{
  Cell[][] d;
  int otr;
  int inr;
  boolean rOt;
  CellIterator(Cell[][] d) 
  {
    this.d = d;
    otr = 0;
    inr = 0;
    rOt = false;
  }
  @Override
  public boolean hasNext() 
  {
    return !rOt;
  }
  @Override
  public Cell next() 
  {
    Cell ret = d[otr][inr];
    inr++;
    if (inr >= d[otr].length) 
    {
      inr = 0;
      otr++;
      if (otr >= d.length) 
      {
        rOt = true;
      }
    }
    return ret;
  }
}
94461/Code/ChoosingActor.java
94461/Code/ChoosingActor.java
import java.awt.Graphics;
import java.util.Optional;
public class ChoosingActor implements GameState 
{
  @Override
  public void mouseClick(int x, int y, Stage s) 
  {
    s.aInActn = Optional.empty();
    for (Actor a : s.actrs) 
    {
      if (a.location().contains(x, y) && a.isTeamRed() && a.turnsLeft() > 0) 
      {
        s.cOvrlay = s.grid.getRadius(a.location(), a.getMoves(), true);
        s.cOvrlay.removeIf(a.filter);
        s.aInActn = Optional.of(a);
        s.cSt = new SelectingNewLocation();
      }
    }
    if (s.aInActn.isEmpty()) 
    {
      s.cSt = new SelectingMenuItem();
      s.mOvrlay.add(new MenuItem("Oops", x, y,
          () -> s.cSt = new ChoosingActor()));
      s.mOvrlay.add(new MenuItem("End Turn", x, y + MenuItem.h,
          () -> s.cSt = new CPUMoving()));
      s.mOvrlay.add(new MenuItem("End Game", x, y + MenuItem.h * 2,
          () -> System.exit(0)));
    }
  }
  @Override
  public void paint(Graphics g, Stage s) {}
  @Override
  public String toString() 
  {
    return getClass().getSimpleName();
  }
}
94461/Code/ColorMixer.java
94461/Code/ColorMixer.java
import java.awt.Color;
public class ColorMixer 
{
  public static final float RED = 0 * 60;
  public static final float YELLOW = 1 * 60;
  public static final float GREEN = 2 * 60;
  public static final float CYAN = 3 * 60;
  public static final float BLUE = 4 * 60;
  public static final float MAGENTA = 5 * 60;
  protected float h;
  protected float intsty;
  protected float brgtns;
  public ColorMixer() 
  {
    intsty = 1.0f;
    brgtns = 1.0f;
  }
  public Color mix(float val) 
  {
    float tint = (val * (RED - BLUE + 360.0f) + BLUE) / 360.0f;
    return Color.getHSBColor(tint, intsty, brgtns);
  }
  public void setH(float newH) 
  {
    h = newH;
  }
  public void setIntsty(float newIntsty) 
  {
    intsty = newIntsty;
  }
  public void setBrgtns(float newBrgtns) 
  {
    brgtns = newBrgtns;
  }
}
94461/Code/CPUMoving.java
94461/Code/CPUMoving.java
import java.awt.Graphics;
import java.util.List;
public class CPUMoving implements GameState 
{
  @Override
  public void mouseClick(int x, int y, Stage s) {}
  @Override
  public void paint(Graphics g, Stage s) 
  {
    for (Actor a: s.actors) 
    {
      if (! a.isTeamRed()) 
      {
        List pLocs = s.getClearRadius(a.location(), a.getMoves(), true);
        pLocs.removeIf(a.filter);
        Cell nLoc = a.strategy().chooseNLoc(a.location(), pLocs);
        a.setLocation(nLoc);
      }
    }
    s.currentState = new ChoosingActor();
    for (Actor a: s.actors) 
    {
      a.resetTurns();
    }
  }
  @Override
  public String toString() 
  {
    return getClass().getSimpleName();
  }
}
94461/Code/GameState.java
94461/Code/GameState.java
import java.awt.Graphics;
public interface GameState 
{
  public void mouseClick(int x, int y, Stage s);
  public void paint(Graphics g, Stage s);
}
94461/Code/Grass.java
94461/Code/Grass.java
import java.awt.Color;
class Grass extends Landscape 
{
  public Grass(char c, int r, int a, int b, int c) 
  {
    super(c, r, x, y, z);
    dscrptn = "Grass";
    clr = Color.getHSBColor(120.0f / 360.0f, 1.0f - shade, 0.35f + 0.65f * shade);
  }
}
94461/Code/Grid.java
94461/Code/Grid.java
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Random;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
class Grid implements Iterable 
{
  Cell[][] c = new Cell[20][20];
  private static Random rand = new Random();
  public Grid() 
  {
    int elvtn;
    List dstbtn = new ArrayList();
    dstbtn = IntStream.rangeClosed(0, 20 * 20 - 1).boxed().collect(Collectors.toList());
    int crnt;
    int index;
    for (int i = 0; i < c.length; i++) 
    {
      for (int j = 0; j < c[i].length; j++) 
      {
        elvtn = rand.nextInt(8001) - 2000;
        index = rand.nextInt(dstbtn.s());
        crnt = dstbtn.get(index);
        dstbtn.remove(index);
        char c = colToLabel(i);
        int x = 10 + 35 * i;
        int y = 10 + 35 * j;
        if (crnt < 40) 
        {
          c[i][j] = new Track(c, j, x, y, elvtn);
        }
        if (crnt >= 40 && crnt < 120) 
        {
          c[i][j] = new Water(c, j, x, y, elvtn);
        }
        if (crnt >= 120 && crnt < 280) 
        {
          c[i][j] = new Grass(c, j, x, y, elvtn);
        }
        if (crnt >= 280 && crnt < 380) 
        {
          c[i][j] = new Mountain(c, j, x, y, elvtn);
        }
        if (crnt >= 380 && crnt < 400) 
        {
          c[i][j] = new Building(c, j, x, y);
        }
      }
    }
  }
  private char colToLabel(int col) 
  {
    return (char) (col + 65);
  }
  private int labelToCol(char col) 
  {
    return (int) col - 65;
  }
  public void paint(Graphics g, Point mPos) 
  {
    doToEachCell((Cell c) -> c.paint(g, mPos));
  }
  private Optional cAtColRow(int c, int r) 
  {
    if (c >= 0 && c < c.length && r >= 0 && r < c[c].length) 
    {
      return Optional.of(c[c][r]);
    } 
    else 
    {
      return Optional.empty();
    }
  }
  public Optional cAtColRow(char c, int r) 
  {
    return cAtColRow(labelToCol(c), r);
  }
  public Optional cellAtPoint(Point p) 
  {
    for (int i = 0; i < c.length; i++) 
    {
      for (int j = 0; j < c[i].length; j++) 
      {
        if (c[i][j].contains(p)) 
        {
          return Optional.of(c[i][j]);
        }
      }
    }
    return Optional.empty();
  }
  public List cInRange(char c1, int r1, char c2, int r2) 
  {
    int c1i = labelToCol(c1);
    int c2i = labelToCol(c2);
    List output = new ArrayList();
    for (int i = c1i; i <= c2i; i++) 
    {
      for (int j = r1; j <= r2; j++) 
      {
        cAtColRow(colToLabel(i), j).ifPrsnt(output::add);
      }
    }
    return output;
  }
  public void replaceCell(Cell old, Cell replacement) 
  {
    c[labelToCol(old.col)][old.row] = replacement;
  }
  public void doToEachCell(Consumer func) 
  {
    for (int i = 0; i < c.length; i++) 
    {
      for (int j = 0; j < c[i].length; j++) 
      {
        func.accept(c[i][j]);
      }
    }
  }
  public void paintOverlay(Graphics g, List c, Color color) 
  {
    g.setColor(color);
    for (Cell c : c) 
    {
      g.fillRect(c.x + 2, c.y + 2, c.width - 4, c.height - 4);
    }
  }
  public List getRadius(Cell from, int s, boolean cnsdrElvtn) 
  {
    int i = labelToCol(from.col);
    int j = from.row;
    Set inRds = new HashSet();
    if (s > 0) 
    {
      cAtColRow(colToLabel(i), j - 1).ifPrsnt(inRds::add);
      cAtColRow(colToLabel(i), j + 1).ifPrsnt(inRds::add);
      cAtColRow(colToLabel(i - 1), j).ifPrsnt(inRds::add);
      cAtColRow(colToLabel(i + 1), j).ifPrsnt(inRds::add);
    }
    for (Cell c : inRds.toArray(new Cell[0])) 
    {
      if (from instanceof Building) 
      {
        cnsdrElvtn = false;
      }
      if (cnsdrElvtn) 
      {
        if (c instanceof Landscape) 
        {
          Landscape here = (Landscape) from;
          Landscape there = (Landscape) c;
          if (here.elvtn() > there.elvtn()) 
          {
            inRds.addAll(getRadius(c, s, true));
          } 
          else 
          {
            inRds.addAll(getRadius(c, s - 1, true));
          }
        } 
        else 
        {
          inRds.remove(c);
        }
      } 
      else 
      {
        inRds.addAll(getRadius(c, s - 1, false));
      }
    }
    return new ArrayList(inRds);
  }
  @Override
  public CellIterator iterator() 
  {
    return new CellIterator(c);
  }
  public String toString() 
  {
    String retval = new String();
    for (int i = 0; i < c.length; i++) 
    {
      for (int j = 0; j < c[i].length; j++) 
      {
        retval = retval + c[i][j];
      }
    }
    return retval;
  }
}
94461/Code/InfoPanel.java
94461/Code/InfoPanel.java
import java.awt.Graphics;
import java.awt.Point;
public abstract class InfoPanel 
{
  final int hTab = 10;
  final int vTab = 15;
  final int blockVtab = 35;
  final int mrgn = 21 * blockVtab;
  public void add(InfoPanel panel) 
  {
  }
  public void remove(InfoPanel panel) 
  {
  }
  public InfoPanel getChild(int i) 
  {
    return null;
  }
  public void paint(Graphics g, int yloc, Point mouseLoc) {}
}
94461/Code/Landscape.java
94461/Code/Landscape.java
abstract class Landscape extends Cell 
{
  protected int h;
  protected float shd;
  public Landscape(char c, int r, int a, int b, int c) 
  {
    super(c, r, a, b);
    if (c < -2000) 
    {
      c = -2000;
    }
    if (c > 8000) 
    {
      c = 8000;
    }
    h = c;
    shd = ((float) h + 2000) / 10000; 
  }
  public int elevation() 
  {
    return h;
  }
}
94461/Code/LeftMostMove.java
94461/Code/LeftMostMove.java
import java.util.List;
class LeftMostMove implements MoveStrategy 
{
  @Override
  public Cell chooseNextLoc(Cell cLoc, List psblLocs) 
  {
    Cell cLftMst;
    if (psblLocs.size() > 0) 
    {
      cLftMst = psblLocs.get(0);
      for (Cell c : psblLocs) 
      {
        if (c.leftOfComparison(cLftMst) < 0) 
        {
          cLftMst = c;
        }
      }
    } 
    else
    {
      cLftMst = cLoc;
    }
    return cLftMst;
  }
  public String toString() 
  {
    return "left-most movement strategy";
  }
}
94461/Code/Main.java
94461/Code/Main.java
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GraphicsEnvironment;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.time.Duration;
import java.time.Instant;
import javax.swing.JFrame;
import javax.swing.JPanel;
class Main extends JFrame 

  class App extends JPanel implements MouseListener 
  {
    Stage stg;
    boolean stgBuilt = false;
    public App() 
    {
      setPreferredSize(new Dimension(1024, 720));
      this.addMouseListener(this);
      stg = StageReader.readStage(3);
      stgBuilt = true;
    }
    @Override
    public void paint(Graphics g) 
    {
      if (stgBuilt && isVisible()) 
      {
        stg.paint(g, getMousePosition());
      }
    }
    @Override
    public void mouseClicked(MouseEvent e) 
    {
      stg.mouseClicked(e.getX(), e.getY());
    }
    @Override
    public void mousePressed(MouseEvent e) 
    {
    }
    @Override
    public void mouseReleased(MouseEvent e)
    {
    }
    @Override
    public void mouseEntered(MouseEvent e) 
    {
    }
    @Override
    public void mouseExited(MouseEvent e) 
    {
    }
  }
  public static void main(String[] args) throws Exception 
  {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    File fp2025 = new File("data/full_pack_2025.ttf");
    ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, fp2025));
    Main wnd = new Main();
    wnd.run();
  }
  private Main() 
  {
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    App canvas = new App();
    this.setContentPane(canvas);
    this.pack();
    this.setVisible(true);
  }
  public void run() 
  {
    while (true) 
    {
      Instant sTime = Instant.now();
      this.repaint();
      Instant eTime = Instant.now();
      long howLong = Duration.between(sTime, eTime).toMillis();
      try 
      {
        Thread.sleep(20L - howLong);
      } 
      catch (InterruptedException e) 
      {
        System.out.println("thread was interrupted, but who cares?");
      } 
      catch (IllegalArgumentException e) 
      {
        System.out.println("application can't keep up with fra...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here