首页 > 代码库 > amazon 设计 7 genial card game

amazon 设计 7 genial card game

package card;public class Game implements Runnable{    int numPlayers;    int startNumber;    //players and hands seperate so players can‘t change their cards    Player player[] = new Player[numPlayers];    Hand hands[] = new Hand[numPlayers];    Card topCard;    Deck deck;    public Game(){        int numPlayers=2;        int startNumber=7;        deck = new Deck();        for (int i=0; i<numPlayers; i++){            //naming of players and hands should be the same, I havn‘t figured the best way to do this yet            hands[i] = new Hand(deck, startNumber);            player[i] = new Player(""+i,hands[i]);        }    }    @Override    public void run() {        // TODO Auto-generated method stub        boolean InGame = true;        topCard = deck.drawCard();        while(InGame){                    }    }}

 

package card;import java.util.ArrayList;import java.util.Random;public class Deck {    ArrayList<Card> cards;    public Deck(){        cards = new ArrayList<Card>();        for (int a=0; a<13; a++) {            for (int b=0; b<4 ; b++) {                cards.add(new Card(a,b));            }        }        shuffle();    }        private void swap(int i,int j){        Card buf = cards.get(i);        cards.set(i, cards.get(j));        cards.set(j, buf);    }        private void shuffle(){        Random rand = new Random();        for(int i=0; i<cards.size(); i++){            int ran = rand.nextInt(cards.size());            swap(i,ran);        }    }        public Card drawCard(){        if(cards.size() <= 0){            //        }else{            Card temp = (Card) cards.get(cards.size()-1);            cards.remove(cards.size()-1);            System.out.println("Card "+temp+" drawn from deck\n");            return temp;                 }        return null;    }}

 

package card;import java.util.ArrayList;public class Hand {        private ArrayList<Card> cards = new ArrayList<Card>();        private Card toPlay;        private Deck deck;        private final String name;        public Hand(Deck d, int num){            deck = d;            start(num);        }        private void start(int num){            for (int i=0; i<num; i++) {                pickUp();            }        }        public Card getCard(int i){            return (Card)(cards.get(i));        }        public int size(){            return cards.size();        }        public void setPlay(Card c){            toPlay = c;        }        public void print(){            for (int i=0; i<size(); i++){                System.out.println(cards.get(i));            }            System.out.println("\n\n");        }        private void pickUp(){            cards.add(deck.drawCard());        }        public Card play(Card topCard){            }    }

 

/*http://facepunch.com/showthread.php?t=1179730*/package card;public class Player {    private final String name;    private Hand myHand;        public Player(String name, Hand hand){        myHand = hand;        this.name = name;     }    public void turn(Card topCard);            }

 

package card;public class Card {    private static String[] COLOR = {"red","black"};    private static String[] SUITS = {"heart","spade","club","diamond"};    private static String[] ranks = {"Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King", "Joker"};        private final int suit;    private final int color;    private final int values;       private final String name;        public Card(int val, int suit){        this.values = val;        this.suit = suit;    }     public String getNmae();    public int getSuit();    public int getVaule();    }