|
You didn’t say how Pharaoh would judge, so I can’t do anything. I wrote one. I hope it will help you. This program does not compare cards. First of all, I don’t know how you want to compare the two cards Pharaoh. I'm too lazy to write. Please see.
import java.util.*;
class Pockers extends Stack //This is a class of a deck of cards. There are 54 cards in it. The wash method is to shuffle the cards and inherit the stack, because the card is originally taken from the top one.
{
public Pockers()
{
this.add(new Pocker(Pocker.JOCKER_BLACK));
this.add(new Pocker(Pocker.JOCKER_RED)); //Add two old kings
for(int i=2;i<=14;i++)
for(int j=1;j<=4;j++)
{
this.add(new Pocker(i,j)); //Add card, j is suit
}
for(int i=1;i<=4;i++) wash(); //shuffle four times
}
public void wash()
{
Pocker temp=null;
Random r=new Random();
for(int i=0;i<54;i++)
{
temp=(Pocker)this.pop();
this.insertElementAt(temp,Math.abs(r.nextInt()%54)); //Insert the i-th card into this set of cards at random positions
}
}
public boolean needReWash() // Determine whether to rewash.
{
return this.elementCount<10;
}
public void output() //This is for writing program testing.
{
for(int i=0;i<54;i++)
{
((Pocker)this.get(i)).output();
}
}
}
class Player //Player class
{
String name;
public Pocker[] recieve=new Pocker[5];
public Player(int i)
{
if(i==1) name="player1";
else name="player 2";
}
public void getPocker(Pocker pocker,int queue) //get a card
{
recieve[queue]=pocker;
}
public void showPocker() //Display the player's card
{
System.out.println(name+"The card is:");
for(int i=0;i<5;i++)
{
recieve[i].output();
}
System.out.println();
}
}
class Judge //Judge
{
public static void compare(Player player1,Player player2) //Compare player's cards
{
}
public static void give(Pockers p,Player p1,Player p2) //Deal cards.
{
for(int i=0;i<5;i++)
{
p1.getPocker((Pocker)p.pop(),i);
p2.getPocker((Pocker)p.pop(),i);
}
}
}
class Pocker //A card class
{
static int BLOCK=1;
static int FLOWER=2;
static int HEART=3;
static int PEACH=4; //The suit field originally intended to be used, but unfortunately it was not used.
static int JOCKER_RED=20;
static int JOCKER_BLACK=10;
public int number,flower;
public Pocker(int number,int flower) //Construction 1, which is a construction of general cards
{
this.number=number;
this.flower=flower;
}
public Pocker(int flower) //This structure is used to construct the jocker card.
{
this(100,flower);
}
public void output() //Output this card, here is the "(size, suit)" format.
{
System.out.print("("+number+","+flower+")");
}
}
public class a //The main function of the game.
{
public static void main(String[] args)
{
Pockers p=new Pockers();
Player player1=new Player(1);
Player player2=new Player(2);
Judge.give(p,player1,player2);
player1.showPocker();
player2.showPocker();
/*
Judge.compare(player1,player2); //There is no comparison function written here, this is a waste of time, I am too lazy to write it, and you did not explain how to calculate the JOCKER card, and write it for nothing. You have to write it yourself. Haha, the method is written in the compare method of the Judge class, you can change it appropriately, or create a new class or something. Haha.
*/
}
} |
|