2-APL UPC project.
0
fork

Configure Feed

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

updatescore/displayhand updated and fixed

fdesan 14096417 f5537a04

+45 -7
+12 -1
code/2apl_platform/environments/cardtable/Deck.java
··· 17 17 Iterator rankIterator = Rank.VALUES.iterator(); 18 18 while ( rankIterator.hasNext() ) { 19 19 Rank rank = (Rank) rankIterator.next(); 20 - ImageIcon cardImage = new ImageIcon( "cards/" + Card.getFilename( suit, rank ) ); 20 + java.net.URL imgURL = getClass().getResource("cards/" + Card.getFilename( suit, rank )); 21 + ImageIcon cardImage = new ImageIcon(imgURL); 21 22 Card card = new Card( suit, rank, cardImage ); 22 23 addCard( card ); 23 24 } ··· 51 52 public List getDeck() { 52 53 return deck; 53 54 } 55 + 56 + public Card getCard(String suit, String rank) { 57 + Iterator it = deck.iterator(); 58 + while ( it.hasNext() ) { 59 + Card card = (Card) it.next(); 60 + if(card.getSuit().getName().toLowerCase().equals(suit) && card.getRank().getName().toLowerCase().equals(rank)) 61 + return card; 62 + } 63 + return null; 64 + } 54 65 55 66 }
+24 -2
code/2apl_platform/environments/cardtable/Env.java
··· 164 164 public Term playCard(String sAgent, APLIdent suit, APLIdent rank) throws ExternalActionFailedException { 165 165 Agent agent = getAgent(sAgent); 166 166 notifyEvent("cardPlayed", suit, rank, agent); 167 - table.playCard(agent.getName(), agent._position); 167 + //table.playCard(agent.getName(), agent._position); 168 168 return wrapBoolean(true); 169 169 } 170 170 171 171 public Term updateScore(String sAgent, APLIdent player_name, APLNum score) throws ExternalActionFailedException { 172 - Agent agent = getAgent(sAgent); 172 + Agent agent = getAgent(player_name.toString()); 173 173 sb.updateScore(player_name.toString(), score.toInt()); 174 174 table.updateScore(agent.getName(), agent._position, score.toInt()); 175 175 notifyEvent("scoreUpdated", player_name, score); ··· 180 180 Agent agent = getAgent(sAgent); 181 181 table.updateBid(agent.getName(), agent._position, bid.toInt()); 182 182 return wrapBoolean(true); 183 + } 184 + 185 + public Term handDealt(String sAgent, APLList cards, APLIdent player_name) throws ExternalActionFailedException { 186 + Agent agent = getAgent(sAgent); 187 + 188 + if (agent.getType()!=3) 189 + { 190 + throw new ExternalActionFailedException("Only the dealer can deal cards."); 191 + } 192 + 193 + LinkedList<Term> ll = cards.toLinkedList(); 194 + Card[] hand = new Card[8]; 195 + for(int i=0, j=0; i<8; i++, j+=2) { 196 + hand[i] = deck.getCard(ll.get(j).toString(), ll.get(j+1).toString()); 197 + //System.out.println(hand[i].getSuit().getName()+" "+hand[i].getRank().getName()); 198 + } 199 + 200 + Agent player_agent = getAgent(player_name.toString()); 201 + 202 + table.displayHand(player_name.toString(), player_agent._position, hand); 203 + 204 + return wrapBoolean(true); 183 205 } 184 206 185 207 /* Standard functions --------------------------------------*/
+9 -4
code/2apl_platform/environments/cardtable/Table.java
··· 75 75 setVisible( true ); 76 76 } 77 77 78 - public void playCard(String name, int position) { 78 + public void displayHand(String name, int position, Card[] cards) { 79 79 80 80 java.net.URL imgURL = getClass().getResource("cards/b.gif"); 81 81 ImageIcon cardBack = new ImageIcon(imgURL); 82 82 83 - cardsPane[position].add(new JLabel(cardBack), position); 83 + for(int i=0; i<8; i++) { 84 + cardsPane[position].add(new JLabel(cards[i].getCardImage()), i); 85 + // writeLog(cards[i].getRank()+cards[i].getSuit()); 86 + } 87 + 88 + setVisible( true ); 84 89 } 85 90 86 91 ··· 110 115 111 116 public void updateScore(String name, int position, int score) { 112 117 Integer scoreInt = new Integer(score); 113 - JLabel scoreLab = (JLabel) playersPane[position].getComponent(4); 118 + JLabel scoreLab = (JLabel) playersPane[position].getComponent(3); 114 119 scoreLab.setText("Score: "+scoreInt.toString()); 115 120 setVisible( true ); 116 121 } 117 122 118 123 public void updateBid(String name, int position, int bid) { 119 124 Integer bidInt = new Integer(bid); 120 - JLabel bidLab = (JLabel) playersPane[position].getComponent(2); 125 + JLabel bidLab = (JLabel) playersPane[position].getComponent(1); 121 126 bidLab.setText("Bid: "+bidInt.toString()); 122 127 setVisible( true ); 123 128 }