diff --git a/Cow.java b/Cow.java index db55ca3..0215ede 100755 --- a/Cow.java +++ b/Cow.java @@ -114,7 +114,7 @@ String trait = ""; if (use == "dairy") trait = "milk"; else if (use == "plowing") trait = "strength"; - else if (use == "meat") trait = "meat"; + else if (use == "beef") trait = "meat"; else System.out.println("ERROR No such use: "+use); rating = (traits.get(trait)*2) - (int) (Math.pow(traits.get("aggression"),2)); return "This is a "+rating2string(rating)+" cow for "+use+"."; diff --git a/Cow.java b/Cow.java index db55ca3..0215ede 100755 --- a/Cow.java +++ b/Cow.java @@ -114,7 +114,7 @@ String trait = ""; if (use == "dairy") trait = "milk"; else if (use == "plowing") trait = "strength"; - else if (use == "meat") trait = "meat"; + else if (use == "beef") trait = "meat"; else System.out.println("ERROR No such use: "+use); rating = (traits.get(trait)*2) - (int) (Math.pow(traits.get("aggression"),2)); return "This is a "+rating2string(rating)+" cow for "+use+"."; diff --git a/Herd.java b/Herd.java index 7234325..eaa754f 100755 --- a/Herd.java +++ b/Herd.java @@ -35,6 +35,8 @@ if ((i % 2) == 0) sex = "male"; herd.add(new Cow(sex)); } + setParent(1); //XXX A layout hack + setParent(2); } public static Herd getInstance() diff --git a/Cow.java b/Cow.java index db55ca3..0215ede 100755 --- a/Cow.java +++ b/Cow.java @@ -114,7 +114,7 @@ String trait = ""; if (use == "dairy") trait = "milk"; else if (use == "plowing") trait = "strength"; - else if (use == "meat") trait = "meat"; + else if (use == "beef") trait = "meat"; else System.out.println("ERROR No such use: "+use); rating = (traits.get(trait)*2) - (int) (Math.pow(traits.get("aggression"),2)); return "This is a "+rating2string(rating)+" cow for "+use+"."; diff --git a/Herd.java b/Herd.java index 7234325..eaa754f 100755 --- a/Herd.java +++ b/Herd.java @@ -35,6 +35,8 @@ if ((i % 2) == 0) sex = "male"; herd.add(new Cow(sex)); } + setParent(1); //XXX A layout hack + setParent(2); } public static Herd getInstance() diff --git a/MooBreeder.java b/MooBreeder.java index c823a5f..5c23685 100755 --- a/MooBreeder.java +++ b/MooBreeder.java @@ -27,15 +27,13 @@ private JMenuBar menubar; private JMenu fileMenu, helpMenu; - private JMenuItem save, load, reset, quit, help, about; + private JMenuItem select, save, load, reset, quit, help, about; private JPanel breedPanel; private JScrollPane herdScroller; private Box herdBox, motherBox, fatherBox, calf1Box, calf2Box; private JButton breedButton; private JFileChooser fileChooser; - //TODO Insert the "breed" button! - private HelpWindow helpWindow; public static void main(String[] args) @@ -47,17 +45,17 @@ public MooBreeder() { this.setTitle("MooBreeder"); - this.setSize(800, 400); //FIXME Adjust width and spacing + this.setSize(900, 450); this.setDefaultCloseOperation(EXIT_ON_CLOSE); - goal = "dairy"; //FIXME + goal = "dairy"; helpWindow = new HelpWindow(); fileChooser = new JFileChooser(System.getProperty("user.dir")); FileFilter datFilter = new FileNameExtensionFilter("MooBreeder (.dat) files", "dat"); fileChooser.setFileFilter(datFilter); this.createMenu(); this.createLayout(); - //TODO this.setVisible(true); + chooseGoal(); } private void createMenu() @@ -65,12 +63,18 @@ menubar = new JMenuBar(); fileMenu = new JMenu("File"); helpMenu = new JMenu("Help"); + select = new JMenuItem("Select a goal"); save = new JMenuItem("Save"); load = new JMenuItem("Load"); reset = new JMenuItem("Reset"); quit = new JMenuItem("Quit"); help = new JMenuItem("Help"); about = new JMenuItem("About"); + select.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + chooseGoal(); + } + }); save.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int saveConfirm = fileChooser.showSaveDialog(null); @@ -134,9 +138,12 @@ "About", JOptionPane.INFORMATION_MESSAGE); } }); + fileMenu.add(select); fileMenu.add(save); + fileMenu.add(new JSeparator()); fileMenu.add(load); fileMenu.add(reset); + fileMenu.add(new JSeparator()); fileMenu.add(quit); helpMenu.add(help); helpMenu.add(about); @@ -197,14 +204,18 @@ updateHerdBox(); updateParentBox(); updateOffspringBox(); + //this.validate(); this.repaint(); } private void updateHerdBox() { + //TODO It should be possible to choose just bulls or cows herdBox.removeAll(); for (int c = 0; c < Herd.getInstance().size(); c++) { - Box cowBox = getCowBox(Herd.getInstance().getNthCow(c)); + Cow cow = Herd.getInstance().getNthCow(c); + if (Herd.getInstance().isParent(cow.getID())) continue; + Box cowBox = getCowBox(cow); herdBox.add(cowBox); herdBox.add(Box.createVerticalStrut(1)); } @@ -257,6 +268,8 @@ { Box cowBox = new Box(BoxLayout.Y_AXIS); cowBox.setBorder(new BevelBorder(BevelBorder.RAISED)); + cowBox.setMaximumSize(new Dimension(300, 110)); + cowBox.setMinimumSize(new Dimension(300, 110)); cowBox.add(Box.createVerticalStrut(7)); //If there is no cow here, display an empty panel if (c == null) { @@ -305,6 +318,15 @@ } } + private void chooseGoal() + { + String[] possible = {"dairy", "beef", "plowing"}; + goal = (String) JOptionPane.showInputDialog(null, "What do you want to breed for?", + "Select a goal", JOptionPane.QUESTION_MESSAGE, + null, possible, possible[0]); + updateGUI(); + } + private void resetGame() { Herd.getInstance().resetHerd();