似乎少了什么的棋盘

 一、课程理解

  在今后的软件设计中,一定要先搞清楚类和类之间的关系,这样才不会不知道什么地方调用什么参数。即使初始的类图比较简陋,也比在最后软件完成后发现问题要好很多。这样在初期只需要修改设计即可,如果在后期发现由于类之间关系没有写好而出现的底层代码问题需要修改的地方就太多了。在作业开始前,我先设计了一张简洁的类图,后来不断往里面添加各个方法、参数。

 

二、设计实现

 1.首先我设计了3种对象Zone(区域)、Role(角色)、Sifter(筛子)以供可视化界面调用,其中他们的值通过各种getValue()方法取得,实现数据的封装。

 2.然后我设计了一个Setting页面,用来设置地图的各个属性,比如人物的初始金钱,游戏人数等等

 3.接下来就是地图的主要页面了,其中生成多个jlabel、jpanel等构造可视化页面,通过调用对象获得数据并在可视化页面上显示

三、代码说明

  三个对象类Zone(区域)、Role(角色)、Sifter(筛子)代码:

 1 public class Role {
 2     int name=0;
 3     int money =0;
 4     int location =0;
 5     
 6     public int move(int i) {
 7         location = location + i;    
 8         return location;
 9     }
10 
11 }
 1 import java.util.*;
 2  
 3  public class Sifter{
 4       public int value = 0;
 5          
 6      public static void getValue(Sifter S){
 7           S.value = (int)(1+Math.random()*6);
 8      }
 9  }
10  
 1 import java.util.Scanner;
 2 
 3 public class Zone {
 4     
 5     int price = 0 ;
 6     int fee = 0;
 7     int tax = 0;
 8     int owner = 0 ;
 9     
10     public void Initialization(int i) {
11         this.price = i;
12         this.fee = (int)(i * 0.1);
13         this.tax = (int)(i * 0.2);
14     }
15     
16     public int getValue(int i) {
17         int result=0;
18         switch(i){
19         case(1):result=this.price;break;
20         case(2):result=this.fee;break;
21         case(3):result=this.tax;break;}
22         return result;
23     }
24     
25     /*public void passZone(int i) {
26         if(this.owner == 0) {
27             System.out.println("是否购买这块地? 1为购买 2为取消");
28             int answer = new Scanner(System.in).nextInt();
29                 if(answer==1) {
30             //人物金钱 - price;
31             owner = i;}else {
32                 System.out.println("您放弃购买这块地");
33             }
34         }
35         else {
36             //人物金钱 - fee
37             System.out.println("您向"+owner+"号玩家缴纳了"+fee+"元过路费!");
38         }
39     }*/
40     
41     
42 }

下面为Setting类代码:设置游戏参数

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextPane;

public class Setting {

    private JFrame frame;
    private JTextField setNumber;
    private JTextField setMoney;
    private JTextField setRound;
    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    Setting window = new Setting();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public void launchSetting() {
        
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    Setting window = new Setting();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        
    }
        
    public Setting() {
        initialize();
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        
        
        
        
        frame = new JFrame();
        frame.setResizable(false);
        frame.setTitle("\u6E38\u620F\u8BBE\u7F6E");
        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("\u73A9\u5BB6\u4EBA\u6570\uFF1A");
        lblNewLabel.setFont(new Font("宋体", Font.BOLD, 15));
        lblNewLabel.setBounds(80, 35, 86, 34);
        panel.add(lblNewLabel);
        
        JLabel label = new JLabel("\u521D\u59CB\u91D1\u94B1\uFF1A");
        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("\u5F00\u59CB\u6E38\u620F");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                MapGui.setting[0]= Integer.parseInt(setNumber.getText()); 
                MapGui.setting[1]= Integer.parseInt(setMoney.getText());
                MapGui.setting[2]= Integer.parseInt(setRound.getText());
                for(int i=0;i<MapGui.setting[0];i++) {
                    MapGui.role[i]=new Role();
                    MapGui.role[i].money=MapGui.setting[1];
                    MapGui.role[i].location=0;
                }
                frame.dispose();
            }
        });
        btnNewButton.setBounds(80, 200, 101, 42);
        panel.add(btnNewButton);
        
        JButton button_1 = new JButton("\u53D6\u6D88");
        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("\u8BF7\u5728\u6E38\u620F\u5F00\u59CB\u524D\u4FEE\u6539\u6E38\u620F\u9ED8\u8BA4\u8BBE\u7F6E\uFF01");
        textPane.setBounds(290, 45, 101, 102);
        panel.add(textPane);
    }
    public int getSetting(int i) {
        int result=0;
        switch(i) {
        case(1):result=MapGui.setting[0];break;
        case(2):result=MapGui.setting[1];break;
        case(3):result=MapGui.setting[2];break;
        }
        return result;
    }
}

