2-APL UPC project.
0
fork

Configure Feed

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

GUI improvements

fdesan f5e02817 e6b77263

+86 -29
+1 -1
code/2apl_platform/briscola_chiamata/player.2apl
··· 186 186 // --- Declare Briscola 187 187 //B( getcard(H, 3, Briscola) ); FIXME this line do not work 188 188 send(n, inform, declarebriscola([clubs, ace])); 189 - //@cardtable(briscolaDeclared(clubs,ace)); 189 + @cardtable(briscolaDeclared(clubs,ace)); 190 190 if B( iscard(H, [clubs, ace]) ) then 191 191 { 192 192 print("I go alone!");
+9 -2
code/2apl_platform/environments/cardtable/Env.java
··· 188 188 table.updateBid(agent.getName(), agent._position, bid.toInt()); 189 189 return wrapBoolean(true); 190 190 } 191 + 192 + public Term briscolaDeclared(String sAgent, APLIdent suit, APLIdent rank) throws ExternalActionFailedException { 193 + Agent agent = getAgent(sAgent); 194 + Card played_card = deck.getCard(suit.toString(), rank.toString()); 195 + table.briscolaDeclared(agent.getName(), agent._position, played_card); 196 + return wrapBoolean(true); 197 + } 191 198 192 199 public Term handDealt(String sAgent, APLList cards, APLIdent player_name) throws ExternalActionFailedException { 193 200 Agent agent = getAgent(sAgent); ··· 198 205 } 199 206 200 207 LinkedList<Term> ll = cards.toLinkedList(); 201 - Card[] hand = new Card[8]; 208 + Hand hand = new Hand(); 202 209 for(int i=0, j=0; i<8; i++, j+=2) { 203 - hand[i] = deck.getCard(ll.get(j).toString(), ll.get(j+1).toString()); 210 + hand.addCard(deck.getCard(ll.get(j).toString(), ll.get(j+1).toString())); 204 211 //System.out.println(hand[i].getSuit().getName()+" "+hand[i].getRank().getName()); 205 212 } 206 213
+1 -2
code/2apl_platform/environments/cardtable/Hand.java
··· 3 3 import java.util.*; 4 4 5 5 6 - public abstract class Hand implements Comparable { 6 + public class Hand { 7 7 8 8 private java.util.List hand = new ArrayList(); 9 - 10 9 11 10 public void addCard( Card card ) { 12 11 hand.add( card );
+75 -24
code/2apl_platform/environments/cardtable/Table.java
··· 2 2 3 3 import javax.swing.*; 4 4 import java.awt.*; 5 + import java.lang.Integer; 5 6 6 7 7 8 ··· 10 11 private JPanel leftDisplayPane; 11 12 private JPanel[] playersPane, cardsPane; 12 13 13 - private JLayeredPane layeredTablePane; 14 + private JLayeredPane layeredPane; 14 15 private JSplitPane VerticalSplitPane; 15 16 private JScrollPane GameInfo; 16 17 private JSplitPane HorizontalSplitPlane; 17 18 private JTextArea infoTextArea; 19 + private int round; 20 + private Hand[] hands; 18 21 19 22 public Table( ){ 20 23 super( "Briscola Chiamata" ); 24 + round = 0; 25 + hands = new Hand[5]; 26 + 21 27 leftDisplayPane = new JPanel(new GridBagLayout()); 22 28 playersPane = new JPanel[5]; 23 29 cardsPane = new JPanel[5]; ··· 37 43 38 44 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 39 45 40 - layeredTablePane = new JLayeredPane(); 46 + layeredPane = new JLayeredPane(); 41 47 Point origin = new Point(10, 20); 42 - Color[] layerColors = { Color.yellow, Color.magenta, 43 - Color.cyan, Color.red, 44 - Color.green }; 45 - 46 48 int offset = 35; 47 49 for (int i = 0; i < 5; i++) { 48 50 JLabel label = new JLabel(); ··· 58 60 label.setBorder(BorderFactory.createLineBorder(Color.black)); 59 61 label.setBounds(origin.x, origin.y, 73, 97); 60 62 61 - layeredTablePane.add(label, new Integer(i)); 63 + layeredPane.add(label, new Integer(i)); 62 64 } 65 + JLabel label = new JLabel("Player : -"); 66 + origin.x = 73; 67 + origin.y += offset+97; 68 + label.setBounds(origin.x, origin.y, 150, 20); 69 + layeredPane.add(label, 5); 70 + label = new JLabel("Round : -"); 71 + origin.x += 150; 72 + origin.y += 0; 73 + label.setBounds(origin.x, origin.y, 150, 20); 74 + layeredPane.add(label, 6); 75 + label = new JLabel("Briscola : -"); 76 + origin.x = 73; 77 + origin.y += 40; 78 + label.setBounds(origin.x, origin.y, 300, 20); 79 + layeredPane.add(label, 7); 63 80 64 81 infoTextArea = new JTextArea(5,00); 65 82 infoTextArea.setEditable(false); 66 83 GameInfo = new JScrollPane(infoTextArea); 67 84 68 - VerticalSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, layeredTablePane,GameInfo); 69 - //VerticalSplitPane.setPreferredSize(new Dimension(150,50)); 85 + VerticalSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, layeredPane,GameInfo); 70 86 VerticalSplitPane.setOneTouchExpandable(false); 71 87 VerticalSplitPane.setDividerLocation(450); 72 88 73 89 HorizontalSplitPlane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftDisplayPane,VerticalSplitPane ); 74 - //HorizontalSplitPlane.setPreferredSize(new Dimension(150,150)); 75 90 HorizontalSplitPlane.setOneTouchExpandable(false); 76 91 HorizontalSplitPlane.setDividerLocation(900); 77 92 ··· 80 95 setSize( 1280, 768 ); 81 96 setVisible( true ); 82 97 } 83 - 84 - public void displayHand(String name, int position, Card[] cards) { 85 - for(int i=0; i<8; i++) { 86 - cardsPane[position].add(new JLabel(cards[i].getCardImage()), i); 87 - } 88 - setVisible( true ); 89 - } 90 - 91 - public void playedCard(String name, int position, Card card) { 92 - JLabel label = (JLabel) layeredTablePane.getComponent(position); 93 - label.setIcon(card.getCardImage()); 94 - setVisible( true ); 95 - } 96 98 97 99 public void addPlayer(String name, int position, int score, int bid) { 98 100 Integer scoreInt = new Integer(score); ··· 136 138 137 139 setVisible( true ); 138 140 } 139 - 141 + 142 + public void displayHand(String name, int position, Hand hand) { 143 + hands[position] = hand; 144 + for(int i=0; i<8; i++) { 145 + cardsPane[position].add(new JLabel(hand.getCard(i).getCardImage()), i); 146 + } 147 + setVisible( true ); 148 + } 149 + 150 + public void playedCard(String name, int position, Card card) { 151 + java.net.URL imgURL = getClass().getResource("cards/b.gif"); 152 + ImageIcon cardBack = new ImageIcon(imgURL); 153 + 154 + int pos = hands[position].findCard(card); 155 + JLabel imgLab = (JLabel) cardsPane[position].getComponent(pos); 156 + imgLab.setIcon(cardBack); 157 + 158 + JLabel label = (JLabel) layeredPane.getComponent(position); 159 + label.setIcon(card.getCardImage()); 160 + JLabel player = (JLabel) layeredPane.getComponent(5); 161 + player.setText("Player : "+name); 162 + if(round==0) { 163 + JLabel roundLab = (JLabel) layeredPane.getComponent(6); 164 + roundLab.setText("Round : 1"); 165 + round++; 166 + } 167 + setVisible( true ); 168 + } 169 + 170 + public void briscolaDeclared(String name, int position, Card card) { 171 + JLabel briscolaLab = (JLabel) layeredPane.getComponent(7); 172 + briscolaLab.setText("Briscola : "+card.getRank().getName()+" of "+card.getSuit().getName()+" by "+name); 173 + JLabel declarer = (JLabel) playersPane[position].getComponent(0); 174 + declarer.setForeground(Color.blue); 175 + for(int i=0;i<5;i++) { 176 + if(hands[i].findCard(card)!=-1) { 177 + int pos = hands[i].findCard(card); 178 + JLabel teammate = (JLabel) playersPane[i].getComponent(0); 179 + teammate.setForeground(Color.blue); 180 + } 181 + } 182 + setVisible( true ); 183 + } 184 + 140 185 public void updateScore(String name, int position, int score) { 141 186 Integer scoreInt = new Integer(score); 142 187 JLabel scoreLab = (JLabel) playersPane[position].getComponent(3); ··· 148 193 Integer pointsInt = new Integer(points); 149 194 JLabel pointsLab = (JLabel) playersPane[position].getComponent(2); 150 195 pointsLab.setText("Points: "+pointsInt.toString()); 196 + JLabel roundLab = (JLabel) layeredPane.getComponent(6); 197 + round++; 198 + if(round<9) { 199 + Integer roundInt = new Integer(round); 200 + roundLab.setText("Round : "+roundInt.toString()); 201 + } 151 202 setVisible( true ); 152 203 } 153 204