From 32440d2fa35104f9233fd781bd96f190222a2b07 Mon Sep 17 00:00:00 2001 From: Dmdeer <73979650+kim08237@users.noreply.github.com> Date: Wed, 31 May 2023 11:36:46 +0900 Subject: [PATCH 1/5] pinsetter --- .../AddPartyView.java | 245 +++++++ .../AgainGameCommand.java | 9 + .../Alley.java | 42 ++ .../BOWLERS.DAT | 5 + .../Bowler.java | 69 ++ .../BowlerFile.java | 108 +++ .../ButtonCommand.java | 3 + .../ControlDesk.java | 237 +++++++ .../ControlDeskEvent.java | 46 ++ .../ControlDeskObserver.java | 20 + .../ControlDeskView.java | 180 +++++ .../EndGameCommand.java | 9 + .../EndGamePrompt.java | 112 ++++ .../EndGameReport.java | 143 ++++ .../EndGameReportClickEvent.java | 14 + BallingManagementSystem_refactoring/Lane.java | 621 ++++++++++++++++++ .../LaneEvent.java | 95 +++ .../LaneEventInterface.java | 15 + .../LaneObserver.java | 17 + .../LaneServer.java | 4 + .../LaneStatusView.java | 155 +++++ .../LaneView.java | 209 ++++++ .../NewPatronView.java | 156 +++++ .../Party.java | 52 ++ .../PinSetterView.java | 194 ++++++ .../Pinsetter.java | 202 ++++++ .../PinsetterEvent.java | 90 +++ .../PinsetterObserver.java | 28 + .../PrintableText.java | 47 ++ .../Queue.java | 40 ++ BallingManagementSystem_refactoring/README.md | 1 + .../SCOREHISTORY.DAT | 15 + .../Score.java | 37 ++ .../ScoreHistoryFile.java | 45 ++ .../ScoreReport.java | 125 ++++ .../drive.java | 18 + 36 files changed, 3408 insertions(+) create mode 100644 BallingManagementSystem_refactoring/AddPartyView.java create mode 100644 BallingManagementSystem_refactoring/AgainGameCommand.java create mode 100644 BallingManagementSystem_refactoring/Alley.java create mode 100644 BallingManagementSystem_refactoring/BOWLERS.DAT create mode 100644 BallingManagementSystem_refactoring/Bowler.java create mode 100644 BallingManagementSystem_refactoring/BowlerFile.java create mode 100644 BallingManagementSystem_refactoring/ButtonCommand.java create mode 100644 BallingManagementSystem_refactoring/ControlDesk.java create mode 100644 BallingManagementSystem_refactoring/ControlDeskEvent.java create mode 100644 BallingManagementSystem_refactoring/ControlDeskObserver.java create mode 100644 BallingManagementSystem_refactoring/ControlDeskView.java create mode 100644 BallingManagementSystem_refactoring/EndGameCommand.java create mode 100644 BallingManagementSystem_refactoring/EndGamePrompt.java create mode 100644 BallingManagementSystem_refactoring/EndGameReport.java create mode 100644 BallingManagementSystem_refactoring/EndGameReportClickEvent.java create mode 100644 BallingManagementSystem_refactoring/Lane.java create mode 100644 BallingManagementSystem_refactoring/LaneEvent.java create mode 100644 BallingManagementSystem_refactoring/LaneEventInterface.java create mode 100644 BallingManagementSystem_refactoring/LaneObserver.java create mode 100644 BallingManagementSystem_refactoring/LaneServer.java create mode 100644 BallingManagementSystem_refactoring/LaneStatusView.java create mode 100644 BallingManagementSystem_refactoring/LaneView.java create mode 100644 BallingManagementSystem_refactoring/NewPatronView.java create mode 100644 BallingManagementSystem_refactoring/Party.java create mode 100644 BallingManagementSystem_refactoring/PinSetterView.java create mode 100644 BallingManagementSystem_refactoring/Pinsetter.java create mode 100644 BallingManagementSystem_refactoring/PinsetterEvent.java create mode 100644 BallingManagementSystem_refactoring/PinsetterObserver.java create mode 100644 BallingManagementSystem_refactoring/PrintableText.java create mode 100644 BallingManagementSystem_refactoring/Queue.java create mode 100644 BallingManagementSystem_refactoring/README.md create mode 100644 BallingManagementSystem_refactoring/SCOREHISTORY.DAT create mode 100644 BallingManagementSystem_refactoring/Score.java create mode 100644 BallingManagementSystem_refactoring/ScoreHistoryFile.java create mode 100644 BallingManagementSystem_refactoring/ScoreReport.java create mode 100644 BallingManagementSystem_refactoring/drive.java diff --git a/BallingManagementSystem_refactoring/AddPartyView.java b/BallingManagementSystem_refactoring/AddPartyView.java new file mode 100644 index 0000000..58d2422 --- /dev/null +++ b/BallingManagementSystem_refactoring/AddPartyView.java @@ -0,0 +1,245 @@ +/* AddPartyView.java + * + * Version: + * $Id$ + * + * Revisions: + * $Log: AddPartyView.java,v $ + * Revision 1.7 2003/02/20 02:05:53 ??? + * Fixed addPatron so that duplicates won't be created. + * + * Revision 1.6 2003/02/09 20:52:46 ??? + * Added comments. + * + * Revision 1.5 2003/02/02 17:42:09 ??? + * Made updates to migrate to observer model. + * + * Revision 1.4 2003/02/02 16:29:52 ??? + * Added ControlDeskEvent and ControlDeskObserver. Updated Queue to allow access to Vector so that contents could be viewed without destroying. Implemented observer model for most of ControlDesk. + * + * + */ + +/** + * Class for GUI components need to add a party + * + */ + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.border.*; +import javax.swing.event.*; + +import java.util.*; +import java.text.*; + +/** + * Constructor for GUI used to Add Parties to the waiting party queue. + * + */ + +public class AddPartyView implements ActionListener, ListSelectionListener { + + private int maxSize; + + private JFrame win; + private JButton addPatron, newPatron, remPatron, finished; + private JList partyList, allBowlers; + private Vector party, bowlerdb; + private Integer lock; + + private ControlDeskView controlDesk; + + private String selectedNick, selectedMember; + + public AddPartyView(ControlDeskView controlDesk, int max) { + + this.controlDesk = controlDesk; + maxSize = max; + + win = new JFrame("Add Party"); + win.getContentPane().setLayout(new BorderLayout()); + ((JPanel) win.getContentPane()).setOpaque(false); + + JPanel colPanel = new JPanel(); + colPanel.setLayout(new GridLayout(1, 3)); + + // Party Panel + JPanel partyPanel = new JPanel(); + partyPanel.setLayout(new FlowLayout()); + partyPanel.setBorder(new TitledBorder("Your Party")); + + party = new Vector(); + Vector empty = new Vector(); + empty.add("(Empty)"); + + partyList = new JList(empty); + partyList.setFixedCellWidth(120); + partyList.setVisibleRowCount(5); + partyList.addListSelectionListener(this); + JScrollPane partyPane = new JScrollPane(partyList); + // partyPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + partyPanel.add(partyPane); + + // Bowler Database + JPanel bowlerPanel = new JPanel(); + bowlerPanel.setLayout(new FlowLayout()); + bowlerPanel.setBorder(new TitledBorder("Bowler Database")); + + try { + bowlerdb = new Vector(BowlerFile.getBowlers()); + } catch (Exception e) { + System.err.println("File Error"); + bowlerdb = new Vector(); + } + allBowlers = new JList(bowlerdb); + allBowlers.setVisibleRowCount(8); + allBowlers.setFixedCellWidth(120); + JScrollPane bowlerPane = new JScrollPane(allBowlers); + bowlerPane.setVerticalScrollBarPolicy( + JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + allBowlers.addListSelectionListener(this); + bowlerPanel.add(bowlerPane); + + // Button Panel + JPanel buttonPanel = new JPanel(); + buttonPanel.setLayout(new GridLayout(4, 1)); + + Insets buttonMargin = new Insets(4, 4, 4, 4); + + addPatron = new JButton("Add to Party"); + JPanel addPatronPanel = new JPanel(); + addPatronPanel.setLayout(new FlowLayout()); + addPatron.addActionListener(this); + addPatronPanel.add(addPatron); + + remPatron = new JButton("Remove Member"); + JPanel remPatronPanel = new JPanel(); + remPatronPanel.setLayout(new FlowLayout()); + remPatron.addActionListener(this); + remPatronPanel.add(remPatron); + + newPatron = new JButton("New Patron"); + JPanel newPatronPanel = new JPanel(); + newPatronPanel.setLayout(new FlowLayout()); + newPatron.addActionListener(this); + newPatronPanel.add(newPatron); + + finished = new JButton("Finished"); + JPanel finishedPanel = new JPanel(); + finishedPanel.setLayout(new FlowLayout()); + finished.addActionListener(this); + finishedPanel.add(finished); + + buttonPanel.add(addPatronPanel); + buttonPanel.add(remPatronPanel); + buttonPanel.add(newPatronPanel); + buttonPanel.add(finishedPanel); + + // Clean up main panel + colPanel.add(partyPanel); + colPanel.add(bowlerPanel); + colPanel.add(buttonPanel); + + win.getContentPane().add("Center", colPanel); + + win.pack(); + + // Center Window on Screen + Dimension screenSize = (Toolkit.getDefaultToolkit()).getScreenSize(); + win.setLocation( + ((screenSize.width) / 2) - ((win.getSize().width) / 2), + ((screenSize.height) / 2) - ((win.getSize().height) / 2)); + win.show(); + + } + + public void actionPerformed(ActionEvent e) { + if (e.getSource().equals(addPatron)) { + if (selectedNick != null && party.size() < maxSize) { + if (party.contains(selectedNick)) { + System.err.println("Member already in Party"); + } else { + party.add(selectedNick); + partyList.setListData(party); + } + } + } + if (e.getSource().equals(remPatron)) { + if (selectedMember != null) { + party.removeElement(selectedMember); + partyList.setListData(party); + } + } + if (e.getSource().equals(newPatron)) { + NewPatronView newPatron = new NewPatronView( this ); + } + if (e.getSource().equals(finished)) { + if ( party != null && party.size() > 0) { + controlDesk.updateAddParty( this ); + } + win.hide(); + } + + } + +/** + * Handler for List actions + * @param e the ListActionEvent that triggered the handler + */ + + public void valueChanged(ListSelectionEvent e) { + if (e.getSource().equals(allBowlers)) { + selectedNick = + ((String) ((JList) e.getSource()).getSelectedValue()); + } + if (e.getSource().equals(partyList)) { + selectedMember = + ((String) ((JList) e.getSource()).getSelectedValue()); + } + } + +/** + * Accessor for Party + */ + + public Vector getNames() { + return party; + } + +/** + * Called by NewPatronView to notify AddPartyView to update + * + * @param newPatron the NewPatronView that called this method + */ + + public void updateNewPatron(NewPatronView newPatron) { + try { + Bowler checkBowler = BowlerFile.getBowlerInfo( newPatron.getNick() ); + if ( checkBowler == null ) { + BowlerFile.putBowlerInfo( + newPatron.getNick(), + newPatron.getFull(), + newPatron.getEmail()); + bowlerdb = new Vector(BowlerFile.getBowlers()); + allBowlers.setListData(bowlerdb); + party.add(newPatron.getNick()); + partyList.setListData(party); + } else { + System.err.println( "A Bowler with that name already exists." ); + } + } catch (Exception e2) { + System.err.println("File I/O Error"); + } + } + +/** + * Accessor for Party + */ + + public Vector getParty() { + return party; + } + +} diff --git a/BallingManagementSystem_refactoring/AgainGameCommand.java b/BallingManagementSystem_refactoring/AgainGameCommand.java new file mode 100644 index 0000000..51907d5 --- /dev/null +++ b/BallingManagementSystem_refactoring/AgainGameCommand.java @@ -0,0 +1,9 @@ +public class AgainGameCommand implements ButtonCommand { + EndGamePrompt endGamePrompt; + public AgainGameCommand(EndGamePrompt endGamePrompt){ + this.endGamePrompt = endGamePrompt; + } + public void execute(){ + endGamePrompt.setResult(1); + } +} diff --git a/BallingManagementSystem_refactoring/Alley.java b/BallingManagementSystem_refactoring/Alley.java new file mode 100644 index 0000000..d31d110 --- /dev/null +++ b/BallingManagementSystem_refactoring/Alley.java @@ -0,0 +1,42 @@ +/* + * Alley.java + * + * Version: + * $Id$ + * + * Revisions: + * $Log: Alley.java,v $ + * Revision 1.4 2003/02/02 20:28:58 ??? + * fixed sleep thread bug in lane + * + * Revision 1.3 2003/01/12 22:23:32 ??? + * *** empty log message *** + * + * Revision 1.2 2003/01/12 20:44:30 ??? + * *** empty log message *** + * + * Revision 1.1 2003/01/12 19:09:12 ??? + * Adding Party, Lane, Bowler, and Alley. + * + */ + +/** + * Class that is the outer container for the bowling sim + * + */ + +public class Alley { + public ControlDesk controldesk; + + public Alley( int numLanes ) { + controldesk = new ControlDesk( numLanes ); + } + + public ControlDesk getControlDesk() { + return controldesk; + } + +} + + + diff --git a/BallingManagementSystem_refactoring/BOWLERS.DAT b/BallingManagementSystem_refactoring/BOWLERS.DAT new file mode 100644 index 0000000..4024de4 --- /dev/null +++ b/BallingManagementSystem_refactoring/BOWLERS.DAT @@ -0,0 +1,5 @@ +Mike M. J. Lutz ml@nowhere.net +Jim J. R. Vallino jv@nowhere.net +Tom T. R. Reichmayr tr@nowhere.net +Lana L. R. Verschage lv@nowhere.net +TomH T. Hilburn th@nowhere.net diff --git a/BallingManagementSystem_refactoring/Bowler.java b/BallingManagementSystem_refactoring/Bowler.java new file mode 100644 index 0000000..33ae3fa --- /dev/null +++ b/BallingManagementSystem_refactoring/Bowler.java @@ -0,0 +1,69 @@ +/* + * Bowler.java + * + * Version: + * $Id$ + * + * Revisions: + * $Log: Bowler.java,v $ + * Revision 1.3 2003/01/15 02:57:40 ??? + * Added accessors and and equals() method + * + * Revision 1.2 2003/01/12 22:23:32 ??? + * *** empty log message *** + * + * Revision 1.1 2003/01/12 19:09:12 ??? + * Adding Party, Lane, Bowler, and Alley. + * + */ + +/** + * Class that holds all bowler info + * + */ + +public class Bowler { + + private String fullName; + private String nickName; + private String email; + + public Bowler( String nick, String full, String mail ) { + nickName = nick; + fullName = full; + email = mail; + } + + + public String getNickName() { + + return nickName; + + } + + public String getFullName ( ) { + return fullName; + } + + public String getNick ( ) { + return nickName; + } + + public String getEmail ( ) { + return email; + } + + public boolean equals ( Bowler b) { + boolean retval = true; + if ( !(nickName.equals(b.getNickName())) ) { + retval = false; + } + if ( !(fullName.equals(b.getFullName())) ) { + retval = false; + } + if ( !(email.equals(b.getEmail())) ) { + retval = false; + } + return retval; + } +} \ No newline at end of file diff --git a/BallingManagementSystem_refactoring/BowlerFile.java b/BallingManagementSystem_refactoring/BowlerFile.java new file mode 100644 index 0000000..8ab8fb5 --- /dev/null +++ b/BallingManagementSystem_refactoring/BowlerFile.java @@ -0,0 +1,108 @@ +/* BowlerFile.java + * + * Version: + * $Id$ + * + * Revisions: + * $Log: BowlerFile.java,v $ + * Revision 1.5 2003/02/02 17:36:45 ??? + * Updated comments to match javadoc format. + * + * Revision 1.4 2003/02/02 16:29:52 ??? + * Added ControlDeskEvent and ControlDeskObserver. Updated Queue to allow access to Vector so that contents could be viewed without destroying. Implemented observer model for most of ControlDesk. + * + * + */ + +/** + * Class for interfacing with Bowler database + * + */ + +import java.util.*; +import java.io.*; + +class BowlerFile { + + /** The location of the bowelr database */ + private static String BOWLER_DAT = "BOWLERS.DAT"; + + /** + * Retrieves bowler information from the database and returns a Bowler objects with populated fields. + * + * @param nickName the nickName of the bolwer to retrieve + * + * @return a Bowler object + * + */ + + public static Bowler getBowlerInfo(String nickName) + throws IOException, FileNotFoundException { + + BufferedReader in = new BufferedReader(new FileReader(BOWLER_DAT)); + String data; + while ((data = in.readLine()) != null) { + // File format is nick\tfname\te-mail + String[] bowler = data.split("\t"); + if (nickName.equals(bowler[0])) { + System.out.println( + "Nick: " + + bowler[0] + + " Full: " + + bowler[1] + + " email: " + + bowler[2]); + return (new Bowler(bowler[0], bowler[1], bowler[2])); + } + } + System.out.println("Nick not found..."); + return null; + } + + /** + * Stores a Bowler in the database + * + * @param nickName the NickName of the Bowler + * @param fullName the FullName of the Bowler + * @param email the E-mail Address of the Bowler + * + */ + + public static void putBowlerInfo( + String nickName, + String fullName, + String email) + throws IOException, FileNotFoundException { + + String data = nickName + "\t" + fullName + "\t" + email + "\n"; + + RandomAccessFile out = new RandomAccessFile(BOWLER_DAT, "rw"); + out.skipBytes((int) out.length()); + out.writeBytes(data); + out.close(); + } + + /** + * Retrieves a list of nicknames in the bowler database + * + * @return a Vector of Strings + * + */ + + public static Vector getBowlers() + throws IOException, FileNotFoundException { + + Vector allBowlers = new Vector(); + + BufferedReader in = new BufferedReader(new FileReader(BOWLER_DAT)); + String data; + while ((data = in.readLine()) != null) { + // File format is nick\tfname\te-mail + String[] bowler = data.split("\t"); + //"Nick: bowler[0] Full: bowler[1] email: bowler[2] + allBowlers.add(bowler[0]); + } + return allBowlers; + } + +} \ No newline at end of file diff --git a/BallingManagementSystem_refactoring/ButtonCommand.java b/BallingManagementSystem_refactoring/ButtonCommand.java new file mode 100644 index 0000000..8fcf374 --- /dev/null +++ b/BallingManagementSystem_refactoring/ButtonCommand.java @@ -0,0 +1,3 @@ +public interface ButtonCommand { + public void execute(); +} diff --git a/BallingManagementSystem_refactoring/ControlDesk.java b/BallingManagementSystem_refactoring/ControlDesk.java new file mode 100644 index 0000000..4395bfd --- /dev/null +++ b/BallingManagementSystem_refactoring/ControlDesk.java @@ -0,0 +1,237 @@ +/* ControlDesk.java + * + * Version: + * $Id$ + * + * Revisions: + * $Log: ControlDesk.java,v $ + * Revision 1.13 2003/02/02 23:26:32 ??? + * ControlDesk now runs its own thread and polls for free lanes to assign queue members to + * + * Revision 1.12 2003/02/02 20:46:13 ??? + * Added " 's Party" to party names. + * + * Revision 1.11 2003/02/02 20:43:25 ??? + * misc cleanup + * + * Revision 1.10 2003/02/02 17:49:10 ??? + * Fixed problem in getPartyQueue that was returning the first element as every element. + * + * Revision 1.9 2003/02/02 17:39:48 ??? + * Added accessor for lanes. + * + * Revision 1.8 2003/02/02 16:53:59 ??? + * Updated comments to match javadoc format. + * + * Revision 1.7 2003/02/02 16:29:52 ??? + * Added ControlDeskEvent and ControlDeskObserver. Updated Queue to allow access to Vector so that contents could be viewed without destroying. Implemented observer model for most of ControlDesk. + * + * Revision 1.6 2003/02/02 06:09:39 ??? + * Updated many classes to support the ControlDeskView. + * + * Revision 1.5 2003/01/26 23:16:10 ??? + * Improved thread handeling in lane/controldesk + * + * + */ + +/** + * Class that represents control desk + * + */ + +import java.util.*; +import java.io.*; + +class ControlDesk extends Thread { + + /** The collection of Lanes */ + private HashSet lanes; + + /** The party wait queue */ + private Queue partyQueue; + + /** The number of lanes represented */ + private int numLanes; + + /** The collection of subscribers */ + private Vector subscribers; + + /** + * Constructor for the ControlDesk class + * + * @param numlanes the numbler of lanes to be represented + * + */ + + public ControlDesk(int numLanes) { + this.numLanes = numLanes; + lanes = new HashSet(numLanes); + partyQueue = new Queue(); + + subscribers = new Vector(); + + for (int i = 0; i < numLanes; i++) { + lanes.add(new Lane()); + } + + this.start(); + + } + + /** + * Main loop for ControlDesk's thread + * + */ + public void run() { + while (true) { + + assignLane(); + + try { + sleep(250); + } catch (Exception e) {} + } + } + + + /** + * Retrieves a matching Bowler from the bowler database. + * + * @param nickName The NickName of the Bowler + * + * @return a Bowler object. + * + */ + + private Bowler registerPatron(String nickName) { + Bowler patron = null; + + try { + // only one patron / nick.... no dupes, no checks + + patron = BowlerFile.getBowlerInfo(nickName); + + } catch (FileNotFoundException e) { + System.err.println("Error..." + e); + } catch (IOException e) { + System.err.println("Error..." + e); + } + + return patron; + } + + /** + * Iterate through the available lanes and assign the paties in the wait queue if lanes are available. + * + */ + + public void assignLane() { + Iterator it = lanes.iterator(); + + while (it.hasNext() && partyQueue.hasMoreElements()) { + Lane curLane = (Lane) it.next(); + + if (curLane.isPartyAssigned() == false) { + System.out.println("ok... assigning this party"); + curLane.assignParty(((Party) partyQueue.next())); + } + } + publish(new ControlDeskEvent(getPartyQueue())); + } + + /** + */ + + public void viewScores(Lane ln) { + // TODO: attach a LaneScoreView object to that lane + } + + /** + * Creates a party from a Vector of nickNAmes and adds them to the wait queue. + * + * @param partyNicks A Vector of NickNames + * + */ + + public void addPartyQueue(Vector partyNicks) { + Vector partyBowlers = new Vector(); + for (int i = 0; i < partyNicks.size(); i++) { + Bowler newBowler = registerPatron(((String) partyNicks.get(i))); + partyBowlers.add(newBowler); + } + Party newParty = new Party(partyBowlers); + partyQueue.add(newParty); + publish(new ControlDeskEvent(getPartyQueue())); + } + + /** + * Returns a Vector of party names to be displayed in the GUI representation of the wait queue. + * + * @return a Vecotr of Strings + * + */ + + public Vector getPartyQueue() { + Vector displayPartyQueue = new Vector(); + for ( int i=0; i < ( (Vector)partyQueue.asVector()).size(); i++ ) { + String nextParty = + ((Bowler) ((Vector) ((Party) partyQueue.asVector().get( i ) ).getMembers()) + .get(0)) + .getNickName() + "'s Party"; + displayPartyQueue.addElement(nextParty); + } + return displayPartyQueue; + } + + /** + * Accessor for the number of lanes represented by the ControlDesk + * + * @return an int containing the number of lanes represented + * + */ + + public int getNumLanes() { + return numLanes; + } + + /** + * Allows objects to subscribe as observers + * + * @param adding the ControlDeskObserver that will be subscribed + * + */ + + public void subscribe(ControlDeskObserver adding) { + subscribers.add(adding); + } + + /** + * Broadcast an event to subscribing objects. + * + * @param event the ControlDeskEvent to broadcast + * + */ + + public void publish(ControlDeskEvent event) { + Iterator eventIterator = subscribers.iterator(); + while (eventIterator.hasNext()) { + ( + (ControlDeskObserver) eventIterator + .next()) + .receiveControlDeskEvent( + event); + } + } + + /** + * Accessor method for lanes + * + * @return a HashSet of Lanes + * + */ + + public HashSet getLanes() { + return lanes; + } +} diff --git a/BallingManagementSystem_refactoring/ControlDeskEvent.java b/BallingManagementSystem_refactoring/ControlDeskEvent.java new file mode 100644 index 0000000..4d8d81c --- /dev/null +++ b/BallingManagementSystem_refactoring/ControlDeskEvent.java @@ -0,0 +1,46 @@ +/* ControlDeskEvent.java + * + * Version: + * $Id$ + * + * Revisions: + * $Log$ + * + */ + +/** + * Class that represents control desk event + * + */ + +import java.util.*; + +public class ControlDeskEvent { + + /** A representation of the wait queue, containing party names */ + private Vector partyQueue; + + /** + * Contstructor for the ControlDeskEvent + * + * @param partyQueue a Vector of Strings containing the names of the parties in the wait queue + * + */ + + public ControlDeskEvent( Vector partyQueue ) { + this.partyQueue = partyQueue; + } + + /** + * Accessor for partyQueue + * @param key the key of the vertex being looked for. + * + * @return a Vector of Strings representing the names of the parties in the wait queue + * + */ + + public Vector getPartyQueue() { + return partyQueue; + } + +} diff --git a/BallingManagementSystem_refactoring/ControlDeskObserver.java b/BallingManagementSystem_refactoring/ControlDeskObserver.java new file mode 100644 index 0000000..96aa970 --- /dev/null +++ b/BallingManagementSystem_refactoring/ControlDeskObserver.java @@ -0,0 +1,20 @@ +/* ControlDeskObserver.java + * + * Version + * $Id$ + * + * Revisions: + * $Log$ + * + */ + +/** + * Interface for classes that observe control desk events + * + */ + +public interface ControlDeskObserver { + + public void receiveControlDeskEvent(ControlDeskEvent ce); + +} diff --git a/BallingManagementSystem_refactoring/ControlDeskView.java b/BallingManagementSystem_refactoring/ControlDeskView.java new file mode 100644 index 0000000..95c5300 --- /dev/null +++ b/BallingManagementSystem_refactoring/ControlDeskView.java @@ -0,0 +1,180 @@ +/* ControlDeskView.java + * + * Version: + * $Id$ + * + * Revisions: + * $Log$ + * + */ + +/** + * Class for representation of the control desk + * + */ + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.border.*; +import javax.swing.event.*; + +import java.util.*; + +public class ControlDeskView implements ActionListener, ControlDeskObserver { + + private JButton addParty, finished, assign; + private JFrame win; + private JList partyList; + + /** The maximum number of members in a party */ + private int maxMembers; + + private ControlDesk controlDesk; + + /** + * Displays a GUI representation of the ControlDesk + * + */ + + public ControlDeskView(ControlDesk controlDesk, int maxMembers) { + + this.controlDesk = controlDesk; + this.maxMembers = maxMembers; + int numLanes = controlDesk.getNumLanes(); + + win = new JFrame("Control Desk"); + win.getContentPane().setLayout(new BorderLayout()); + ((JPanel) win.getContentPane()).setOpaque(false); + + JPanel colPanel = new JPanel(); + colPanel.setLayout(new BorderLayout()); + + // Controls Panel + JPanel controlsPanel = new JPanel(); + controlsPanel.setLayout(new GridLayout(3, 1)); + controlsPanel.setBorder(new TitledBorder("Controls")); + + addParty = new JButton("Add Party"); + JPanel addPartyPanel = new JPanel(); + addPartyPanel.setLayout(new FlowLayout()); + addParty.addActionListener(this); + addPartyPanel.add(addParty); + controlsPanel.add(addPartyPanel); + + assign = new JButton("Assign Lanes"); + JPanel assignPanel = new JPanel(); + assignPanel.setLayout(new FlowLayout()); + assign.addActionListener(this); + assignPanel.add(assign); +// controlsPanel.add(assignPanel); + + finished = new JButton("Finished"); + JPanel finishedPanel = new JPanel(); + finishedPanel.setLayout(new FlowLayout()); + finished.addActionListener(this); + finishedPanel.add(finished); + controlsPanel.add(finishedPanel); + + // Lane Status Panel + JPanel laneStatusPanel = new JPanel(); + laneStatusPanel.setLayout(new GridLayout(numLanes, 1)); + laneStatusPanel.setBorder(new TitledBorder("Lane Status")); + + HashSet lanes=controlDesk.getLanes(); + Iterator it = lanes.iterator(); + int laneCount=0; + while (it.hasNext()) { + Lane curLane = (Lane) it.next(); + LaneStatusView laneStat = new LaneStatusView(curLane,(laneCount+1)); + curLane.subscribe(laneStat); + ((Pinsetter)curLane.getPinsetter()).subscribe(laneStat); + JPanel lanePanel = laneStat.showLane(); + lanePanel.setBorder(new TitledBorder("Lane" + ++laneCount )); + laneStatusPanel.add(lanePanel); + } + + // Party Queue Panel + JPanel partyPanel = new JPanel(); + partyPanel.setLayout(new FlowLayout()); + partyPanel.setBorder(new TitledBorder("Party Queue")); + + Vector empty = new Vector(); + empty.add("(Empty)"); + + partyList = new JList(empty); + partyList.setFixedCellWidth(120); + partyList.setVisibleRowCount(10); + JScrollPane partyPane = new JScrollPane(partyList); + partyPane.setVerticalScrollBarPolicy( + JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + partyPanel.add(partyPane); + // partyPanel.add(partyList); + + // Clean up main panel + colPanel.add(controlsPanel, "East"); + colPanel.add(laneStatusPanel, "Center"); + colPanel.add(partyPanel, "West"); + + win.getContentPane().add("Center", colPanel); + + win.pack(); + + /* Close program when this window closes */ + win.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.exit(0); + } + }); + + // Center Window on Screen + Dimension screenSize = (Toolkit.getDefaultToolkit()).getScreenSize(); + win.setLocation( + ((screenSize.width) / 2) - ((win.getSize().width) / 2), + ((screenSize.height) / 2) - ((win.getSize().height) / 2)); + win.show(); + + } + + /** + * Handler for actionEvents + * + * @param e the ActionEvent that triggered the handler + * + */ + + public void actionPerformed(ActionEvent e) { + if (e.getSource().equals(addParty)) { + AddPartyView addPartyWin = new AddPartyView(this, maxMembers); + } + if (e.getSource().equals(assign)) { + controlDesk.assignLane(); + } + if (e.getSource().equals(finished)) { + win.hide(); + System.exit(0); + } + } + + /** + * Receive a new party from andPartyView. + * + * @param addPartyView the AddPartyView that is providing a new party + * + */ + + public void updateAddParty(AddPartyView addPartyView) { + controlDesk.addPartyQueue(addPartyView.getParty()); + } + + /** + * Receive a broadcast from a ControlDesk + * + * @param ce the ControlDeskEvent that triggered the handler + * + */ + + public void receiveControlDeskEvent(ControlDeskEvent ce) { + partyList.setListData(((Vector) ce.getPartyQueue())); + } +} diff --git a/BallingManagementSystem_refactoring/EndGameCommand.java b/BallingManagementSystem_refactoring/EndGameCommand.java new file mode 100644 index 0000000..b116cf9 --- /dev/null +++ b/BallingManagementSystem_refactoring/EndGameCommand.java @@ -0,0 +1,9 @@ +public class EndGameCommand implements ButtonCommand { + EndGamePrompt endGamePrompt; + public EndGameCommand(EndGamePrompt endGamePrompt){ + this.endGamePrompt = endGamePrompt; + } + public void execute(){ + endGamePrompt.setResult(2); + } +} diff --git a/BallingManagementSystem_refactoring/EndGamePrompt.java b/BallingManagementSystem_refactoring/EndGamePrompt.java new file mode 100644 index 0000000..4cc773a --- /dev/null +++ b/BallingManagementSystem_refactoring/EndGamePrompt.java @@ -0,0 +1,112 @@ +/** + * + * To change this generated comment edit the template variable "typecomment": + * Window>Preferences>Java>Templates. + * To enable and disable the creation of type comments go to + * Window>Preferences>Java>Code Generation. + */ + +import java.awt.*; +import javax.swing.*; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; + +public class EndGamePrompt { + private ButtonCommand command; + private JFrame win; + private JButton yesButton, noButton; + private JFrame endGameFrame; + private int result; + + public EndGamePrompt( String partyName ) { + + result = 0; + + endGameFrame = new JFrame("Another Game for " + partyName + "?"); + endGameFrame.getContentPane().setLayout(new BorderLayout()); + ((JPanel) endGameFrame.getContentPane()).setOpaque(false); + + JPanel colPanel = new JPanel(); + colPanel.setLayout(new GridLayout(2, 1)); + + // Label Panel + JPanel labelPanel = new JPanel(); + labelPanel.setLayout(new FlowLayout()); + + JLabel message = new JLabel("Party " + partyName + " has finished bowling.\nWould they like to bowl another game?"); + labelPanel.add(message); + + // Button Panel + JPanel buttonPanel = new JPanel(); + buttonPanel.setLayout(new GridLayout(1, 2)); + + Insets buttonMargin = new Insets(4, 4, 4, 4); + + EndGamePromptClickEvent listener = new EndGamePromptClickEvent(); + + yesButton = createButton("Yes", listener); + noButton = createButton("No", listener); + + buttonPanel.setLayout(new GridLayout(1, 2)); + buttonPanel.add(yesButton); + buttonPanel.add(noButton); + + // Clean up main panel + colPanel.add(labelPanel); + colPanel.add(buttonPanel); + + endGameFrame.getContentPane().add("Center", colPanel); + + endGameFrame.pack(); + + // Center Window on Screen + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + endGameFrame.setLocation((screenSize.width / 2) - (endGameFrame.getSize().width / 2), + (screenSize.height / 2) - (endGameFrame.getSize().height / 2)); + endGameFrame.setVisible(true); + + } + private JButton createButton(String text, EndGamePromptClickEvent listener) { + JButton button = new JButton(text); + button.addActionListener(listener); + return button; + } + + public int getResult() { + while ( result == 0 ) { + try { + Thread.sleep(10); + } catch ( InterruptedException e ) { + System.err.println( "Interrupted" ); + } + } + return result; + } + public void setResult(int i) { + result = i; + } + public void distroy() { + endGameFrame.setVisible(false); + } + + public void setCommand(ButtonCommand command) { + this.command = command; + } + public void buttonPressed() { + command.execute(); + } + public class EndGamePromptClickEvent implements ActionListener { + + public void actionPerformed(ActionEvent e) { + if (e.getSource().equals(yesButton)) { + setCommand(new AgainGameCommand(EndGamePrompt.this)); + } + if (e.getSource().equals(noButton)) { + setCommand(new EndGameCommand(EndGamePrompt.this)); + } + buttonPressed(); + } + } + +} + diff --git a/BallingManagementSystem_refactoring/EndGameReport.java b/BallingManagementSystem_refactoring/EndGameReport.java new file mode 100644 index 0000000..6a591ce --- /dev/null +++ b/BallingManagementSystem_refactoring/EndGameReport.java @@ -0,0 +1,143 @@ +/** + * + * To change this generated comment edit the template variable "typecomment": + * Window>Preferences>Java>Templates. + * To enable and disable the creation of type comments go to + * Window>Preferences>Java>Code Generation. + */ + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.border.*; +import javax.swing.event.*; + +import java.util.*; +import java.text.*; + +public class EndGameReport implements ActionListener, ListSelectionListener { + + private JFrame win; + private JButton printButton, finished; + private JList memberList; + private Vector myVector; + private Vector retVal; + + private int result; + + private String selectedMember; + + public EndGameReport( String partyName, Party party ) { + + result =0; + retVal = new Vector(); + win = new JFrame("End Game Report for " + partyName + "?" ); + win.getContentPane().setLayout(new BorderLayout()); + ((JPanel) win.getContentPane()).setOpaque(false); + + JPanel colPanel = new JPanel(); + colPanel.setLayout(new GridLayout( 1, 2 )); + + // Member Panel + JPanel partyPanel = new JPanel(); + partyPanel.setLayout(new FlowLayout()); + partyPanel.setBorder(new TitledBorder("Party Members")); + + Vector myVector = new Vector(); + Iterator iter = (party.getMembers()).iterator(); + while (iter.hasNext()){ + myVector.add( ((Bowler)iter.next()).getNick() ); + } + memberList = new JList(myVector); + memberList.setFixedCellWidth(120); + memberList.setVisibleRowCount(5); + memberList.addListSelectionListener(this); + JScrollPane partyPane = new JScrollPane(memberList); + // partyPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + partyPanel.add(partyPane); + + partyPanel.add( memberList ); + + // Button Panel + // Button Panel + JPanel buttonPanel = new JPanel(); + buttonPanel.setLayout(new GridLayout(2, 1)); + + Insets buttonMargin = new Insets(4, 4, 4, 4); + + printButton = new JButton("Print Report"); + JPanel printButtonPanel = new JPanel(); + printButtonPanel.setLayout(new FlowLayout()); + printButton.addActionListener(this); + printButtonPanel.add(printButton); + + finished = new JButton("Finished"); + JPanel finishedPanel = new JPanel(); + finishedPanel.setLayout(new FlowLayout()); + finished.addActionListener(this); + finishedPanel.add(finished); + + buttonPanel.add(printButton); + buttonPanel.add(finished); + + // Clean up main panel + colPanel.add(partyPanel); + colPanel.add(buttonPanel); + + win.getContentPane().add("Center", colPanel); + + win.pack(); + + // Center Window on Screen + Dimension screenSize = (Toolkit.getDefaultToolkit()).getScreenSize(); + win.setLocation( + ((screenSize.width) / 2) - ((win.getSize().width) / 2), + ((screenSize.height) / 2) - ((win.getSize().height) / 2)); + win.show(); + + } + + public void actionPerformed(ActionEvent e) { + if (e.getSource().equals(printButton)) { + //Add selected to the vector. + retVal.add(selectedMember); + } + if (e.getSource().equals(finished)) { + win.hide(); + result = 1; + } + + } + + public void valueChanged(ListSelectionEvent e) { + selectedMember = + ((String) ((JList) e.getSource()).getSelectedValue()); + } + + public Vector getResult() { + while ( result == 0 ) { + try { + Thread.sleep(10); + } catch ( InterruptedException e ) { + System.err.println( "Interrupted" ); + } + } + return retVal; + } + + public void destroy() { + win.hide(); + } + + public static void main( String args[] ) { + Vector bowlers = new Vector(); + for ( int i=0; i<4; i++ ) { + bowlers.add( new Bowler( "aaaaa", "aaaaa", "aaaaa" ) ); + } + Party party = new Party( bowlers ); + String partyName="wank"; + EndGameReport e = new EndGameReport( partyName, party ); + } + +} + diff --git a/BallingManagementSystem_refactoring/EndGameReportClickEvent.java b/BallingManagementSystem_refactoring/EndGameReportClickEvent.java new file mode 100644 index 0000000..eea014e --- /dev/null +++ b/BallingManagementSystem_refactoring/EndGameReportClickEvent.java @@ -0,0 +1,14 @@ +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; + +public class EndGameReportClickEvent implements ActionListener { + private EndGameReport endGameReport; + + EndGameReportClickEvent(EndGameReport endGameReport) { + this.endGameReport = endGameReport; + } + + public void actionPerformed(ActionEvent e) { + + } +} diff --git a/BallingManagementSystem_refactoring/Lane.java b/BallingManagementSystem_refactoring/Lane.java new file mode 100644 index 0000000..f1785c8 --- /dev/null +++ b/BallingManagementSystem_refactoring/Lane.java @@ -0,0 +1,621 @@ + +/* $Id$ + * + * Revisions: + * $Log: Lane.java,v $ + * Revision 1.52 2003/02/20 20:27:45 ??? + * Fouls disables. + * + * Revision 1.51 2003/02/20 20:01:32 ??? + * Added things. + * + * Revision 1.50 2003/02/20 19:53:52 ??? + * Added foul support. Still need to update laneview and test this. + * + * Revision 1.49 2003/02/20 11:18:22 ??? + * Works beautifully. + * + * Revision 1.48 2003/02/20 04:10:58 ??? + * Score reporting code should be good. + * + * Revision 1.47 2003/02/17 00:25:28 ??? + * Added disbale controls for View objects. + * + * Revision 1.46 2003/02/17 00:20:47 ??? + * fix for event when game ends + * + * Revision 1.43 2003/02/17 00:09:42 ??? + * fix for event when game ends + * + * Revision 1.42 2003/02/17 00:03:34 ??? + * Bug fixed + * + * Revision 1.41 2003/02/16 23:59:49 ??? + * Reporting of sorts. + * + * Revision 1.40 2003/02/16 23:44:33 ??? + * added mechnanical problem flag + * + * Revision 1.39 2003/02/16 23:43:08 ??? + * added mechnanical problem flag + * + * Revision 1.38 2003/02/16 23:41:05 ??? + * added mechnanical problem flag + * + * Revision 1.37 2003/02/16 23:00:26 ??? + * added mechnanical problem flag + * + * Revision 1.36 2003/02/16 21:31:04 ??? + * Score logging. + * + * Revision 1.35 2003/02/09 21:38:00 ??? + * Added lots of comments + * + * Revision 1.34 2003/02/06 00:27:46 ??? + * Fixed a race condition + * + * Revision 1.33 2003/02/05 11:16:34 ??? + * Boom-Shacka-Lacka!!! + * + * Revision 1.32 2003/02/05 01:15:19 ??? + * Real close now. Honest. + * + * Revision 1.31 2003/02/04 22:02:04 ??? + * Still not quite working... + * + * Revision 1.30 2003/02/04 13:33:04 ??? + * Lane may very well work now. + * + * Revision 1.29 2003/02/02 23:57:27 ??? + * fix on pinsetter hack + * + * Revision 1.28 2003/02/02 23:49:48 ??? + * Pinsetter generates an event when all pins are reset + * + * Revision 1.27 2003/02/02 23:26:32 ??? + * ControlDesk now runs its own thread and polls for free lanes to assign queue members to + * + * Revision 1.26 2003/02/02 23:11:42 ??? + * parties can now play more than 1 game on a lane, and lanes are properly released after games + * + * Revision 1.25 2003/02/02 22:52:19 ??? + * Lane compiles + * + * Revision 1.24 2003/02/02 22:50:10 ??? + * Lane compiles + * + * Revision 1.23 2003/02/02 22:47:34 ??? + * More observering. + * + * Revision 1.22 2003/02/02 22:15:40 ??? + * Add accessor for pinsetter. + * + * Revision 1.21 2003/02/02 21:59:20 ??? + * added conditions for the party choosing to play another game + * + * Revision 1.20 2003/02/02 21:51:54 ??? + * LaneEvent may very well be observer method. + * + * Revision 1.19 2003/02/02 20:28:59 ??? + * fixed sleep thread bug in lane + * + * Revision 1.18 2003/02/02 18:18:51 ??? + * more changes. just need to fix scoring. + * + * Revision 1.17 2003/02/02 17:47:02 ??? + * Things are pretty close to working now... + * + * Revision 1.16 2003/01/30 22:09:32 ??? + * Worked on scoring. + * + * Revision 1.15 2003/01/30 21:45:08 ??? + * Fixed speling of received in Lane. + * + * Revision 1.14 2003/01/30 21:29:30 ??? + * Fixed some MVC stuff + * + * Revision 1.13 2003/01/30 03:45:26 ??? + * *** empty log message *** + * + * Revision 1.12 2003/01/26 23:16:10 ??? + * Improved thread handeling in lane/controldesk + * + * Revision 1.11 2003/01/26 22:34:44 ??? + * Total rewrite of lane and pinsetter for R2's observer model + * Added Lane/Pinsetter Observer + * Rewrite of scoring algorythm in lane + * + * Revision 1.10 2003/01/26 20:44:05 ??? + * small changes + * + * + */ + +import java.util.Vector; +import java.util.Iterator; +import java.util.HashMap; +import java.util.Date; + +public class Lane extends Thread implements PinsetterObserver { + private Party party; + private Pinsetter setter; + private HashMap scores; + private Vector subscribers; + + private boolean gameIsHalted; + + private boolean partyAssigned; + private boolean gameFinished; + private Iterator bowlerIterator; + private int ball; + private int bowlIndex; + private int frameNumber; + private boolean tenthFrameStrike; + + private int[] curScores; + private int[][] cumulScores; + private boolean canThrowAgain; + + private int[][] finalScores; + private int gameNumber; + + private Bowler currentThrower; // = the thrower who just took a throw + + /** Lane() + * + * Constructs a new lane and starts its thread + * + * @pre none + * @post a new lane has been created and its thered is executing + */ + public Lane() { + setter = new Pinsetter(); + scores = new HashMap(); + subscribers = new Vector(); + + gameIsHalted = false; + partyAssigned = false; + + gameNumber = 0; + + setter.subscribe( this ); + + this.start(); + } + + /** run() + * + * entry point for execution of this lane + */ + public void run() { + + while (true) { + if (partyAssigned && !gameFinished) { // we have a party on this lane, + // so next bower can take a throw + + while (gameIsHalted) { + try { + sleep(10); + } catch (Exception e) {} + } + + + if (bowlerIterator.hasNext()) { + currentThrower = (Bowler)bowlerIterator.next(); + + canThrowAgain = true; + tenthFrameStrike = false; + ball = 0; + while (canThrowAgain) { + setter.ballThrown(); // simulate the thrower's ball hiting + ball++; + } + + if (frameNumber == 9){ + finalScores[bowlIndex][gameNumber] = cumulScores[bowlIndex][9]; + try{ + Date date = new Date(); + String dateString = "" + date.getHours() + ":" + date.getMinutes() + " " + date.getMonth() + "/" + date.getDay() + "/" + (date.getYear() + 1900); + ScoreHistoryFile.addScore(currentThrower.getNick(), dateString, new Integer(cumulScores[bowlIndex][9]).toString()); + } catch (Exception e) {System.err.println("Exception in addScore. "+ e );} + } + + + setter.reset(); + bowlIndex++; + + } else { + frameNumber++; + resetBowlerIterator(); + bowlIndex = 0; + if (frameNumber > 9) { + gameFinished = true; + gameNumber++; + } + } + } else if (partyAssigned && gameFinished) { + EndGamePrompt egp = new EndGamePrompt( ((Bowler) party.getMembers().get(0)).getNickName() + "'s Party" ); + int result = egp.getResult(); + egp.distroy(); + egp = null; + + + System.out.println("result was: " + result); + + // TODO: send record of scores to control desk + if (result == 1) { // yes, want to play again + resetScores(); + resetBowlerIterator(); + + } else if (result == 2) {// no, dont want to play another game + Vector printVector; + EndGameReport egr = new EndGameReport( ((Bowler)party.getMembers().get(0)).getNickName() + "'s Party", party); + printVector = egr.getResult(); + partyAssigned = false; + Iterator scoreIt = party.getMembers().iterator(); + party = null; + partyAssigned = false; + + publish(lanePublish()); + + int myIndex = 0; + while (scoreIt.hasNext()){ + Bowler thisBowler = (Bowler)scoreIt.next(); + ScoreReport sr = new ScoreReport( thisBowler, finalScores[myIndex++], gameNumber ); + sr.sendEmail(thisBowler.getEmail()); + Iterator printIt = printVector.iterator(); + while (printIt.hasNext()){ + if (thisBowler.getNick() == (String)printIt.next()){ + System.out.println("Printing " + thisBowler.getNick()); + sr.sendPrintout(); + } + } + + } + } + } + + + try { + sleep(10); + } catch (Exception e) {} + } + } + + /** recievePinsetterEvent() + * + * recieves the thrown event from the pinsetter + * + * @pre none + * @post the event has been acted upon if desiered + * + * @param pe The pinsetter event that has been received. + */ + public void receivePinsetterEvent(PinsetterEvent pe) { + + if (pe.pinsDownOnThisThrow() >= 0) { // this is a real throw + markScore(currentThrower, frameNumber + 1, pe.getThrowNumber(), pe.pinsDownOnThisThrow()); + + // next logic handles the ?: what conditions dont allow them another throw? + // handle the case of 10th frame first + if (frameNumber == 9) { + if (pe.totalPinsDown() == 10) { + setter.resetPins(); + if(pe.getThrowNumber() == 1) { + tenthFrameStrike = true; + } + } + + if ((pe.totalPinsDown() != 10) && (pe.getThrowNumber() == 2 && tenthFrameStrike == false)) { + canThrowAgain = false; + //publish( lanePublish() ); + } + + if (pe.getThrowNumber() == 3) { + canThrowAgain = false; + //publish( lanePublish() ); + } + } else { // its not the 10th frame + + if (pe.pinsDownOnThisThrow() == 10) { // threw a strike + canThrowAgain = false; + //publish( lanePublish() ); + } else if (pe.getThrowNumber() == 2) { + canThrowAgain = false; + //publish( lanePublish() ); + } else if (pe.getThrowNumber() == 3) + System.out.println("I'm here..."); + } + } else { // this is not a real throw, probably a reset + } + } + + /** resetBowlerIterator() + * + * sets the current bower iterator back to the first bowler + * + * @pre the party as been assigned + * @post the iterator points to the first bowler in the party + */ + private void resetBowlerIterator() { + bowlerIterator = (party.getMembers()).iterator(); + } + + /** resetScores() + * + * resets the scoring mechanism, must be called before scoring starts + * + * @pre the party has been assigned + * @post scoring system is initialized + */ + private void resetScores() { + Iterator bowlIt = (party.getMembers()).iterator(); + + while ( bowlIt.hasNext() ) { + int[] toPut = new int[25]; + for ( int i = 0; i != 25; i++){ + toPut[i] = -1; + } + scores.put( bowlIt.next(), toPut ); + } + + + + gameFinished = false; + frameNumber = 0; + } + + /** assignParty() + * + * assigns a party to this lane + * + * @pre none + * @post the party has been assigned to the lane + * + * @param theParty Party to be assigned + */ + public void assignParty( Party theParty ) { + party = theParty; + resetBowlerIterator(); + partyAssigned = true; + + curScores = new int[party.getMembers().size()]; + cumulScores = new int[party.getMembers().size()][10]; + finalScores = new int[party.getMembers().size()][128]; //Hardcoding a max of 128 games, bite me. + gameNumber = 0; + + resetScores(); + } + + /** markScore() + * + * Method that marks a bowlers score on the board. + * + * @param Cur The current bowler + * @param frame The frame that bowler is on + * @param ball The ball the bowler is on + * @param score The bowler's score + */ + private void markScore( Bowler Cur, int frame, int ball, int score ){ + int[] curScore; + int index = ( (frame - 1) * 2 + ball); + + curScore = (int[]) scores.get(Cur); + + + curScore[ index - 1] = score; + scores.put(Cur, curScore); + getScore( Cur, frame ); + publish( lanePublish() ); + } + + /** lanePublish() + * + * Method that creates and returns a newly created laneEvent + * + * @return The new lane event + */ + private LaneEvent lanePublish( ) { + LaneEvent laneEvent = new LaneEvent(party, bowlIndex, currentThrower, cumulScores, scores, frameNumber+1, curScores, ball, gameIsHalted); + return laneEvent; + } + + /** getScore() + * + * Method that calculates a bowlers score + * + * @param Cur The bowler that is currently up + * @param frame The frame the current bowler is on + * + * @return The bowlers total score + */ + private int getScore( Bowler Cur, int frame) { + int[] curScore; + int strikeballs = 0; + int totalScore = 0; + curScore = (int[]) scores.get(Cur); + for (int i = 0; i != 10; i++){ + cumulScores[bowlIndex][i] = 0; + } + int current = 2*(frame - 1)+ball-1; + //Iterate through each ball until the current one. + for (int i = 0; i != current+2; i++){ + //Spare: + if( i%2 == 1 && curScore[i - 1] + curScore[i] == 10 && i < current - 1 && i < 19){ + //This ball was a the second of a spare. + //Also, we're not on the current ball. + //Add the next ball to the ith one in cumul. + cumulScores[bowlIndex][(i/2)] += curScore[i+1] + curScore[i]; + if (i > 1) { + //cumulScores[bowlIndex][i/2] += cumulScores[bowlIndex][i/2 -1]; + } + } else if( i < current && i%2 == 0 && curScore[i] == 10 && i < 18){ + strikeballs = 0; + //This ball is the first ball, and was a strike. + //If we can get 2 balls after it, good add them to cumul. + if (curScore[i+2] != -1) { + strikeballs = 1; + if(curScore[i+3] != -1) { + //Still got em. + strikeballs = 2; + } else if(curScore[i+4] != -1) { + //Ok, got it. + strikeballs = 2; + } + } + if (strikeballs == 2){ + //Add up the strike. + //Add the next two balls to the current cumulscore. + cumulScores[bowlIndex][i/2] += 10; + if(curScore[i+1] != -1) { + cumulScores[bowlIndex][i/2] += curScore[i+1] + cumulScores[bowlIndex][(i/2)-1]; + if (curScore[i+2] != -1){ + if( curScore[i+2] != -2){ + cumulScores[bowlIndex][(i/2)] += curScore[i+2]; + } + } else { + if( curScore[i+3] != -2){ + cumulScores[bowlIndex][(i/2)] += curScore[i+3]; + } + } + } else { + if ( i/2 > 0 ){ + cumulScores[bowlIndex][i/2] += curScore[i+2] + cumulScores[bowlIndex][(i/2)-1]; + } else { + cumulScores[bowlIndex][i/2] += curScore[i+2]; + } + if (curScore[i+3] != -1){ + if( curScore[i+3] != -2){ + cumulScores[bowlIndex][(i/2)] += curScore[i+3]; + } + } else { + cumulScores[bowlIndex][(i/2)] += curScore[i+4]; + } + } + } else { + break; + } + }else { + //We're dealing with a normal throw, add it and be on our way. + if( i%2 == 0 && i < 18){ + if ( i/2 == 0 ) { + //First frame, first ball. Set his cumul score to the first ball + if(curScore[i] != -2){ + cumulScores[bowlIndex][i/2] += curScore[i]; + } + } else if (i/2 != 9){ + //add his last frame's cumul to this ball, make it this frame's cumul. + if(curScore[i] != -2){ + cumulScores[bowlIndex][i/2] += cumulScores[bowlIndex][i/2 - 1] + curScore[i]; + } else { + cumulScores[bowlIndex][i/2] += cumulScores[bowlIndex][i/2 - 1]; + } + } + } else if (i < 18){ + if(curScore[i] != -1 && i > 2){ + if(curScore[i] != -2){ + cumulScores[bowlIndex][i/2] += curScore[i]; + } + } + } + if (i/2 == 9){ + if (i == 18){ + cumulScores[bowlIndex][9] += cumulScores[bowlIndex][8]; + } + if(curScore[i] != -2){ + cumulScores[bowlIndex][9] += curScore[i]; + } + } else if (i/2 == 10) { + if(curScore[i] != -2){ + cumulScores[bowlIndex][9] += curScore[i]; + } + } + } + } + return totalScore; + } + + /** isPartyAssigned() + * + * checks if a party is assigned to this lane + * + * @return true if party assigned, false otherwise + */ + public boolean isPartyAssigned() { + return partyAssigned; + } + + /** isGameFinished + * + * @return true if the game is done, false otherwise + */ + public boolean isGameFinished() { + return gameFinished; + } + + /** subscribe + * + * Method that will add a subscriber + * + * @param subscribe Observer that is to be added + */ + + public void subscribe( LaneObserver adding ) { + subscribers.add( adding ); + } + + /** unsubscribe + * + * Method that unsubscribes an observer from this object + * + * @param removing The observer to be removed + */ + + public void unsubscribe( LaneObserver removing ) { + subscribers.remove( removing ); + } + + /** publish + * + * Method that publishes an event to subscribers + * + * @param event Event that is to be published + */ + + public void publish( LaneEvent event ) { + if( subscribers.size() > 0 ) { + Iterator eventIterator = subscribers.iterator(); + + while ( eventIterator.hasNext() ) { + ( (LaneObserver) eventIterator.next()).receiveLaneEvent( event ); + } + } + } + + /** + * Accessor to get this Lane's pinsetter + * + * @return A reference to this lane's pinsetter + */ + + public Pinsetter getPinsetter() { + return setter; + } + + /** + * Pause the execution of this game + */ + public void pauseGame() { + gameIsHalted = true; + publish(lanePublish()); + } + + /** + * Resume the execution of this game + */ + public void unPauseGame() { + gameIsHalted = false; + publish(lanePublish()); + } + +} diff --git a/BallingManagementSystem_refactoring/LaneEvent.java b/BallingManagementSystem_refactoring/LaneEvent.java new file mode 100644 index 0000000..13e9c5e --- /dev/null +++ b/BallingManagementSystem_refactoring/LaneEvent.java @@ -0,0 +1,95 @@ +/* $Id$ + * + * Revisions: + * $Log: LaneEvent.java,v $ + * Revision 1.6 2003/02/16 22:59:34 ??? + * added mechnanical problem flag + * + * Revision 1.5 2003/02/02 23:55:31 ??? + * Many many changes. + * + * Revision 1.4 2003/02/02 22:44:26 ??? + * More data. + * + * Revision 1.3 2003/02/02 17:49:31 ??? + * Modified. + * + * Revision 1.2 2003/01/30 21:21:07 ??? + * *** empty log message *** + * + * Revision 1.1 2003/01/19 22:12:40 ??? + * created laneevent and laneobserver + * + * + */ + +import java.util.HashMap; + +public class LaneEvent { + + private Party p; + int frame; + int ball; + Bowler bowler; + int[][] cumulScore; + HashMap score; + int index; + int frameNum; + int[] curScores; + boolean mechProb; + + public LaneEvent( Party pty, int theIndex, Bowler theBowler, int[][] theCumulScore, HashMap theScore, int theFrameNum, int[] theCurScores, int theBall, boolean mechProblem) { + p = pty; + index = theIndex; + bowler = theBowler; + cumulScore = theCumulScore; + score = theScore; + curScores = theCurScores; + frameNum = theFrameNum; + ball = theBall; + mechProb = mechProblem; + } + + public boolean isMechanicalProblem() { + return mechProb; + } + + public int getFrameNum() { + return frameNum; + } + + public HashMap getScore( ) { + return score; + } + + + public int[] getCurScores(){ + return curScores; + } + + public int getIndex() { + return index; + } + + public int getFrame( ) { + return frame; + } + + public int getBall( ) { + return ball; + } + + public int[][] getCumulScore(){ + return cumulScore; + } + + public Party getParty() { + return p; + } + + public Bowler getBowler() { + return bowler; + } + +}; + diff --git a/BallingManagementSystem_refactoring/LaneEventInterface.java b/BallingManagementSystem_refactoring/LaneEventInterface.java new file mode 100644 index 0000000..c3936fc --- /dev/null +++ b/BallingManagementSystem_refactoring/LaneEventInterface.java @@ -0,0 +1,15 @@ +import java.util.HashMap; + +public interface LaneEventInterface extends java.rmi.Remote { + public int getFrameNum( ) throws java.rmi.RemoteException; + public HashMap getScore( ) throws java.rmi.RemoteException; + public int[] getCurScores( ) throws java.rmi.RemoteException; + public int getIndex() throws java.rmi.RemoteException; + public int getFrame() throws java.rmi.RemoteException; + public int getBall() throws java.rmi.RemoteException; + public int[][] getCumulScore() throws java.rmi.RemoteException; + public Party getParty() throws java.rmi.RemoteException; + public Bowler getBowler() throws java.rmi.RemoteException; + +} + diff --git a/BallingManagementSystem_refactoring/LaneObserver.java b/BallingManagementSystem_refactoring/LaneObserver.java new file mode 100644 index 0000000..a7c468b --- /dev/null +++ b/BallingManagementSystem_refactoring/LaneObserver.java @@ -0,0 +1,17 @@ +/* $Id$ + * + * Revisions: + * $Log: LaneObserver.java,v $ + * Revision 1.2 2003/01/30 21:44:25 ??? + * Fixed speling of received in may places. + * + * Revision 1.1 2003/01/19 22:12:40 ??? + * created laneevent and laneobserver + * + * + */ + +public interface LaneObserver { + public void receiveLaneEvent(LaneEvent le); +}; + diff --git a/BallingManagementSystem_refactoring/LaneServer.java b/BallingManagementSystem_refactoring/LaneServer.java new file mode 100644 index 0000000..05b3dd1 --- /dev/null +++ b/BallingManagementSystem_refactoring/LaneServer.java @@ -0,0 +1,4 @@ +public interface LaneServer extends java.rmi.Remote { + public void subscribe(LaneObserver toAdd) throws java.rmi.RemoteException; +}; + diff --git a/BallingManagementSystem_refactoring/LaneStatusView.java b/BallingManagementSystem_refactoring/LaneStatusView.java new file mode 100644 index 0000000..9c530e9 --- /dev/null +++ b/BallingManagementSystem_refactoring/LaneStatusView.java @@ -0,0 +1,155 @@ +/** + * + * To change this generated comment edit the template variable "typecomment": + * Window>Preferences>Java>Templates. + * To enable and disable the creation of type comments go to + * Window>Preferences>Java>Code Generation. + */ + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.border.*; +import javax.swing.event.*; + +public class LaneStatusView implements ActionListener, LaneObserver, PinsetterObserver { + + private JPanel jp; + + private JLabel curBowler, foul, pinsDown; + private JButton viewLane; + private JButton viewPinSetter, maintenance; + + private PinSetterView psv; + private LaneView lv; + private Lane lane; + int laneNum; + + boolean laneShowing; + boolean psShowing; + + public LaneStatusView(Lane lane, int laneNum ) { + + this.lane = lane; + this.laneNum = laneNum; + + laneShowing=false; + psShowing=false; + + psv = new PinSetterView( laneNum ); + Pinsetter ps = lane.getPinsetter(); + ps.subscribe(psv); + + lv = new LaneView( lane, laneNum ); + lane.subscribe(lv); + + + jp = new JPanel(); + jp.setLayout(new FlowLayout()); + JLabel cLabel = new JLabel( "Now Bowling: " ); + curBowler = new JLabel( "(no one)" ); + JLabel fLabel = new JLabel( "Foul: " ); + foul = new JLabel( " " ); + JLabel pdLabel = new JLabel( "Pins Down: " ); + pinsDown = new JLabel( "0" ); + + // Button Panel + JPanel buttonPanel = new JPanel(); + buttonPanel.setLayout(new FlowLayout()); + + Insets buttonMargin = new Insets(4, 4, 4, 4); + + viewLane = new JButton("View Lane"); + JPanel viewLanePanel = new JPanel(); + viewLanePanel.setLayout(new FlowLayout()); + viewLane.addActionListener(this); + viewLanePanel.add(viewLane); + + viewPinSetter = new JButton("Pinsetter"); + JPanel viewPinSetterPanel = new JPanel(); + viewPinSetterPanel.setLayout(new FlowLayout()); + viewPinSetter.addActionListener(this); + viewPinSetterPanel.add(viewPinSetter); + + maintenance = new JButton(" "); + maintenance.setBackground( Color.GREEN ); + JPanel maintenancePanel = new JPanel(); + maintenancePanel.setLayout(new FlowLayout()); + maintenance.addActionListener(this); + maintenancePanel.add(maintenance); + + viewLane.setEnabled( false ); + viewPinSetter.setEnabled( false ); + + + buttonPanel.add(viewLanePanel); + buttonPanel.add(viewPinSetterPanel); + buttonPanel.add(maintenancePanel); + + jp.add( cLabel ); + jp.add( curBowler ); +// jp.add( fLabel ); +// jp.add( foul ); + jp.add( pdLabel ); + jp.add( pinsDown ); + + jp.add(buttonPanel); + + } + + public JPanel showLane() { + return jp; + } + + public void actionPerformed( ActionEvent e ) { + if ( lane.isPartyAssigned() ) { + if (e.getSource().equals(viewPinSetter)) { + if ( psShowing == false ) { + psv.show(); + psShowing=true; + } else if ( psShowing == true ) { + psv.hide(); + psShowing=false; + } + } + } + if (e.getSource().equals(viewLane)) { + if ( lane.isPartyAssigned() ) { + if ( laneShowing == false ) { + lv.show(); + laneShowing=true; + } else if ( laneShowing == true ) { + lv.hide(); + laneShowing=false; + } + } + } + if (e.getSource().equals(maintenance)) { + if ( lane.isPartyAssigned() ) { + lane.unPauseGame(); + maintenance.setBackground( Color.GREEN ); + } + } + } + + public void receiveLaneEvent(LaneEvent le) { + curBowler.setText( ( (Bowler)le.getBowler()).getNickName() ); + if ( le.isMechanicalProblem() ) { + maintenance.setBackground( Color.RED ); + } + if ( lane.isPartyAssigned() == false ) { + viewLane.setEnabled( false ); + viewPinSetter.setEnabled( false ); + } else { + viewLane.setEnabled( true ); + viewPinSetter.setEnabled( true ); + } + } + + public void receivePinsetterEvent(PinsetterEvent pe) { + pinsDown.setText( ( new Integer(pe.totalPinsDown()) ).toString() ); +// foul.setText( ( new Boolean(pe.isFoulCommited()) ).toString() ); + + } + +} diff --git a/BallingManagementSystem_refactoring/LaneView.java b/BallingManagementSystem_refactoring/LaneView.java new file mode 100644 index 0000000..3a000cd --- /dev/null +++ b/BallingManagementSystem_refactoring/LaneView.java @@ -0,0 +1,209 @@ +/* + * constructs a prototype Lane View + * + */ + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import java.util.*; + +public class LaneView implements LaneObserver, ActionListener { + + private int roll; + private boolean initDone = true; + + JFrame frame; + Container cpanel; + Vector bowlers; + int cur; + Iterator bowlIt; + + JPanel[][] balls; + JLabel[][] ballLabel; + JPanel[][] scores; + JLabel[][] scoreLabel; + JPanel[][] ballGrid; + JPanel[] pins; + + JButton maintenance; + Lane lane; + + public LaneView(Lane lane, int laneNum) { + + this.lane = lane; + + initDone = true; + frame = new JFrame("Lane " + laneNum + ":"); + cpanel = frame.getContentPane(); + cpanel.setLayout(new BorderLayout()); + + frame.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + frame.hide(); + } + }); + + cpanel.add(new JPanel()); + + } + + public void show() { + frame.show(); + } + + public void hide() { + frame.hide(); + } + + private JPanel makeFrame(Party party) { + + initDone = false; + bowlers = party.getMembers(); + int numBowlers = bowlers.size(); + + JPanel panel = new JPanel(); + + panel.setLayout(new GridLayout(0, 1)); + + balls = new JPanel[numBowlers][23]; + ballLabel = new JLabel[numBowlers][23]; + scores = new JPanel[numBowlers][10]; + scoreLabel = new JLabel[numBowlers][10]; + ballGrid = new JPanel[numBowlers][10]; + pins = new JPanel[numBowlers]; + + for (int i = 0; i != numBowlers; i++) { + for (int j = 0; j != 23; j++) { + ballLabel[i][j] = new JLabel(" "); + balls[i][j] = new JPanel(); + balls[i][j].setBorder( + BorderFactory.createLineBorder(Color.BLACK)); + balls[i][j].add(ballLabel[i][j]); + } + } + + for (int i = 0; i != numBowlers; i++) { + for (int j = 0; j != 9; j++) { + ballGrid[i][j] = new JPanel(); + ballGrid[i][j].setLayout(new GridLayout(0, 3)); + ballGrid[i][j].add(new JLabel(" "), BorderLayout.EAST); + ballGrid[i][j].add(balls[i][2 * j], BorderLayout.EAST); + ballGrid[i][j].add(balls[i][2 * j + 1], BorderLayout.EAST); + } + int j = 9; + ballGrid[i][j] = new JPanel(); + ballGrid[i][j].setLayout(new GridLayout(0, 3)); + ballGrid[i][j].add(balls[i][2 * j]); + ballGrid[i][j].add(balls[i][2 * j + 1]); + ballGrid[i][j].add(balls[i][2 * j + 2]); + } + + for (int i = 0; i != numBowlers; i++) { + pins[i] = new JPanel(); + pins[i].setBorder( + BorderFactory.createTitledBorder( + ((Bowler) bowlers.get(i)).getNick())); + pins[i].setLayout(new GridLayout(0, 10)); + for (int k = 0; k != 10; k++) { + scores[i][k] = new JPanel(); + scoreLabel[i][k] = new JLabel(" ", SwingConstants.CENTER); + scores[i][k].setBorder( + BorderFactory.createLineBorder(Color.BLACK)); + scores[i][k].setLayout(new GridLayout(0, 1)); + scores[i][k].add(ballGrid[i][k], BorderLayout.EAST); + scores[i][k].add(scoreLabel[i][k], BorderLayout.SOUTH); + pins[i].add(scores[i][k], BorderLayout.EAST); + } + panel.add(pins[i]); + } + + initDone = true; + return panel; + } + + public void receiveLaneEvent(LaneEvent le) { + if (lane.isPartyAssigned()) { + int numBowlers = le.getParty().getMembers().size(); + while (!initDone) { + //System.out.println("chillin' here."); + try { + Thread.sleep(1); + } catch (Exception e) { + } + } + + if (le.getFrameNum() == 1 + && le.getBall() == 0 + && le.getIndex() == 0) { + System.out.println("Making the frame."); + cpanel.removeAll(); + cpanel.add(makeFrame(le.getParty()), "Center"); + + // Button Panel + JPanel buttonPanel = new JPanel(); + buttonPanel.setLayout(new FlowLayout()); + + Insets buttonMargin = new Insets(4, 4, 4, 4); + + maintenance = new JButton("Maintenance Call"); + JPanel maintenancePanel = new JPanel(); + maintenancePanel.setLayout(new FlowLayout()); + maintenance.addActionListener(this); + maintenancePanel.add(maintenance); + + buttonPanel.add(maintenancePanel); + + cpanel.add(buttonPanel, "South"); + + frame.pack(); + + } + + int[][] lescores = le.getCumulScore(); + for (int k = 0; k < numBowlers; k++) { + for (int i = 0; i <= le.getFrameNum() - 1; i++) { + if (lescores[k][i] != 0) + scoreLabel[k][i].setText( + (new Integer(lescores[k][i])).toString()); + } + for (int i = 0; i < 21; i++) { + if (((int[]) ((HashMap) le.getScore()) + .get(bowlers.get(k)))[i] + != -1) + if (((int[]) ((HashMap) le.getScore()) + .get(bowlers.get(k)))[i] + == 10 + && (i % 2 == 0 || i == 19)) + ballLabel[k][i].setText("X"); + else if ( + i > 0 + && ((int[]) ((HashMap) le.getScore()) + .get(bowlers.get(k)))[i] + + ((int[]) ((HashMap) le.getScore()) + .get(bowlers.get(k)))[i + - 1] + == 10 + && i % 2 == 1) + ballLabel[k][i].setText("/"); + else if ( ((int[])((HashMap) le.getScore()).get(bowlers.get(k)))[i] == -2 ){ + + ballLabel[k][i].setText("F"); + } else + ballLabel[k][i].setText( + (new Integer(((int[]) ((HashMap) le.getScore()) + .get(bowlers.get(k)))[i])) + .toString()); + } + } + + } + } + + public void actionPerformed(ActionEvent e) { + if (e.getSource().equals(maintenance)) { + lane.pauseGame(); + } + } + +} diff --git a/BallingManagementSystem_refactoring/NewPatronView.java b/BallingManagementSystem_refactoring/NewPatronView.java new file mode 100644 index 0000000..84cbb9b --- /dev/null +++ b/BallingManagementSystem_refactoring/NewPatronView.java @@ -0,0 +1,156 @@ +/* AddPartyView.java + * + * Version + * $Id$ + * + * Revisions: + * $Log: NewPatronView.java,v $ + * Revision 1.3 2003/02/02 16:29:52 ??? + * Added ControlDeskEvent and ControlDeskObserver. Updated Queue to allow access to Vector so that contents could be viewed without destroying. Implemented observer model for most of ControlDesk. + * + * + */ + +/** + * Class for GUI components need to add a patron + * + */ + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; +import javax.swing.border.*; +import javax.swing.event.*; + +import java.util.*; +import java.text.*; + +public class NewPatronView implements ActionListener { + + private int maxSize; + + private JFrame win; + private JButton abort, finished; + private JLabel nickLabel, fullLabel, emailLabel; + private JTextField nickField, fullField, emailField; + private String nick, full, email; + + private boolean done; + + private String selectedNick, selectedMember; + private AddPartyView addParty; + + public NewPatronView(AddPartyView v) { + + addParty=v; + done = false; + + win = new JFrame("Add Patron"); + win.getContentPane().setLayout(new BorderLayout()); + ((JPanel) win.getContentPane()).setOpaque(false); + + JPanel colPanel = new JPanel(); + colPanel.setLayout(new BorderLayout()); + + // Patron Panel + JPanel patronPanel = new JPanel(); + patronPanel.setLayout(new GridLayout(3, 1)); + patronPanel.setBorder(new TitledBorder("Your Info")); + + JPanel nickPanel = new JPanel(); + nickPanel.setLayout(new FlowLayout()); + nickLabel = new JLabel("Nick Name"); + nickField = new JTextField("", 15); + nickPanel.add(nickLabel); + nickPanel.add(nickField); + + JPanel fullPanel = new JPanel(); + fullPanel.setLayout(new FlowLayout()); + fullLabel = new JLabel("Full Name"); + fullField = new JTextField("", 15); + fullPanel.add(fullLabel); + fullPanel.add(fullField); + + JPanel emailPanel = new JPanel(); + emailPanel.setLayout(new FlowLayout()); + emailLabel = new JLabel("E-Mail"); + emailField = new JTextField("", 15); + emailPanel.add(emailLabel); + emailPanel.add(emailField); + + patronPanel.add(nickPanel); + patronPanel.add(fullPanel); + patronPanel.add(emailPanel); + + // Button Panel + JPanel buttonPanel = new JPanel(); + buttonPanel.setLayout(new GridLayout(4, 1)); + + Insets buttonMargin = new Insets(4, 4, 4, 4); + + finished = new JButton("Add Patron"); + JPanel finishedPanel = new JPanel(); + finishedPanel.setLayout(new FlowLayout()); + finished.addActionListener(this); + finishedPanel.add(finished); + + abort = new JButton("Abort"); + JPanel abortPanel = new JPanel(); + abortPanel.setLayout(new FlowLayout()); + abort.addActionListener(this); + abortPanel.add(abort); + + buttonPanel.add(abortPanel); + buttonPanel.add(finishedPanel); + + // Clean up main panel + colPanel.add(patronPanel, "Center"); + colPanel.add(buttonPanel, "East"); + + win.getContentPane().add("Center", colPanel); + + win.pack(); + + // Center Window on Screen + Dimension screenSize = (Toolkit.getDefaultToolkit()).getScreenSize(); + win.setLocation( + ((screenSize.width) / 2) - ((win.getSize().width) / 2), + ((screenSize.height) / 2) - ((win.getSize().height) / 2)); + win.show(); + + } + + public void actionPerformed(ActionEvent e) { + if (e.getSource().equals(abort)) { + done = true; + win.hide(); + } + + if (e.getSource().equals(finished)) { + nick = nickField.getText(); + full = fullField.getText(); + email = emailField.getText(); + done = true; + addParty.updateNewPatron( this ); + win.hide(); + } + + } + + public boolean done() { + return done; + } + + public String getNick() { + return nick; + } + + public String getFull() { + return full; + } + + public String getEmail() { + return email; + } + +} diff --git a/BallingManagementSystem_refactoring/Party.java b/BallingManagementSystem_refactoring/Party.java new file mode 100644 index 0000000..3aa4533 --- /dev/null +++ b/BallingManagementSystem_refactoring/Party.java @@ -0,0 +1,52 @@ +/* + * Party.java + * + * Version: + * $Id$ + * + * Revisions: + * $Log: Party.java,v $ + * Revision 1.3 2003/02/09 21:21:31 ??? + * Added lots of comments + * + * Revision 1.2 2003/01/12 22:23:32 ??? + * *** empty log message *** + * + * Revision 1.1 2003/01/12 19:09:12 ??? + * Adding Party, Lane, Bowler, and Alley. + * + */ + +/** + * Container that holds bowlers + * + */ + +import java.util.*; + +public class Party { + + /** Vector of bowlers in this party */ + private Vector myBowlers; + + /** + * Constructor for a Party + * + * @param bowlers Vector of bowlers that are in this party + */ + + public Party( Vector bowlers ) { + myBowlers = new Vector(bowlers); + } + + /** + * Accessor for members in this party + * + * @return A vector of the bowlers in this party + */ + + public Vector getMembers() { + return myBowlers; + } + +} diff --git a/BallingManagementSystem_refactoring/PinSetterView.java b/BallingManagementSystem_refactoring/PinSetterView.java new file mode 100644 index 0000000..db2d561 --- /dev/null +++ b/BallingManagementSystem_refactoring/PinSetterView.java @@ -0,0 +1,194 @@ +/* + * PinSetterView/.java + * + * Version: + * $Id$ + * + * Revision: + * $Log$ + */ + +/** + * constructs a prototype PinSetter GUI + * + */ + +import java.awt.*; +import javax.swing.*; +import java.util.Vector; + + +public class PinSetterView implements PinsetterObserver { + + + private Vector pinVect = new Vector ( ); + private JPanel firstRoll; + private JPanel secondRoll; + + /** + * Constructs a Pin Setter GUI displaying which roll it is with + * yellow boxes along the top (1 box for first roll, 2 boxes for second) + * and displays the pins as numbers in this format: + * + * 7 8 9 10 + * 4 5 6 + * 2 3 + * 1 + * + */ + + + private JFrame frame; + + public PinSetterView ( int laneNum ) { + + frame = new JFrame ( "Lane " + laneNum + ":" ); + + Container cpanel = frame.getContentPane ( ); + + JPanel pins = new JPanel ( ); + + pins.setLayout ( new GridLayout ( 4, 7 ) ); + + //********************Top of GUI indicates first or second roll + + JPanel top = new JPanel ( ); + + firstRoll = new JPanel ( ); + firstRoll.setBackground( Color.yellow ); + + secondRoll = new JPanel ( ); + secondRoll.setBackground ( Color.black ); + + top.add ( firstRoll, BorderLayout.WEST ); + + top.add ( secondRoll, BorderLayout.EAST ); + + //****************************************************************** + + //**********************Grid of the pins************************** + + private JPanel createPanel( String pinNumber, JPanel panel) { + //JPanel label = new JPanel(); + JLabel label = new JLabel(pinNumber); + panel.add (label); + pinVect.add (label); + } + + createPanel(1, oneL); + createPanel(2, twoL); + createPanel(3, threeL); + createPanel(4, fourL); + createPanel(5, fiveL); + createPanel(6, sixL); + createPanel(7, sevenL); + createPanel(8, eightL); + createPanel(9, nineL); + createPanel(10, tenL); + + + //This Vector will keep references to the pin labels to show + //which ones have fallen. + + + //******************************Fourth Row************** + + pins.add ( seven ); + pins.add ( new JPanel ( ) ); + pins.add ( eight ); + pins.add ( new JPanel ( ) ); + pins.add ( nine ); + pins.add ( new JPanel ( ) ); + pins.add ( ten ); + + //*****************************Third Row*********** + + pins.add ( new JPanel ( ) ); + pins.add ( four ); + pins.add ( new JPanel ( ) ); + pins.add ( five ); + pins.add ( new JPanel ( ) ); + pins.add ( six ); + + //*****************************Second Row************** + + pins.add ( new JPanel ( ) ); + pins.add ( new JPanel ( ) ); + pins.add ( new JPanel ( ) ); + pins.add ( two ); + pins.add ( new JPanel ( ) ); + pins.add ( three ); + pins.add ( new JPanel ( ) ); + pins.add ( new JPanel ( ) ); + + //******************************First Row***************** + + pins.add ( new JPanel ( ) ); + pins.add ( new JPanel ( ) ); + pins.add ( new JPanel ( ) ); + pins.add ( one ); + pins.add ( new JPanel ( ) ); + pins.add ( new JPanel ( ) ); + pins.add ( new JPanel ( ) ); + //********************************************************* + + top.setBackground ( Color.black ); + + cpanel.add ( top, BorderLayout.NORTH ); + + pins.setBackground ( Color.black ); + pins.setForeground ( Color.yellow ); + + cpanel.add ( pins, BorderLayout.CENTER ); + + frame.pack(); + + } + + + /** + * This method receives a pinsetter event. The event is the current + * state of the PinSetter and the method changes how the GUI looks + * accordingly. When pins are "knocked down" the corresponding label + * is grayed out. When it is the second roll, it is indicated by the + * appearance of a second yellow box at the top. + * + * @param e The state of the pinsetter is sent in this event. + */ + + + public void receivePinsetterEvent(PinsetterEvent pe){ + if ( !(pe.isFoulCommited()) ) { + JLabel tempPin = new JLabel ( ); + for ( int c = 0; c < 10; c++ ) { + boolean pin = pe.pinKnockedDown ( c ); + tempPin = (JLabel)pinVect.get ( c ); + if ( pin ) { + tempPin.setForeground ( Color.lightGray ); + } + } + } + if ( pe.getThrowNumber() == 1 ) { + secondRoll.setBackground ( Color.yellow ); + } + if ( pe.pinsDownOnThisThrow() == -1) { + for ( int i = 0; i != 10; i++){ + ((JLabel)pinVect.get(i)).setForeground(Color.black); + } + secondRoll.setBackground( Color.black); + } + } + + public void show() { + frame.show(); + } + + public void hide() { + frame.hide(); + } + + public static void main ( String args [ ] ) { + PinSetterView pg = new PinSetterView ( 1 ); + } + +} diff --git a/BallingManagementSystem_refactoring/Pinsetter.java b/BallingManagementSystem_refactoring/Pinsetter.java new file mode 100644 index 0000000..35dbb2e --- /dev/null +++ b/BallingManagementSystem_refactoring/Pinsetter.java @@ -0,0 +1,202 @@ +/* + * Pinsetter.java + * + * Version: + * $Id$ + * + * Revisions: + * $Log: Pinsetter.java,v $ + * Revision 1.21 2003/02/20 20:27:45 ??? + * Fouls disables. + * + * Revision 1.20 2003/02/20 19:53:52 ??? + * Added foul support. Still need to update laneview and test this. + * + * Revision 1.19 2003/02/06 22:28:51 ??? + * added delay + * + * Revision 1.18 2003/02/06 00:27:46 ??? + * Fixed a race condition + * + * Revision 1.17 2003/02/05 23:56:07 ??? + * *** empty log message *** + * + * Revision 1.16 2003/02/05 23:51:09 ??? + * Better random numbers. + * + * Revision 1.15 2003/02/02 23:49:48 ??? + * Pinsetter generates an event when all pins are reset + * + * Revision 1.14 2003/02/02 23:26:32 ??? + * ControlDesk now runs its own thread and polls for free lanes to assign queue members to + * + * Revision 1.13 2003/02/02 23:21:30 ??? + * pinsetter should give better results + * + * Revision 1.12 2003/02/02 23:20:28 ??? + * pinsetter should give better results + * + * Revision 1.11 2003/02/02 23:11:41 ??? + * parties can now play more than 1 game on a lane, and lanes are properly released after games + * + * Revision 1.10 2003/02/01 19:14:42 ??? + * Will now set the pins back up at times other than the 10th frame. + * + * Revision 1.9 2003/01/30 21:44:25 ??? + * Fixed speling of received in may places. + * + * Revision 1.8 2003/01/26 22:34:44 ??? + * Total rewrite of lane and pinsetter for R2's observer model + * Added Lane/Pinsetter Observer + * Rewrite of scoring algorythm in lane + * + * Revision 1.7 2003/01/19 21:55:24 ??? + * updated pinsetter to new spec + * + * Revision 1.6 2003/01/16 04:59:59 ??? + * misc fixes across the board + * + * Revision 1.5 2003/01/13 22:35:21 ??? + * Scoring works. + * + * Revision 1.3 2003/01/12 22:37:20 ??? + * Wrote a better algorythm for knocking down pins + * + * + */ + +/** + * Class to represent the pinsetter + * + */ + +import java.util.*; + +public class Pinsetter { + + private Random rnd; + private Vector subscribers; + + private boolean[] pins; + /* 0-9 of state of pine, true for standing, + false for knocked down + + 6 7 8 9 + 3 4 5 + 2 1 + 0 + + */ + private boolean foul; + private int throwNumber; + + /** sendEvent() + * + * Sends pinsetter events to all subscribers + * + * @pre none + * @post all subscribers have recieved pinsetter event with updated state + * */ + private void sendEvent(int jdpins) { // send events when our state is changd + for (int i=0; i < subscribers.size(); i++) { + ((PinsetterObserver)subscribers.get(i)).receivePinsetterEvent( + new PinsetterEvent(pins, foul, throwNumber, jdpins)); + } + } + + /** Pinsetter() + * + * Constructs a new pinsetter + * + * @pre none + * @post a new pinsetter is created + * @return Pinsetter object + */ + public Pinsetter() { + pins = new boolean[10]; + rnd = new Random(); + subscribers = new Vector(); + foul = false; + reset(); + } + + /** ballThrown() + * + * Called to simulate a ball thrown comming in contact with the pinsetter + * + * @pre none + * @post pins may have been knocked down and the thrownumber has been incremented + */ + public void ballThrown() { // simulated event of ball hits sensor + int count = 0; + foul = false; + double skill = rnd.nextDouble(); + for (int i=0; i <= 9; i++) { + if (pins[i]) { + double pinluck = rnd.nextDouble(); + if (pinluck <= .04){ + foul = true; + } + if ( ((skill + pinluck)/2.0 * 1.2) > .5 ){ + pins[i] = false; + } + if (!pins[i]) { // this pin just knocked down + count++; + } + } + } + + try { + Thread.sleep(500); // pinsetter is where delay will be in a real game + } catch (Exception e) {} + + sendEvent(count); + + throwNumber++; + } + + /** reset() + * + * Reset the pinsetter to its complete state + * + * @pre none + * @post pinsetters state is reset + */ + public void reset() { + foul = false; + throwNumber = 1; + resetPins(); + + try { + Thread.sleep(1000); + } catch (Exception e) {} + + sendEvent(-1); + } + + /** resetPins() + * + * Reset the pins on the pinsetter + * + * @pre none + * @post pins array is reset to all pins up + */ + public void resetPins() { + for (int i=0; i <= 9; i++) { + pins[i] = true; + } + } + + /** subscribe() + * + * subscribe objects to send events to + * + * @pre none + * @post the subscriber object will recieve events when their generated + */ + public void subscribe(PinsetterObserver subscriber) { + subscribers.add(subscriber); + } + +}; + diff --git a/BallingManagementSystem_refactoring/PinsetterEvent.java b/BallingManagementSystem_refactoring/PinsetterEvent.java new file mode 100644 index 0000000..3509873 --- /dev/null +++ b/BallingManagementSystem_refactoring/PinsetterEvent.java @@ -0,0 +1,90 @@ +/* $Id$ + * + * Revisions: + * $Log: PinsetterEvent.java,v $ + * Revision 1.2 2003/01/26 22:34:44 ??? + * Total rewrite of lane and pinsetter for R2's observer model + * Added Lane/Pinsetter Observer + * Rewrite of scoring algorythm in lane + * + * Revision 1.1 2003/01/19 21:04:24 ??? + * created pinsetterevent and pinsetterobserver + * + */ + +public class PinsetterEvent { + + private boolean[] pinsStillStanding; + private boolean foulCommited; + private int throwNumber; + private int pinsDownThisThrow; + + /** PinsetterEvent() + * + * creates a new pinsetter event + * + * @pre none + * @post the object has been initialized + */ + public PinsetterEvent(boolean[] ps, boolean foul, int tn, int pinsDownThisThrow) { + pinsStillStanding = new boolean[10]; + + for (int i=0; i <= 9; i++) { + pinsStillStanding[i] = ps[i]; + } + + foulCommited = foul; + throwNumber = tn; + this.pinsDownThisThrow = pinsDownThisThrow; + } + + /** pinKnockedDown() + * + * check if a pin has been knocked down + * + * @return true if pin [i] has been knocked down + */ + public boolean pinKnockedDown(int i) { + return !pinsStillStanding[i]; + } + + /** pinsDownOnThisThrow() + * + * @return the number of pins knocked down assosicated with this event + */ + public int pinsDownOnThisThrow() { + return pinsDownThisThrow; + } + + /** totalPinsDown() + * + * @return the total number of pins down for pinsetter that generated the event + */ + public int totalPinsDown() { + int count = 0; + + for (boolean pinStanding : pinsStillStanding) { + if (!pinStanding) { + count++; + } + } + return count; + } + + /** isFoulCommited() + * + * @return true if a foul was commited on the lane, false otherwise + */ + public boolean isFoulCommited() { + return foulCommited; + } + + /** getThrowNumber() + * + * @return current number of throws taken on this lane after last reset + */ + public int getThrowNumber() { + return throwNumber; + } +}; + diff --git a/BallingManagementSystem_refactoring/PinsetterObserver.java b/BallingManagementSystem_refactoring/PinsetterObserver.java new file mode 100644 index 0000000..666ae04 --- /dev/null +++ b/BallingManagementSystem_refactoring/PinsetterObserver.java @@ -0,0 +1,28 @@ +/* $Id$ + * + * Revisions: + * $Log: PinsetterObserver.java,v $ + * Revision 1.3 2003/01/30 21:44:25 ??? + * Fixed speling of received in may places. + * + * Revision 1.2 2003/01/26 22:34:44 ??? + * Total rewrite of lane and pinsetter for R2's observer model + * Added Lane/Pinsetter Observer + * Rewrite of scoring algorythm in lane + * + * Revision 1.1 2003/01/19 21:04:24 ??? + * created pinsetterevent and pinsetterobserver + * + * + */ + + +public interface PinsetterObserver { + + /** recievePinsetterEvent() + * + * defines the method for an object torecieve a pinsetter event + */ + public void receivePinsetterEvent(PinsetterEvent pe); +}; + diff --git a/BallingManagementSystem_refactoring/PrintableText.java b/BallingManagementSystem_refactoring/PrintableText.java new file mode 100644 index 0000000..9505048 --- /dev/null +++ b/BallingManagementSystem_refactoring/PrintableText.java @@ -0,0 +1,47 @@ +/** + * + */ + +import java.awt.*; +import java.awt.print.*; +import java.awt.geom.*; +import java.awt.font.*; +import java.text.*; + +public class PrintableText implements Printable { + String text; + int POINTS_PER_INCH; + + public PrintableText(String t) { + POINTS_PER_INCH = 72; + text = t; + } + + public int print(Graphics g, PageFormat pageFormat, int pageIndex) { + if (pageIndex > 0) { + return NO_SUCH_PAGE; + } + + Graphics2D g2d = (Graphics2D) g; // Allow use of Java 2 graphics on + + g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); + g2d.setPaint(Color.black); + + Point2D.Double pen = new Point2D.Double(0.25 * POINTS_PER_INCH, 0.25 * POINTS_PER_INCH); + + Font font = new Font ("courier", Font.PLAIN, 12); + FontRenderContext frc = g2d.getFontRenderContext(); + + String lines[] = text.split("\n"); + + for (int i=0; i < lines.length; i++) { + if (lines[i].length() > 0) { + TextLayout layout = new TextLayout(lines[i], font, frc); + layout.draw(g2d, (float) pen.x, (float) (pen.y + i*14)); + } + } + + return PAGE_EXISTS; + } + +} diff --git a/BallingManagementSystem_refactoring/Queue.java b/BallingManagementSystem_refactoring/Queue.java new file mode 100644 index 0000000..2f23814 --- /dev/null +++ b/BallingManagementSystem_refactoring/Queue.java @@ -0,0 +1,40 @@ +/* Queue.java + * + * Version + * $Id$ + * + * Revisions: + * $Log$ + * + */ + +import java.util.Vector; + +public class Queue { + private Vector v; + + /** Queue() + * + * creates a new queue + */ + public Queue() { + v = new Vector(); + } + + public Object next() { + return v.remove(0); + } + + public void add(Object o) { + v.addElement(o); + } + + public boolean hasMoreElements() { + return v.size() != 0; + } + + public Vector asVector() { + return v; + } + +} diff --git a/BallingManagementSystem_refactoring/README.md b/BallingManagementSystem_refactoring/README.md new file mode 100644 index 0000000..738ee2a --- /dev/null +++ b/BallingManagementSystem_refactoring/README.md @@ -0,0 +1 @@ +# BallingManagementSystem_refactoring \ No newline at end of file diff --git a/BallingManagementSystem_refactoring/SCOREHISTORY.DAT b/BallingManagementSystem_refactoring/SCOREHISTORY.DAT new file mode 100644 index 0000000..1a3e071 --- /dev/null +++ b/BallingManagementSystem_refactoring/SCOREHISTORY.DAT @@ -0,0 +1,15 @@ +Mike 22:25 3/6/2004 130 +Jim 22:25 3/6/2004 113 +Tom 22:25 3/6/2004 105 +Lana 22:25 3/6/2004 130 +TomH 22:25 3/6/2004 125 +Mike 22:26 3/6/2004 153 +TomH 22:26 3/6/2004 174 +Mike 15:52 4/2/2023 162 +Jim 15:52 4/2/2023 139 +Tom 15:54 4/2/2023 124 +Jim 15:54 4/2/2023 134 +Mike 16:26 4/2/2023 133 +Jim 16:26 4/2/2023 127 +Mike 16:28 4/2/2023 91 +Jim 16:28 4/2/2023 111 diff --git a/BallingManagementSystem_refactoring/Score.java b/BallingManagementSystem_refactoring/Score.java new file mode 100644 index 0000000..deaedc7 --- /dev/null +++ b/BallingManagementSystem_refactoring/Score.java @@ -0,0 +1,37 @@ +/** + * + * To change this generated comment edit the template variable "typecomment": + * Window>Preferences>Java>Templates. + * To enable and disable the creation of type comments go to + * Window>Preferences>Java>Code Generation. + */ + +public class Score { + + private String nick; + private String date; + private String score; + + public Score( String nick, String date, String score ) { + this.nick=nick; + this.date=date; + this.score=score; + } + + public String getNickName() { + return nick; + } + + public String getDate() { + return date; + } + + public String getScore() { + return score; + } + + public String toString() { + return nick + "\t" + date + "\t" + score; + } + +} diff --git a/BallingManagementSystem_refactoring/ScoreHistoryFile.java b/BallingManagementSystem_refactoring/ScoreHistoryFile.java new file mode 100644 index 0000000..34bfd57 --- /dev/null +++ b/BallingManagementSystem_refactoring/ScoreHistoryFile.java @@ -0,0 +1,45 @@ +/** + * + * To change this generated comment edit the template variable "typecomment": + * Window>Preferences>Java>Templates. + * To enable and disable the creation of type comments go to + * Window>Preferences>Java>Code Generation. + */ + +import java.util.*; +import java.io.*; + +public class ScoreHistoryFile { + + private static String SCOREHISTORY_DAT = "SCOREHISTORY.DAT"; + + public static void addScore(String nick, String date, String score) + throws IOException, FileNotFoundException { + + String data = nick + "\t" + date + "\t" + score + "\n"; + + RandomAccessFile out = new RandomAccessFile(SCOREHISTORY_DAT, "rw"); + out.skipBytes((int) out.length()); + out.writeBytes(data); + out.close(); + } + + public static Vector getScores(String nick) + throws IOException, FileNotFoundException { + Vector scores = new Vector(); + + BufferedReader in = + new BufferedReader(new FileReader(SCOREHISTORY_DAT)); + String data; + while ((data = in.readLine()) != null) { + // File format is nick\tfname\te-mail + String[] scoredata = data.split("\t"); + //"Nick: scoredata[0] Date: scoredata[1] Score: scoredata[2] + if (nick.equals(scoredata[0])) { + scores.add(new Score(scoredata[0], scoredata[1], scoredata[2])); + } + } + return scores; + } + +} diff --git a/BallingManagementSystem_refactoring/ScoreReport.java b/BallingManagementSystem_refactoring/ScoreReport.java new file mode 100644 index 0000000..934a511 --- /dev/null +++ b/BallingManagementSystem_refactoring/ScoreReport.java @@ -0,0 +1,125 @@ +/** + * + * SMTP implementation based on code by Réal Gagnon mailto:real@rgagnon.com + * + */ + + +import java.io.*; +import java.util.Vector; +import java.util.Iterator; +import java.net.*; +import java.awt.*; +import java.awt.print.*; + +public class ScoreReport { + + private String content; + + public ScoreReport( Bowler bowler, int[] scores, int games ) { + String nick = bowler.getNick(); + String full = bowler.getFullName(); + Vector v = null; + try{ + v = ScoreHistoryFile.getScores(nick); + } catch (Exception e){System.err.println("Error: " + e);} + + Iterator scoreIt = v.iterator(); + + content = ""; + content += "--Lucky Strike Bowling Alley Score Report--\n"; + content += "\n"; + content += "Report for " + full + ", aka \"" + nick + "\":\n"; + content += "\n"; + content += "Final scores for this session: "; + content += scores[0]; + for (int i = 1; i < games; i++){ + content += ", " + scores[i]; + } + content += ".\n"; + content += "\n"; + content += "\n"; + content += "Previous scores by date: \n"; + while (scoreIt.hasNext()){ + Score score = (Score) scoreIt.next(); + content += " " + score.getDate() + " - " + score.getScore(); + content += "\n"; + } + content += "\n\n"; + content += "Thank you for your continuing patronage."; + + } + + public void sendEmail(String recipient) { + try { + Socket s = new Socket("osfmail.rit.edu", 25); + BufferedReader in = + new BufferedReader( + new InputStreamReader(s.getInputStream(), "8859_1")); + BufferedWriter out = + new BufferedWriter( + new OutputStreamWriter(s.getOutputStream(), "8859_1")); + + String boundary = "DataSeparatorString"; + + // here you are supposed to send your username + sendln(in, out, "HELO world"); + sendln(in, out, "MAIL FROM: "); + sendln(in, out, "RCPT TO: <" + recipient + ">"); + sendln(in, out, "DATA"); + sendln(out, "Subject: Bowling Score Report "); + sendln(out, "From: "); + + sendln(out, "Content-Type: text/plain; charset=\"us-ascii\"\r\n"); + sendln(out, content + "\n\n"); + sendln(out, "\r\n"); + + sendln(in, out, "."); + sendln(in, out, "QUIT"); + s.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void sendPrintout() { + PrinterJob job = PrinterJob.getPrinterJob(); + + PrintableText printobj = new PrintableText(content); + + job.setPrintable(printobj); + + if (job.printDialog()) { + try { + job.print(); + } catch (PrinterException e) { + System.out.println(e); + } + } + + } + + public void sendln(BufferedReader in, BufferedWriter out, String s) { + try { + out.write(s + "\r\n"); + out.flush(); + // System.out.println(s); + s = in.readLine(); + // System.out.println(s); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void sendln(BufferedWriter out, String s) { + try { + out.write(s + "\r\n"); + out.flush(); + System.out.println(s); + } catch (Exception e) { + e.printStackTrace(); + } + } + + +} diff --git a/BallingManagementSystem_refactoring/drive.java b/BallingManagementSystem_refactoring/drive.java new file mode 100644 index 0000000..20811bf --- /dev/null +++ b/BallingManagementSystem_refactoring/drive.java @@ -0,0 +1,18 @@ +import java.util.Vector; +import java.io.*; + +public class drive { + + public static void main(String[] args) { + + int numLanes = 3; + int maxPatronsPerParty=5; + + Alley a = new Alley( numLanes ); + ControlDesk controlDesk = a.getControlDesk(); + + ControlDeskView cdv = new ControlDeskView( controlDesk, maxPatronsPerParty); + controlDesk.subscribe( cdv ); + + } +} From 09323cfda23a579880648f8f2ec04718ed7f2d57 Mon Sep 17 00:00:00 2001 From: Dmdeer <73979650+kim08237@users.noreply.github.com> Date: Wed, 31 May 2023 11:39:21 +0900 Subject: [PATCH 2/5] Update --- PinSetterView.java | 103 +++++++++++++++++---------------------------- 1 file changed, 38 insertions(+), 65 deletions(-) diff --git a/PinSetterView.java b/PinSetterView.java index cd66b20..db2d561 100644 --- a/PinSetterView.java +++ b/PinSetterView.java @@ -14,7 +14,6 @@ */ import java.awt.*; -import java.awt.event.*; import javax.swing.*; import java.util.Vector; @@ -68,53 +67,29 @@ public PinSetterView ( int laneNum ) { //****************************************************************** //**********************Grid of the pins************************** - - - JPanel one = new JPanel (); - JLabel oneL = new JLabel ( "1" ); - one.add (oneL); - JPanel two = new JPanel (); - JLabel twoL = new JLabel ( "2" ); - two.add (twoL); - JPanel three = new JPanel (); - JLabel threeL = new JLabel ( "3" ); - three.add (threeL); - JPanel four = new JPanel (); - JLabel fourL = new JLabel ( "4" ); - four.add (fourL); - JPanel five = new JPanel (); - JLabel fiveL = new JLabel ( "5" ); - five.add (fiveL); - JPanel six = new JPanel (); - JLabel sixL = new JLabel ( "6" ); - six.add (sixL); - JPanel seven = new JPanel (); - JLabel sevenL = new JLabel ( "7" ); - seven.add (sevenL); - JPanel eight = new JPanel (); - JLabel eightL = new JLabel ( "8" ); - eight.add (eightL); - JPanel nine = new JPanel (); - JLabel nineL = new JLabel ( "9" ); - nine.add (nineL); - JPanel ten = new JPanel (); - JLabel tenL = new JLabel ( "10" ); - ten.add (tenL); + + private JPanel createPanel( String pinNumber, JPanel panel) { + //JPanel label = new JPanel(); + JLabel label = new JLabel(pinNumber); + panel.add (label); + pinVect.add (label); + } + + createPanel(1, oneL); + createPanel(2, twoL); + createPanel(3, threeL); + createPanel(4, fourL); + createPanel(5, fiveL); + createPanel(6, sixL); + createPanel(7, sevenL); + createPanel(8, eightL); + createPanel(9, nineL); + createPanel(10, tenL); + //This Vector will keep references to the pin labels to show //which ones have fallen. - - pinVect.add ( oneL ); - pinVect.add ( twoL ); - pinVect.add ( threeL ); - pinVect.add ( fourL ); - pinVect.add ( fiveL ); - pinVect.add ( sixL ); - pinVect.add ( sevenL ); - pinVect.add ( eightL ); - pinVect.add ( nineL ); - pinVect.add ( tenL ); - + //******************************Fourth Row************** @@ -167,9 +142,7 @@ public PinSetterView ( int laneNum ) { cpanel.add ( pins, BorderLayout.CENTER ); frame.pack(); - - -// frame.show(); + } @@ -185,25 +158,25 @@ public PinSetterView ( int laneNum ) { public void receivePinsetterEvent(PinsetterEvent pe){ - if ( !(pe.isFoulCommited()) ) { - JLabel tempPin = new JLabel ( ); - for ( int c = 0; c < 10; c++ ) { - boolean pin = pe.pinKnockedDown ( c ); - tempPin = (JLabel)pinVect.get ( c ); - if ( pin ) { - tempPin.setForeground ( Color.lightGray ); + if ( !(pe.isFoulCommited()) ) { + JLabel tempPin = new JLabel ( ); + for ( int c = 0; c < 10; c++ ) { + boolean pin = pe.pinKnockedDown ( c ); + tempPin = (JLabel)pinVect.get ( c ); + if ( pin ) { + tempPin.setForeground ( Color.lightGray ); + } } - } - } - if ( pe.getThrowNumber() == 1 ) { - secondRoll.setBackground ( Color.yellow ); - } - if ( pe.pinsDownOnThisThrow() == -1) { - for ( int i = 0; i != 10; i++){ - ((JLabel)pinVect.get(i)).setForeground(Color.black); + } + if ( pe.getThrowNumber() == 1 ) { + secondRoll.setBackground ( Color.yellow ); + } + if ( pe.pinsDownOnThisThrow() == -1) { + for ( int i = 0; i != 10; i++){ + ((JLabel)pinVect.get(i)).setForeground(Color.black); + } + secondRoll.setBackground( Color.black); } - secondRoll.setBackground( Color.black); - } } public void show() { From 2361aae94281a392484f420a6ca74df6228f9100 Mon Sep 17 00:00:00 2001 From: Dmdeer <73979650+kim08237@users.noreply.github.com> Date: Wed, 31 May 2023 11:40:27 +0900 Subject: [PATCH 3/5] Update --- PinsetterEvent.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/PinsetterEvent.java b/PinsetterEvent.java index 0608bc2..3509873 100644 --- a/PinsetterEvent.java +++ b/PinsetterEvent.java @@ -62,13 +62,12 @@ public int pinsDownOnThisThrow() { */ public int totalPinsDown() { int count = 0; - - for (int i=0; i <= 9; i++) { - if (pinKnockedDown(i)) { + + for (boolean pinStanding : pinsStillStanding) { + if (!pinStanding) { count++; } } - return count; } From 8961da30bd04810f8b2049fb297d58cf92853668 Mon Sep 17 00:00:00 2001 From: Dmdeer <73979650+kim08237@users.noreply.github.com> Date: Wed, 31 May 2023 11:42:56 +0900 Subject: [PATCH 4/5] Update --- PinSetterView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PinSetterView.java b/PinSetterView.java index db2d561..084622f 100644 --- a/PinSetterView.java +++ b/PinSetterView.java @@ -85,7 +85,7 @@ private JPanel createPanel( String pinNumber, JPanel panel) { createPanel(8, eightL); createPanel(9, nineL); createPanel(10, tenL); - +// //This Vector will keep references to the pin labels to show //which ones have fallen. From f273ddec022da271c26513d97d2942e520a92f87 Mon Sep 17 00:00:00 2001 From: lightorange0v0 <94609651+lightorange0v0@users.noreply.github.com> Date: Wed, 31 May 2023 15:08:05 +0900 Subject: [PATCH 5/5] Delete BallingManagementSystem_refactoring directory --- .../AddPartyView.java | 245 ------- .../AgainGameCommand.java | 9 - .../Alley.java | 42 -- .../BOWLERS.DAT | 5 - .../Bowler.java | 69 -- .../BowlerFile.java | 108 --- .../ButtonCommand.java | 3 - .../ControlDesk.java | 237 ------- .../ControlDeskEvent.java | 46 -- .../ControlDeskObserver.java | 20 - .../ControlDeskView.java | 180 ----- .../EndGameCommand.java | 9 - .../EndGamePrompt.java | 112 ---- .../EndGameReport.java | 143 ---- .../EndGameReportClickEvent.java | 14 - BallingManagementSystem_refactoring/Lane.java | 621 ------------------ .../LaneEvent.java | 95 --- .../LaneEventInterface.java | 15 - .../LaneObserver.java | 17 - .../LaneServer.java | 4 - .../LaneStatusView.java | 155 ----- .../LaneView.java | 209 ------ .../NewPatronView.java | 156 ----- .../Party.java | 52 -- .../PinSetterView.java | 194 ------ .../Pinsetter.java | 202 ------ .../PinsetterEvent.java | 90 --- .../PinsetterObserver.java | 28 - .../PrintableText.java | 47 -- .../Queue.java | 40 -- BallingManagementSystem_refactoring/README.md | 1 - .../SCOREHISTORY.DAT | 15 - .../Score.java | 37 -- .../ScoreHistoryFile.java | 45 -- .../ScoreReport.java | 125 ---- .../drive.java | 18 - 36 files changed, 3408 deletions(-) delete mode 100644 BallingManagementSystem_refactoring/AddPartyView.java delete mode 100644 BallingManagementSystem_refactoring/AgainGameCommand.java delete mode 100644 BallingManagementSystem_refactoring/Alley.java delete mode 100644 BallingManagementSystem_refactoring/BOWLERS.DAT delete mode 100644 BallingManagementSystem_refactoring/Bowler.java delete mode 100644 BallingManagementSystem_refactoring/BowlerFile.java delete mode 100644 BallingManagementSystem_refactoring/ButtonCommand.java delete mode 100644 BallingManagementSystem_refactoring/ControlDesk.java delete mode 100644 BallingManagementSystem_refactoring/ControlDeskEvent.java delete mode 100644 BallingManagementSystem_refactoring/ControlDeskObserver.java delete mode 100644 BallingManagementSystem_refactoring/ControlDeskView.java delete mode 100644 BallingManagementSystem_refactoring/EndGameCommand.java delete mode 100644 BallingManagementSystem_refactoring/EndGamePrompt.java delete mode 100644 BallingManagementSystem_refactoring/EndGameReport.java delete mode 100644 BallingManagementSystem_refactoring/EndGameReportClickEvent.java delete mode 100644 BallingManagementSystem_refactoring/Lane.java delete mode 100644 BallingManagementSystem_refactoring/LaneEvent.java delete mode 100644 BallingManagementSystem_refactoring/LaneEventInterface.java delete mode 100644 BallingManagementSystem_refactoring/LaneObserver.java delete mode 100644 BallingManagementSystem_refactoring/LaneServer.java delete mode 100644 BallingManagementSystem_refactoring/LaneStatusView.java delete mode 100644 BallingManagementSystem_refactoring/LaneView.java delete mode 100644 BallingManagementSystem_refactoring/NewPatronView.java delete mode 100644 BallingManagementSystem_refactoring/Party.java delete mode 100644 BallingManagementSystem_refactoring/PinSetterView.java delete mode 100644 BallingManagementSystem_refactoring/Pinsetter.java delete mode 100644 BallingManagementSystem_refactoring/PinsetterEvent.java delete mode 100644 BallingManagementSystem_refactoring/PinsetterObserver.java delete mode 100644 BallingManagementSystem_refactoring/PrintableText.java delete mode 100644 BallingManagementSystem_refactoring/Queue.java delete mode 100644 BallingManagementSystem_refactoring/README.md delete mode 100644 BallingManagementSystem_refactoring/SCOREHISTORY.DAT delete mode 100644 BallingManagementSystem_refactoring/Score.java delete mode 100644 BallingManagementSystem_refactoring/ScoreHistoryFile.java delete mode 100644 BallingManagementSystem_refactoring/ScoreReport.java delete mode 100644 BallingManagementSystem_refactoring/drive.java diff --git a/BallingManagementSystem_refactoring/AddPartyView.java b/BallingManagementSystem_refactoring/AddPartyView.java deleted file mode 100644 index 58d2422..0000000 --- a/BallingManagementSystem_refactoring/AddPartyView.java +++ /dev/null @@ -1,245 +0,0 @@ -/* AddPartyView.java - * - * Version: - * $Id$ - * - * Revisions: - * $Log: AddPartyView.java,v $ - * Revision 1.7 2003/02/20 02:05:53 ??? - * Fixed addPatron so that duplicates won't be created. - * - * Revision 1.6 2003/02/09 20:52:46 ??? - * Added comments. - * - * Revision 1.5 2003/02/02 17:42:09 ??? - * Made updates to migrate to observer model. - * - * Revision 1.4 2003/02/02 16:29:52 ??? - * Added ControlDeskEvent and ControlDeskObserver. Updated Queue to allow access to Vector so that contents could be viewed without destroying. Implemented observer model for most of ControlDesk. - * - * - */ - -/** - * Class for GUI components need to add a party - * - */ - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.border.*; -import javax.swing.event.*; - -import java.util.*; -import java.text.*; - -/** - * Constructor for GUI used to Add Parties to the waiting party queue. - * - */ - -public class AddPartyView implements ActionListener, ListSelectionListener { - - private int maxSize; - - private JFrame win; - private JButton addPatron, newPatron, remPatron, finished; - private JList partyList, allBowlers; - private Vector party, bowlerdb; - private Integer lock; - - private ControlDeskView controlDesk; - - private String selectedNick, selectedMember; - - public AddPartyView(ControlDeskView controlDesk, int max) { - - this.controlDesk = controlDesk; - maxSize = max; - - win = new JFrame("Add Party"); - win.getContentPane().setLayout(new BorderLayout()); - ((JPanel) win.getContentPane()).setOpaque(false); - - JPanel colPanel = new JPanel(); - colPanel.setLayout(new GridLayout(1, 3)); - - // Party Panel - JPanel partyPanel = new JPanel(); - partyPanel.setLayout(new FlowLayout()); - partyPanel.setBorder(new TitledBorder("Your Party")); - - party = new Vector(); - Vector empty = new Vector(); - empty.add("(Empty)"); - - partyList = new JList(empty); - partyList.setFixedCellWidth(120); - partyList.setVisibleRowCount(5); - partyList.addListSelectionListener(this); - JScrollPane partyPane = new JScrollPane(partyList); - // partyPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); - partyPanel.add(partyPane); - - // Bowler Database - JPanel bowlerPanel = new JPanel(); - bowlerPanel.setLayout(new FlowLayout()); - bowlerPanel.setBorder(new TitledBorder("Bowler Database")); - - try { - bowlerdb = new Vector(BowlerFile.getBowlers()); - } catch (Exception e) { - System.err.println("File Error"); - bowlerdb = new Vector(); - } - allBowlers = new JList(bowlerdb); - allBowlers.setVisibleRowCount(8); - allBowlers.setFixedCellWidth(120); - JScrollPane bowlerPane = new JScrollPane(allBowlers); - bowlerPane.setVerticalScrollBarPolicy( - JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); - allBowlers.addListSelectionListener(this); - bowlerPanel.add(bowlerPane); - - // Button Panel - JPanel buttonPanel = new JPanel(); - buttonPanel.setLayout(new GridLayout(4, 1)); - - Insets buttonMargin = new Insets(4, 4, 4, 4); - - addPatron = new JButton("Add to Party"); - JPanel addPatronPanel = new JPanel(); - addPatronPanel.setLayout(new FlowLayout()); - addPatron.addActionListener(this); - addPatronPanel.add(addPatron); - - remPatron = new JButton("Remove Member"); - JPanel remPatronPanel = new JPanel(); - remPatronPanel.setLayout(new FlowLayout()); - remPatron.addActionListener(this); - remPatronPanel.add(remPatron); - - newPatron = new JButton("New Patron"); - JPanel newPatronPanel = new JPanel(); - newPatronPanel.setLayout(new FlowLayout()); - newPatron.addActionListener(this); - newPatronPanel.add(newPatron); - - finished = new JButton("Finished"); - JPanel finishedPanel = new JPanel(); - finishedPanel.setLayout(new FlowLayout()); - finished.addActionListener(this); - finishedPanel.add(finished); - - buttonPanel.add(addPatronPanel); - buttonPanel.add(remPatronPanel); - buttonPanel.add(newPatronPanel); - buttonPanel.add(finishedPanel); - - // Clean up main panel - colPanel.add(partyPanel); - colPanel.add(bowlerPanel); - colPanel.add(buttonPanel); - - win.getContentPane().add("Center", colPanel); - - win.pack(); - - // Center Window on Screen - Dimension screenSize = (Toolkit.getDefaultToolkit()).getScreenSize(); - win.setLocation( - ((screenSize.width) / 2) - ((win.getSize().width) / 2), - ((screenSize.height) / 2) - ((win.getSize().height) / 2)); - win.show(); - - } - - public void actionPerformed(ActionEvent e) { - if (e.getSource().equals(addPatron)) { - if (selectedNick != null && party.size() < maxSize) { - if (party.contains(selectedNick)) { - System.err.println("Member already in Party"); - } else { - party.add(selectedNick); - partyList.setListData(party); - } - } - } - if (e.getSource().equals(remPatron)) { - if (selectedMember != null) { - party.removeElement(selectedMember); - partyList.setListData(party); - } - } - if (e.getSource().equals(newPatron)) { - NewPatronView newPatron = new NewPatronView( this ); - } - if (e.getSource().equals(finished)) { - if ( party != null && party.size() > 0) { - controlDesk.updateAddParty( this ); - } - win.hide(); - } - - } - -/** - * Handler for List actions - * @param e the ListActionEvent that triggered the handler - */ - - public void valueChanged(ListSelectionEvent e) { - if (e.getSource().equals(allBowlers)) { - selectedNick = - ((String) ((JList) e.getSource()).getSelectedValue()); - } - if (e.getSource().equals(partyList)) { - selectedMember = - ((String) ((JList) e.getSource()).getSelectedValue()); - } - } - -/** - * Accessor for Party - */ - - public Vector getNames() { - return party; - } - -/** - * Called by NewPatronView to notify AddPartyView to update - * - * @param newPatron the NewPatronView that called this method - */ - - public void updateNewPatron(NewPatronView newPatron) { - try { - Bowler checkBowler = BowlerFile.getBowlerInfo( newPatron.getNick() ); - if ( checkBowler == null ) { - BowlerFile.putBowlerInfo( - newPatron.getNick(), - newPatron.getFull(), - newPatron.getEmail()); - bowlerdb = new Vector(BowlerFile.getBowlers()); - allBowlers.setListData(bowlerdb); - party.add(newPatron.getNick()); - partyList.setListData(party); - } else { - System.err.println( "A Bowler with that name already exists." ); - } - } catch (Exception e2) { - System.err.println("File I/O Error"); - } - } - -/** - * Accessor for Party - */ - - public Vector getParty() { - return party; - } - -} diff --git a/BallingManagementSystem_refactoring/AgainGameCommand.java b/BallingManagementSystem_refactoring/AgainGameCommand.java deleted file mode 100644 index 51907d5..0000000 --- a/BallingManagementSystem_refactoring/AgainGameCommand.java +++ /dev/null @@ -1,9 +0,0 @@ -public class AgainGameCommand implements ButtonCommand { - EndGamePrompt endGamePrompt; - public AgainGameCommand(EndGamePrompt endGamePrompt){ - this.endGamePrompt = endGamePrompt; - } - public void execute(){ - endGamePrompt.setResult(1); - } -} diff --git a/BallingManagementSystem_refactoring/Alley.java b/BallingManagementSystem_refactoring/Alley.java deleted file mode 100644 index d31d110..0000000 --- a/BallingManagementSystem_refactoring/Alley.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Alley.java - * - * Version: - * $Id$ - * - * Revisions: - * $Log: Alley.java,v $ - * Revision 1.4 2003/02/02 20:28:58 ??? - * fixed sleep thread bug in lane - * - * Revision 1.3 2003/01/12 22:23:32 ??? - * *** empty log message *** - * - * Revision 1.2 2003/01/12 20:44:30 ??? - * *** empty log message *** - * - * Revision 1.1 2003/01/12 19:09:12 ??? - * Adding Party, Lane, Bowler, and Alley. - * - */ - -/** - * Class that is the outer container for the bowling sim - * - */ - -public class Alley { - public ControlDesk controldesk; - - public Alley( int numLanes ) { - controldesk = new ControlDesk( numLanes ); - } - - public ControlDesk getControlDesk() { - return controldesk; - } - -} - - - diff --git a/BallingManagementSystem_refactoring/BOWLERS.DAT b/BallingManagementSystem_refactoring/BOWLERS.DAT deleted file mode 100644 index 4024de4..0000000 --- a/BallingManagementSystem_refactoring/BOWLERS.DAT +++ /dev/null @@ -1,5 +0,0 @@ -Mike M. J. Lutz ml@nowhere.net -Jim J. R. Vallino jv@nowhere.net -Tom T. R. Reichmayr tr@nowhere.net -Lana L. R. Verschage lv@nowhere.net -TomH T. Hilburn th@nowhere.net diff --git a/BallingManagementSystem_refactoring/Bowler.java b/BallingManagementSystem_refactoring/Bowler.java deleted file mode 100644 index 33ae3fa..0000000 --- a/BallingManagementSystem_refactoring/Bowler.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Bowler.java - * - * Version: - * $Id$ - * - * Revisions: - * $Log: Bowler.java,v $ - * Revision 1.3 2003/01/15 02:57:40 ??? - * Added accessors and and equals() method - * - * Revision 1.2 2003/01/12 22:23:32 ??? - * *** empty log message *** - * - * Revision 1.1 2003/01/12 19:09:12 ??? - * Adding Party, Lane, Bowler, and Alley. - * - */ - -/** - * Class that holds all bowler info - * - */ - -public class Bowler { - - private String fullName; - private String nickName; - private String email; - - public Bowler( String nick, String full, String mail ) { - nickName = nick; - fullName = full; - email = mail; - } - - - public String getNickName() { - - return nickName; - - } - - public String getFullName ( ) { - return fullName; - } - - public String getNick ( ) { - return nickName; - } - - public String getEmail ( ) { - return email; - } - - public boolean equals ( Bowler b) { - boolean retval = true; - if ( !(nickName.equals(b.getNickName())) ) { - retval = false; - } - if ( !(fullName.equals(b.getFullName())) ) { - retval = false; - } - if ( !(email.equals(b.getEmail())) ) { - retval = false; - } - return retval; - } -} \ No newline at end of file diff --git a/BallingManagementSystem_refactoring/BowlerFile.java b/BallingManagementSystem_refactoring/BowlerFile.java deleted file mode 100644 index 8ab8fb5..0000000 --- a/BallingManagementSystem_refactoring/BowlerFile.java +++ /dev/null @@ -1,108 +0,0 @@ -/* BowlerFile.java - * - * Version: - * $Id$ - * - * Revisions: - * $Log: BowlerFile.java,v $ - * Revision 1.5 2003/02/02 17:36:45 ??? - * Updated comments to match javadoc format. - * - * Revision 1.4 2003/02/02 16:29:52 ??? - * Added ControlDeskEvent and ControlDeskObserver. Updated Queue to allow access to Vector so that contents could be viewed without destroying. Implemented observer model for most of ControlDesk. - * - * - */ - -/** - * Class for interfacing with Bowler database - * - */ - -import java.util.*; -import java.io.*; - -class BowlerFile { - - /** The location of the bowelr database */ - private static String BOWLER_DAT = "BOWLERS.DAT"; - - /** - * Retrieves bowler information from the database and returns a Bowler objects with populated fields. - * - * @param nickName the nickName of the bolwer to retrieve - * - * @return a Bowler object - * - */ - - public static Bowler getBowlerInfo(String nickName) - throws IOException, FileNotFoundException { - - BufferedReader in = new BufferedReader(new FileReader(BOWLER_DAT)); - String data; - while ((data = in.readLine()) != null) { - // File format is nick\tfname\te-mail - String[] bowler = data.split("\t"); - if (nickName.equals(bowler[0])) { - System.out.println( - "Nick: " - + bowler[0] - + " Full: " - + bowler[1] - + " email: " - + bowler[2]); - return (new Bowler(bowler[0], bowler[1], bowler[2])); - } - } - System.out.println("Nick not found..."); - return null; - } - - /** - * Stores a Bowler in the database - * - * @param nickName the NickName of the Bowler - * @param fullName the FullName of the Bowler - * @param email the E-mail Address of the Bowler - * - */ - - public static void putBowlerInfo( - String nickName, - String fullName, - String email) - throws IOException, FileNotFoundException { - - String data = nickName + "\t" + fullName + "\t" + email + "\n"; - - RandomAccessFile out = new RandomAccessFile(BOWLER_DAT, "rw"); - out.skipBytes((int) out.length()); - out.writeBytes(data); - out.close(); - } - - /** - * Retrieves a list of nicknames in the bowler database - * - * @return a Vector of Strings - * - */ - - public static Vector getBowlers() - throws IOException, FileNotFoundException { - - Vector allBowlers = new Vector(); - - BufferedReader in = new BufferedReader(new FileReader(BOWLER_DAT)); - String data; - while ((data = in.readLine()) != null) { - // File format is nick\tfname\te-mail - String[] bowler = data.split("\t"); - //"Nick: bowler[0] Full: bowler[1] email: bowler[2] - allBowlers.add(bowler[0]); - } - return allBowlers; - } - -} \ No newline at end of file diff --git a/BallingManagementSystem_refactoring/ButtonCommand.java b/BallingManagementSystem_refactoring/ButtonCommand.java deleted file mode 100644 index 8fcf374..0000000 --- a/BallingManagementSystem_refactoring/ButtonCommand.java +++ /dev/null @@ -1,3 +0,0 @@ -public interface ButtonCommand { - public void execute(); -} diff --git a/BallingManagementSystem_refactoring/ControlDesk.java b/BallingManagementSystem_refactoring/ControlDesk.java deleted file mode 100644 index 4395bfd..0000000 --- a/BallingManagementSystem_refactoring/ControlDesk.java +++ /dev/null @@ -1,237 +0,0 @@ -/* ControlDesk.java - * - * Version: - * $Id$ - * - * Revisions: - * $Log: ControlDesk.java,v $ - * Revision 1.13 2003/02/02 23:26:32 ??? - * ControlDesk now runs its own thread and polls for free lanes to assign queue members to - * - * Revision 1.12 2003/02/02 20:46:13 ??? - * Added " 's Party" to party names. - * - * Revision 1.11 2003/02/02 20:43:25 ??? - * misc cleanup - * - * Revision 1.10 2003/02/02 17:49:10 ??? - * Fixed problem in getPartyQueue that was returning the first element as every element. - * - * Revision 1.9 2003/02/02 17:39:48 ??? - * Added accessor for lanes. - * - * Revision 1.8 2003/02/02 16:53:59 ??? - * Updated comments to match javadoc format. - * - * Revision 1.7 2003/02/02 16:29:52 ??? - * Added ControlDeskEvent and ControlDeskObserver. Updated Queue to allow access to Vector so that contents could be viewed without destroying. Implemented observer model for most of ControlDesk. - * - * Revision 1.6 2003/02/02 06:09:39 ??? - * Updated many classes to support the ControlDeskView. - * - * Revision 1.5 2003/01/26 23:16:10 ??? - * Improved thread handeling in lane/controldesk - * - * - */ - -/** - * Class that represents control desk - * - */ - -import java.util.*; -import java.io.*; - -class ControlDesk extends Thread { - - /** The collection of Lanes */ - private HashSet lanes; - - /** The party wait queue */ - private Queue partyQueue; - - /** The number of lanes represented */ - private int numLanes; - - /** The collection of subscribers */ - private Vector subscribers; - - /** - * Constructor for the ControlDesk class - * - * @param numlanes the numbler of lanes to be represented - * - */ - - public ControlDesk(int numLanes) { - this.numLanes = numLanes; - lanes = new HashSet(numLanes); - partyQueue = new Queue(); - - subscribers = new Vector(); - - for (int i = 0; i < numLanes; i++) { - lanes.add(new Lane()); - } - - this.start(); - - } - - /** - * Main loop for ControlDesk's thread - * - */ - public void run() { - while (true) { - - assignLane(); - - try { - sleep(250); - } catch (Exception e) {} - } - } - - - /** - * Retrieves a matching Bowler from the bowler database. - * - * @param nickName The NickName of the Bowler - * - * @return a Bowler object. - * - */ - - private Bowler registerPatron(String nickName) { - Bowler patron = null; - - try { - // only one patron / nick.... no dupes, no checks - - patron = BowlerFile.getBowlerInfo(nickName); - - } catch (FileNotFoundException e) { - System.err.println("Error..." + e); - } catch (IOException e) { - System.err.println("Error..." + e); - } - - return patron; - } - - /** - * Iterate through the available lanes and assign the paties in the wait queue if lanes are available. - * - */ - - public void assignLane() { - Iterator it = lanes.iterator(); - - while (it.hasNext() && partyQueue.hasMoreElements()) { - Lane curLane = (Lane) it.next(); - - if (curLane.isPartyAssigned() == false) { - System.out.println("ok... assigning this party"); - curLane.assignParty(((Party) partyQueue.next())); - } - } - publish(new ControlDeskEvent(getPartyQueue())); - } - - /** - */ - - public void viewScores(Lane ln) { - // TODO: attach a LaneScoreView object to that lane - } - - /** - * Creates a party from a Vector of nickNAmes and adds them to the wait queue. - * - * @param partyNicks A Vector of NickNames - * - */ - - public void addPartyQueue(Vector partyNicks) { - Vector partyBowlers = new Vector(); - for (int i = 0; i < partyNicks.size(); i++) { - Bowler newBowler = registerPatron(((String) partyNicks.get(i))); - partyBowlers.add(newBowler); - } - Party newParty = new Party(partyBowlers); - partyQueue.add(newParty); - publish(new ControlDeskEvent(getPartyQueue())); - } - - /** - * Returns a Vector of party names to be displayed in the GUI representation of the wait queue. - * - * @return a Vecotr of Strings - * - */ - - public Vector getPartyQueue() { - Vector displayPartyQueue = new Vector(); - for ( int i=0; i < ( (Vector)partyQueue.asVector()).size(); i++ ) { - String nextParty = - ((Bowler) ((Vector) ((Party) partyQueue.asVector().get( i ) ).getMembers()) - .get(0)) - .getNickName() + "'s Party"; - displayPartyQueue.addElement(nextParty); - } - return displayPartyQueue; - } - - /** - * Accessor for the number of lanes represented by the ControlDesk - * - * @return an int containing the number of lanes represented - * - */ - - public int getNumLanes() { - return numLanes; - } - - /** - * Allows objects to subscribe as observers - * - * @param adding the ControlDeskObserver that will be subscribed - * - */ - - public void subscribe(ControlDeskObserver adding) { - subscribers.add(adding); - } - - /** - * Broadcast an event to subscribing objects. - * - * @param event the ControlDeskEvent to broadcast - * - */ - - public void publish(ControlDeskEvent event) { - Iterator eventIterator = subscribers.iterator(); - while (eventIterator.hasNext()) { - ( - (ControlDeskObserver) eventIterator - .next()) - .receiveControlDeskEvent( - event); - } - } - - /** - * Accessor method for lanes - * - * @return a HashSet of Lanes - * - */ - - public HashSet getLanes() { - return lanes; - } -} diff --git a/BallingManagementSystem_refactoring/ControlDeskEvent.java b/BallingManagementSystem_refactoring/ControlDeskEvent.java deleted file mode 100644 index 4d8d81c..0000000 --- a/BallingManagementSystem_refactoring/ControlDeskEvent.java +++ /dev/null @@ -1,46 +0,0 @@ -/* ControlDeskEvent.java - * - * Version: - * $Id$ - * - * Revisions: - * $Log$ - * - */ - -/** - * Class that represents control desk event - * - */ - -import java.util.*; - -public class ControlDeskEvent { - - /** A representation of the wait queue, containing party names */ - private Vector partyQueue; - - /** - * Contstructor for the ControlDeskEvent - * - * @param partyQueue a Vector of Strings containing the names of the parties in the wait queue - * - */ - - public ControlDeskEvent( Vector partyQueue ) { - this.partyQueue = partyQueue; - } - - /** - * Accessor for partyQueue - * @param key the key of the vertex being looked for. - * - * @return a Vector of Strings representing the names of the parties in the wait queue - * - */ - - public Vector getPartyQueue() { - return partyQueue; - } - -} diff --git a/BallingManagementSystem_refactoring/ControlDeskObserver.java b/BallingManagementSystem_refactoring/ControlDeskObserver.java deleted file mode 100644 index 96aa970..0000000 --- a/BallingManagementSystem_refactoring/ControlDeskObserver.java +++ /dev/null @@ -1,20 +0,0 @@ -/* ControlDeskObserver.java - * - * Version - * $Id$ - * - * Revisions: - * $Log$ - * - */ - -/** - * Interface for classes that observe control desk events - * - */ - -public interface ControlDeskObserver { - - public void receiveControlDeskEvent(ControlDeskEvent ce); - -} diff --git a/BallingManagementSystem_refactoring/ControlDeskView.java b/BallingManagementSystem_refactoring/ControlDeskView.java deleted file mode 100644 index 95c5300..0000000 --- a/BallingManagementSystem_refactoring/ControlDeskView.java +++ /dev/null @@ -1,180 +0,0 @@ -/* ControlDeskView.java - * - * Version: - * $Id$ - * - * Revisions: - * $Log$ - * - */ - -/** - * Class for representation of the control desk - * - */ - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.border.*; -import javax.swing.event.*; - -import java.util.*; - -public class ControlDeskView implements ActionListener, ControlDeskObserver { - - private JButton addParty, finished, assign; - private JFrame win; - private JList partyList; - - /** The maximum number of members in a party */ - private int maxMembers; - - private ControlDesk controlDesk; - - /** - * Displays a GUI representation of the ControlDesk - * - */ - - public ControlDeskView(ControlDesk controlDesk, int maxMembers) { - - this.controlDesk = controlDesk; - this.maxMembers = maxMembers; - int numLanes = controlDesk.getNumLanes(); - - win = new JFrame("Control Desk"); - win.getContentPane().setLayout(new BorderLayout()); - ((JPanel) win.getContentPane()).setOpaque(false); - - JPanel colPanel = new JPanel(); - colPanel.setLayout(new BorderLayout()); - - // Controls Panel - JPanel controlsPanel = new JPanel(); - controlsPanel.setLayout(new GridLayout(3, 1)); - controlsPanel.setBorder(new TitledBorder("Controls")); - - addParty = new JButton("Add Party"); - JPanel addPartyPanel = new JPanel(); - addPartyPanel.setLayout(new FlowLayout()); - addParty.addActionListener(this); - addPartyPanel.add(addParty); - controlsPanel.add(addPartyPanel); - - assign = new JButton("Assign Lanes"); - JPanel assignPanel = new JPanel(); - assignPanel.setLayout(new FlowLayout()); - assign.addActionListener(this); - assignPanel.add(assign); -// controlsPanel.add(assignPanel); - - finished = new JButton("Finished"); - JPanel finishedPanel = new JPanel(); - finishedPanel.setLayout(new FlowLayout()); - finished.addActionListener(this); - finishedPanel.add(finished); - controlsPanel.add(finishedPanel); - - // Lane Status Panel - JPanel laneStatusPanel = new JPanel(); - laneStatusPanel.setLayout(new GridLayout(numLanes, 1)); - laneStatusPanel.setBorder(new TitledBorder("Lane Status")); - - HashSet lanes=controlDesk.getLanes(); - Iterator it = lanes.iterator(); - int laneCount=0; - while (it.hasNext()) { - Lane curLane = (Lane) it.next(); - LaneStatusView laneStat = new LaneStatusView(curLane,(laneCount+1)); - curLane.subscribe(laneStat); - ((Pinsetter)curLane.getPinsetter()).subscribe(laneStat); - JPanel lanePanel = laneStat.showLane(); - lanePanel.setBorder(new TitledBorder("Lane" + ++laneCount )); - laneStatusPanel.add(lanePanel); - } - - // Party Queue Panel - JPanel partyPanel = new JPanel(); - partyPanel.setLayout(new FlowLayout()); - partyPanel.setBorder(new TitledBorder("Party Queue")); - - Vector empty = new Vector(); - empty.add("(Empty)"); - - partyList = new JList(empty); - partyList.setFixedCellWidth(120); - partyList.setVisibleRowCount(10); - JScrollPane partyPane = new JScrollPane(partyList); - partyPane.setVerticalScrollBarPolicy( - JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); - partyPanel.add(partyPane); - // partyPanel.add(partyList); - - // Clean up main panel - colPanel.add(controlsPanel, "East"); - colPanel.add(laneStatusPanel, "Center"); - colPanel.add(partyPanel, "West"); - - win.getContentPane().add("Center", colPanel); - - win.pack(); - - /* Close program when this window closes */ - win.addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - System.exit(0); - } - }); - - // Center Window on Screen - Dimension screenSize = (Toolkit.getDefaultToolkit()).getScreenSize(); - win.setLocation( - ((screenSize.width) / 2) - ((win.getSize().width) / 2), - ((screenSize.height) / 2) - ((win.getSize().height) / 2)); - win.show(); - - } - - /** - * Handler for actionEvents - * - * @param e the ActionEvent that triggered the handler - * - */ - - public void actionPerformed(ActionEvent e) { - if (e.getSource().equals(addParty)) { - AddPartyView addPartyWin = new AddPartyView(this, maxMembers); - } - if (e.getSource().equals(assign)) { - controlDesk.assignLane(); - } - if (e.getSource().equals(finished)) { - win.hide(); - System.exit(0); - } - } - - /** - * Receive a new party from andPartyView. - * - * @param addPartyView the AddPartyView that is providing a new party - * - */ - - public void updateAddParty(AddPartyView addPartyView) { - controlDesk.addPartyQueue(addPartyView.getParty()); - } - - /** - * Receive a broadcast from a ControlDesk - * - * @param ce the ControlDeskEvent that triggered the handler - * - */ - - public void receiveControlDeskEvent(ControlDeskEvent ce) { - partyList.setListData(((Vector) ce.getPartyQueue())); - } -} diff --git a/BallingManagementSystem_refactoring/EndGameCommand.java b/BallingManagementSystem_refactoring/EndGameCommand.java deleted file mode 100644 index b116cf9..0000000 --- a/BallingManagementSystem_refactoring/EndGameCommand.java +++ /dev/null @@ -1,9 +0,0 @@ -public class EndGameCommand implements ButtonCommand { - EndGamePrompt endGamePrompt; - public EndGameCommand(EndGamePrompt endGamePrompt){ - this.endGamePrompt = endGamePrompt; - } - public void execute(){ - endGamePrompt.setResult(2); - } -} diff --git a/BallingManagementSystem_refactoring/EndGamePrompt.java b/BallingManagementSystem_refactoring/EndGamePrompt.java deleted file mode 100644 index 4cc773a..0000000 --- a/BallingManagementSystem_refactoring/EndGamePrompt.java +++ /dev/null @@ -1,112 +0,0 @@ -/** - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ - -import java.awt.*; -import javax.swing.*; -import java.awt.event.ActionListener; -import java.awt.event.ActionEvent; - -public class EndGamePrompt { - private ButtonCommand command; - private JFrame win; - private JButton yesButton, noButton; - private JFrame endGameFrame; - private int result; - - public EndGamePrompt( String partyName ) { - - result = 0; - - endGameFrame = new JFrame("Another Game for " + partyName + "?"); - endGameFrame.getContentPane().setLayout(new BorderLayout()); - ((JPanel) endGameFrame.getContentPane()).setOpaque(false); - - JPanel colPanel = new JPanel(); - colPanel.setLayout(new GridLayout(2, 1)); - - // Label Panel - JPanel labelPanel = new JPanel(); - labelPanel.setLayout(new FlowLayout()); - - JLabel message = new JLabel("Party " + partyName + " has finished bowling.\nWould they like to bowl another game?"); - labelPanel.add(message); - - // Button Panel - JPanel buttonPanel = new JPanel(); - buttonPanel.setLayout(new GridLayout(1, 2)); - - Insets buttonMargin = new Insets(4, 4, 4, 4); - - EndGamePromptClickEvent listener = new EndGamePromptClickEvent(); - - yesButton = createButton("Yes", listener); - noButton = createButton("No", listener); - - buttonPanel.setLayout(new GridLayout(1, 2)); - buttonPanel.add(yesButton); - buttonPanel.add(noButton); - - // Clean up main panel - colPanel.add(labelPanel); - colPanel.add(buttonPanel); - - endGameFrame.getContentPane().add("Center", colPanel); - - endGameFrame.pack(); - - // Center Window on Screen - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - endGameFrame.setLocation((screenSize.width / 2) - (endGameFrame.getSize().width / 2), - (screenSize.height / 2) - (endGameFrame.getSize().height / 2)); - endGameFrame.setVisible(true); - - } - private JButton createButton(String text, EndGamePromptClickEvent listener) { - JButton button = new JButton(text); - button.addActionListener(listener); - return button; - } - - public int getResult() { - while ( result == 0 ) { - try { - Thread.sleep(10); - } catch ( InterruptedException e ) { - System.err.println( "Interrupted" ); - } - } - return result; - } - public void setResult(int i) { - result = i; - } - public void distroy() { - endGameFrame.setVisible(false); - } - - public void setCommand(ButtonCommand command) { - this.command = command; - } - public void buttonPressed() { - command.execute(); - } - public class EndGamePromptClickEvent implements ActionListener { - - public void actionPerformed(ActionEvent e) { - if (e.getSource().equals(yesButton)) { - setCommand(new AgainGameCommand(EndGamePrompt.this)); - } - if (e.getSource().equals(noButton)) { - setCommand(new EndGameCommand(EndGamePrompt.this)); - } - buttonPressed(); - } - } - -} - diff --git a/BallingManagementSystem_refactoring/EndGameReport.java b/BallingManagementSystem_refactoring/EndGameReport.java deleted file mode 100644 index 6a591ce..0000000 --- a/BallingManagementSystem_refactoring/EndGameReport.java +++ /dev/null @@ -1,143 +0,0 @@ -/** - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.border.*; -import javax.swing.event.*; - -import java.util.*; -import java.text.*; - -public class EndGameReport implements ActionListener, ListSelectionListener { - - private JFrame win; - private JButton printButton, finished; - private JList memberList; - private Vector myVector; - private Vector retVal; - - private int result; - - private String selectedMember; - - public EndGameReport( String partyName, Party party ) { - - result =0; - retVal = new Vector(); - win = new JFrame("End Game Report for " + partyName + "?" ); - win.getContentPane().setLayout(new BorderLayout()); - ((JPanel) win.getContentPane()).setOpaque(false); - - JPanel colPanel = new JPanel(); - colPanel.setLayout(new GridLayout( 1, 2 )); - - // Member Panel - JPanel partyPanel = new JPanel(); - partyPanel.setLayout(new FlowLayout()); - partyPanel.setBorder(new TitledBorder("Party Members")); - - Vector myVector = new Vector(); - Iterator iter = (party.getMembers()).iterator(); - while (iter.hasNext()){ - myVector.add( ((Bowler)iter.next()).getNick() ); - } - memberList = new JList(myVector); - memberList.setFixedCellWidth(120); - memberList.setVisibleRowCount(5); - memberList.addListSelectionListener(this); - JScrollPane partyPane = new JScrollPane(memberList); - // partyPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); - partyPanel.add(partyPane); - - partyPanel.add( memberList ); - - // Button Panel - // Button Panel - JPanel buttonPanel = new JPanel(); - buttonPanel.setLayout(new GridLayout(2, 1)); - - Insets buttonMargin = new Insets(4, 4, 4, 4); - - printButton = new JButton("Print Report"); - JPanel printButtonPanel = new JPanel(); - printButtonPanel.setLayout(new FlowLayout()); - printButton.addActionListener(this); - printButtonPanel.add(printButton); - - finished = new JButton("Finished"); - JPanel finishedPanel = new JPanel(); - finishedPanel.setLayout(new FlowLayout()); - finished.addActionListener(this); - finishedPanel.add(finished); - - buttonPanel.add(printButton); - buttonPanel.add(finished); - - // Clean up main panel - colPanel.add(partyPanel); - colPanel.add(buttonPanel); - - win.getContentPane().add("Center", colPanel); - - win.pack(); - - // Center Window on Screen - Dimension screenSize = (Toolkit.getDefaultToolkit()).getScreenSize(); - win.setLocation( - ((screenSize.width) / 2) - ((win.getSize().width) / 2), - ((screenSize.height) / 2) - ((win.getSize().height) / 2)); - win.show(); - - } - - public void actionPerformed(ActionEvent e) { - if (e.getSource().equals(printButton)) { - //Add selected to the vector. - retVal.add(selectedMember); - } - if (e.getSource().equals(finished)) { - win.hide(); - result = 1; - } - - } - - public void valueChanged(ListSelectionEvent e) { - selectedMember = - ((String) ((JList) e.getSource()).getSelectedValue()); - } - - public Vector getResult() { - while ( result == 0 ) { - try { - Thread.sleep(10); - } catch ( InterruptedException e ) { - System.err.println( "Interrupted" ); - } - } - return retVal; - } - - public void destroy() { - win.hide(); - } - - public static void main( String args[] ) { - Vector bowlers = new Vector(); - for ( int i=0; i<4; i++ ) { - bowlers.add( new Bowler( "aaaaa", "aaaaa", "aaaaa" ) ); - } - Party party = new Party( bowlers ); - String partyName="wank"; - EndGameReport e = new EndGameReport( partyName, party ); - } - -} - diff --git a/BallingManagementSystem_refactoring/EndGameReportClickEvent.java b/BallingManagementSystem_refactoring/EndGameReportClickEvent.java deleted file mode 100644 index eea014e..0000000 --- a/BallingManagementSystem_refactoring/EndGameReportClickEvent.java +++ /dev/null @@ -1,14 +0,0 @@ -import java.awt.event.ActionListener; -import java.awt.event.ActionEvent; - -public class EndGameReportClickEvent implements ActionListener { - private EndGameReport endGameReport; - - EndGameReportClickEvent(EndGameReport endGameReport) { - this.endGameReport = endGameReport; - } - - public void actionPerformed(ActionEvent e) { - - } -} diff --git a/BallingManagementSystem_refactoring/Lane.java b/BallingManagementSystem_refactoring/Lane.java deleted file mode 100644 index f1785c8..0000000 --- a/BallingManagementSystem_refactoring/Lane.java +++ /dev/null @@ -1,621 +0,0 @@ - -/* $Id$ - * - * Revisions: - * $Log: Lane.java,v $ - * Revision 1.52 2003/02/20 20:27:45 ??? - * Fouls disables. - * - * Revision 1.51 2003/02/20 20:01:32 ??? - * Added things. - * - * Revision 1.50 2003/02/20 19:53:52 ??? - * Added foul support. Still need to update laneview and test this. - * - * Revision 1.49 2003/02/20 11:18:22 ??? - * Works beautifully. - * - * Revision 1.48 2003/02/20 04:10:58 ??? - * Score reporting code should be good. - * - * Revision 1.47 2003/02/17 00:25:28 ??? - * Added disbale controls for View objects. - * - * Revision 1.46 2003/02/17 00:20:47 ??? - * fix for event when game ends - * - * Revision 1.43 2003/02/17 00:09:42 ??? - * fix for event when game ends - * - * Revision 1.42 2003/02/17 00:03:34 ??? - * Bug fixed - * - * Revision 1.41 2003/02/16 23:59:49 ??? - * Reporting of sorts. - * - * Revision 1.40 2003/02/16 23:44:33 ??? - * added mechnanical problem flag - * - * Revision 1.39 2003/02/16 23:43:08 ??? - * added mechnanical problem flag - * - * Revision 1.38 2003/02/16 23:41:05 ??? - * added mechnanical problem flag - * - * Revision 1.37 2003/02/16 23:00:26 ??? - * added mechnanical problem flag - * - * Revision 1.36 2003/02/16 21:31:04 ??? - * Score logging. - * - * Revision 1.35 2003/02/09 21:38:00 ??? - * Added lots of comments - * - * Revision 1.34 2003/02/06 00:27:46 ??? - * Fixed a race condition - * - * Revision 1.33 2003/02/05 11:16:34 ??? - * Boom-Shacka-Lacka!!! - * - * Revision 1.32 2003/02/05 01:15:19 ??? - * Real close now. Honest. - * - * Revision 1.31 2003/02/04 22:02:04 ??? - * Still not quite working... - * - * Revision 1.30 2003/02/04 13:33:04 ??? - * Lane may very well work now. - * - * Revision 1.29 2003/02/02 23:57:27 ??? - * fix on pinsetter hack - * - * Revision 1.28 2003/02/02 23:49:48 ??? - * Pinsetter generates an event when all pins are reset - * - * Revision 1.27 2003/02/02 23:26:32 ??? - * ControlDesk now runs its own thread and polls for free lanes to assign queue members to - * - * Revision 1.26 2003/02/02 23:11:42 ??? - * parties can now play more than 1 game on a lane, and lanes are properly released after games - * - * Revision 1.25 2003/02/02 22:52:19 ??? - * Lane compiles - * - * Revision 1.24 2003/02/02 22:50:10 ??? - * Lane compiles - * - * Revision 1.23 2003/02/02 22:47:34 ??? - * More observering. - * - * Revision 1.22 2003/02/02 22:15:40 ??? - * Add accessor for pinsetter. - * - * Revision 1.21 2003/02/02 21:59:20 ??? - * added conditions for the party choosing to play another game - * - * Revision 1.20 2003/02/02 21:51:54 ??? - * LaneEvent may very well be observer method. - * - * Revision 1.19 2003/02/02 20:28:59 ??? - * fixed sleep thread bug in lane - * - * Revision 1.18 2003/02/02 18:18:51 ??? - * more changes. just need to fix scoring. - * - * Revision 1.17 2003/02/02 17:47:02 ??? - * Things are pretty close to working now... - * - * Revision 1.16 2003/01/30 22:09:32 ??? - * Worked on scoring. - * - * Revision 1.15 2003/01/30 21:45:08 ??? - * Fixed speling of received in Lane. - * - * Revision 1.14 2003/01/30 21:29:30 ??? - * Fixed some MVC stuff - * - * Revision 1.13 2003/01/30 03:45:26 ??? - * *** empty log message *** - * - * Revision 1.12 2003/01/26 23:16:10 ??? - * Improved thread handeling in lane/controldesk - * - * Revision 1.11 2003/01/26 22:34:44 ??? - * Total rewrite of lane and pinsetter for R2's observer model - * Added Lane/Pinsetter Observer - * Rewrite of scoring algorythm in lane - * - * Revision 1.10 2003/01/26 20:44:05 ??? - * small changes - * - * - */ - -import java.util.Vector; -import java.util.Iterator; -import java.util.HashMap; -import java.util.Date; - -public class Lane extends Thread implements PinsetterObserver { - private Party party; - private Pinsetter setter; - private HashMap scores; - private Vector subscribers; - - private boolean gameIsHalted; - - private boolean partyAssigned; - private boolean gameFinished; - private Iterator bowlerIterator; - private int ball; - private int bowlIndex; - private int frameNumber; - private boolean tenthFrameStrike; - - private int[] curScores; - private int[][] cumulScores; - private boolean canThrowAgain; - - private int[][] finalScores; - private int gameNumber; - - private Bowler currentThrower; // = the thrower who just took a throw - - /** Lane() - * - * Constructs a new lane and starts its thread - * - * @pre none - * @post a new lane has been created and its thered is executing - */ - public Lane() { - setter = new Pinsetter(); - scores = new HashMap(); - subscribers = new Vector(); - - gameIsHalted = false; - partyAssigned = false; - - gameNumber = 0; - - setter.subscribe( this ); - - this.start(); - } - - /** run() - * - * entry point for execution of this lane - */ - public void run() { - - while (true) { - if (partyAssigned && !gameFinished) { // we have a party on this lane, - // so next bower can take a throw - - while (gameIsHalted) { - try { - sleep(10); - } catch (Exception e) {} - } - - - if (bowlerIterator.hasNext()) { - currentThrower = (Bowler)bowlerIterator.next(); - - canThrowAgain = true; - tenthFrameStrike = false; - ball = 0; - while (canThrowAgain) { - setter.ballThrown(); // simulate the thrower's ball hiting - ball++; - } - - if (frameNumber == 9){ - finalScores[bowlIndex][gameNumber] = cumulScores[bowlIndex][9]; - try{ - Date date = new Date(); - String dateString = "" + date.getHours() + ":" + date.getMinutes() + " " + date.getMonth() + "/" + date.getDay() + "/" + (date.getYear() + 1900); - ScoreHistoryFile.addScore(currentThrower.getNick(), dateString, new Integer(cumulScores[bowlIndex][9]).toString()); - } catch (Exception e) {System.err.println("Exception in addScore. "+ e );} - } - - - setter.reset(); - bowlIndex++; - - } else { - frameNumber++; - resetBowlerIterator(); - bowlIndex = 0; - if (frameNumber > 9) { - gameFinished = true; - gameNumber++; - } - } - } else if (partyAssigned && gameFinished) { - EndGamePrompt egp = new EndGamePrompt( ((Bowler) party.getMembers().get(0)).getNickName() + "'s Party" ); - int result = egp.getResult(); - egp.distroy(); - egp = null; - - - System.out.println("result was: " + result); - - // TODO: send record of scores to control desk - if (result == 1) { // yes, want to play again - resetScores(); - resetBowlerIterator(); - - } else if (result == 2) {// no, dont want to play another game - Vector printVector; - EndGameReport egr = new EndGameReport( ((Bowler)party.getMembers().get(0)).getNickName() + "'s Party", party); - printVector = egr.getResult(); - partyAssigned = false; - Iterator scoreIt = party.getMembers().iterator(); - party = null; - partyAssigned = false; - - publish(lanePublish()); - - int myIndex = 0; - while (scoreIt.hasNext()){ - Bowler thisBowler = (Bowler)scoreIt.next(); - ScoreReport sr = new ScoreReport( thisBowler, finalScores[myIndex++], gameNumber ); - sr.sendEmail(thisBowler.getEmail()); - Iterator printIt = printVector.iterator(); - while (printIt.hasNext()){ - if (thisBowler.getNick() == (String)printIt.next()){ - System.out.println("Printing " + thisBowler.getNick()); - sr.sendPrintout(); - } - } - - } - } - } - - - try { - sleep(10); - } catch (Exception e) {} - } - } - - /** recievePinsetterEvent() - * - * recieves the thrown event from the pinsetter - * - * @pre none - * @post the event has been acted upon if desiered - * - * @param pe The pinsetter event that has been received. - */ - public void receivePinsetterEvent(PinsetterEvent pe) { - - if (pe.pinsDownOnThisThrow() >= 0) { // this is a real throw - markScore(currentThrower, frameNumber + 1, pe.getThrowNumber(), pe.pinsDownOnThisThrow()); - - // next logic handles the ?: what conditions dont allow them another throw? - // handle the case of 10th frame first - if (frameNumber == 9) { - if (pe.totalPinsDown() == 10) { - setter.resetPins(); - if(pe.getThrowNumber() == 1) { - tenthFrameStrike = true; - } - } - - if ((pe.totalPinsDown() != 10) && (pe.getThrowNumber() == 2 && tenthFrameStrike == false)) { - canThrowAgain = false; - //publish( lanePublish() ); - } - - if (pe.getThrowNumber() == 3) { - canThrowAgain = false; - //publish( lanePublish() ); - } - } else { // its not the 10th frame - - if (pe.pinsDownOnThisThrow() == 10) { // threw a strike - canThrowAgain = false; - //publish( lanePublish() ); - } else if (pe.getThrowNumber() == 2) { - canThrowAgain = false; - //publish( lanePublish() ); - } else if (pe.getThrowNumber() == 3) - System.out.println("I'm here..."); - } - } else { // this is not a real throw, probably a reset - } - } - - /** resetBowlerIterator() - * - * sets the current bower iterator back to the first bowler - * - * @pre the party as been assigned - * @post the iterator points to the first bowler in the party - */ - private void resetBowlerIterator() { - bowlerIterator = (party.getMembers()).iterator(); - } - - /** resetScores() - * - * resets the scoring mechanism, must be called before scoring starts - * - * @pre the party has been assigned - * @post scoring system is initialized - */ - private void resetScores() { - Iterator bowlIt = (party.getMembers()).iterator(); - - while ( bowlIt.hasNext() ) { - int[] toPut = new int[25]; - for ( int i = 0; i != 25; i++){ - toPut[i] = -1; - } - scores.put( bowlIt.next(), toPut ); - } - - - - gameFinished = false; - frameNumber = 0; - } - - /** assignParty() - * - * assigns a party to this lane - * - * @pre none - * @post the party has been assigned to the lane - * - * @param theParty Party to be assigned - */ - public void assignParty( Party theParty ) { - party = theParty; - resetBowlerIterator(); - partyAssigned = true; - - curScores = new int[party.getMembers().size()]; - cumulScores = new int[party.getMembers().size()][10]; - finalScores = new int[party.getMembers().size()][128]; //Hardcoding a max of 128 games, bite me. - gameNumber = 0; - - resetScores(); - } - - /** markScore() - * - * Method that marks a bowlers score on the board. - * - * @param Cur The current bowler - * @param frame The frame that bowler is on - * @param ball The ball the bowler is on - * @param score The bowler's score - */ - private void markScore( Bowler Cur, int frame, int ball, int score ){ - int[] curScore; - int index = ( (frame - 1) * 2 + ball); - - curScore = (int[]) scores.get(Cur); - - - curScore[ index - 1] = score; - scores.put(Cur, curScore); - getScore( Cur, frame ); - publish( lanePublish() ); - } - - /** lanePublish() - * - * Method that creates and returns a newly created laneEvent - * - * @return The new lane event - */ - private LaneEvent lanePublish( ) { - LaneEvent laneEvent = new LaneEvent(party, bowlIndex, currentThrower, cumulScores, scores, frameNumber+1, curScores, ball, gameIsHalted); - return laneEvent; - } - - /** getScore() - * - * Method that calculates a bowlers score - * - * @param Cur The bowler that is currently up - * @param frame The frame the current bowler is on - * - * @return The bowlers total score - */ - private int getScore( Bowler Cur, int frame) { - int[] curScore; - int strikeballs = 0; - int totalScore = 0; - curScore = (int[]) scores.get(Cur); - for (int i = 0; i != 10; i++){ - cumulScores[bowlIndex][i] = 0; - } - int current = 2*(frame - 1)+ball-1; - //Iterate through each ball until the current one. - for (int i = 0; i != current+2; i++){ - //Spare: - if( i%2 == 1 && curScore[i - 1] + curScore[i] == 10 && i < current - 1 && i < 19){ - //This ball was a the second of a spare. - //Also, we're not on the current ball. - //Add the next ball to the ith one in cumul. - cumulScores[bowlIndex][(i/2)] += curScore[i+1] + curScore[i]; - if (i > 1) { - //cumulScores[bowlIndex][i/2] += cumulScores[bowlIndex][i/2 -1]; - } - } else if( i < current && i%2 == 0 && curScore[i] == 10 && i < 18){ - strikeballs = 0; - //This ball is the first ball, and was a strike. - //If we can get 2 balls after it, good add them to cumul. - if (curScore[i+2] != -1) { - strikeballs = 1; - if(curScore[i+3] != -1) { - //Still got em. - strikeballs = 2; - } else if(curScore[i+4] != -1) { - //Ok, got it. - strikeballs = 2; - } - } - if (strikeballs == 2){ - //Add up the strike. - //Add the next two balls to the current cumulscore. - cumulScores[bowlIndex][i/2] += 10; - if(curScore[i+1] != -1) { - cumulScores[bowlIndex][i/2] += curScore[i+1] + cumulScores[bowlIndex][(i/2)-1]; - if (curScore[i+2] != -1){ - if( curScore[i+2] != -2){ - cumulScores[bowlIndex][(i/2)] += curScore[i+2]; - } - } else { - if( curScore[i+3] != -2){ - cumulScores[bowlIndex][(i/2)] += curScore[i+3]; - } - } - } else { - if ( i/2 > 0 ){ - cumulScores[bowlIndex][i/2] += curScore[i+2] + cumulScores[bowlIndex][(i/2)-1]; - } else { - cumulScores[bowlIndex][i/2] += curScore[i+2]; - } - if (curScore[i+3] != -1){ - if( curScore[i+3] != -2){ - cumulScores[bowlIndex][(i/2)] += curScore[i+3]; - } - } else { - cumulScores[bowlIndex][(i/2)] += curScore[i+4]; - } - } - } else { - break; - } - }else { - //We're dealing with a normal throw, add it and be on our way. - if( i%2 == 0 && i < 18){ - if ( i/2 == 0 ) { - //First frame, first ball. Set his cumul score to the first ball - if(curScore[i] != -2){ - cumulScores[bowlIndex][i/2] += curScore[i]; - } - } else if (i/2 != 9){ - //add his last frame's cumul to this ball, make it this frame's cumul. - if(curScore[i] != -2){ - cumulScores[bowlIndex][i/2] += cumulScores[bowlIndex][i/2 - 1] + curScore[i]; - } else { - cumulScores[bowlIndex][i/2] += cumulScores[bowlIndex][i/2 - 1]; - } - } - } else if (i < 18){ - if(curScore[i] != -1 && i > 2){ - if(curScore[i] != -2){ - cumulScores[bowlIndex][i/2] += curScore[i]; - } - } - } - if (i/2 == 9){ - if (i == 18){ - cumulScores[bowlIndex][9] += cumulScores[bowlIndex][8]; - } - if(curScore[i] != -2){ - cumulScores[bowlIndex][9] += curScore[i]; - } - } else if (i/2 == 10) { - if(curScore[i] != -2){ - cumulScores[bowlIndex][9] += curScore[i]; - } - } - } - } - return totalScore; - } - - /** isPartyAssigned() - * - * checks if a party is assigned to this lane - * - * @return true if party assigned, false otherwise - */ - public boolean isPartyAssigned() { - return partyAssigned; - } - - /** isGameFinished - * - * @return true if the game is done, false otherwise - */ - public boolean isGameFinished() { - return gameFinished; - } - - /** subscribe - * - * Method that will add a subscriber - * - * @param subscribe Observer that is to be added - */ - - public void subscribe( LaneObserver adding ) { - subscribers.add( adding ); - } - - /** unsubscribe - * - * Method that unsubscribes an observer from this object - * - * @param removing The observer to be removed - */ - - public void unsubscribe( LaneObserver removing ) { - subscribers.remove( removing ); - } - - /** publish - * - * Method that publishes an event to subscribers - * - * @param event Event that is to be published - */ - - public void publish( LaneEvent event ) { - if( subscribers.size() > 0 ) { - Iterator eventIterator = subscribers.iterator(); - - while ( eventIterator.hasNext() ) { - ( (LaneObserver) eventIterator.next()).receiveLaneEvent( event ); - } - } - } - - /** - * Accessor to get this Lane's pinsetter - * - * @return A reference to this lane's pinsetter - */ - - public Pinsetter getPinsetter() { - return setter; - } - - /** - * Pause the execution of this game - */ - public void pauseGame() { - gameIsHalted = true; - publish(lanePublish()); - } - - /** - * Resume the execution of this game - */ - public void unPauseGame() { - gameIsHalted = false; - publish(lanePublish()); - } - -} diff --git a/BallingManagementSystem_refactoring/LaneEvent.java b/BallingManagementSystem_refactoring/LaneEvent.java deleted file mode 100644 index 13e9c5e..0000000 --- a/BallingManagementSystem_refactoring/LaneEvent.java +++ /dev/null @@ -1,95 +0,0 @@ -/* $Id$ - * - * Revisions: - * $Log: LaneEvent.java,v $ - * Revision 1.6 2003/02/16 22:59:34 ??? - * added mechnanical problem flag - * - * Revision 1.5 2003/02/02 23:55:31 ??? - * Many many changes. - * - * Revision 1.4 2003/02/02 22:44:26 ??? - * More data. - * - * Revision 1.3 2003/02/02 17:49:31 ??? - * Modified. - * - * Revision 1.2 2003/01/30 21:21:07 ??? - * *** empty log message *** - * - * Revision 1.1 2003/01/19 22:12:40 ??? - * created laneevent and laneobserver - * - * - */ - -import java.util.HashMap; - -public class LaneEvent { - - private Party p; - int frame; - int ball; - Bowler bowler; - int[][] cumulScore; - HashMap score; - int index; - int frameNum; - int[] curScores; - boolean mechProb; - - public LaneEvent( Party pty, int theIndex, Bowler theBowler, int[][] theCumulScore, HashMap theScore, int theFrameNum, int[] theCurScores, int theBall, boolean mechProblem) { - p = pty; - index = theIndex; - bowler = theBowler; - cumulScore = theCumulScore; - score = theScore; - curScores = theCurScores; - frameNum = theFrameNum; - ball = theBall; - mechProb = mechProblem; - } - - public boolean isMechanicalProblem() { - return mechProb; - } - - public int getFrameNum() { - return frameNum; - } - - public HashMap getScore( ) { - return score; - } - - - public int[] getCurScores(){ - return curScores; - } - - public int getIndex() { - return index; - } - - public int getFrame( ) { - return frame; - } - - public int getBall( ) { - return ball; - } - - public int[][] getCumulScore(){ - return cumulScore; - } - - public Party getParty() { - return p; - } - - public Bowler getBowler() { - return bowler; - } - -}; - diff --git a/BallingManagementSystem_refactoring/LaneEventInterface.java b/BallingManagementSystem_refactoring/LaneEventInterface.java deleted file mode 100644 index c3936fc..0000000 --- a/BallingManagementSystem_refactoring/LaneEventInterface.java +++ /dev/null @@ -1,15 +0,0 @@ -import java.util.HashMap; - -public interface LaneEventInterface extends java.rmi.Remote { - public int getFrameNum( ) throws java.rmi.RemoteException; - public HashMap getScore( ) throws java.rmi.RemoteException; - public int[] getCurScores( ) throws java.rmi.RemoteException; - public int getIndex() throws java.rmi.RemoteException; - public int getFrame() throws java.rmi.RemoteException; - public int getBall() throws java.rmi.RemoteException; - public int[][] getCumulScore() throws java.rmi.RemoteException; - public Party getParty() throws java.rmi.RemoteException; - public Bowler getBowler() throws java.rmi.RemoteException; - -} - diff --git a/BallingManagementSystem_refactoring/LaneObserver.java b/BallingManagementSystem_refactoring/LaneObserver.java deleted file mode 100644 index a7c468b..0000000 --- a/BallingManagementSystem_refactoring/LaneObserver.java +++ /dev/null @@ -1,17 +0,0 @@ -/* $Id$ - * - * Revisions: - * $Log: LaneObserver.java,v $ - * Revision 1.2 2003/01/30 21:44:25 ??? - * Fixed speling of received in may places. - * - * Revision 1.1 2003/01/19 22:12:40 ??? - * created laneevent and laneobserver - * - * - */ - -public interface LaneObserver { - public void receiveLaneEvent(LaneEvent le); -}; - diff --git a/BallingManagementSystem_refactoring/LaneServer.java b/BallingManagementSystem_refactoring/LaneServer.java deleted file mode 100644 index 05b3dd1..0000000 --- a/BallingManagementSystem_refactoring/LaneServer.java +++ /dev/null @@ -1,4 +0,0 @@ -public interface LaneServer extends java.rmi.Remote { - public void subscribe(LaneObserver toAdd) throws java.rmi.RemoteException; -}; - diff --git a/BallingManagementSystem_refactoring/LaneStatusView.java b/BallingManagementSystem_refactoring/LaneStatusView.java deleted file mode 100644 index 9c530e9..0000000 --- a/BallingManagementSystem_refactoring/LaneStatusView.java +++ /dev/null @@ -1,155 +0,0 @@ -/** - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.border.*; -import javax.swing.event.*; - -public class LaneStatusView implements ActionListener, LaneObserver, PinsetterObserver { - - private JPanel jp; - - private JLabel curBowler, foul, pinsDown; - private JButton viewLane; - private JButton viewPinSetter, maintenance; - - private PinSetterView psv; - private LaneView lv; - private Lane lane; - int laneNum; - - boolean laneShowing; - boolean psShowing; - - public LaneStatusView(Lane lane, int laneNum ) { - - this.lane = lane; - this.laneNum = laneNum; - - laneShowing=false; - psShowing=false; - - psv = new PinSetterView( laneNum ); - Pinsetter ps = lane.getPinsetter(); - ps.subscribe(psv); - - lv = new LaneView( lane, laneNum ); - lane.subscribe(lv); - - - jp = new JPanel(); - jp.setLayout(new FlowLayout()); - JLabel cLabel = new JLabel( "Now Bowling: " ); - curBowler = new JLabel( "(no one)" ); - JLabel fLabel = new JLabel( "Foul: " ); - foul = new JLabel( " " ); - JLabel pdLabel = new JLabel( "Pins Down: " ); - pinsDown = new JLabel( "0" ); - - // Button Panel - JPanel buttonPanel = new JPanel(); - buttonPanel.setLayout(new FlowLayout()); - - Insets buttonMargin = new Insets(4, 4, 4, 4); - - viewLane = new JButton("View Lane"); - JPanel viewLanePanel = new JPanel(); - viewLanePanel.setLayout(new FlowLayout()); - viewLane.addActionListener(this); - viewLanePanel.add(viewLane); - - viewPinSetter = new JButton("Pinsetter"); - JPanel viewPinSetterPanel = new JPanel(); - viewPinSetterPanel.setLayout(new FlowLayout()); - viewPinSetter.addActionListener(this); - viewPinSetterPanel.add(viewPinSetter); - - maintenance = new JButton(" "); - maintenance.setBackground( Color.GREEN ); - JPanel maintenancePanel = new JPanel(); - maintenancePanel.setLayout(new FlowLayout()); - maintenance.addActionListener(this); - maintenancePanel.add(maintenance); - - viewLane.setEnabled( false ); - viewPinSetter.setEnabled( false ); - - - buttonPanel.add(viewLanePanel); - buttonPanel.add(viewPinSetterPanel); - buttonPanel.add(maintenancePanel); - - jp.add( cLabel ); - jp.add( curBowler ); -// jp.add( fLabel ); -// jp.add( foul ); - jp.add( pdLabel ); - jp.add( pinsDown ); - - jp.add(buttonPanel); - - } - - public JPanel showLane() { - return jp; - } - - public void actionPerformed( ActionEvent e ) { - if ( lane.isPartyAssigned() ) { - if (e.getSource().equals(viewPinSetter)) { - if ( psShowing == false ) { - psv.show(); - psShowing=true; - } else if ( psShowing == true ) { - psv.hide(); - psShowing=false; - } - } - } - if (e.getSource().equals(viewLane)) { - if ( lane.isPartyAssigned() ) { - if ( laneShowing == false ) { - lv.show(); - laneShowing=true; - } else if ( laneShowing == true ) { - lv.hide(); - laneShowing=false; - } - } - } - if (e.getSource().equals(maintenance)) { - if ( lane.isPartyAssigned() ) { - lane.unPauseGame(); - maintenance.setBackground( Color.GREEN ); - } - } - } - - public void receiveLaneEvent(LaneEvent le) { - curBowler.setText( ( (Bowler)le.getBowler()).getNickName() ); - if ( le.isMechanicalProblem() ) { - maintenance.setBackground( Color.RED ); - } - if ( lane.isPartyAssigned() == false ) { - viewLane.setEnabled( false ); - viewPinSetter.setEnabled( false ); - } else { - viewLane.setEnabled( true ); - viewPinSetter.setEnabled( true ); - } - } - - public void receivePinsetterEvent(PinsetterEvent pe) { - pinsDown.setText( ( new Integer(pe.totalPinsDown()) ).toString() ); -// foul.setText( ( new Boolean(pe.isFoulCommited()) ).toString() ); - - } - -} diff --git a/BallingManagementSystem_refactoring/LaneView.java b/BallingManagementSystem_refactoring/LaneView.java deleted file mode 100644 index 3a000cd..0000000 --- a/BallingManagementSystem_refactoring/LaneView.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * constructs a prototype Lane View - * - */ - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import java.util.*; - -public class LaneView implements LaneObserver, ActionListener { - - private int roll; - private boolean initDone = true; - - JFrame frame; - Container cpanel; - Vector bowlers; - int cur; - Iterator bowlIt; - - JPanel[][] balls; - JLabel[][] ballLabel; - JPanel[][] scores; - JLabel[][] scoreLabel; - JPanel[][] ballGrid; - JPanel[] pins; - - JButton maintenance; - Lane lane; - - public LaneView(Lane lane, int laneNum) { - - this.lane = lane; - - initDone = true; - frame = new JFrame("Lane " + laneNum + ":"); - cpanel = frame.getContentPane(); - cpanel.setLayout(new BorderLayout()); - - frame.addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - frame.hide(); - } - }); - - cpanel.add(new JPanel()); - - } - - public void show() { - frame.show(); - } - - public void hide() { - frame.hide(); - } - - private JPanel makeFrame(Party party) { - - initDone = false; - bowlers = party.getMembers(); - int numBowlers = bowlers.size(); - - JPanel panel = new JPanel(); - - panel.setLayout(new GridLayout(0, 1)); - - balls = new JPanel[numBowlers][23]; - ballLabel = new JLabel[numBowlers][23]; - scores = new JPanel[numBowlers][10]; - scoreLabel = new JLabel[numBowlers][10]; - ballGrid = new JPanel[numBowlers][10]; - pins = new JPanel[numBowlers]; - - for (int i = 0; i != numBowlers; i++) { - for (int j = 0; j != 23; j++) { - ballLabel[i][j] = new JLabel(" "); - balls[i][j] = new JPanel(); - balls[i][j].setBorder( - BorderFactory.createLineBorder(Color.BLACK)); - balls[i][j].add(ballLabel[i][j]); - } - } - - for (int i = 0; i != numBowlers; i++) { - for (int j = 0; j != 9; j++) { - ballGrid[i][j] = new JPanel(); - ballGrid[i][j].setLayout(new GridLayout(0, 3)); - ballGrid[i][j].add(new JLabel(" "), BorderLayout.EAST); - ballGrid[i][j].add(balls[i][2 * j], BorderLayout.EAST); - ballGrid[i][j].add(balls[i][2 * j + 1], BorderLayout.EAST); - } - int j = 9; - ballGrid[i][j] = new JPanel(); - ballGrid[i][j].setLayout(new GridLayout(0, 3)); - ballGrid[i][j].add(balls[i][2 * j]); - ballGrid[i][j].add(balls[i][2 * j + 1]); - ballGrid[i][j].add(balls[i][2 * j + 2]); - } - - for (int i = 0; i != numBowlers; i++) { - pins[i] = new JPanel(); - pins[i].setBorder( - BorderFactory.createTitledBorder( - ((Bowler) bowlers.get(i)).getNick())); - pins[i].setLayout(new GridLayout(0, 10)); - for (int k = 0; k != 10; k++) { - scores[i][k] = new JPanel(); - scoreLabel[i][k] = new JLabel(" ", SwingConstants.CENTER); - scores[i][k].setBorder( - BorderFactory.createLineBorder(Color.BLACK)); - scores[i][k].setLayout(new GridLayout(0, 1)); - scores[i][k].add(ballGrid[i][k], BorderLayout.EAST); - scores[i][k].add(scoreLabel[i][k], BorderLayout.SOUTH); - pins[i].add(scores[i][k], BorderLayout.EAST); - } - panel.add(pins[i]); - } - - initDone = true; - return panel; - } - - public void receiveLaneEvent(LaneEvent le) { - if (lane.isPartyAssigned()) { - int numBowlers = le.getParty().getMembers().size(); - while (!initDone) { - //System.out.println("chillin' here."); - try { - Thread.sleep(1); - } catch (Exception e) { - } - } - - if (le.getFrameNum() == 1 - && le.getBall() == 0 - && le.getIndex() == 0) { - System.out.println("Making the frame."); - cpanel.removeAll(); - cpanel.add(makeFrame(le.getParty()), "Center"); - - // Button Panel - JPanel buttonPanel = new JPanel(); - buttonPanel.setLayout(new FlowLayout()); - - Insets buttonMargin = new Insets(4, 4, 4, 4); - - maintenance = new JButton("Maintenance Call"); - JPanel maintenancePanel = new JPanel(); - maintenancePanel.setLayout(new FlowLayout()); - maintenance.addActionListener(this); - maintenancePanel.add(maintenance); - - buttonPanel.add(maintenancePanel); - - cpanel.add(buttonPanel, "South"); - - frame.pack(); - - } - - int[][] lescores = le.getCumulScore(); - for (int k = 0; k < numBowlers; k++) { - for (int i = 0; i <= le.getFrameNum() - 1; i++) { - if (lescores[k][i] != 0) - scoreLabel[k][i].setText( - (new Integer(lescores[k][i])).toString()); - } - for (int i = 0; i < 21; i++) { - if (((int[]) ((HashMap) le.getScore()) - .get(bowlers.get(k)))[i] - != -1) - if (((int[]) ((HashMap) le.getScore()) - .get(bowlers.get(k)))[i] - == 10 - && (i % 2 == 0 || i == 19)) - ballLabel[k][i].setText("X"); - else if ( - i > 0 - && ((int[]) ((HashMap) le.getScore()) - .get(bowlers.get(k)))[i] - + ((int[]) ((HashMap) le.getScore()) - .get(bowlers.get(k)))[i - - 1] - == 10 - && i % 2 == 1) - ballLabel[k][i].setText("/"); - else if ( ((int[])((HashMap) le.getScore()).get(bowlers.get(k)))[i] == -2 ){ - - ballLabel[k][i].setText("F"); - } else - ballLabel[k][i].setText( - (new Integer(((int[]) ((HashMap) le.getScore()) - .get(bowlers.get(k)))[i])) - .toString()); - } - } - - } - } - - public void actionPerformed(ActionEvent e) { - if (e.getSource().equals(maintenance)) { - lane.pauseGame(); - } - } - -} diff --git a/BallingManagementSystem_refactoring/NewPatronView.java b/BallingManagementSystem_refactoring/NewPatronView.java deleted file mode 100644 index 84cbb9b..0000000 --- a/BallingManagementSystem_refactoring/NewPatronView.java +++ /dev/null @@ -1,156 +0,0 @@ -/* AddPartyView.java - * - * Version - * $Id$ - * - * Revisions: - * $Log: NewPatronView.java,v $ - * Revision 1.3 2003/02/02 16:29:52 ??? - * Added ControlDeskEvent and ControlDeskObserver. Updated Queue to allow access to Vector so that contents could be viewed without destroying. Implemented observer model for most of ControlDesk. - * - * - */ - -/** - * Class for GUI components need to add a patron - * - */ - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; -import javax.swing.border.*; -import javax.swing.event.*; - -import java.util.*; -import java.text.*; - -public class NewPatronView implements ActionListener { - - private int maxSize; - - private JFrame win; - private JButton abort, finished; - private JLabel nickLabel, fullLabel, emailLabel; - private JTextField nickField, fullField, emailField; - private String nick, full, email; - - private boolean done; - - private String selectedNick, selectedMember; - private AddPartyView addParty; - - public NewPatronView(AddPartyView v) { - - addParty=v; - done = false; - - win = new JFrame("Add Patron"); - win.getContentPane().setLayout(new BorderLayout()); - ((JPanel) win.getContentPane()).setOpaque(false); - - JPanel colPanel = new JPanel(); - colPanel.setLayout(new BorderLayout()); - - // Patron Panel - JPanel patronPanel = new JPanel(); - patronPanel.setLayout(new GridLayout(3, 1)); - patronPanel.setBorder(new TitledBorder("Your Info")); - - JPanel nickPanel = new JPanel(); - nickPanel.setLayout(new FlowLayout()); - nickLabel = new JLabel("Nick Name"); - nickField = new JTextField("", 15); - nickPanel.add(nickLabel); - nickPanel.add(nickField); - - JPanel fullPanel = new JPanel(); - fullPanel.setLayout(new FlowLayout()); - fullLabel = new JLabel("Full Name"); - fullField = new JTextField("", 15); - fullPanel.add(fullLabel); - fullPanel.add(fullField); - - JPanel emailPanel = new JPanel(); - emailPanel.setLayout(new FlowLayout()); - emailLabel = new JLabel("E-Mail"); - emailField = new JTextField("", 15); - emailPanel.add(emailLabel); - emailPanel.add(emailField); - - patronPanel.add(nickPanel); - patronPanel.add(fullPanel); - patronPanel.add(emailPanel); - - // Button Panel - JPanel buttonPanel = new JPanel(); - buttonPanel.setLayout(new GridLayout(4, 1)); - - Insets buttonMargin = new Insets(4, 4, 4, 4); - - finished = new JButton("Add Patron"); - JPanel finishedPanel = new JPanel(); - finishedPanel.setLayout(new FlowLayout()); - finished.addActionListener(this); - finishedPanel.add(finished); - - abort = new JButton("Abort"); - JPanel abortPanel = new JPanel(); - abortPanel.setLayout(new FlowLayout()); - abort.addActionListener(this); - abortPanel.add(abort); - - buttonPanel.add(abortPanel); - buttonPanel.add(finishedPanel); - - // Clean up main panel - colPanel.add(patronPanel, "Center"); - colPanel.add(buttonPanel, "East"); - - win.getContentPane().add("Center", colPanel); - - win.pack(); - - // Center Window on Screen - Dimension screenSize = (Toolkit.getDefaultToolkit()).getScreenSize(); - win.setLocation( - ((screenSize.width) / 2) - ((win.getSize().width) / 2), - ((screenSize.height) / 2) - ((win.getSize().height) / 2)); - win.show(); - - } - - public void actionPerformed(ActionEvent e) { - if (e.getSource().equals(abort)) { - done = true; - win.hide(); - } - - if (e.getSource().equals(finished)) { - nick = nickField.getText(); - full = fullField.getText(); - email = emailField.getText(); - done = true; - addParty.updateNewPatron( this ); - win.hide(); - } - - } - - public boolean done() { - return done; - } - - public String getNick() { - return nick; - } - - public String getFull() { - return full; - } - - public String getEmail() { - return email; - } - -} diff --git a/BallingManagementSystem_refactoring/Party.java b/BallingManagementSystem_refactoring/Party.java deleted file mode 100644 index 3aa4533..0000000 --- a/BallingManagementSystem_refactoring/Party.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Party.java - * - * Version: - * $Id$ - * - * Revisions: - * $Log: Party.java,v $ - * Revision 1.3 2003/02/09 21:21:31 ??? - * Added lots of comments - * - * Revision 1.2 2003/01/12 22:23:32 ??? - * *** empty log message *** - * - * Revision 1.1 2003/01/12 19:09:12 ??? - * Adding Party, Lane, Bowler, and Alley. - * - */ - -/** - * Container that holds bowlers - * - */ - -import java.util.*; - -public class Party { - - /** Vector of bowlers in this party */ - private Vector myBowlers; - - /** - * Constructor for a Party - * - * @param bowlers Vector of bowlers that are in this party - */ - - public Party( Vector bowlers ) { - myBowlers = new Vector(bowlers); - } - - /** - * Accessor for members in this party - * - * @return A vector of the bowlers in this party - */ - - public Vector getMembers() { - return myBowlers; - } - -} diff --git a/BallingManagementSystem_refactoring/PinSetterView.java b/BallingManagementSystem_refactoring/PinSetterView.java deleted file mode 100644 index db2d561..0000000 --- a/BallingManagementSystem_refactoring/PinSetterView.java +++ /dev/null @@ -1,194 +0,0 @@ -/* - * PinSetterView/.java - * - * Version: - * $Id$ - * - * Revision: - * $Log$ - */ - -/** - * constructs a prototype PinSetter GUI - * - */ - -import java.awt.*; -import javax.swing.*; -import java.util.Vector; - - -public class PinSetterView implements PinsetterObserver { - - - private Vector pinVect = new Vector ( ); - private JPanel firstRoll; - private JPanel secondRoll; - - /** - * Constructs a Pin Setter GUI displaying which roll it is with - * yellow boxes along the top (1 box for first roll, 2 boxes for second) - * and displays the pins as numbers in this format: - * - * 7 8 9 10 - * 4 5 6 - * 2 3 - * 1 - * - */ - - - private JFrame frame; - - public PinSetterView ( int laneNum ) { - - frame = new JFrame ( "Lane " + laneNum + ":" ); - - Container cpanel = frame.getContentPane ( ); - - JPanel pins = new JPanel ( ); - - pins.setLayout ( new GridLayout ( 4, 7 ) ); - - //********************Top of GUI indicates first or second roll - - JPanel top = new JPanel ( ); - - firstRoll = new JPanel ( ); - firstRoll.setBackground( Color.yellow ); - - secondRoll = new JPanel ( ); - secondRoll.setBackground ( Color.black ); - - top.add ( firstRoll, BorderLayout.WEST ); - - top.add ( secondRoll, BorderLayout.EAST ); - - //****************************************************************** - - //**********************Grid of the pins************************** - - private JPanel createPanel( String pinNumber, JPanel panel) { - //JPanel label = new JPanel(); - JLabel label = new JLabel(pinNumber); - panel.add (label); - pinVect.add (label); - } - - createPanel(1, oneL); - createPanel(2, twoL); - createPanel(3, threeL); - createPanel(4, fourL); - createPanel(5, fiveL); - createPanel(6, sixL); - createPanel(7, sevenL); - createPanel(8, eightL); - createPanel(9, nineL); - createPanel(10, tenL); - - - //This Vector will keep references to the pin labels to show - //which ones have fallen. - - - //******************************Fourth Row************** - - pins.add ( seven ); - pins.add ( new JPanel ( ) ); - pins.add ( eight ); - pins.add ( new JPanel ( ) ); - pins.add ( nine ); - pins.add ( new JPanel ( ) ); - pins.add ( ten ); - - //*****************************Third Row*********** - - pins.add ( new JPanel ( ) ); - pins.add ( four ); - pins.add ( new JPanel ( ) ); - pins.add ( five ); - pins.add ( new JPanel ( ) ); - pins.add ( six ); - - //*****************************Second Row************** - - pins.add ( new JPanel ( ) ); - pins.add ( new JPanel ( ) ); - pins.add ( new JPanel ( ) ); - pins.add ( two ); - pins.add ( new JPanel ( ) ); - pins.add ( three ); - pins.add ( new JPanel ( ) ); - pins.add ( new JPanel ( ) ); - - //******************************First Row***************** - - pins.add ( new JPanel ( ) ); - pins.add ( new JPanel ( ) ); - pins.add ( new JPanel ( ) ); - pins.add ( one ); - pins.add ( new JPanel ( ) ); - pins.add ( new JPanel ( ) ); - pins.add ( new JPanel ( ) ); - //********************************************************* - - top.setBackground ( Color.black ); - - cpanel.add ( top, BorderLayout.NORTH ); - - pins.setBackground ( Color.black ); - pins.setForeground ( Color.yellow ); - - cpanel.add ( pins, BorderLayout.CENTER ); - - frame.pack(); - - } - - - /** - * This method receives a pinsetter event. The event is the current - * state of the PinSetter and the method changes how the GUI looks - * accordingly. When pins are "knocked down" the corresponding label - * is grayed out. When it is the second roll, it is indicated by the - * appearance of a second yellow box at the top. - * - * @param e The state of the pinsetter is sent in this event. - */ - - - public void receivePinsetterEvent(PinsetterEvent pe){ - if ( !(pe.isFoulCommited()) ) { - JLabel tempPin = new JLabel ( ); - for ( int c = 0; c < 10; c++ ) { - boolean pin = pe.pinKnockedDown ( c ); - tempPin = (JLabel)pinVect.get ( c ); - if ( pin ) { - tempPin.setForeground ( Color.lightGray ); - } - } - } - if ( pe.getThrowNumber() == 1 ) { - secondRoll.setBackground ( Color.yellow ); - } - if ( pe.pinsDownOnThisThrow() == -1) { - for ( int i = 0; i != 10; i++){ - ((JLabel)pinVect.get(i)).setForeground(Color.black); - } - secondRoll.setBackground( Color.black); - } - } - - public void show() { - frame.show(); - } - - public void hide() { - frame.hide(); - } - - public static void main ( String args [ ] ) { - PinSetterView pg = new PinSetterView ( 1 ); - } - -} diff --git a/BallingManagementSystem_refactoring/Pinsetter.java b/BallingManagementSystem_refactoring/Pinsetter.java deleted file mode 100644 index 35dbb2e..0000000 --- a/BallingManagementSystem_refactoring/Pinsetter.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Pinsetter.java - * - * Version: - * $Id$ - * - * Revisions: - * $Log: Pinsetter.java,v $ - * Revision 1.21 2003/02/20 20:27:45 ??? - * Fouls disables. - * - * Revision 1.20 2003/02/20 19:53:52 ??? - * Added foul support. Still need to update laneview and test this. - * - * Revision 1.19 2003/02/06 22:28:51 ??? - * added delay - * - * Revision 1.18 2003/02/06 00:27:46 ??? - * Fixed a race condition - * - * Revision 1.17 2003/02/05 23:56:07 ??? - * *** empty log message *** - * - * Revision 1.16 2003/02/05 23:51:09 ??? - * Better random numbers. - * - * Revision 1.15 2003/02/02 23:49:48 ??? - * Pinsetter generates an event when all pins are reset - * - * Revision 1.14 2003/02/02 23:26:32 ??? - * ControlDesk now runs its own thread and polls for free lanes to assign queue members to - * - * Revision 1.13 2003/02/02 23:21:30 ??? - * pinsetter should give better results - * - * Revision 1.12 2003/02/02 23:20:28 ??? - * pinsetter should give better results - * - * Revision 1.11 2003/02/02 23:11:41 ??? - * parties can now play more than 1 game on a lane, and lanes are properly released after games - * - * Revision 1.10 2003/02/01 19:14:42 ??? - * Will now set the pins back up at times other than the 10th frame. - * - * Revision 1.9 2003/01/30 21:44:25 ??? - * Fixed speling of received in may places. - * - * Revision 1.8 2003/01/26 22:34:44 ??? - * Total rewrite of lane and pinsetter for R2's observer model - * Added Lane/Pinsetter Observer - * Rewrite of scoring algorythm in lane - * - * Revision 1.7 2003/01/19 21:55:24 ??? - * updated pinsetter to new spec - * - * Revision 1.6 2003/01/16 04:59:59 ??? - * misc fixes across the board - * - * Revision 1.5 2003/01/13 22:35:21 ??? - * Scoring works. - * - * Revision 1.3 2003/01/12 22:37:20 ??? - * Wrote a better algorythm for knocking down pins - * - * - */ - -/** - * Class to represent the pinsetter - * - */ - -import java.util.*; - -public class Pinsetter { - - private Random rnd; - private Vector subscribers; - - private boolean[] pins; - /* 0-9 of state of pine, true for standing, - false for knocked down - - 6 7 8 9 - 3 4 5 - 2 1 - 0 - - */ - private boolean foul; - private int throwNumber; - - /** sendEvent() - * - * Sends pinsetter events to all subscribers - * - * @pre none - * @post all subscribers have recieved pinsetter event with updated state - * */ - private void sendEvent(int jdpins) { // send events when our state is changd - for (int i=0; i < subscribers.size(); i++) { - ((PinsetterObserver)subscribers.get(i)).receivePinsetterEvent( - new PinsetterEvent(pins, foul, throwNumber, jdpins)); - } - } - - /** Pinsetter() - * - * Constructs a new pinsetter - * - * @pre none - * @post a new pinsetter is created - * @return Pinsetter object - */ - public Pinsetter() { - pins = new boolean[10]; - rnd = new Random(); - subscribers = new Vector(); - foul = false; - reset(); - } - - /** ballThrown() - * - * Called to simulate a ball thrown comming in contact with the pinsetter - * - * @pre none - * @post pins may have been knocked down and the thrownumber has been incremented - */ - public void ballThrown() { // simulated event of ball hits sensor - int count = 0; - foul = false; - double skill = rnd.nextDouble(); - for (int i=0; i <= 9; i++) { - if (pins[i]) { - double pinluck = rnd.nextDouble(); - if (pinluck <= .04){ - foul = true; - } - if ( ((skill + pinluck)/2.0 * 1.2) > .5 ){ - pins[i] = false; - } - if (!pins[i]) { // this pin just knocked down - count++; - } - } - } - - try { - Thread.sleep(500); // pinsetter is where delay will be in a real game - } catch (Exception e) {} - - sendEvent(count); - - throwNumber++; - } - - /** reset() - * - * Reset the pinsetter to its complete state - * - * @pre none - * @post pinsetters state is reset - */ - public void reset() { - foul = false; - throwNumber = 1; - resetPins(); - - try { - Thread.sleep(1000); - } catch (Exception e) {} - - sendEvent(-1); - } - - /** resetPins() - * - * Reset the pins on the pinsetter - * - * @pre none - * @post pins array is reset to all pins up - */ - public void resetPins() { - for (int i=0; i <= 9; i++) { - pins[i] = true; - } - } - - /** subscribe() - * - * subscribe objects to send events to - * - * @pre none - * @post the subscriber object will recieve events when their generated - */ - public void subscribe(PinsetterObserver subscriber) { - subscribers.add(subscriber); - } - -}; - diff --git a/BallingManagementSystem_refactoring/PinsetterEvent.java b/BallingManagementSystem_refactoring/PinsetterEvent.java deleted file mode 100644 index 3509873..0000000 --- a/BallingManagementSystem_refactoring/PinsetterEvent.java +++ /dev/null @@ -1,90 +0,0 @@ -/* $Id$ - * - * Revisions: - * $Log: PinsetterEvent.java,v $ - * Revision 1.2 2003/01/26 22:34:44 ??? - * Total rewrite of lane and pinsetter for R2's observer model - * Added Lane/Pinsetter Observer - * Rewrite of scoring algorythm in lane - * - * Revision 1.1 2003/01/19 21:04:24 ??? - * created pinsetterevent and pinsetterobserver - * - */ - -public class PinsetterEvent { - - private boolean[] pinsStillStanding; - private boolean foulCommited; - private int throwNumber; - private int pinsDownThisThrow; - - /** PinsetterEvent() - * - * creates a new pinsetter event - * - * @pre none - * @post the object has been initialized - */ - public PinsetterEvent(boolean[] ps, boolean foul, int tn, int pinsDownThisThrow) { - pinsStillStanding = new boolean[10]; - - for (int i=0; i <= 9; i++) { - pinsStillStanding[i] = ps[i]; - } - - foulCommited = foul; - throwNumber = tn; - this.pinsDownThisThrow = pinsDownThisThrow; - } - - /** pinKnockedDown() - * - * check if a pin has been knocked down - * - * @return true if pin [i] has been knocked down - */ - public boolean pinKnockedDown(int i) { - return !pinsStillStanding[i]; - } - - /** pinsDownOnThisThrow() - * - * @return the number of pins knocked down assosicated with this event - */ - public int pinsDownOnThisThrow() { - return pinsDownThisThrow; - } - - /** totalPinsDown() - * - * @return the total number of pins down for pinsetter that generated the event - */ - public int totalPinsDown() { - int count = 0; - - for (boolean pinStanding : pinsStillStanding) { - if (!pinStanding) { - count++; - } - } - return count; - } - - /** isFoulCommited() - * - * @return true if a foul was commited on the lane, false otherwise - */ - public boolean isFoulCommited() { - return foulCommited; - } - - /** getThrowNumber() - * - * @return current number of throws taken on this lane after last reset - */ - public int getThrowNumber() { - return throwNumber; - } -}; - diff --git a/BallingManagementSystem_refactoring/PinsetterObserver.java b/BallingManagementSystem_refactoring/PinsetterObserver.java deleted file mode 100644 index 666ae04..0000000 --- a/BallingManagementSystem_refactoring/PinsetterObserver.java +++ /dev/null @@ -1,28 +0,0 @@ -/* $Id$ - * - * Revisions: - * $Log: PinsetterObserver.java,v $ - * Revision 1.3 2003/01/30 21:44:25 ??? - * Fixed speling of received in may places. - * - * Revision 1.2 2003/01/26 22:34:44 ??? - * Total rewrite of lane and pinsetter for R2's observer model - * Added Lane/Pinsetter Observer - * Rewrite of scoring algorythm in lane - * - * Revision 1.1 2003/01/19 21:04:24 ??? - * created pinsetterevent and pinsetterobserver - * - * - */ - - -public interface PinsetterObserver { - - /** recievePinsetterEvent() - * - * defines the method for an object torecieve a pinsetter event - */ - public void receivePinsetterEvent(PinsetterEvent pe); -}; - diff --git a/BallingManagementSystem_refactoring/PrintableText.java b/BallingManagementSystem_refactoring/PrintableText.java deleted file mode 100644 index 9505048..0000000 --- a/BallingManagementSystem_refactoring/PrintableText.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * - */ - -import java.awt.*; -import java.awt.print.*; -import java.awt.geom.*; -import java.awt.font.*; -import java.text.*; - -public class PrintableText implements Printable { - String text; - int POINTS_PER_INCH; - - public PrintableText(String t) { - POINTS_PER_INCH = 72; - text = t; - } - - public int print(Graphics g, PageFormat pageFormat, int pageIndex) { - if (pageIndex > 0) { - return NO_SUCH_PAGE; - } - - Graphics2D g2d = (Graphics2D) g; // Allow use of Java 2 graphics on - - g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); - g2d.setPaint(Color.black); - - Point2D.Double pen = new Point2D.Double(0.25 * POINTS_PER_INCH, 0.25 * POINTS_PER_INCH); - - Font font = new Font ("courier", Font.PLAIN, 12); - FontRenderContext frc = g2d.getFontRenderContext(); - - String lines[] = text.split("\n"); - - for (int i=0; i < lines.length; i++) { - if (lines[i].length() > 0) { - TextLayout layout = new TextLayout(lines[i], font, frc); - layout.draw(g2d, (float) pen.x, (float) (pen.y + i*14)); - } - } - - return PAGE_EXISTS; - } - -} diff --git a/BallingManagementSystem_refactoring/Queue.java b/BallingManagementSystem_refactoring/Queue.java deleted file mode 100644 index 2f23814..0000000 --- a/BallingManagementSystem_refactoring/Queue.java +++ /dev/null @@ -1,40 +0,0 @@ -/* Queue.java - * - * Version - * $Id$ - * - * Revisions: - * $Log$ - * - */ - -import java.util.Vector; - -public class Queue { - private Vector v; - - /** Queue() - * - * creates a new queue - */ - public Queue() { - v = new Vector(); - } - - public Object next() { - return v.remove(0); - } - - public void add(Object o) { - v.addElement(o); - } - - public boolean hasMoreElements() { - return v.size() != 0; - } - - public Vector asVector() { - return v; - } - -} diff --git a/BallingManagementSystem_refactoring/README.md b/BallingManagementSystem_refactoring/README.md deleted file mode 100644 index 738ee2a..0000000 --- a/BallingManagementSystem_refactoring/README.md +++ /dev/null @@ -1 +0,0 @@ -# BallingManagementSystem_refactoring \ No newline at end of file diff --git a/BallingManagementSystem_refactoring/SCOREHISTORY.DAT b/BallingManagementSystem_refactoring/SCOREHISTORY.DAT deleted file mode 100644 index 1a3e071..0000000 --- a/BallingManagementSystem_refactoring/SCOREHISTORY.DAT +++ /dev/null @@ -1,15 +0,0 @@ -Mike 22:25 3/6/2004 130 -Jim 22:25 3/6/2004 113 -Tom 22:25 3/6/2004 105 -Lana 22:25 3/6/2004 130 -TomH 22:25 3/6/2004 125 -Mike 22:26 3/6/2004 153 -TomH 22:26 3/6/2004 174 -Mike 15:52 4/2/2023 162 -Jim 15:52 4/2/2023 139 -Tom 15:54 4/2/2023 124 -Jim 15:54 4/2/2023 134 -Mike 16:26 4/2/2023 133 -Jim 16:26 4/2/2023 127 -Mike 16:28 4/2/2023 91 -Jim 16:28 4/2/2023 111 diff --git a/BallingManagementSystem_refactoring/Score.java b/BallingManagementSystem_refactoring/Score.java deleted file mode 100644 index deaedc7..0000000 --- a/BallingManagementSystem_refactoring/Score.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ - -public class Score { - - private String nick; - private String date; - private String score; - - public Score( String nick, String date, String score ) { - this.nick=nick; - this.date=date; - this.score=score; - } - - public String getNickName() { - return nick; - } - - public String getDate() { - return date; - } - - public String getScore() { - return score; - } - - public String toString() { - return nick + "\t" + date + "\t" + score; - } - -} diff --git a/BallingManagementSystem_refactoring/ScoreHistoryFile.java b/BallingManagementSystem_refactoring/ScoreHistoryFile.java deleted file mode 100644 index 34bfd57..0000000 --- a/BallingManagementSystem_refactoring/ScoreHistoryFile.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * - * To change this generated comment edit the template variable "typecomment": - * Window>Preferences>Java>Templates. - * To enable and disable the creation of type comments go to - * Window>Preferences>Java>Code Generation. - */ - -import java.util.*; -import java.io.*; - -public class ScoreHistoryFile { - - private static String SCOREHISTORY_DAT = "SCOREHISTORY.DAT"; - - public static void addScore(String nick, String date, String score) - throws IOException, FileNotFoundException { - - String data = nick + "\t" + date + "\t" + score + "\n"; - - RandomAccessFile out = new RandomAccessFile(SCOREHISTORY_DAT, "rw"); - out.skipBytes((int) out.length()); - out.writeBytes(data); - out.close(); - } - - public static Vector getScores(String nick) - throws IOException, FileNotFoundException { - Vector scores = new Vector(); - - BufferedReader in = - new BufferedReader(new FileReader(SCOREHISTORY_DAT)); - String data; - while ((data = in.readLine()) != null) { - // File format is nick\tfname\te-mail - String[] scoredata = data.split("\t"); - //"Nick: scoredata[0] Date: scoredata[1] Score: scoredata[2] - if (nick.equals(scoredata[0])) { - scores.add(new Score(scoredata[0], scoredata[1], scoredata[2])); - } - } - return scores; - } - -} diff --git a/BallingManagementSystem_refactoring/ScoreReport.java b/BallingManagementSystem_refactoring/ScoreReport.java deleted file mode 100644 index 934a511..0000000 --- a/BallingManagementSystem_refactoring/ScoreReport.java +++ /dev/null @@ -1,125 +0,0 @@ -/** - * - * SMTP implementation based on code by Réal Gagnon mailto:real@rgagnon.com - * - */ - - -import java.io.*; -import java.util.Vector; -import java.util.Iterator; -import java.net.*; -import java.awt.*; -import java.awt.print.*; - -public class ScoreReport { - - private String content; - - public ScoreReport( Bowler bowler, int[] scores, int games ) { - String nick = bowler.getNick(); - String full = bowler.getFullName(); - Vector v = null; - try{ - v = ScoreHistoryFile.getScores(nick); - } catch (Exception e){System.err.println("Error: " + e);} - - Iterator scoreIt = v.iterator(); - - content = ""; - content += "--Lucky Strike Bowling Alley Score Report--\n"; - content += "\n"; - content += "Report for " + full + ", aka \"" + nick + "\":\n"; - content += "\n"; - content += "Final scores for this session: "; - content += scores[0]; - for (int i = 1; i < games; i++){ - content += ", " + scores[i]; - } - content += ".\n"; - content += "\n"; - content += "\n"; - content += "Previous scores by date: \n"; - while (scoreIt.hasNext()){ - Score score = (Score) scoreIt.next(); - content += " " + score.getDate() + " - " + score.getScore(); - content += "\n"; - } - content += "\n\n"; - content += "Thank you for your continuing patronage."; - - } - - public void sendEmail(String recipient) { - try { - Socket s = new Socket("osfmail.rit.edu", 25); - BufferedReader in = - new BufferedReader( - new InputStreamReader(s.getInputStream(), "8859_1")); - BufferedWriter out = - new BufferedWriter( - new OutputStreamWriter(s.getOutputStream(), "8859_1")); - - String boundary = "DataSeparatorString"; - - // here you are supposed to send your username - sendln(in, out, "HELO world"); - sendln(in, out, "MAIL FROM: "); - sendln(in, out, "RCPT TO: <" + recipient + ">"); - sendln(in, out, "DATA"); - sendln(out, "Subject: Bowling Score Report "); - sendln(out, "From: "); - - sendln(out, "Content-Type: text/plain; charset=\"us-ascii\"\r\n"); - sendln(out, content + "\n\n"); - sendln(out, "\r\n"); - - sendln(in, out, "."); - sendln(in, out, "QUIT"); - s.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void sendPrintout() { - PrinterJob job = PrinterJob.getPrinterJob(); - - PrintableText printobj = new PrintableText(content); - - job.setPrintable(printobj); - - if (job.printDialog()) { - try { - job.print(); - } catch (PrinterException e) { - System.out.println(e); - } - } - - } - - public void sendln(BufferedReader in, BufferedWriter out, String s) { - try { - out.write(s + "\r\n"); - out.flush(); - // System.out.println(s); - s = in.readLine(); - // System.out.println(s); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void sendln(BufferedWriter out, String s) { - try { - out.write(s + "\r\n"); - out.flush(); - System.out.println(s); - } catch (Exception e) { - e.printStackTrace(); - } - } - - -} diff --git a/BallingManagementSystem_refactoring/drive.java b/BallingManagementSystem_refactoring/drive.java deleted file mode 100644 index 20811bf..0000000 --- a/BallingManagementSystem_refactoring/drive.java +++ /dev/null @@ -1,18 +0,0 @@ -import java.util.Vector; -import java.io.*; - -public class drive { - - public static void main(String[] args) { - - int numLanes = 3; - int maxPatronsPerParty=5; - - Alley a = new Alley( numLanes ); - ControlDesk controlDesk = a.getControlDesk(); - - ControlDeskView cdv = new ControlDeskView( controlDesk, maxPatronsPerParty); - controlDesk.subscribe( cdv ); - - } -}