⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gambler.java

📁 这个也是用Java编写的博饼的游戏
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package package1;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import java.awt.*;
import java.awt.event.*;
import java.applet.AudioClip;
import javax.swing.*;
import java.util.Date;
import java.awt.image.BufferedImage;
import javax.swing.border.*;
import com.swtdesigner.SwingResourceManager;
public class Gambler extends JApplet implements ActionListener,ItemListener,Runnable 
{   //用application执行时,有异常抛出,应去掉AudioClip功能,如果一定要保留此功能,可用applet 执行,默认此功能未添加
	//static AudioClip		A1;
	JFrame  showframe=new JFrame("Image Show");//附加显示窗口,以数字形式显示结果
	Date    timenow;//Date是一个时间定义与创建函数
	Thread  runner=null;//设置一个线程
	JLabel  timelabel;//显示时间的label
	JLabel  helplabel=new JLabel("Help Information");
	JLabel  restartlabel=new JLabel("Restart Game");
	JLabel  addPlayerlabel=new JLabel("Add  one  Player");
    JLabel  nextlabel=new JLabel("Next   Player");
	JLabel  presslabel=new JLabel("Press button");
    JButton restartbutton=new JButton("Restart");
	JButton addbutton = new JButton("AddPlayer");
	JButton Helpbutton=new JButton("Help Info");
	JTextArea	ta				= new JTextArea(30, 60);//帮助窗口文本域
	JTextArea	are				= new JTextArea(10, 10);//主窗口文本域
	JScrollPane	scroll2			= new JScrollPane(are);
	JScrollPane	scroll			= new JScrollPane(ta);
	JCheckBox   checkbox        = new JCheckBox("  Disable");//是否禁用button
	JCheckBox   disableshow     = new JCheckBox(" Disable  Image  show");//是否禁用附加显示窗口
	ImageButton	button			= new ImageButton("images/button.png");//自定义类,右下角游戏按钮
	ImageButton	readmebutton	= new ImageButton("images/readme.png");//本用作解释程序结构,未添加功能
	ImageLabel	label			= new ImageLabel("images/reactor.png");
	ImageLabel	left			= new ImageLabel("images/大绿箭头.png");//我取得名字,贼帅,哈哈哈哈
	ImageLabel	right			= new ImageLabel("images/大绿箭头.png");
	String  flag;//标志,获得当前玩家姓名
	String  []playername =new String[10];//作用于choice控件用于存储玩家姓名
    Choice  choice=new Choice();//
    Container   container=getContentPane();
    int	         number[] = new int[6];//随机数
    static long  total;
    static int i=0;
    static int lastflag=0;
    static int sum1=0,sum2=0;
    static int zhuangyuan=1;
    static int duitang=2;
    static int sanhong=4;
    static int sijin=8;
    static int erju=16;
    static int yixiu=32;
    static String HolderOfZhuangyuan;//状元获得者
    static String HolderOfDuitang1;//对堂获得者
    static String HolderOfDuitang2;//对堂获得者
    static int   currentflag4=0,newflag4=0,currentflag5=0,newflag5=0,currentflag51=0,newflag51=0,currentflag54=0,newflag54=0;//用于追缴状元的数据
    static boolean showflag=true;//是否显示附加显示窗口
    int randomer;//产生选择边框的随机数

    
    
