diff --git a/Cow.java b/Cow.java index 5a11a43..658d665 100755 --- a/Cow.java +++ b/Cow.java @@ -107,17 +107,17 @@ return traits; } - public String rateCow(Cow c, String use) + public String rateCow(String use) { int rating = 0; if (use == "dairy") { - rating = rateDairyCow(c); + rating = rateDairyCow(); } else if (use == "plowing") { - rating = ratePlowCow(c); + rating = ratePlowCow(); } else if (use == "meat") { - rating = rateMeatCow(c); + rating = rateMeatCow(); } else { rating = 0; @@ -126,19 +126,19 @@ return "This is a "+rating2string(rating)+" cow for "+use+"."; } - private int rateDairyCow(Cow c) + private int rateDairyCow() { //TODO return 0; } - private int rateMeatCow(Cow c) + private int rateMeatCow() { //TODO return 0; } - private int ratePlowCow(Cow c) + private int ratePlowCow() { //TODO return 0; @@ -174,5 +174,10 @@ int randomfactor = Herd.random.nextInt(quartertrait*2) - quartertrait; return newtrait+randomfactor; } - + + public static void resetCounters() + { + idCounter = 1; + maxGen = 1; + } } diff --git a/Cow.java b/Cow.java index 5a11a43..658d665 100755 --- a/Cow.java +++ b/Cow.java @@ -107,17 +107,17 @@ return traits; } - public String rateCow(Cow c, String use) + public String rateCow(String use) { int rating = 0; if (use == "dairy") { - rating = rateDairyCow(c); + rating = rateDairyCow(); } else if (use == "plowing") { - rating = ratePlowCow(c); + rating = ratePlowCow(); } else if (use == "meat") { - rating = rateMeatCow(c); + rating = rateMeatCow(); } else { rating = 0; @@ -126,19 +126,19 @@ return "This is a "+rating2string(rating)+" cow for "+use+"."; } - private int rateDairyCow(Cow c) + private int rateDairyCow() { //TODO return 0; } - private int rateMeatCow(Cow c) + private int rateMeatCow() { //TODO return 0; } - private int ratePlowCow(Cow c) + private int ratePlowCow() { //TODO return 0; @@ -174,5 +174,10 @@ int randomfactor = Herd.random.nextInt(quartertrait*2) - quartertrait; return newtrait+randomfactor; } - + + public static void resetCounters() + { + idCounter = 1; + maxGen = 1; + } } diff --git a/Herd.java b/Herd.java index 16cf1f5..f0f91b6 100755 --- a/Herd.java +++ b/Herd.java @@ -194,5 +194,6 @@ public static void resetHerd() { singleton = null; + Cow.resetCounters(); } } diff --git a/Cow.java b/Cow.java index 5a11a43..658d665 100755 --- a/Cow.java +++ b/Cow.java @@ -107,17 +107,17 @@ return traits; } - public String rateCow(Cow c, String use) + public String rateCow(String use) { int rating = 0; if (use == "dairy") { - rating = rateDairyCow(c); + rating = rateDairyCow(); } else if (use == "plowing") { - rating = ratePlowCow(c); + rating = ratePlowCow(); } else if (use == "meat") { - rating = rateMeatCow(c); + rating = rateMeatCow(); } else { rating = 0; @@ -126,19 +126,19 @@ return "This is a "+rating2string(rating)+" cow for "+use+"."; } - private int rateDairyCow(Cow c) + private int rateDairyCow() { //TODO return 0; } - private int rateMeatCow(Cow c) + private int rateMeatCow() { //TODO return 0; } - private int ratePlowCow(Cow c) + private int ratePlowCow() { //TODO return 0; @@ -174,5 +174,10 @@ int randomfactor = Herd.random.nextInt(quartertrait*2) - quartertrait; return newtrait+randomfactor; } - + + public static void resetCounters() + { + idCounter = 1; + maxGen = 1; + } } diff --git a/Herd.java b/Herd.java index 16cf1f5..f0f91b6 100755 --- a/Herd.java +++ b/Herd.java @@ -194,5 +194,6 @@ public static void resetHerd() { singleton = null; + Cow.resetCounters(); } } diff --git a/MooBreeder.java b/MooBreeder.java index 756bb30..16beba3 100755 --- a/MooBreeder.java +++ b/MooBreeder.java @@ -17,9 +17,12 @@ import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; +import java.util.HashMap; public class MooBreeder extends JFrame implements MouseListener { + private String goal; //TODO implement goal picking + private JMenuBar menubar; private JMenu fileMenu, helpMenu; private JMenuItem save, load, reset, quit, help, about; @@ -28,6 +31,8 @@ private Box herdBox, motherBox, fatherBox, calf1Box, calf2Box; private JButton add, breed, keep, remove; + //TODO Insert the "breed" button! + private HelpWindow helpWindow; public static void main(String[] args) @@ -41,6 +46,7 @@ this.setTitle("MooBreeder"); this.setSize(800, 400); this.setDefaultCloseOperation(EXIT_ON_CLOSE); + goal = "dairy"; //FIXME helpWindow = new HelpWindow(); this.createMenu(); this.createLayout(); @@ -112,18 +118,18 @@ this.setLayout(new BoxLayout(this.getContentPane(), BoxLayout.X_AXIS)); //Create the left half of the window with the herd box JPanel herdBorderPanel = new JPanel(new BorderLayout()); - JLabel herdlabel = new JLabel("Your current herd:", JLabel.CENTER); - herdBorderPanel.add(herdlabel, BorderLayout.NORTH); herdBox = new Box(BoxLayout.Y_AXIS); herdScroller = new JScrollPane(herdBox, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); herdScroller.setWheelScrollingEnabled(true); herdBorderPanel.add(herdScroller, BorderLayout.CENTER); + herdBorderPanel.add(Box.createVerticalStrut(25), BorderLayout.NORTH); herdBorderPanel.add(Box.createVerticalStrut(25), BorderLayout.SOUTH); herdBorderPanel.add(Box.createHorizontalStrut(25), BorderLayout.EAST); herdBorderPanel.add(Box.createHorizontalStrut(25), BorderLayout.WEST); this.add(herdBorderPanel); //Create the right half of the window with the breeding interface + JPanel breedBorderPanel = new JPanel(new BorderLayout()); breedPanel = new JPanel(new GridLayout(2,2)); fatherBox = new Box(BoxLayout.Y_AXIS); motherBox = new Box(BoxLayout.Y_AXIS); @@ -133,7 +139,12 @@ breedPanel.add(motherBox); breedPanel.add(calf1Box); breedPanel.add(calf2Box); - this.add(breedPanel); + breedBorderPanel.add(breedPanel, BorderLayout.CENTER); + breedBorderPanel.add(Box.createVerticalStrut(25), BorderLayout.NORTH); + breedBorderPanel.add(Box.createVerticalStrut(25), BorderLayout.SOUTH); + breedBorderPanel.add(Box.createHorizontalStrut(25), BorderLayout.EAST); + breedBorderPanel.add(breedPanel); + this.add(breedBorderPanel); updateGUI(); } @@ -167,16 +178,12 @@ motherBox.add(ml); //Include information boxes Cow[] parents = Herd.getInstance().getParents(); - if (parents[0] != null) { - Box db = getCowBox(parents[0]); - fatherBox.add(Box.createVerticalStrut(10)); - fatherBox.add(db); - } - if (parents[1] != null) { - Box mb = getCowBox(parents[1]); - motherBox.add(Box.createVerticalStrut(10)); - motherBox.add(mb); - } + Box db = getCowBox(parents[0]); + fatherBox.add(Box.createVerticalStrut(10)); + fatherBox.add(db); + Box mb = getCowBox(parents[1]); + motherBox.add(Box.createVerticalStrut(10)); + motherBox.add(mb); fatherBox.validate(); motherBox.validate(); } @@ -192,16 +199,12 @@ calf2Box.add(l2); //Include information boxes Cow[] calves = Herd.getInstance().getCalves(); - if (calves[0] != null) { - Box db = getCowBox(calves[0]); - fatherBox.add(Box.createVerticalStrut(10)); - fatherBox.add(db); - } - if (calves[1] != null) { - Box mb = getCowBox(calves[1]); - motherBox.add(Box.createVerticalStrut(10)); - motherBox.add(mb); - } + Box c1b = getCowBox(calves[0]); + calf1Box.add(Box.createVerticalStrut(10)); + calf1Box.add(c1b); + Box c2b = getCowBox(calves[1]); + calf2Box.add(Box.createVerticalStrut(10)); + calf2Box.add(c2b); calf1Box.validate(); calf2Box.validate(); } @@ -215,21 +218,36 @@ private Box getCowBox(Cow c) { Box cowBox = new Box(BoxLayout.Y_AXIS); + cowBox.setBorder(new BevelBorder(BevelBorder.RAISED)); + cowBox.add(Box.createVerticalStrut(5)); + //If there is no cow here, display an empty panel + if (c == null) { + cowBox.add(new JLabel(" ", JLabel.CENTER)); + cowBox.add(Box.createVerticalStrut(5)); + return cowBox; + } + //Genealogy labels cowBox.setName(String.valueOf(c.getID())); JLabel name = new JLabel(c.getName()); JLabel genealogy = new JLabel("Generation "+c.getGeneration()+ - " Father "+c.getParents()[0]+ - " Mother "+c.getParents()[1]); - //TODO display cow traits and rating - //cowBox.add(Box.createGlue()); + ", Father: "+c.getParents()[0]+ + ", Mother: "+c.getParents()[1]); cowBox.add(name); cowBox.add(Box.createVerticalStrut(3)); - //cowBox.add(Box.createGlue()); cowBox.add(genealogy); - //TODO insert remaining labels - //cowBox.add(Box.createGlue()); + cowBox.add(Box.createVerticalStrut(3)); + //Trait and rating labels + HashMap t = c.getTraits(); + JLabel tl1 = new JLabel("Milk: "+t.get("milk")+" Meat: "+t.get("meat")); + JLabel tl2 = new JLabel("Strength: "+t.get("strength")+" Aggression: "+ + t.get("aggression")); + cowBox.add(tl1); + cowBox.add(tl2); + cowBox.add(Box.createVerticalStrut(3)); + JLabel rl = new JLabel(c.rateCow(goal)); + cowBox.add(rl); + //Final stuff cowBox.add(Box.createVerticalStrut(5)); - cowBox.setBorder(new BevelBorder(BevelBorder.RAISED)); cowBox.addMouseListener(this); return cowBox; } @@ -251,7 +269,6 @@ me.getClickCount() == 2) { mouseMainAction(selectionID); } - updateGUI(); } /* @@ -266,6 +283,7 @@ else if (Herd.getInstance().isCalf(selection)) Herd.getInstance().keepCalf(selection); else Herd.getInstance().setParent(selection); + updateGUI(); } /* @@ -317,18 +335,25 @@ contextMenu.add(item1); if (item2.getText() != "") contextMenu.add(item2); contextMenu.show(me.getComponent(), me.getX(), me.getY()); + updateGUI(); } @Override - public void mouseEntered(MouseEvent arg0) {} + public void mouseEntered(MouseEvent me) {} @Override - public void mouseExited(MouseEvent arg0) {} + public void mouseExited(MouseEvent me) {} @Override - public void mousePressed(MouseEvent arg0) {} + public void mousePressed(MouseEvent me) { + Box tile = (Box) me.getComponent(); + tile.setBorder(new BevelBorder(BevelBorder.LOWERED)); + } @Override - public void mouseReleased(MouseEvent arg0) {} + public void mouseReleased(MouseEvent me) { + Box tile = (Box) me.getComponent(); + tile.setBorder(new BevelBorder(BevelBorder.RAISED)); + } }