最后为MapGui类:整个地图的可视化实现

  1 import java.awt.Color;
  2 import java.awt.EventQueue;
  3 
  4 import javax.swing.ImageIcon;
  5 import javax.swing.JFrame;
  6 import javax.swing.JLabel;
  7 import javax.swing.JPanel;
  8 import javax.swing.JTable;
  9 import java.awt.Font;
 10 import javax.swing.SwingConstants;
 11 import javax.swing.JButton;
 12 import java.awt.event.ActionListener;
 13 import java.awt.event.ActionEvent;
 14 
 15 public class MapGui {
 16     
 17     private JFrame frame;
 18     public static int[] setting = new int[3];
 19     public static Role[] role = new Role[4];
 20     int i=1;
 21         
 22     /**
 23      * Launch the application.
 24      */
 25     public static void main(String[] args) { 
 26         
 27         EventQueue.invokeLater(new Runnable() {
 28             public void run() {
 29                 try {
 30                     MapGui window = new MapGui();
 31                     window.frame.setVisible(true);
 32                 } catch (Exception e) {
 33                     e.printStackTrace();
 34                 }
 35             }
 36         });
 37     }
 38 
 39     /**
 40      * Create the application.
 41      */    
 42     
 43     public MapGui() {
 44         initialize();
 45     }
 46 
 47     /**
 48      * Initialize the contents of the frame.
 49      */
 50     private void initialize() {
 51         JLabel[] jLabel = new  JLabel[26];
 52         Zone[] zone = new Zone[26];
 53         Sifter Asifter = new Sifter();
 54         JLabel lblNewLabel_2 = new JLabel("\u7B5B\u5B50\u56FE\u7247");
 55         ImageIcon[] image = new ImageIcon[7];
 56         image[0] = new ImageIcon("E:\\Win10\\Eclipse\\workspace\\Map\\src\\0.gif");
 57         image[1] = new ImageIcon("E:\\Win10\\Eclipse\\workspace\\Map\\src\\1.png");
 58         image[2] = new ImageIcon("E:\\Win10\\Eclipse\\workspace\\Map\\src\\2.png");
 59         image[3] = new ImageIcon("E:\\Win10\\Eclipse\\workspace\\Map\\src\\3.png");
 60         image[4] = new ImageIcon("E:\\Win10\\Eclipse\\workspace\\Map\\src\\4.png");
 61         image[5] = new ImageIcon("E:\\Win10\\Eclipse\\workspace\\Map\\src\\5.png");
 62         image[6] = new ImageIcon("E:\\Win10\\Eclipse\\workspace\\Map\\src\\6.png");
 63     
 64         
 65         for(int i=1;i<=25;i++) {
 66             if(i<=13) {
 67                 zone[i] = new Zone();
 68                 zone[i].Initialization(i*100);
 69             }else {
 70                 zone[i] = new Zone();
 71                 zone[i].Initialization((26-i)*100);
 72             }
 73         }
 74         
 75         
 76         frame = new JFrame();
 77         frame.setTitle("\u9003\u79BB\u7A3D\u7F8E\u5927\u7262");
 78         frame.setResizable(false);
 79         frame.setBounds(100, 100, 1284, 720);
 80         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 81         frame.getContentPane().setLayout(null);
 82         
 83         JPanel panel = new JPanel();
 84         panel.setBounds(0, 0, 1280, 720);
 85         frame.getContentPane().add(panel);
 86         panel.setLayout(null);
 87         
 88         jLabel[13] = new JLabel();
 89         jLabel[13].setOpaque(true);
 90         jLabel[13].setBackground(Color.WHITE);
 91         jLabel[13].setFont(new Font("宋体", Font.BOLD, 12));
 92         jLabel[13].setText("<html><body><center>区域1<br>" + "地价为:" +zone[13].getValue(1) 
 93         +"<br>如果有人拥有<br>您将付"+zone[13].getValue(2)+"元</center></body></html>");
 94         jLabel[13].setBounds(289, 44, 87, 84);
 95         panel.add(jLabel[13]);
 96         
 97         jLabel[14] = new JLabel();
 98         jLabel[14].setOpaque(true);
 99         jLabel[14].setBackground(Color.WHITE);
100         jLabel[14].setFont(new Font("宋体", Font.BOLD, 12));
101         jLabel[14].setText("<html><body><center>区域1<br>" + "地价为:" +zone[14].getValue(1) 
102         +"<br>如果有人拥有<br>您将付"+zone[14].getValue(2)+"元</center></body></html>");
103         jLabel[14].setBounds(386, 44, 87, 84);
104         panel.add(jLabel[14]);
105         
106         jLabel[15] = new JLabel();
107         jLabel[15].setOpaque(true);
108         jLabel[15].setBackground(Color.WHITE);
109         jLabel[15].setFont(new Font("宋体", Font.BOLD, 12));
110         jLabel[15].setText("<html><body><center>区域1<br>" + "地价为:" +zone[15].getValue(1) 
111         +"<br>如果有人拥有<br>您将付"+zone[15].getValue(2)+"元</center></body></html>");
112         jLabel[15].setBounds(483, 44, 87, 84);
113         panel.add(jLabel[15]);
114         
115         jLabel[16] = new JLabel();
116         jLabel[16].setOpaque(true);
117         jLabel[16].setBackground(Color.WHITE);
118         jLabel[16].setFont(new Font("宋体", Font.BOLD, 12));
119         jLabel[16].setText("<html><body><center>区域1<br>" + "地价为:" +zone[16].getValue(1) 
120         +"<br>如果有人拥有<br>您将付"+zone[16].getValue(2)+"元</center></body></html>");
121         jLabel[16].setBounds(580, 44, 87, 84);
122         panel.add(jLabel[16]);
123         
124         jLabel[17] = new JLabel();
125         jLabel[17].setOpaque(true);
126         jLabel[17].setBackground(Color.WHITE);
127         jLabel[17].setFont(new Font("宋体", Font.BOLD, 12));
128         jLabel[17].setText("<html><body><center>区域1<br>" + "地价为:" +zone[17].getValue(1) 
129         +"<br>如果有人拥有<br>您将付"+zone[17].getValue(2)+"元</center></body></html>");
130         jLabel[17].setBounds(677, 44, 87, 84);
131         panel.add(jLabel[17]);
132         
133         jLabel[18] = new JLabel();
134         jLabel[18].setOpaque(true);
135         jLabel[18].setBackground(Color.WHITE);
136         jLabel[18].setFont(new Font("宋体", Font.BOLD, 12));
137         jLabel[18].setText("<html><body><center>区域6<br>" + "地价为:" +zone[18].getValue(1) 
138         +"<br>如果有人拥有<br>您将付"+zone[18].getValue(2)+"元</center></body></html>");
139         jLabel[18].setBounds(774, 44, 87, 84);
140         panel.add(jLabel[18]);
141         
142         jLabel[19] = new JLabel();
143         jLabel[19].setOpaque(true);
144         jLabel[19].setBackground(Color.WHITE);
145         jLabel[19].setFont(new Font("宋体", Font.BOLD, 12));
146         jLabel[19].setText("<html><body><center>区域6<br>" + "地价为:" +zone[19].getValue(1) 
147         +"<br>如果有人拥有<br>您将付"+zone[19].getValue(2)+"元</center></body></html>");
148         jLabel[19].setBounds(871, 44, 87, 84);
149         panel.add(jLabel[19]);
150         
151         jLabel[20] = new JLabel();
152         jLabel[20].setOpaque(true);
153         jLabel[20].setBackground(Color.WHITE);
154         jLabel[20].setFont(new Font("宋体", Font.BOLD, 12));
155         jLabel[20].setText("<html><body><center>区域6<br>" + "地价为:" +zone[20].getValue(1) 
156         +"<br>如果有人拥有<br>您将付"+zone[20].getValue(2)+"元</center></body></html>");
157         jLabel[20].setBounds(968, 44, 87, 84);
158         panel.add(jLabel[20]);
159         
160         jLabel[21] = new JLabel();
161         jLabel[21].setOpaque(true);
162         jLabel[21].setBackground(Color.WHITE);
163         jLabel[21].setFont(new Font("宋体", Font.BOLD, 12));
164         jLabel[21].setText("<html><body><center>区域6<br>" + "地价为:" +zone[21].getValue(1) 
165         +"<br>如果有人拥有<br>您将付"+zone[21].getValue(2)+"元</center></body></html>");
166         jLabel[21].setBounds(1065, 44, 87, 84);
167         panel.add(jLabel[21]);
168         
169         jLabel[22] = new JLabel();
170         jLabel[22].setOpaque(true);
171         jLabel[22].setBackground(Color.WHITE);
172         jLabel[22].setFont(new Font("宋体", Font.BOLD, 12));
173         jLabel[22].setText("<html><body><center>区域6<br>" + "地价为:" +zone[22].getValue(1) 
174         +"<br>如果有人拥有<br>您将付"+zone[22].getValue(2)+"元</center></body></html>");
175         jLabel[22].setBounds(1065, 138, 87, 84);
176         panel.add(jLabel[22]);
177         
178         jLabel[23] = new JLabel();
179         jLabel[23].setOpaque(true);
180         jLabel[23].setBackground(Color.WHITE);
181         jLabel[23].setFont(new Font("宋体", Font.BOLD, 12));
182         jLabel[23].setText("<html><body><center>区域6<br>" + "地价为:" +zone[23].getValue(1) 
183         +"<br>如果有人拥有<br>您将付"+zone[23].getValue(2)+"元</center></body></html>");
184         jLabel[23].setBounds(1065, 232, 87, 84);
185         panel.add(jLabel[23]);
186         
187         jLabel[24] = new JLabel();
188         jLabel[24].setOpaque(true);
189         jLabel[24].setBackground(Color.WHITE);
190         jLabel[24].setFont(new Font("宋体", Font.BOLD, 12));
191         jLabel[24].setText("<html><body><center>区域6<br>" + "地价为:" +zone[24].getValue(1) 
192         +"<br>如果有人拥有<br>您将付"+zone[24].getValue(2)+"元</center></body></html>");
193         jLabel[24].setBounds(1065, 326, 87, 84);
194         panel.add(jLabel[24]);
195         
196         jLabel[25] = new JLabel();
197         jLabel[25].setOpaque(true);
198         jLabel[25].setBackground(Color.WHITE);
199         jLabel[25].setFont(new Font("宋体", Font.BOLD, 12));
200         jLabel[25].setText("<html><body><center>区域6<br>" + "地价为:" +zone[25].getValue(1) 
201         +"<br>如果有人拥有<br>您将付"+zone[25].getValue(2)+"元</center></body></html>");
202         jLabel[25].setBounds(1065, 420, 87, 84);
203         panel.add(jLabel[25]);
204         
205         JLabel label_14 = new JLabel();
206         label_14.setOpaque(true);
207         label_14.setBackground(Color.WHITE);
208         label_14.setFont(new Font("宋体", Font.BOLD, 12));
209         label_14.setText("    起点");
210         label_14.setBounds(1065, 514, 87, 84);
211         panel.add(label_14);
212         
213         jLabel[1] = new JLabel();
214         jLabel[1].setOpaque(true);
215         jLabel[1].setBackground(Color.WHITE);
216         jLabel[1].setFont(new Font("宋体", Font.BOLD, 12));
217         jLabel[1].setText("<html><body><center>区域1<br>" + "地价为:" +zone[1].getValue(1) 
218         +"<br> 如果有人拥有<br>您将付"+zone[1].getValue(2)+"元</center></body></html>");
219         jLabel[1].setBounds(968, 514, 87, 84);
220         panel.add(jLabel[1]);
221         
222         jLabel[2] = new JLabel();
223         jLabel[2].setOpaque(true);
224         jLabel[2].setBackground(Color.WHITE);
225         jLabel[2].setFont(new Font("宋体", Font.BOLD, 12));
226         jLabel[2].setText("<html><body><center>区域1<br>" + "地价为:" +zone[2].getValue(1) 
227         +"<br> 如果有人拥有<br>您将付"+zone[2].getValue(2)+"元</center></body></html>");
228         jLabel[2].setBounds(871, 514, 87, 84);
229         panel.add(jLabel[2]);
230         
231         jLabel[3] = new JLabel();
232         jLabel[3].setOpaque(true);
233         jLabel[3].setBackground(Color.WHITE);
234         jLabel[3].setFont(new Font("宋体", Font.BOLD, 12));
235         jLabel[3].setText("<html><body><center>区域1<br>" + "地价为:" +zone[3].getValue(1) 
236         +"<br> 如果有人拥有<br>您将付"+zone[3].getValue(2)+"元</center></body></html>");
237         jLabel[3].setBounds(774, 514, 87, 84);
238         panel.add(jLabel[3]);
239         
240         jLabel[4] = new JLabel();
241         jLabel[4].setOpaque(true);
242         jLabel[4].setBackground(Color.WHITE);
243         jLabel[4].setFont(new Font("宋体", Font.BOLD, 12));
244         jLabel[4].setText("<html><body><center>区域1<br>" + "地价为:" +zone[4].getValue(1) 
245         +"<br> 如果有人拥有<br>您将付"+zone[4].getValue(2)+"元</center></body></html>");
246         jLabel[4].setBounds(677, 514, 87, 84);
247         panel.add(jLabel[4]);
248         
249         jLabel[5] = new JLabel();
250         jLabel[5].setOpaque(true);
251         jLabel[5].setBackground(Color.WHITE);
252         jLabel[5].setFont(new Font("宋体", Font.BOLD, 12));
253         jLabel[5].setText("<html><body><center>区域1<br>" + "地价为:" +zone[5].getValue(1) 
254         +"<br> 如果有人拥有<br>您将付"+zone[5].getValue(2)+"元</center></body></html>");
255         jLabel[5].setBounds(580, 514, 87, 84);
256         panel.add(jLabel[5]);
257         
258         jLabel[6] = new JLabel();
259         jLabel[6].setOpaque(true);
260         jLabel[6].setBackground(Color.WHITE);
261         jLabel[6].setFont(new Font("宋体", Font.BOLD, 12));
262         jLabel[6].setText("<html><body><center>区域1<br>" + "地价为:" +zone[6].getValue(1) 
263         +"<br> 如果有人拥有<br>您将付"+zone[6].getValue(2)+"元</center></body></html>");
264         jLabel[6].setBounds(483, 514, 87, 84);
265         panel.add(jLabel[6]);
266         
267         jLabel[7] = new JLabel();
268         jLabel[7].setOpaque(true);
269         jLabel[7].setBackground(Color.WHITE);
270         jLabel[7].setFont(new Font("宋体", Font.BOLD, 12));
271         jLabel[7].setText("<html><body><center>区域1<br>" + "地价为:" +zone[7].getValue(1) 
272         +"<br> 如果有人拥有<br>您将付"+zone[7].getValue(2)+"元</center></body></html>");
273         jLabel[7].setBounds(386, 514, 87, 84);
274         panel.add(jLabel[7]);
275         
276         jLabel[8] = new JLabel();
277         jLabel[8].setOpaque(true);
278         jLabel[8].setBackground(Color.WHITE);
279         jLabel[8].setFont(new Font("宋体", Font.BOLD, 12));
280         jLabel[8].setText("<html><body><center>区域1<br>" + "地价为:" +zone[8].getValue(1) 
281         +"<br> 如果有人拥有<br>您将付"+zone[8].getValue(2)+"元</center></body></html>");
282         jLabel[8].setBounds(289, 514, 87, 84);
283         panel.add(jLabel[8]);
284         
285         jLabel[9] = new JLabel();
286         jLabel[9].setOpaque(true);
287         jLabel[9].setBackground(Color.WHITE);
288         jLabel[9].setFont(new Font("宋体", Font.BOLD, 12));
289         jLabel[9].setText("<html><body><center>区域1<br>" + "地价为:" +zone[9].getValue(1) 
290         +"<br> 如果有人拥有<br>您将付"+zone[9].getValue(2)+"元</center></body></html>");
291         jLabel[9].setBounds(289, 420, 87, 84);
292         panel.add(jLabel[9]);
293         
294         jLabel[10] = new JLabel();
295         jLabel[10].setOpaque(true);
296         jLabel[10].setBackground(Color.WHITE);
297         jLabel[10].setFont(new Font("宋体", Font.BOLD, 12));
298         jLabel[10].setText("<html><body><center>区域1<br>" + "地价为:" +zone[10].getValue(1) 
299         +"<br> 如果有人拥有<br>您将付"+zone[10].getValue(2)+"元</center></body></html>");
300         jLabel[10].setBounds(289, 326, 87, 84);
301         panel.add(jLabel[10]);
302         
303         jLabel[11] = new JLabel();
304         jLabel[11].setOpaque(true);
305         jLabel[11].setBackground(Color.WHITE);
306         jLabel[11].setFont(new Font("宋体", Font.BOLD, 12));
307         jLabel[11].setText("<html><body><center>区域1<br>" + "地价为:" +zone[11].getValue(1) 
308         +"<br> 如果有人拥有<br>您将付"+zone[11].getValue(2)+"元</center></body></html>");
309         jLabel[11].setBounds(289, 232, 87, 84);
310         panel.add(jLabel[11]);
311         
312         jLabel[12] = new JLabel();
313         jLabel[12].setOpaque(true);
314         jLabel[12].setBackground(Color.WHITE);
315         jLabel[12].setFont(new Font("宋体", Font.BOLD, 12));
316         jLabel[12].setText("<html><body><center>区域1<br>" + "地价为:" +zone[12].getValue(1) 
317         +"<br> 如果有人拥有<br>您将付"+zone[12].getValue(2)+"元</center></body></html>");
318         jLabel[12].setBounds(289, 138, 87, 84);
319         panel.add(jLabel[12]);
320         
321         JPanel panel_1 = new JPanel();
322         panel_1.setBounds(31, 115, 224, 501);
323         panel.add(panel_1);
324         panel_1.setLayout(null);
325         
326         JLabel lblNewLabel_1 = new JLabel("  \u4EBA\u7269\u9762\u677F\u4FE1\u606F");
327         lblNewLabel_1.setFont(new Font("宋体", Font.BOLD, 24));
328         lblNewLabel_1.setBounds(10, 10, 204, 49);
329         panel_1.add(lblNewLabel_1);
330         
331         JLabel Label_name = new JLabel("\u4EBA\u7269\u540D\u79F0\uFF1A");
332         Label_name.setFont(new Font("宋体", Font.BOLD, 15));
333         Label_name.setBounds(10, 69, 197, 30);
334         panel_1.add(Label_name);
335         
336         JLabel Label_money = new JLabel("\u4EBA\u7269\u91D1\u94B1\uFF1A");
337         Label_money.setFont(new Font("宋体", Font.BOLD, 15));
338         Label_money.setBounds(10, 108, 197, 30);
339         panel_1.add(Label_money);
340         
341         JLabel Label_location = new JLabel("\u4EBA\u7269\u4F4D\u7F6E\uFF1A");
342         Label_location.setFont(new Font("宋体", Font.BOLD, 15));
343         Label_location.setBounds(10, 146, 197, 30);
344         panel_1.add(Label_location);
345         
346         JLabel Label_info = new JLabel("\u73B0\u5728\u8F6E\u5230\uFF1An\u53F7\u73A9\u5BB6\u4F7F\u7528\u7B5B\u5B50");
347         Label_info.setFont(new Font("宋体", Font.BOLD, 15));
348         Label_info.setBounds(10, 209, 204, 30);
349         panel_1.add(Label_info);
350         
351         JButton useSifter = new JButton("\u4F7F\u7528\u7B5B\u5B50");
352         useSifter.setVisible(false);
353         useSifter.addActionListener(new ActionListener() {
354             public void actionPerformed(ActionEvent arg0) {
355                 Asifter.getValue(Asifter);    
356                 switch(Asifter.value){
357                 case(1):lblNewLabel_2.setIcon(image[1]);break;
358                 case(2):lblNewLabel_2.setIcon(image[2]);break;
359                 case(3):lblNewLabel_2.setIcon(image[3]);break;
360                 case(4):lblNewLabel_2.setIcon(image[4]);break;
361                 case(5):lblNewLabel_2.setIcon(image[5]);break;
362                 case(6):lblNewLabel_2.setIcon(image[6]);break;
363                 }
364                 
365                 if(i<setting[0]) {
366                 Label_name.setText("人物名称:"+ i +"号玩家");
367                 Label_money.setText("人物金钱:"+role[i-1].money+"元");
368                 role[i-1].location=role[i-1].location+Asifter.value;
369                 Label_location.setText("人物位置:"+role[i-1].location+"区域");
370                 Label_info.setText("现在轮到"+i+"号玩家投掷筛子");
371                 i=i+1;
372                 }
373                 else {
374                 Label_name.setText("人物名称:"+ i +"号玩家");
375                 Label_money.setText("人物金钱:"+role[i-1].money+"元");
376                 role[i-1].location=role[i-1].location+Asifter.value;
377                 Label_location.setText("人物位置:"+role[i-1].location+"区域");
378                 Label_info.setText("现在是"+i+"号玩家的回合");
379                 i=1;
380                 }
381             }
382         });
383         useSifter.setBounds(67, 385, 93, 39);
384         panel_1.add(useSifter);
385         
386         lblNewLabel_2.setIcon(new ImageIcon("E:\\Win10\\Eclipse\\workspace\\Map\\src\\0.gif"));
387         lblNewLabel_2.setBounds(57, 249, 105, 107);
388         panel_1.add(lblNewLabel_2);
389         
390         JButton button = new JButton("\u5F00\u59CB\u6E38\u620F");
391         button.addActionListener(new ActionListener() {
392             public void actionPerformed(ActionEvent arg0) {
393                 useSifter.setVisible(true);
394                 Setting settingWindow = new Setting();
395                 settingWindow.launchSetting();
396             }
397         });
398         button.setBounds(10, 434, 93, 39);
399         panel_1.add(button);
400         
401         JButton button_1 = new JButton("\u9000\u51FA\u6E38\u620F");
402         button_1.setBounds(121, 434, 93, 39);
403         panel_1.add(button_1);
404         
405         JLabel lblNewLabel = new JLabel("New label");
406         lblNewLabel.setIcon(new ImageIcon("E:\\Win10\\Eclipse\\workspace\\Map\\src\\background.jpg"));
407         lblNewLabel.setBounds(0, -23, 1280, 720);
408         panel.add(lblNewLabel);
409     }
410 }

