大富翁

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了大富翁相关的知识,希望对你有一定的参考价值。

简单的棋盘

课程的理解

在一次次的不断堆叠,在一次次的实用类图之后,我体会到了类图的好处,让我们有更加清晰的思路去编写代码,经过这次的学习也明白了更多关于面向对象的思想,这次的作业是骰子,地块的综合,把这些结合在一起也费了我好大一会的功夫,类之间的关系,也需要我好好地去整理和消化。

设计实现

技术分享图片

代码说明

Dice.java

package youxi;

import java.util.Random;

public class Dice { 
    private int faceValue;
  public Dice(){ 
    }

public void Roll(){ 
    Random random=new Random();
    faceValue=random.nextInt(5)+1;
    }
public int getFaceValue(){

    return faceValue;
}

}

  Roler.java

技术分享图片Roler

Place.java

package youxi;

public class Place {

        public int  price;
        public int owner;
        public int cost;
        public int placename;
        
        public  Place(int b,int s,int i,int a) {
            price=i;
            owner=s;
            cost=a;
            placename=b;
            
        }
        public int Showplacename() {
            return placename;
        }
        public int Showprice() {
            return price;
        }
        
        public int Showcost() {
            return cost;
        }
        
        public int Showowner() {
            return owner;
        }
        public void setowner(int s) {
            owner=s;
        }



}

MapGUI.java

技术分享图片
package youxi;

import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JTextPane;

public class MapGUI {

    private JTextField setNumber;
    private JTextField setMoney;
    private JTextField setRound;
    int h=1;
    int m=0;
    int number=1;
    int[]show= new int[5];
    int money,count;
    int playnumber;
    int ask;
     int shou;
     int jiao;
    public void Set() {
      setting();
     
 }
    public MapGUI() {
        //Asking();
        setting();
        //initialize();
        
       
   }
    
