win32汇编
病毒 加密
目前兴趣所在
加个界面
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Arrays;
import java.util.Collections;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
public class CardTest extends JFrame
{
/**
*
*/
private static final long serialVersionUID = -1508030602972994349L;
CardTest(){
final Cards c = new Cards();
c.shuffle();
final Player p1 = new Player("张三");
final Player p2 = new Player("李四");
setSize(300, 300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLayout(new BorderLayout());
JPanel panel1 = new JPanel();
panel1.setBackground(Color.red);
panel1.setLayout(new FlowLayout());
JButton but1=new JButton("拿牌");
JButton but2=new JButton("重来");
panel1.add(but1);
panel1.add(but2);
add(panel1,BorderLayout.NORTH);
final JLabel label1 = new JLabel();
final JLabel label2 = new JLabel();
final JLabel label3 = new JLabel();
final JPanel panel2 = new JPanel();
label1.setHorizontalAlignment(SwingConstants.CENTER);
label2.setHorizontalAlignment(SwingConstants.CENTER);
label3.setHorizontalAlignment(SwingConstants.CENTER);
panel2.setLayout(new BorderLayout());
panel2.add(label1,BorderLayout.NORTH);
panel2.add(label2,BorderLayout.SOUTH);
add(panel2);
but1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if(c.getCount()>0){
p1.getOneCard(c);
p2.getOneCard(c);
p1.napai(p2);
label1.setText(p1.s1);
label2.setText(p1.s2);
p1.compare(p2);
label3.setText(p1.s3+"还剩:"+c.getCount()+"张牌!");
}else{
label3.setText("已经没有牌了");
}
panel2.add(label3,BorderLayout.CENTER);
setVisible(true);
}
});
but2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
c.setCount(52);
label3.setText("请拿牌");
}
});
setVisible(true);
}
public static void main(String[] args)
{
new CardTest();
}
}
//扑克类
class Cards
{
String [] type = new String[]{"黑桃","红桃","梅花","方片"};
String[] card = new String[52];
int[] overCard = new int[52]; //保存抽出的牌索引
int count = 52; //还剩多少张牌没抽
public Cards()
{
init();
}
void init()
{
int n=0;
for(int i=0;i<type.length;i++)
{
for(int j=1;j<=13;j++)
{
card[n] = type[i] + j;
n++;
}
}
}
void display()
{
for(int k=0;k<card.length;k++)
{
System.out.println(card[k]);
}
}
void shuffle()
{
Collections.shuffle(Arrays.asList(card));
}
public String getCard()
{
int random = 0;
while(true)
{
random = new Random().nextInt(52);
if(!Arrays.asList(overCard).contains(random))
{
overCard[52-count] = random;
break;
}
}
count--;
return card[random];
}
public void setCount(int i){
this.count=i;
}
public int getCount()
{
return count;
}
}
//玩家类
class Player
{
String s1;
String s2;
String s3;
String pCard;
String myCard;
String name;
String card;
Player(String name)
{
this.name = name;
}
public void getOneCard(Cards c)
{
this.card = c.getCard();
}
public void napai(Player p){
pCard = p.getCard().replace("11", "J").replace("12", "Q")
.replace("13", "K").replace("1", "A");
myCard = this.getCard().replace("11", "J").replace("12", "Q")
.replace("13", "K").replace("1", "A");
s1 = p.getName()+"抓的是:" + pCard;
s2 = this.getName()+"抓的是:" + myCard;
}
public void compare(Player p)
{
int play1 = Integer.parseInt(p.getCard().replaceAll("\\W", ""));
int my = Integer.parseInt(this.getCard().replaceAll("\\W", ""));
if(play1>my)s3=p.getName()+"赢了!";
if(my>play1)s3=this.getName()+"赢了!";
if(play1==my)s3="平手!";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCard() {
return card;
}
public void setCard(String card) {
this.card = card;
}
[此贴子已经被作者于2007-3-4 11:41:58编辑过]