四、测试运行

1.初始界面发布

2.点击开始游戏按钮,并设置游戏参数,通过全局变量子窗口将参数传递父窗口。点击开始游戏初始化n名游戏角色,并初始化他们的参数。

3.点击使用筛子按钮,通过getValue()方法获取初始化筛子的值。然后加到人物的location参数上,实现了人物的移动。并通过开关、循环变量的设置使得各个玩家轮流使用筛子改变自己的位置

五、小结

  总体上实现了各个玩家的移动要求。并且能通过可视化界面和玩家友好的交互,无太大操作难度。但由于可视化界面和运动算法的问题,暂时无法实现棋子在界面上的移动。后期不断进行整改,其中遇到不少bug,通过查询资料和询问同学获得答案。

 

博文要求

提交的博客(MarkDown格式)必须完整包含下面五个部分:

  • 课程的理解。你现在理解了类了吗?知道类图的画法了吗?对于类的用途,你有什么体会。这次的作业是如何开展的。

  • 设计实现,设计包括代码如何组织,这些类分别负责什么功能,他们之间的关系怎样?骰子类有那些属性和方法,重要的函数,关键的函数是否需要画出流程图?必须画类图,并展示你的类图。注意类图的类之间的关系。

  • 代码说明,你一定花了最多时间在代码的编写与调试上,那么,这个环节请把你的重要代码展示出来,代码的排版请做好。(就是贴出代码,并说明)

  • 测试运行,你的程序必须是可运行的,请展示你的程序运行的截图,包括题目要求的所有需求,都有运行的截图。说明你的程序确实完成了所有需求,如果有实现了扩展需求或者高级需求,也请大方秀出来。

  • 小结。对比自己的预估时间和实际消耗时间,哪个环节耗时最多,哪个环节估计失败?为什么?假设认真做了以上环节,此处请你和大家分享你的经验和心得。

posted on 2017-11-17 21:16  稽美大学小学生  阅读(242)  评论(0编辑  收藏  举报