2-APL UPC project.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

playedCard changed as requested

fdesan abf554aa c2544956

+97 -198
-3
code/2apl_platform/environments/cardtable/Card.java
··· 8 8 private Rank rankValue; 9 9 private ImageIcon cardImage; 10 10 11 - 12 - 13 - 14 11 public Card( Suit suit, Rank rank, ImageIcon cardFace ) { 15 12 cardImage = cardFace; 16 13 suitValue = suit;
+11 -29
code/2apl_platform/environments/cardtable/Env.java
··· 161 161 return wrapBoolean(true); 162 162 } 163 163 164 - public Term playCard(String sAgent, APLIdent suit, APLIdent rank) { 165 - notifyEvent("cardPlayed", suit, rank); 164 + public Term playCard(String sAgent, APLIdent suit, APLIdent rank) throws ExternalActionFailedException { 165 + Agent agent = getAgent(sAgent); 166 + notifyEvent("cardPlayed", suit, rank, agent); 166 167 return wrapBoolean(true); 167 168 } 168 169 169 - public Term updateScore(String sAgent, APLIdent player_name, APLNum score) { 170 + public Term updateScore(String sAgent, APLIdent player_name, APLNum score) throws ExternalActionFailedException { 171 + Agent agent = getAgent(sAgent); 170 172 sb.updateScore(player_name.toString(), score.toInt()); 173 + table.updateScore(agent.getName(), agent._position, score.toInt()); 171 174 notifyEvent("scoreUpdated", player_name, score); 172 175 return wrapBoolean(true); 173 176 } ··· 207 210 } 208 211 } 209 212 210 - private void notifyEvent(String parm1, APLIdent suit, APLIdent rank) { 213 + private void notifyEvent(String parm1, APLIdent suit, APLIdent rank, Agent player) { 211 214 ArrayList<String> targetAgents = new ArrayList<String>(); 212 215 for (Agent a : agentmap.values()) 213 216 { 214 217 if ((a.isSit() && a.getType()==0) || (a.isSit() && a.getType()==2)) // player or notary 215 218 targetAgents.add(a.getName()); 216 219 } 217 - 220 + APLIdent player_name = new APLIdent(player.getName()); 218 221 if (!targetAgents.isEmpty()) 219 222 { 220 - notifyAgents(new APLFunction(parm1,suit,rank),targetAgents.toArray(new String[0])); 221 - writeToLog("EVENT: "+parm1+"("+suit.toString()+","+rank.toString()+")"+" to "+targetAgents); 223 + notifyAgents(new APLFunction(parm1,suit,rank,player_name),targetAgents.toArray(new String[0])); 224 + writeToLog("EVENT: "+parm1+"("+suit.toString()+","+rank.toString()+","+player.getName()+")"+" to "+targetAgents); 222 225 } 223 226 } 224 227 ··· 339 342 else 340 343 return sAgent.substring(0, dotPos); 341 344 } 342 - 343 - 344 - // Redrawing the window is a nightmare, this does some redraw stuff 345 - // private void validatewindow() 346 - // { 347 - // Runnable repaint = new Runnable() 348 - // { 349 - // public void run() 350 - // { 351 - // //try {Thread.sleep(500);} catch(Exception e) {} 352 - // m_window.doLayout(); 353 - // 354 - // /*if (!m_window.isVisible()) 355 - // { 356 - // m_window.setVisible( true ); 357 - // }*/ 358 - // } 359 - // }; 360 - // SwingUtilities.invokeLater(repaint); 361 - // } 362 345 363 - 364 - // Print a message to the console 365 346 public void writeToLog(String message) { 366 347 System.out.println("cardtable: " + message); 367 348 table.writeLog(message); ··· 399 380 { 400 381 //try {Thread.sleep(500);} catch(Exception e) {} 401 382 table.doLayout(); 383 + table.repaint(); 402 384 403 385 /*if (!m_window.isVisible()) 404 386 {
+86 -166
code/2apl_platform/environments/cardtable/Table.java
··· 7 7 8 8 public class Table extends JFrame{ 9 9 10 - public JLabel[][] PlayerCards = new JLabel[8][5]; 10 + private JPanel leftDisplayPane; 11 + private JPanel[] playersPane, cardsPane; 11 12 12 - private static JPanel CardDisplayPane; 13 13 private JLayeredPane TablePane; 14 14 private JSplitPane VerticalSplitPane; 15 15 private JScrollPane GameInfo; 16 16 private JSplitPane HorizontalSplitPlane; 17 - private JTextArea Info; 18 - 19 - private static ImageIcon CardBack = new ImageIcon("cards/b.gif"); 20 - 21 - 22 - public Table( ){ 23 - super( "Briscola Chiamata" ); 24 - //----------GUI STUFF---------------------------- 17 + private JTextArea infoTextArea; 25 18 19 + public Table( ){ 20 + super( "Briscola Chiamata" ); 21 + leftDisplayPane = new JPanel(new GridLayout(5,2)); 22 + playersPane = new JPanel[5]; 23 + cardsPane = new JPanel[5]; 26 24 25 + for(int i=0; i<5; i++) { 26 + playersPane[i] = new JPanel(new GridLayout(4,1)); 27 + cardsPane[i] = new JPanel(new GridLayout(1,8)); 28 + leftDisplayPane.add(playersPane[i]); 29 + leftDisplayPane.add(cardsPane[i]); 30 + } 27 31 28 - CardDisplayPane = new JPanel(); 32 + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 29 33 30 - 31 - TablePane = new JLayeredPane(); 32 - 33 - 34 - 35 - Point origin = new Point(50, 20); 36 - Color[] layerColors = { Color.yellow, Color.magenta, 37 - Color.cyan, Color.red, 38 - Color.green }; 39 - //This is the offset for computing the origin for the next label. 40 - int offset = 35; 41 - 42 - //Add several overlapping, colored labels to the layered pane 43 - //using absolute positioning/sizing. 44 - for (int i = 0; i < 5; i++) { 45 - JLabel label = createColoredLabel("card", 46 - layerColors[i], origin); 47 - TablePane.add(label, new Integer(i)); 48 - origin.x += offset; 49 - origin.y += offset; 50 - } 51 - 52 - // where cards are displayed 53 - CardDisplayPane.setLayout(new GridBagLayout()); 54 - 55 - Info = new JTextArea(5,00); 56 - Info.setEditable(false); 57 - GameInfo = new JScrollPane(Info); 58 - 59 - VerticalSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, 60 - TablePane,GameInfo); 34 + TablePane = new JLayeredPane(); 35 + Point origin = new Point(50, 20); 36 + Color[] layerColors = { Color.yellow, Color.magenta, 37 + Color.cyan, Color.red, 38 + Color.green }; 39 + //This is the offset for computing the origin for the next label. 40 + int offset = 35; 41 + //Add several overlapping, colored labels to the layered pane 42 + //using absolute positioning/sizing. 43 + for (int i = 0; i < 5; i++) { 44 + JLabel label = createColoredLabel("card", layerColors[i], origin); 45 + TablePane.add(label, new Integer(i)); 46 + origin.x += offset; 47 + origin.y += offset; 48 + } 49 + 50 + infoTextArea = new JTextArea(5,00); 51 + infoTextArea.setEditable(false); 52 + GameInfo = new JScrollPane(infoTextArea); 61 53 62 - VerticalSplitPane.setPreferredSize(new Dimension(150,150)); 54 + VerticalSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, TablePane,GameInfo); 55 + VerticalSplitPane.setPreferredSize(new Dimension(150,150)); 63 56 VerticalSplitPane.setOneTouchExpandable(false); 64 57 VerticalSplitPane.setDividerLocation(400); 65 - 66 58 67 - HorizontalSplitPlane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, 68 - CardDisplayPane,VerticalSplitPane ); 69 - 70 - //Provide a preferred size for the split pane. 71 - HorizontalSplitPlane.setPreferredSize(new Dimension(150,150)); 59 + HorizontalSplitPlane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftDisplayPane,VerticalSplitPane ); 60 + HorizontalSplitPlane.setPreferredSize(new Dimension(150,150)); 72 61 HorizontalSplitPlane.setOneTouchExpandable(false); 73 62 HorizontalSplitPlane.setDividerLocation(600); 74 63 75 - 76 - getContentPane().add(HorizontalSplitPlane); 77 - 78 - setVisible( true ); 79 - } 80 - 81 - private JLabel createColoredLabel(String text, 82 - Color color, 83 - Point origin) { 84 - JLabel label = new JLabel(text); 85 - label.setVerticalAlignment(JLabel.TOP); 86 - label.setHorizontalAlignment(JLabel.CENTER); 87 - label.setOpaque(true); 88 - label.setBackground(color); 89 - label.setForeground(Color.black); 90 - label.setBorder(BorderFactory.createLineBorder(Color.black)); 91 - label.setBounds(origin.x, origin.y, 140, 140); 92 - 93 - pack(); 94 - setSize( 1024, 768 ); 64 + getContentPane().add(HorizontalSplitPlane); 95 65 setVisible( true ); 96 - 97 - return label; 98 66 } 99 67 100 - 101 - public void addPlayer(String name, int position, int score, int bid) { 102 - JButton button; 103 - GridBagConstraints c = new GridBagConstraints(); 104 - GridBagConstraints c1 = new GridBagConstraints(); 105 - Integer scoreInt = new Integer(score); 106 - Integer bidInt = new Integer(bid); 107 - 108 - JButton P1NameTag = new JButton(name); 109 - c.fill = GridBagConstraints.HORIZONTAL; 110 - c.gridx = 0; 111 - c.gridy = 2*position; 112 - c.gridwidth = 4; 113 - CardDisplayPane.add(P1NameTag, c); 114 - 115 - //Player Score 116 - JButton P1Score = new JButton("Score : "+ scoreInt.toString()); 117 - c.fill = GridBagConstraints.HORIZONTAL; 118 - c.gridx = 4; 119 - c.gridy = 2*position; 120 - c.gridwidth = 2; 121 - CardDisplayPane.add(P1Score, c); 122 - 123 - //Player Bid 124 - JButton P1Bid = new JButton("Bid : "+ bidInt.toString()); 125 - c.fill = GridBagConstraints.HORIZONTAL; 126 - c.gridx = 6; 127 - c.gridy = 2*position; 128 - c.gridwidth = 2; 129 - CardDisplayPane.add(P1Bid, c); 130 - 131 - //1st Card 132 - JButton P1C1 = new JButton(CardBack); 133 - P1C1.setPreferredSize(new Dimension(55,80)); 134 - c1.fill = GridBagConstraints.HORIZONTAL; 135 - c1.gridx = 0; 136 - c1.gridy = 1+2*position; 137 - CardDisplayPane.add(P1C1, c1); 138 - 139 - //2nd Card 140 - JButton P1C2 = new JButton(CardBack); 141 - P1C2.setPreferredSize(new Dimension(55,80)); 142 - c1.fill = GridBagConstraints.HORIZONTAL; 143 - c1.gridx = 1; 144 - c1.gridy = 1+2*position; 145 - CardDisplayPane.add(P1C2, c1); 146 - 147 - //3rd Card 148 - JButton P1C3 = new JButton(CardBack); 149 - P1C3.setPreferredSize(new Dimension(55,80)); 150 - c1.fill = GridBagConstraints.HORIZONTAL; 151 - c1.gridx = 2; 152 - c1.gridy = 1+2*position; 153 - CardDisplayPane.add(P1C3, c1); 154 - 155 - //4th Card 156 - JButton P1C4 = new JButton(CardBack); 157 - P1C4.setPreferredSize(new Dimension(55,80)); 158 - c1.fill = GridBagConstraints.HORIZONTAL; 159 - c1.gridx = 3; 160 - c1.gridy = 1+2*position; 161 - CardDisplayPane.add(P1C4, c1); 162 - 163 - //5th Card 164 - JButton P1C5 = new JButton(CardBack); 165 - P1C5.setPreferredSize(new Dimension(55,80)); 166 - c1.fill = GridBagConstraints.HORIZONTAL; 167 - c1.gridx = 4; 168 - c1.gridy = 1+2*position; 169 - CardDisplayPane.add(P1C5, c1); 170 - 171 - //6th Card 172 - JButton P1C6 = new JButton(CardBack); 173 - P1C6.setPreferredSize(new Dimension(55,80)); 174 - c1.fill = GridBagConstraints.HORIZONTAL; 175 - c1.gridx = 5; 176 - c1.gridy = 1+2*position; 177 - CardDisplayPane.add(P1C6, c1); 68 + private JLabel createColoredLabel(String text, Color color, Point origin) { 69 + JLabel label = new JLabel(text); 70 + label.setVerticalAlignment(JLabel.TOP); 71 + label.setHorizontalAlignment(JLabel.CENTER); 72 + label.setOpaque(true); 73 + label.setBackground(color); 74 + label.setForeground(Color.black); 75 + label.setBorder(BorderFactory.createLineBorder(Color.black)); 76 + label.setBounds(origin.x, origin.y, 140, 140); 77 + 78 + pack(); 79 + setSize( 1024, 768 ); 80 + setVisible( true ); 81 + 82 + return label; 83 + } 178 84 179 - //7th Card 180 - JButton P1C7 = new JButton(CardBack); 181 - P1C7.setPreferredSize(new Dimension(55,80)); 182 - c1.fill = GridBagConstraints.HORIZONTAL; 183 - c1.gridx = 6; 184 - c1.gridy = 1+2*position; 185 - CardDisplayPane.add(P1C7, c1); 186 85 187 - //8th Card 188 - JButton P1C8 = new JButton(CardBack); 189 - P1C8.setPreferredSize(new Dimension(55,80)); 190 - c1.fill = GridBagConstraints.HORIZONTAL; 191 - c1.gridx = 7; 192 - c1.gridy = 1+2*position; 193 - CardDisplayPane.add(P1C8, c1); 86 + public void addPlayer(String name, int position, int score, int bid) { 87 + Integer scoreInt = new Integer(score); 88 + Integer bidInt = new Integer(bid); 89 + ImageIcon cardBack = new ImageIcon("cards/b.gif"); 194 90 195 - setVisible(true); 91 + playersPane[position].add(new JLabel("Player: "+name)); 92 + playersPane[position].add(new JLabel("Bid: "+bidInt.toString())); 93 + playersPane[position].add(new JLabel(new String("Points: points here"))); 94 + playersPane[position].add(new JLabel("Score: "+scoreInt.toString())); 95 + 96 + cardsPane[position].add(new JLabel(cardBack)); 97 + cardsPane[position].add(new JButton(cardBack)); 98 + cardsPane[position].add(new JButton(cardBack)); 99 + cardsPane[position].add(new JButton(cardBack)); 100 + cardsPane[position].add(new JButton(cardBack)); 101 + cardsPane[position].add(new JButton(cardBack)); 102 + cardsPane[position].add(new JButton(cardBack)); 103 + cardsPane[position].add(new JButton(cardBack)); 104 + setVisible(true); 196 105 } 106 + 107 + public void updateScore(String name, int position, int score) { 108 + Integer scoreInt = new Integer(score); 109 + JLabel scoreLab = (JLabel) cardsPane[position].getComponent(4); 110 + scoreLab.setText(scoreInt.toString()); 111 + } 197 112 113 + public void updateBid(String name, int position, int bid) { 114 + Integer bidInt = new Integer(bid); 115 + JLabel bidLab = (JLabel) cardsPane[position].getComponent(2); 116 + bidLab.setText(bidInt.toString()); 117 + } 198 118 199 119 public void writeLog(String text) { 200 - Info.append(text+"\n"); 201 - Info.setCaretPosition(Info.getDocument().getLength()); 120 + infoTextArea.append(text+"\n"); 121 + infoTextArea.setCaretPosition(infoTextArea.getDocument().getLength()); 202 122 } 203 123 } 204 124