    public void paint(Graphics g)
	{
	   super.paint(g);
	   ImageIcon icon = new ImageIcon(this.getClass().getResource("sz.gif"));//添加修饰
	   icon.paintIcon(this, g, 65, 15);
	   icon.paintIcon(this, g, 110, 15);
	   icon.paintIcon(this, g, 155, 15);
	   icon.paintIcon(this, g, 200, 15);
	   icon.paintIcon(this, g, 245, 15);
	   icon.paintIcon(this, g, 290, 15);
	   for(int p=0;p<=5;p++)//绘制色子
   	  {     //g.setColor(Color.white);
			//g.fillRoundRect(10 + 60 * i, 80, 40, 40, 10, 10);
	
		        if (number[p] == 1)
		        {
		         g.setColor(Color.RED);
		         g.fillOval(408 + 12, 80+80*p + 12, 16, 16);
		        }
		        else if (number[p] == 2)
		        {
		            g.setColor(Color.green);
		            g.fillOval(408+ 8, 80+80*p + 8, 10, 10);
		            g.fillOval(408+ 22, 80+80*p + 22, 10, 10);
		        }
		        else if (number[p]== 3)
		        {
		            g.setColor(Color.magenta);
		            g.fillOval(408+ 6, 80+80 *p+ 6, 10, 10);
		            g.fillOval(408+ 15,80+ 80 *p+ 15, 10, 10);
		            g.fillOval(408 + 24, 80+80*p + 24, 10, 10);
		        }
		        else if (number[p]== 4)
		        {
		            g.setColor(Color.RED);
		            g.fillOval(408+ 8,80+ 80 *p+ 8, 10, 10);
		            g.fillOval(408+ 22, 80+80*p + 8, 10, 10);
		            g.fillOval(408+ 8, 80+80*p + 22, 10, 10);
		            g.fillOval(408+ 22,80+ 80 *p+ 22, 10, 10);
		        }
		        else if (number[p]== 5)
		        {
		            g.setColor(Color.BLUE);
		            g.fillOval(408 + 6,80+ 80 *p+ 6, 10, 10);
		            g.fillOval(408 + 24,80+ 80*p + 6, 10, 10);
		            g.fillOval(408+ 15, 80+80 *p+ 15, 10, 10);
		            g.fillOval(408 + 6, 80+80*p + 24, 10, 10);
		            g.fillOval(408+ 24, 80+80*p + 24, 10, 10);
		        }
		        else
		        {
		            g.setColor(Color.black);
		            g.fillOval(408+ 8, 80+80*p + 4, 10, 10);
		            g.fillOval(408+ 8,80+ 80 *p+ 15, 10, 10);
		            g.fillOval(408+ 8, 80+80*p + 26, 10, 10);
		            g.fillOval(408+ 22, 80+80*p + 4, 10, 10);
		            g.fillOval(408+ 22, 80+80 *p+ 15, 10, 10);
		            g.fillOval(408+ 22,80+ 80 *p+ 26, 10, 10);
		        }
   	}
	   // timenow =new Date();
	}
	public void init()
	{    
		this.setName("模拟博饼游戏");
		setLayout(null);
		setSize(700, 550);
		are.setBackground(Color.yellow);
		are.setFont(new Font("宋体", Font.PLAIN, 12));
		//A1 = getAudioClip(getDocumentBase(), "audio/ao.wav");//声音功能,默认不添加
	    JPanel panel=new JPanel();
	    //自定义类,显示框架,下面随机显示
	    ImageBorder image_border = new ImageBorder(
	            new ImageIcon("images/upper_left.png").getImage(),
	            new ImageIcon("images/upper.png").getImage(),
	            new ImageIcon("images/upper_right.png").getImage(),
	            new ImageIcon("images/left_center.png").getImage(),
	            new ImageIcon("images/right_center.png").getImage(),
	            new ImageIcon("images/bottom_left.png").getImage(),
	            new ImageIcon("images/bottom_center.png").getImage(),
	            new ImageIcon("images/bottom_right.png").getImage()
	            );
	    randomer=(int) (Math.random() * 4 + 1);
	    switch(randomer)//随机选择边框
	    {
	    	case 1:
	    	case 2:
	    	case 3:
	    		panel.setBorder(new BevelBorder(BevelBorder.RAISED));
	    		panel.setBackground(Color.LIGHT_GRAY);
	    		break;
	    	case 4:
	    		panel.setBorder(image_border);
	    		break;
	    }
	   
	    panel.setLayout(null);
	    panel.setForeground(Color.black);
	    panel.add(scroll2);
	    scroll2.setFont(new Font("楷体_GB2312", Font.PLAIN, 12));
	    scroll2.setLocation(12,8);
	    scroll2.setSize(330,430);
	    container.add(panel);
	    panel.setLocation(25,70);
		panel.setSize(356,450);
        
		button.setPressedIcon(new ImageIcon("images/button-down.png"));//改变button状态时显示效果
		button.setBorder(new BevelBorder(BevelBorder.RAISED));
		button.setRolloverIcon(new ImageIcon("images/button-over.png"));
		button.setSelectedIcon(new ImageIcon("images/button-sel.png"));
		button.setRolloverSelectedIcon(new ImageIcon("images/button-sel-over.png"));
		button.setDisabledIcon(new ImageIcon("images/button-disabled.png"));
		button.setDisabledSelectedIcon(new ImageIcon("images/button-disabled-selected.png"));
		
		container.add(label);
		label.setBorder(new BevelBorder(BevelBorder.RAISED));
		label.setLocation(492, 25);
		container.add(left);
		left.setLocation(20, 25);
		container.add(right);
		right.setLocation(350, 25);
		
		container.add(button);
		button.setSize(60,60);
		button.setLocation(600, 450);
		container.add(nextlabel);
		nextlabel.setLocation(480, 450);
		nextlabel.setSize(100, 10);
		container.add(presslabel);
		presslabel.setLocation(480, 500);
		presslabel.setSize(100, 10);
		presslabel.setEnabled(false);
		nextlabel.setEnabled(false);
		container.add(checkbox);
		checkbox.setLocation(480, 465);
		checkbox.setOpaque(false);
		checkbox.setSize(checkbox.getPreferredSize());
		container.add(choice);
		choice.setBackground(Color.YELLOW);
        choice.setSize(182, 82);
        choice.setLocation(480,404);
        container.add(disableshow);
        disableshow.setSize(500, 30);
        disableshow.setLocation(480, 518);
        disableshow.setOpaque(false);
        //disableshow.setSize(checkbox.getPreferredSize());
		
		container.add(readmebutton);
		readmebutton.setBorder(new BevelBorder(BevelBorder.LOWERED));
		readmebutton.setBackground(Color.CYAN);
		readmebutton.setLocation(500,60);
		
		//此提示功能可创建一格File并加一窗口另行显示,这里为方便只用简单的文本域显示
		ta.setText("模拟掷色子:\n小特性:\n 鼠标禁用功能及动态变化\n时间的表示及色子动态处理\n文本域的一系列处理\n动态Label的提示功能\n" +
				"Disable Image show用于关闭附显窗口\n\n" +
				"游戏规则(来自百度):\n" +
				"状元是以出现四颗红四点、两颗红一点为最高级,称“状元插金花”,\n可获状元和两个对堂共3个大饼。获状元的以出现四颗四点红为起码级\n,其中又按四红带多少点比大;"+
				"“五子”出现即压过四红,\n即“五颗”除五个红四以外的任何五颗一样算为“五子”,又以带多少点比大。\n"+
				"“五红”就是出现五个红四点,压过“五子”,其中又以带多少点比大。\n称为“对堂”的榜眼、探花出现一至六点都有得饼.\n"+
							"	此外,还有极少出现的“六朴红”,即六颗四点出现。\n“六朴红”得主,就可得全部会饼,但一般友好相处,\n得主只拿状元和对堂,其余就分送给大家吃。\n"+
				"“六朴黑”是指出现除六颗红四点以外的任何六颗相同的。\n“六朴黑”出现,大家可熄灯抢饼,但现在一般不再采用。\n"+ 
				"具体玩法: \n"+
				"有1个“四点”的得一秀饼(秀才).拿完为止. 共32个。\n"+ 
				"有2个“四点”的得二举饼(举人). 拿完为止.共16个。\n "+
				"有4个相同点数的(红四除外的都可以)得四进饼(进士),拿完为止.共8个。\n "+
				"有3个“四点”的得三红饼,拿完为止.共4个。\n "+
				"若骰子点数分别为1至6顺序排列着的得对堂饼(榜眼,探花),共2个。\n"+ 
				"在其他奖品还没有拿完之前,对堂的奖品则采要用“追”的方式,\n即后来获得者向自己前一个获得者追饼。\n"+
				"比如对堂饼已经被人拿完,若还有人博到,则此人按游戏进行的\n反方向向离自己最近的一个对堂饼获得者拿回奖品。\n"+ 
				
				"状元有很多等级,以下状元等级是从小到大排列,具体为:\n"+ 
				"若是有4个“四点”,则为状元,比较另外两个骰子点数的大小,点数大者为胜。\n"+ 
				
				"有5个相同点数的,俗成“五子登科”,比起4个“四点红”的状元要大。\n先比较相同点数的数字大小,5个红4最大,其他按数字顺序,\n如果相同点数的数字一样,则比较后面的点数大小,点数大者胜.\n"+
				"若是4个“四点”加上2个“一点”,则称为“状元插金花”,\n比前面的几种状元都大,并可拿走状元和对堂的所有奖品.\n"+ 
				
				"若是6个“四点”,称为“六抔红”,是状元中最大的,可拿走状元和对堂的所有奖品.\n "+
				"状元的奖品要在所有的奖品全部拿完后,最后一个最大的状元博出者,\n可拿走奖品,如果这个状元是“状元插金花”或“六抔红”,还有拿走2个对堂的所有奖品。\n\n"+
				"操作提示:\n"+ 
				" 首先点击Add one player按钮后,增加玩家昵称,游\n戏开始,根据系统随机产生的六个1-6的数字\n判断得奖情况结果得出后,依据游戏规则\n(见ReadMe)" +
				"判断奖品的分配,待游戏结束\n之后,可按RestartButton重新开始游戏\n\n本游戏最终解释权归本人所有");
		
		container.add(restartbutton);
		restartbutton.setBorder(new BevelBorder(BevelBorder.LOWERED, Color.GREEN, Color.GREEN));
		restartbutton.setLocation(600, 270);
		restartbutton.setSize(60, 40);
		
		container.add(addbutton);
		addbutton.setBorder(new BevelBorder(BevelBorder.RAISED, Color.RED, Color.RED));
		addbutton.setLocation(600, 345);
		addbutton.setSize(60, 40);
		
		container.add(Helpbutton);
		Helpbutton.setBorder(new BevelBorder(BevelBorder.LOWERED, Color.RED, Color.RED));
		Helpbutton.setLocation(600, 200);
		Helpbutton.setSize(60, 40);
        
		container.add(Helpbutton);
		helplabel.setLocation(530, 225);
		helplabel.setSize(60, 40);
		

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -