Amazon designs 7 genial card game

Source: Internet
Author: User
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();    }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.