码迷,mamicode.com
首页 > 其他好文 > 详细

amazon 设计 7 genial card game

时间:2014-08-12 03:12:34      阅读:285      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   java   io   for   ar   

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();
    

}

 

amazon 设计 7 genial card game,布布扣,bubuko.com

amazon 设计 7 genial card game

标签:style   blog   http   color   java   io   for   ar   

原文地址:http://www.cnblogs.com/leetcode/p/3906247.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!