    private void setting() {
        
        

        
       JFrame frame = new JFrame();
        frame.setResizable(false);
       
        frame.setTitle("初始化参数");
        frame.setBounds(100, 100, 450, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().setLayout(null);
        
        JPanel panel = new JPanel();
        panel.setBounds(0, 0, 444, 271);
        frame.getContentPane().add(panel);
        panel.setLayout(null);
        
        JLabel lblNewLabel = new JLabel("玩家人数:");
        lblNewLabel.setFont(new Font("宋体", Font.BOLD, 15));
        lblNewLabel.setBounds(80, 35, 86, 34);
        panel.add(lblNewLabel);
        
        JLabel label = new JLabel("回合");
        label.setFont(new Font("宋体", Font.BOLD, 15));
        label.setBounds(80, 79, 86, 34);
        panel.add(label);
        
        JLabel label_1 = new JLabel("\\u56DE\\u5408\\u6570\\uFF1A");
        label_1.setFont(new Font("宋体", Font.BOLD, 15));
        label_1.setBounds(80, 123, 86, 34);
        panel.add(label_1);
        
        JButton btnNewButton = new JButton("开始游戏");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                number= Integer.parseInt(setNumber.getText()); 
                money= Integer.parseInt(setMoney.getText());
                count= Integer.parseInt(setRound.getText());
                initialize();
                frame.dispose();
               
                
            }
        });
        btnNewButton.setBounds(80, 200, 101, 42);
        panel.add(btnNewButton);
        
        JButton button_1 = new JButton("取消");
        button_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                frame.dispose();
            }
        });
        button_1.setBounds(260, 200, 101, 42);
        panel.add(button_1);
        
        setNumber = new JTextField();
        setNumber.setText("4");
        setNumber.setBounds(198, 36, 66, 34);
        panel.add(setNumber);
        setNumber.setColumns(10);
        
        setMoney = new JTextField();
        setMoney.setText("5000");
        setMoney.setColumns(10);
        setMoney.setBounds(198, 79, 66, 34);
        panel.add(setMoney);
        
        setRound = new JTextField();
        setRound.setText("20");
        setRound.setColumns(10);
        setRound.setBounds(198, 123, 66, 34);
        panel.add(setRound);
        
        JTextPane textPane = new JTextPane();
        textPane.setFont(new Font("宋体", Font.BOLD, 20));
        textPane.setText("输入所需的游戏参数,人数小于四");
        textPane.setBounds(290, 45, 101, 102);
        panel.add(textPane);
        
        
        frame.setVisible(true);

    }
  
    
    private void Over() {
         JFrame frame = new JFrame();
         frame.setResizable(false);
        
         frame.setTitle("游戏结束");
         frame.setBounds(100, 100, 450, 300);
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         frame.getContentPane().setLayout(null);
         
         JPanel panel = new JPanel();
         panel.setBounds(0, 0, 444, 271);
         frame.getContentPane().add(panel);
         panel.setLayout(null);
         
         JLabel lblNewLabel = new JLabel("游戏结束,金币最多的人为胜利者 ");
         lblNewLabel.setFont(new Font("宋体", Font.BOLD, 15));
         lblNewLabel.setBounds(80, 35, 800, 34);
         panel.add(lblNewLabel);
         
         
         JLabel lblNewLabel1 = new JLabel("游戏结束 ");
         lblNewLabel1.setFont(new Font("宋体", Font.BOLD, 15));
         lblNewLabel1.setBounds(100, 70, 800, 100);
         if(number==1){
         lblNewLabel1.setText("<html><body><center>一号"+show[0]+"</center></body></html>");}
         if(number==2){
         lblNewLabel1.setText("<html><body><center>1号"+show[0]+"<br>2号"+show[1]+"</center></body></html>");}
         if(number==3){
         lblNewLabel1.setText("<html><body><center>1号"+show[0]+"<br>2号"+show[1]+"<br>3号"+show[2]+"</center></body></html>");}
         if(number==4){
         lblNewLabel1.setText("<html><body><center>1号"+show[0]+"<br>2号"+show[1]+"<br>3号"+show[2]+"<br>4号"+show[3]+"</center></body></html>");}
         
         panel.add(lblNewLabel1);
         
         
         
         
         
         frame.setVisible(true);
         
      
    
        
    }

    private void Asking() {
        JFrame frame = new JFrame();
        frame.setResizable(false);
       
        frame.setTitle("土地购买");
        frame.setBounds(100, 100, 450, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().setLayout(null);
        
        JPanel panel = new JPanel();
        panel.setBounds(0, 0, 444, 271);
        frame.getContentPane().add(panel);
        panel.setLayout(null);
        
        JLabel lblNewLabel = new JLabel("是否想购买这块土地?  ");
        lblNewLabel.setFont(new Font("宋体", Font.BOLD, 15));
        lblNewLabel.setBounds(80, 35, 200, 34);
        panel.add(lblNewLabel);
        
        JButton btnNewButton = new JButton("确定");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                ask=1;
                frame.dispose();
               
                
            }
        });
        btnNewButton.setBounds(80, 200, 101, 42);
        panel.add(btnNewButton);
        
        JButton button_1 = new JButton("取消");
        button_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                ask=0;
                frame.dispose();
            }
        });
        button_1.setBounds(260, 200, 101, 42);
        panel.add(button_1);
        frame.setVisible(true);
    }
    
    
    
    private void initialize() {

         Roler[] roler= new Roler[number];
         JLabel[] jLabel = new  JLabel[26];
         Place[] place = new Place[26];
         JLabel lblNewLabel_2 = new JLabel("\\u7B5B\\u5B50\\u56FE\\u7247");
         ImageIcon[] image = new ImageIcon[7];
         image[0] = new ImageIcon("F:\\\\ecilise\\\\workplace\\\\youxi\\\\src\\\\youxi\\\\0.gif");
         image[1] = new ImageIcon("F:\\\\ecilise\\\\workplace\\\\youxi\\\\src\\\\youxi\\\\1.png");
         image[2] = new ImageIcon("F:\\\\ecilise\\\\workplace\\\\youxi\\\\src\\\\youxi\\\\2.png");
         image[3] = new ImageIcon("F:\\\\ecilise\\\\workplace\\\\youxi\\\\src\\\\youxi\\\\3.png");
         image[4] = new ImageIcon("F:\\\\ecilise\\\\workplace\\\\youxi\\\\src\\\\youxi\\\\4.png");
         image[5] = new ImageIcon("F:\\\\ecilise\\\\workplace\\\\youxi\\\\src\\\\youxi\\\\5.png");
         image[6] = new ImageIcon("F:\\\\ecilise\\\\workplace\\\\youxi\\\\src\\\\youxi\\\\6.png");
         
         for(int i=0;i<26;i++) {
             if((i%2)==0) {
                 place[i] = new Place(i,0,1000,500); 
             }
             else {
                 place[i] = new Place(i,0,1000,400);  
             }
            
         }
         for(int j=0;j<number;j++) {
                roler[j]=new Roler(money);
         }
         
        JFrame frame = new JFrame();
         frame.setTitle("厦门游一游");
         frame.setResizable(false);
         frame.setBounds(100, 100, 1284, 720);
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         frame.getContentPane().setLayout(null);
         
         JPanel panel = new JPanel();
         panel.setBounds(0, 0, 1280, 720);
         frame.getContentPane().add(panel);
         panel.setLayout(null);
         
         JLabel label_14 = new JLabel();
         label_14.setOpaque(true);
         label_14.setBackground(Color.WHITE);
         label_14.setFont(new Font("宋体", Font.BOLD, 12));
         label_14.setText("    起点");
         label_14.setBounds(1065, 514, 87, 84);
         panel.add(label_14);
         
         jLabel[1] = new JLabel();
         jLabel[1].setOpaque(true);
         jLabel[1].setBackground(Color.WHITE);
         jLabel[1].setFont(new Font("宋体", Font.BOLD, 12));
         jLabel[1].setText("<html><body><center>"+place[1].Showplacename()+"<br>" + "地价为:" +place[1].Showprice() 
         +"<br> 如果有人拥有<br>您将付"+place[1].Showcost()+"元</center></body></html>");
          jLabel[1].setBounds(968, 514, 87, 84);
         panel.add(jLabel[1]);
         
         jLabel[2] = new JLabel();
         jLabel[2].setOpaque(true);
         jLabel[2].setBackground(Color.WHITE);
         jLabel[2].setFont(new Font("宋体", Font.BOLD, 12));
         jLabel[2].setText("<html><body><center>"+place[2].Showplacename()+"<br>" + "地价为:" +place[2].Showprice() 
         +"<br> 如果有人拥有<br>您将付"+place[2].Showcost()+"元</center></body></html>");
          jLabel[2].setBounds(871, 514, 87, 84);
         panel.add(jLabel[2]);
         
         jLabel[3] = new JLabel();
         jLabel[3].setOpaque(true);
         jLabel[3].setBackground(Color.WHITE);
         jLabel[3].setFont(new Font("宋体", Font.BOLD, 12));
         jLabel[3].setText("<html><body><center>"+place[3].Showplacename()+"<br>" + "地价为:" +place[3].Showprice() 
         +"<br> 如果有人拥有<br>您将付"+place[3].Showcost()+"元</center></body></html>");
          jLabel[3].setBounds(774, 514, 87, 84);
         panel.add(jLabel[3]);
         
         jLabel[4] = new JLabel();
         jLabel[4].setOpaque(true);
         jLabel[4].setBackground(Color.WHITE);
         jLabel[4].setFont(new Font("宋体", Font.BOLD, 12));
         jLabel[4].setText("<html><body><center>"+place[4].Showplacename()+"<br>" + "地价为:" +place[4].Showprice() 
         +"<br> 如果有人拥有<br>您将付"+place[4].Showcost()+"元</center></body></html>");
         jLabel[4].setBounds(677, 514, 87, 84);
         panel.add(jLabel[4]);
         
         jLabel[5] = new JLabel();
         jLabel[5].setOpaque(true);
         jLabel[5].setBackground(Color.WHITE);
         jLabel[5].setFont(new Font("宋体", Font.BOLD, 12));
         jLabel[5].setText("<html><body><center>"+place[5].Showplacename()+"<br>" + "地价为:" +place[5].Showprice() 
         +"<br> 如果有人拥有<br>您将付"+place[5].Showcost()+"元</center></body></html>");
          jLabel[5].setBounds(580, 514, 87, 84);
         panel.add(jLabel[5]);
         
         jLabel[6] = new JLabel();
         jLabel[6].setOpaque(true);
         jLabel[6].setBackground(Color.WHITE);
         jLabel[6].setFont(new Font("宋体", Font.BOLD, 12));
         jLabel[6].setText("<html><body><center>"+place[6].Showplacename()+"<br>" + "地价为:" +place[6].Showprice() 
         +"<br> 如果有人拥有<br>您将付"+place[6].Showcost()+"元</center></body></html>");
          jLabel[6].setBounds(483, 514, 87, 84);
         panel.add(jLabel[6]);
         
         jLabel[7] = new JLabel();
         jLabel[7].setOpaque(true);
         jLabel[7].setBackground(Color.WHITE);
         jLabel[7].setFont(new Font("宋体", Font.BOLD, 12));
         jLabel[7].setText("<html><body><center>"+place[7].Showplacename()+"<br>" + "地价为:" +place[7].Showprice() 
         +"<br> 如果有人拥有<br>您将付"+place[7].Showcost()+"元</center></body></html>");
          jLabel[7].setBounds(386, 514, 87, 84);
         panel.add(jLabel[7]);
         
         jLabel[8] = new JLabel();
         jLabel[8].setOpaque(true);
         jLabel[8].setBackground(Color.WHITE);
         jLabel[8].setFont(new Font("宋体", Font.BOLD, 12));
         jLabel[8].setText("<html><body><center>"+place[8].Showplacename()+"<br>" + "地价为:" +place[8].Showprice() 
         +"<br> 如果有人拥有<br>您将付"+place[1].Showcost()+"元</center></body></html>");
          jLabel[8].setBounds(289, 514, 87, 84);
         panel.add(jLabel[8]);
         
         jLabel[9] = new JLabel();
         jLabel[9].setOpaque(true);
         jLabel[9].setBackground(Color.WHITE);
         jLabel[9].setFont(new Font("宋体", Font.BOLD, 12));
         jLabel[9].setText("<html><body><center>"+place[9].Showplacename()+"<br>" + "地价为:" +place[9].Showprice() 
         +"<br> 如果有人拥有<br>您将付"+place[9].Showcost()+"元</center></body></html>");
          jLabel[9].setBounds(289, 420, 87, 84);
         panel.add(jLabel[9]);
         
         jLabel[10] = new JLabel();
         jLabel[10].setOpaque(true);
         jLabel[10].setBackground(Color.WHITE);
         jLabel[10].setFont(new Font("宋体", Font.BOLD, 12));
         jLabel[10].setText("<html><body><center>"+place[10].Showplacename()+"<br>" + "地价为:" +place[10].Showprice() 
         +"<br> 如果有人拥有<br>您将付"+place[10].Showcost()+"元</center></body></html>");
          jLabel[10].setBounds(289, 326, 87, 84);
         panel.add(jLabel[10]);
         
         jLabel[11] = new JLabel();
         jLabel[11].setOpaque(true);
         jLabel[11].setBackground(Color.WHITE);
         jLabel[11].setFont(new Font("宋体", Font.BOLD, 12));
         jLabel[11].setText("<html><body><center>"+place[11].Showplacename()+"<br>" + "地价为:" +place[11].Showprice() 
         +"<br> 如果有人拥有<br>您将付"+place[11].Showcost()+"元</center></body></html>");
          jLabel[11].setBounds(289, 232, 87, 84);
         panel.add(jLabel[11]);
         
         jLabel[12] = new JLabel();
         jLabel[12].setOpaque(true);
         jLabel[12].setBackground(Color.WHITE);
         jLabel[12].setFont(new Font("宋体", Font.BOLD, 12));
         jLabel[12].setText("<html><body><center>"+place[12].Showplacename()+"<br>" + "地价为:" +place[12].Showprice() 
         +"<br> 如果有人拥有<br>您将付"+place[12].Showcost()+"元</center></body></html>");
          jLabel[12].setBounds(289, 138, 87, 84);
         panel.add(jLabel[12]);
         
         jLabel[13] = new JLabel();
         jLabel[13].setOpaque(true);
         jLabel[13].setBackground(Color.WHITE);
         jLabel[13].setFont(new Font("宋体", Font.BOLD, 12));
         jLabel[13].setText("<html><body><center>"+place[13].Showplacename()+"<br>" + "地价为:" +place[13].Showprice() 
         +"<br> 如果有人拥有<br>您将付"+place[13].Showcost()+"元</center></body></html>");
          jLabel[13].setBounds(289, 44, 87, 84);
         panel.add(jLabel[13]);
         
         jLabel[14] = new JLabel();
         jLabel[14].setOpaque(true);
         jLabel[14].setBackground(Color.WHITE);
         jLabel[14].setFont(new Font("宋体", Font.BOLD, 12));
         jLabel[14].setText("<html><body><center>"+place[14].Showplacename()+"<br>" + "地价为:" +place[14].Showprice() 
         +"<br> 如果有人拥有<br>您将付"+place[14].Showcost()+"元</center></body></html>");
          jLabel[14].setBounds(386, 44, 87, 84);
         panel.add(jLabel[14]);
         
         jLabel[15] = new JLabel();
         jLabel[15].setOpaque(true);
         jLabel[15].setBackground(Color.WHITE);
         jLabel[15].setFont(new Font("宋体", Font.BOLD, 12));
         jLabel[15].setText("<html><body><center>"+place[15].Showplacename()+"<br>" + "地价为:" +place[15].Showprice() 
         +"<br> 如果有人拥有<br>您将付"+place[15].Showcost()+"元</center></body></html>");
          jLabel[15].setBounds(483, 44, 87, 84);
         panel.add(jLabel[15]);
         
         jLabel[16] = new JLabel();
         jLabel[16].setOpaque(true);
         jLabel[16].setBackground(Color.WHITE);
         jLabel[16].setFont(new Font("宋体", Font.BOLD, 12));
         jLabel[16].setText("<html><body><center>"+place[16].Showplacename()+"<br>" + "地价为:" +place[16].Showprice() 
         +"<br> 如果有人拥有<br>您将付"+place[16].Showcost()+"元</center></body></html>");
          jLabel[16].setBounds(580, 44, 87, 84);
         panel.add(jLabel[16]);
         
         jLabel[17] = new JLabel();
         jLabel[17].setOpaque(true);
         jLabel[17].setBackground(Color.WHITE);
         jLabel[17].setFont(new Font("宋体", Font.BOLD, 12));
         jLabel[17].setText("<html><body><center>"+place[17].Showplacename()+"<br>" + "地价为:" +place[17].Showprice() 
         +"<br> 如果有人拥有<br>您将付"+place[17].Showcost()+"元</center></body></html>");
          jLabel[17].setBounds(677, 44, 87, 84);
         panel.add(jLabel[17]);
         
         jLabel[18] = new JLabel();
         jLabel[18].setOpaque(true);
         jLabel[18].setBackground(Color.WHITE);
         jLabel[18].setFont(new Font("宋体", Font.BOLD, 12));
         jLabel[18].setText("<html><body><center>"+place[18].Showplacename()+"<br>" + "地价为:" +place[18].Showprice() 
         +"<br> 如果有人拥有<br>您将付"+place[18].Showcost()+"元</center></body></html>");
          jLabel[18].setBounds(774, 44, 87, 84);
         panel.add(jLabel[18]);
         
         jLabel[19] = new JLabel();
         jLabel[19].setOpaque(true);
         jLabel[19].setBackground(Color.WHITE);
         jLabel[19].setFont(new Font("宋体", Font.BOLD, 12));
         jLabel[19].setText("<html><body><center>"+place[19].Showplacename()+"<br>" + "地价为:" +place[19].Showprice() 
         +"<br> 如果有人拥有<br>您将付"+place[19].Showcost()+"元</center></body></html>");
          jLabel[19].setBounds(871, 44, 87, 84);
         panel.add(jLabel[19]);
         
         jLabel[20] = new JLabel();
         jLabel[20].setOpaque(true);
         jLabel[20].setBackground(Color.WHITE);
         jLabel[20].setFont(new Font("宋体", Font.BOLD, 12));
         jLabel[20].setText("<html><body><center>"+place[20].Showplacename()+"<br>" + "地价为:" +place[20].Showprice() 
         +"<br> 如果有人拥有<br>您将付"+place[20].Showcost()+"元</center></body></html>");
          jLabel[20].setBounds(968, 44, 87, 84);
         panel.add(jLabel[20]);
         
         jLabel[21] = new JLabel();
         jLabel[21].setOpaque(true);
         jLabel[21].setBackground(Color.WHITE);
         jLabel[21].setFont(new Font("宋体", Font.BOLD, 12));
         jLabel[21].setText("<html><body><center>"+place[21].Showplacename()+"<br>" + "地价为:" +place[21].Showprice() 
         +"<br> 如果有人拥有<br>您将付"+place[21].Showcost()+"元</center></body></html>");
          jLabel[21].setBounds(1065, 44, 87, 84);
         panel.add(jLabel[21]);
         
         jLabel[22] = new JLabel();
         jLabel[22].setOpaque(true);
         jLabel[22].setBackground(Color.WHITE);
         jLabel[22].setFont(new Font("宋体", Font.BOLD, 12));
         jLabel[22].setText("<html><body><center>"+place[22].Showplacename()+"<br>" + "地价为:" +place[22].Showprice() 
         +"<br> 如果有人拥有<br>您将付"+place[22].Showcost()+"元</center></body></html>");
          jLabel[22].setBounds(1065, 138, 87, 84);
         panel.add(jLabel[22]);
         
         jLabel[23] = new JLabel();
         jLabel[23].setOpaque(true);
         jLabel[23].setBackground(Color.WHITE);
         jLabel[23].setFont(new Font("宋体", Font.BOLD, 12));
         jLabel[23].setText("<html><body><center>"+place[23].Showplacename()+"<br>" + "地价为:" +place[23].Showprice() 
         +"<br> 如果有人拥有<br>您将付"+place[23].Showcost()+"元<br></center></body></html>");
          jLabel[23].setBounds(1065, 232, 87, 84);
         panel.add(jLabel[23]);
         
         jLabel[24] = new JLabel();
         jLabel[24].setOpaque(true);
         jLabel[24].setBackground(Color.WHITE);
         jLabel[24].setFont(new Font("宋体", Font.BOLD, 12));
         jLabel[24].setText("<html><body><center>"+place[24].Showplacename()+"<br>" + "地价为:" +place[24].Showprice() 
         +"<br> 如果有人拥有<br>您将付"+place[24].Showcost()+"元</center></body></html>");
          jLabel[24].setBounds(1065, 326, 87, 84);
         panel.add(jLabel[24]);
         
         jLabel[25] = new JLabel();
         jLabel[25].setOpaque(true);
         jLabel[25].setBackground(Color.WHITE);
         jLabel[25].setFont(new Font("宋体", Font.BOLD, 12));
         jLabel[25].setText("<html><body><center>"+place[25].Showplacename()+"<br>" + "地价为:" +place[25].Showprice() 
         +"<br> 如果有人拥有<br>您将付"+place[25].Showcost()+"元</center></body></html>");
          jLabel[25].setBounds(1065, 420, 87, 84);
         panel.add(jLabel[25]);

         
         JPanel panel_1 = new JPanel();
         panel_1.setBounds(31, 115, 224, 501);
         panel.add(panel_1);
         panel_1.setLayout(null);
         
         JLabel lblNewLabel_1 = new JLabel("  人物信息");
         lblNewLabel_1.setFont(new Font("宋体", Font.BOLD, 24));
         lblNewLabel_1.setBounds(10, 10, 204, 49);
         panel_1.add(lblNewLabel_1);
    
         JLabel Label_name = new JLabel("人物");
         Label_name.setFont(new Font("宋体", Font.BOLD, 15));
         Label_name.setBounds(10, 69, 197, 30);
         panel_1.add(Label_name);
          
         JLabel Label_money = new JLabel("金钱");
         Label_money.setFont(new Font("宋体", Font.BOLD, 15));
         Label_money.setBounds(10, 108, 197, 30);
         panel_1.add(Label_money);
          
         JLabel Label_location = new JLabel("位置");
         Label_location.setFont(new Font("宋体", Font.BOLD, 15));
         Label_location.setBounds(10, 146, 197, 30);
         panel_1.add(Label_location);
           
         JLabel Label_info = new JLabel("现在1号玩家开始投掷");
         Label_info.setFont(new Font("宋体", Font.BOLD, 15));
         Label_info.setBounds(10, 209, 204, 30);
         panel_1.add(Label_info);
         
         JButton useSifter = new JButton("使用骰子");
         useSifter.setVisible(false);
         useSifter.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent arg0) {
                 Dice dice=new Dice();
                 dice.Roll(); 
                 lblNewLabel_2.setIcon(image[0]);
                 switch(dice.getFaceValue()){
                 case(1):lblNewLabel_2.setIcon(image[1]);break;
                 case(2):lblNewLabel_2.setIcon(image[2]);break;
                 case(3):lblNewLabel_2.setIcon(image[3]);break;
                 case(4):lblNewLabel_2.setIcon(image[4]);break;
                 case(5):lblNewLabel_2.setIcon(image[5]);break;
                 case(6):lblNewLabel_2.setIcon(image[6]);break;
         }
                 
            Label_name.setText("人物名称:"+ h +"号玩家");
            Label_name.setText("人物名称:"+ h +"号玩家");
            Label_money.setText("人物金钱:"+roler[h-1].money()+"元");
            roler[h-1].move(dice.getFaceValue());
            Label_location.setText("人物位置:"+roler[h-1].place()+"区域");
           
             if(place[roler[h-1].place()].Showowner()==0) {
               
                 Asking();
                 
                 if(ask==1) {
                   roler[h-1].setmoney((roler[h-1].money()-(place[roler[h-1].place()].Showprice())));
                   place[roler[h-1].place()].setowner(h);
                 }
               
             }
             
             else{
                 jiao=roler[h-1].money()-(place[roler[h-1].place()].Showcost());
               roler[h-1].setmoney(jiao);
                 shou=roler[h-1].money()-(place[roler[h-1].place()].Showcost());
               roler[place[roler[h-1].place()].Showowner()-1].setmoney(shou);  
             }
            h=(h+1)%(number+1);
             if(h==0) {
                 h=1;
                 m++;
                if(m>count) {
                    for(int a=0;a<number;a++) {
                        show[a]=roler[a].money();
                    }
                 
                 
                 Over();
                      
                }
           
             }
           Label_info.setText("现在轮到"+h+"号玩家投掷筛子");
             }
             
         });
        useSifter.setBounds(67, 385, 93, 39);
        panel_1.add(useSifter);
         lblNewLabel_2.setIcon(new ImageIcon("F:\\\\\\\\ecilise\\\\\\\\workplace\\\\\\\\youxi\\\\\\\\src\\\\\\\\youxi\\\\\\\\0.gif"));
         lblNewLabel_2.setBounds(57, 249, 105, 107);
        panel_1.add(lblNewLabel_2);
        JButton button = new JButton("开始游戏");
        button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
        useSifter.setVisible(true);
        
            }
         });
        button.setBounds(10, 434, 93, 39);
         panel_1.add(button);
        JButton button_1 = new JButton("结束");
         button_1.setBounds(121, 434, 93, 39);
        panel_1.add(button_1);
        button_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                   frame.dispose();
            }
            });
     JLabel lblNewLabel = new JLabel("New label");
        lblNewLabel.setIcon(new ImageIcon("F:\\\\ecilise\\\\workplace\\\\youxi\\\\src\\\\youxi\\\\10.jpg"));
         lblNewLabel.setBounds(0, -23, 1280, 720);
         panel.add(lblNewLabel);
         frame.setVisible(true);
         
    }
    
    public static void main(String[] args) { 
    
                           MapGUI window = new MapGUI();
    }}
View Code

 

测试运行

点击开始运行

技术分享图片

跳出初始化参数界面,可以设置我们的游戏参数,然后点击确认进入游戏

 技术分享图片

点击开始游戏

技术分享图片

他会提示几号玩家投掷骰子

当进入未被购买的地块时会弹框显示是否购买

技术分享图片

当你购买以后,经过的玩家向你缴纳过路费

当游戏结束显示金额。

技术分享图片

 

 

小结

在界面的设计上可能有些不够,因此借鉴了同学得界面来显示,在写的过程中我也从中学会了很多,实践果然是学习的一个很好的方式。

 


以上是关于大富翁的主要内容,如果未能解决你的问题,请参考以下文章

32岁开源IPO百亿富翁:13岁做游戏外挂,只爱写代码

请问大富翁3怎样才能在winxp下运行

1034.寻找大富翁

HDU 3785 寻找大富翁

SDUT 3401 数据结构实验之排序四:寻找大富翁

弱鸡小富翁