-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindows.java
More file actions
1446 lines (1354 loc) · 54.4 KB
/
Windows.java
File metadata and controls
1446 lines (1354 loc) · 54.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package final_project;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.*;
import java.util.Timer;
import java.util.*;
public class Windows extends JFrame implements ActionListener {
//國家名字和機會(?)命運(!)標示
public String country_name[] = {"Start", "KOR", " ! ", "JPN", "MEX", " ? ", "NZL", "Toilet", "USA", "RUS", "Back", "SGP", " ! ", "ESP", "THA", " ? ", "AUS", "Park", "TUR", "TWN"};
//4顆棋子在角落的座標
int start_x[] = new int[]{48,78,48,78};
int start_y[] = new int[]{54,54,90,90};
int prison_x[] = new int[]{503,533,503,533};
int prison_y[] = new int[]{54,54,90,90};
int backtostart_x[] = new int[]{503,533,503,533};
int backtostart_y[] = new int[]{341,341,377,377};
int park_x[] = new int[]{48,78,48,78};
int park_y[] = new int[]{341,341,377,377};
/* 玩家資訊
* player_information[i][j]
* i代表玩家
* [i][0] 已購買的土地
* [i][1] 蓋一棟房子的國家
* [i][2] 蓋兩棟房子的國家
* [i][3] 蓋三棟房子的國家
*/
String player_information[][] = new String[4][4];
//houserank[i][j][k] i放入currentRole_ID,代表玩家 j代表房子階級 k放入chessposition[currentRole_ID],代表國家
String houserank[][][] = new String[4][4][20];
int house[] = new int[20]; //house[i][j] ,代表國家的擁有權是誰
int countryinformation[][] = new int[9][20]; //國家資訊
int chessposition[] = new int[4]; //玩家們的所在國家
int chessposition_x[] = new int[4]; //玩家們的所在的x軸位置
int chessposition_y[] = new int[4]; //玩家們的所在的x軸位置
int lap[] = new int[4];//玩家們走的圈數
int currentRole_ID = 0; //玩家順序(0~3):0代表玩家1,1代表玩家2,2代表玩家3,3代表玩家4
int money[] = new int[4]; //玩家們的金錢
int rest[] = new int[4]; //暫停陣列
boolean end = false;
boolean isout[] = new boolean[4]; //紀錄是否淘汰
boolean isclassic = false;
boolean isprop = false;
boolean isroundover = false;
boolean iscontinue = false;
boolean isrolldice = false;
boolean isdicethreetimes = false;
boolean isaccept = false;
boolean iscancel = false;
boolean isexchange = false;
int dice_num = 0; //骰子點數
int page = 1; // 切換玩家資訊頁面
ImageIcon[] role = new ImageIcon[4];
ImageIcon[][] houseicon = new ImageIcon[2][4]; //house[i][j] i = 0代表橫的 i = 1代表直的 j代表1-3棟
String dice_path = String.format("images/dice_%d.png",dice_num); //骰子路徑
ImageIcon diceImage = new ImageIcon(dice_path);//骰子Icon
String country_cost_path; //國家花費卡路徑
String country_fee_path; //國家過路費卡路徑
ImageIcon country_costImage; //國家花費卡Icon
ImageIcon country_feeImage; //國家過路費卡Icon
//層次由低到高:Default, Palette, Modal, PopUp, Drag
JLayeredPane layeredPane; //建立一個JLayeredPane用於分層的。
JPanel jp;
JLabel map_jl, dice_jl, gameinfo_jl, rule_jl, countrycost_jl, countryfee_jl,alert_jl, rank_jl, rest_jl, ownership_jl, lap_jl, chess_jl[], house_jl[][];
JButton dice_jb, start_jb, classic_jb, prop_jb, rule_jb, accept_jb, cancel_jb, exchange_jb, continue_jb, switch_jb;
Timer t = new Timer(); //計時器;
public Windows() {
initImages();
initFrame();
initPosition();
init_info();
country_information();
setFocusable(true);
}
public void initImages(){
role[0] = new ImageIcon("images/suitcase_0.png");
role[1] = new ImageIcon("images/suitcase_1.png");
role[2] = new ImageIcon("images/suitcase_2.png");
role[3] = new ImageIcon("images/suitcase_3.png");
houseicon[0][0] = new ImageIcon("images/flag.png");
houseicon[0][1] = new ImageIcon("images/house_h0.png");
houseicon[0][2] = new ImageIcon("images/house_h1.png");
houseicon[0][3] = new ImageIcon("images/house_h2.png");
houseicon[1][0] = new ImageIcon("images/flag.png");
houseicon[1][1] = new ImageIcon("images/house_v0.png");
houseicon[1][2] = new ImageIcon("images/house_v1.png");
houseicon[1][3] = new ImageIcon("images/house_v2.png");
}
public void initFrame() {
layeredPane = new JLayeredPane(); //new一個JLayeredPane用於分層
String map_path = "images/backgroundmap.png"; //地圖路徑
ImageIcon mapImage = new ImageIcon(map_path);//大富翁地圖(路徑)
//建立地圖背景的元件
jp = new JPanel();
jp.setBounds(0, 0, mapImage.getIconWidth(), mapImage.getIconHeight()); //設定jp的位置和大小(x, y, width, height)
map_jl = new JLabel(mapImage); //new一個Label用來放大富翁地圖
jp.add(map_jl);
layeredPane.add(jp,JLayeredPane.DEFAULT_LAYER); //將jp(大富翁地圖)放到最底層。
initLabel();
initButton();
initHouse();
//JFrame基本設定
this.setTitle("Monopoly");
this.setLayeredPane(layeredPane);
this.setSize(1024,768);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocation(300,50);
this.setVisible(true);
}
public void initLabel() {
//建立遊戲說明畫面
String gamestart_path = "images/gamestart.png";
ImageIcon gamestartImage = new ImageIcon(gamestart_path);
gameinfo_jl = new JLabel(gamestartImage);
gameinfo_jl.setOpaque(true);
gameinfo_jl.setBounds(0, 0, gamestartImage.getIconWidth(), gamestartImage.getIconHeight());
layeredPane.add(gameinfo_jl,JLayeredPane.PALETTE_LAYER);
gameinfo_jl.setVisible(true);
//建立遊戲規則畫面
String gamerule_path = "images/rule.png";
ImageIcon gameruleImage = new ImageIcon(gamerule_path);
rule_jl = new JLabel(gameruleImage);
rule_jl.setOpaque(true);
rule_jl.setBounds(0, 0, gamestartImage.getIconWidth(), gamestartImage.getIconHeight());
layeredPane.add(rule_jl,JLayeredPane.PALETTE_LAYER);
rule_jl.setVisible(false);
//建立棋子圖片
chess_jl = new JLabel[4];
for(int i = 0; i < chess_jl.length ; i++) {
chess_jl[i]= new JLabel(role[i]);
chess_jl[i].setOpaque(false);
layeredPane.add(chess_jl[i],JLayeredPane.PALETTE_LAYER);
chess_jl[i].setVisible(true);
}
//建立骰骰子點數元件
dice_jl = new JLabel(diceImage);
dice_jl.setBounds(254, 190, diceImage.getIconWidth(), diceImage.getIconHeight());
dice_jl.setOpaque(false);
layeredPane.add(dice_jl,JLayeredPane.PALETTE_LAYER);
dice_jl.setVisible(true);
//國家花費卡元件
countrycost_jl = new JLabel(country_costImage);
countrycost_jl.setBounds(605, 480, 200, 250);
countrycost_jl.setOpaque(false);
layeredPane.add(countrycost_jl,JLayeredPane.PALETTE_LAYER);
countrycost_jl.setVisible(false);
//國家過路費卡元件
countryfee_jl = new JLabel(country_feeImage);
countryfee_jl.setBounds(805, 480, 200, 250);
countryfee_jl.setOpaque(false);
layeredPane.add(countryfee_jl,JLayeredPane.PALETTE_LAYER);
countryfee_jl.setVisible(false);
//建立提示說明文字元件
alert_jl = new JLabel("", SwingConstants.CENTER);
alert_jl.setBounds(0, 478, 620, 290);
alert_jl.setOpaque(false);
alert_jl.setForeground(Color.WHITE);
alert_jl.setFont(new Font("標楷體",Font.PLAIN,28));
layeredPane.add(alert_jl,JLayeredPane.PALETTE_LAYER);
//建立資訊欄元件
//排名
rank_jl = new JLabel("", SwingConstants.CENTER);
rank_jl.setBounds(607, 0, 417, 300);
rank_jl.setOpaque(false);
rank_jl.setForeground(Color.BLACK);
rank_jl.setFont(new Font("標楷體",Font.PLAIN,24));
layeredPane.add(rank_jl,JLayeredPane.PALETTE_LAYER);
t.schedule(new print_rank_timerTask(), 0,500);
//休息回合
rest_jl = new JLabel("", SwingConstants.CENTER);
rest_jl.setBounds(607, 200, 417, 300);
rest_jl.setOpaque(false);
rest_jl.setForeground(Color.BLACK);
rest_jl.setFont(new Font("標楷體",Font.PLAIN,24));
layeredPane.add(rest_jl,JLayeredPane.PALETTE_LAYER);
t.schedule(new print_rest_timerTask(), 0,500);
//國家擁有權
ownership_jl = new JLabel("", SwingConstants.CENTER);
ownership_jl.setBounds(607, 0, 417, 478);
ownership_jl.setOpaque(false);
ownership_jl.setForeground(Color.BLACK);
ownership_jl.setBackground(Color.white);
ownership_jl.setFont(new Font("標楷體",Font.PLAIN,24));
layeredPane.add(ownership_jl,JLayeredPane.PALETTE_LAYER);
ownership_jl.setVisible(false);
t.schedule(new print_ownership_timerTask(), 0,500);
//圈數
lap_jl = new JLabel("", SwingConstants.CENTER);
lap_jl.setBounds(607, 0, 417, 300);
lap_jl.setOpaque(false);
lap_jl.setForeground(Color.BLACK);
lap_jl.setFont(new Font("標楷體",Font.PLAIN,24));
layeredPane.add(lap_jl,JLayeredPane.PALETTE_LAYER);
lap_jl.setVisible(false);
t.schedule(new print_lap_timerTask(), 0, 2000);
}
public void initButton() {
//建立開始遊戲按鈕元件
String startbt_path = "images/start_button.png";
ImageIcon startbtImage = new ImageIcon(startbt_path);
start_jb = new JButton(startbtImage);
start_jb.setBounds(462, 384, 100, 50);
start_jb.addActionListener(this);
layeredPane.add(start_jb,JLayeredPane.MODAL_LAYER); //將start_jb放到其他元件高層的地方
start_jb.setVisible(true);
//建立開始遊戲按鈕元件
String rulebt_path = "images/rule_button.png";
ImageIcon rulebtImage = new ImageIcon(rulebt_path);
rule_jb = new JButton(rulebtImage);
rule_jb.setBounds(630, 20, 100, 50);
rule_jb.addActionListener(this);
layeredPane.add(rule_jb,JLayeredPane.MODAL_LAYER); //將rule_jb放到其他元件高層的地方
rule_jb.setVisible(false);
//建立經典模式按鈕元件
String classicbt_path = "images/classic_button.png";
ImageIcon classicbtImage = new ImageIcon(classicbt_path);
classic_jb = new JButton(classicbtImage);
classic_jb.setBounds(332, 300, 100, 50);
classic_jb.addActionListener(this);
layeredPane.add(classic_jb,JLayeredPane.MODAL_LAYER); //將classic_jb放到其他元件高層的地方
classic_jb.setVisible(false);
//建立道具模式按鈕元件
String propbt_path = "images/prop_button.png";
ImageIcon propbtImage = new ImageIcon(propbt_path);
prop_jb = new JButton(propbtImage);
prop_jb.setBounds(592, 300, 100, 50);
prop_jb.addActionListener(this);
layeredPane.add(prop_jb,JLayeredPane.MODAL_LAYER); //將prop_jb放到其他元件高層的地方
prop_jb.setVisible(false);
//建立骰骰子按鈕元件
String dicebt_path = "images/dice_button.png";
ImageIcon dicebtImage = new ImageIcon(dicebt_path);
dice_jb = new JButton(dicebtImage);
dice_jb.setBounds(507, 650, 100, 50);
dice_jb.addActionListener(this);
layeredPane.add(dice_jb,JLayeredPane.PALETTE_LAYER);
dice_jb.setVisible(false);
//建立確認取消按鈕元件
String acceptbt_path = "images/buy_button.png";
ImageIcon acceptbtImage = new ImageIcon(acceptbt_path);
accept_jb = new JButton(acceptbtImage);
accept_jb.setBounds(407, 650, 100, 50);
accept_jb.addActionListener(this);
layeredPane.add(accept_jb,JLayeredPane.PALETTE_LAYER);
accept_jb.setVisible(false);
String cancelbt_path = "images/cancel_button.png";
ImageIcon cancelbtImage = new ImageIcon(cancelbt_path);
cancel_jb = new JButton(cancelbtImage);
cancel_jb.setBounds(507, 650, 100, 50);
cancel_jb.addActionListener(this);
layeredPane.add(cancel_jb,JLayeredPane.PALETTE_LAYER);
cancel_jb.setVisible(false);
//建立兌換道具按鈕元件
String exchangebt_path = "images/exchange_button.png";
ImageIcon exchangebtImage = new ImageIcon(exchangebt_path);
exchange_jb = new JButton(exchangebtImage);
exchange_jb.setBounds(407, 650, 100, 50);
exchange_jb.addActionListener(this);
layeredPane.add(exchange_jb,JLayeredPane.PALETTE_LAYER);
exchange_jb.setVisible(false);
//建立繼續按鈕元件
String continuebt_path = "images/continue_button.png";
ImageIcon continuebtImage = new ImageIcon(continuebt_path);
continue_jb = new JButton(continuebtImage);
continue_jb.setBounds(507, 650, 100, 50);
continue_jb.addActionListener(this);
layeredPane.add(continue_jb,JLayeredPane.PALETTE_LAYER);
continue_jb.setVisible(false);
//建立切換按鈕元件
String switchbt_path = "images/switch_button.png";
ImageIcon switchbtImage = new ImageIcon(switchbt_path);
switch_jb = new JButton(switchbtImage);
switch_jb.setBounds(900, 20, 100, 50);
switch_jb.addActionListener(this);
layeredPane.add(switch_jb,JLayeredPane.PALETTE_LAYER);
switch_jb.setVisible(true);
}
public void initHouse() {
//建立房子圖示
house_jl = new JLabel[20][5]; //house_jl[i][j] i代表國家(0-19) j代表幾棟房子(0=空 1=買土地 2=一棟房子)
for(int i = 0; i < house_jl.length; i++) {
house_jl[i][0] = new JLabel();
layeredPane.add(house_jl[i][0],JLayeredPane.PALETTE_LAYER);
house_jl[i][0].setVisible(true);
}
//橫的
for(int i = 1; i < house_jl.length ; i++) {
for(int j = 1; j < house_jl[0].length ; j++) {
house_jl[i][j]= new JLabel(houseicon[0][j-1]);
house_jl[i][j].setOpaque(false);
layeredPane.add(house_jl[i][j],JLayeredPane.PALETTE_LAYER);
house_jl[i][j].setVisible(false);
}
}
//直的
for(int j = 1; j < house_jl[0].length ; j++) {
house_jl[8][j]= new JLabel(houseicon[1][j-1]);
house_jl[9][j]= new JLabel(houseicon[1][j-1]);
house_jl[18][j]= new JLabel(houseicon[1][j-1]);
house_jl[19][j]= new JLabel(houseicon[1][j-1]);
house_jl[8][j].setOpaque(false);
house_jl[9][j].setOpaque(false);
house_jl[18][j].setOpaque(false);
house_jl[19][j].setOpaque(false);
layeredPane.add(house_jl[8][j],JLayeredPane.PALETTE_LAYER);
layeredPane.add(house_jl[9][j],JLayeredPane.PALETTE_LAYER);
layeredPane.add(house_jl[18][j],JLayeredPane.PALETTE_LAYER);
layeredPane.add(house_jl[19][j],JLayeredPane.PALETTE_LAYER);
house_jl[8][j].setVisible(false);
house_jl[9][j].setVisible(false);
house_jl[18][j].setVisible(false);
house_jl[19][j].setVisible(false);
}
//房子橫的長寬
int housewidth_h1 = houseicon[0][1].getIconWidth();
int housewidth_h2 = houseicon[0][2].getIconWidth();
int housewidth_h3 = houseicon[0][3].getIconWidth();
int househeight_h1 = houseicon[0][1].getIconHeight();
int househeight_h2 = houseicon[0][2].getIconHeight();
int househeight_h3 = houseicon[0][3].getIconHeight();
//房子直的長寬
int housewidth_v1 = houseicon[1][1].getIconWidth();
int housewidth_v2 = houseicon[1][2].getIconWidth();
int housewidth_v3 = houseicon[1][3].getIconWidth();
int househeight_v1 = houseicon[1][1].getIconHeight();
int househeight_v2 = houseicon[1][2].getIconHeight();
int househeight_v3 = houseicon[1][3].getIconHeight();
house_jl[1][1].setBounds(137, 13, housewidth_h1, househeight_h1);
house_jl[1][2].setBounds(132, 13, housewidth_h1, househeight_h1);
house_jl[1][3].setBounds(122, 13, housewidth_h2, househeight_h2);
house_jl[1][4].setBounds(112, 13, housewidth_h3, househeight_h3);
house_jl[3][1].setBounds(267, 13, housewidth_h1, househeight_h1);
house_jl[3][2].setBounds(262, 13, housewidth_h1, househeight_h1);
house_jl[3][3].setBounds(252, 13, housewidth_h2, househeight_h2);
house_jl[3][4].setBounds(242, 13, housewidth_h3, househeight_h3);
house_jl[4][1].setBounds(332, 13, housewidth_h1, househeight_h1);
house_jl[4][2].setBounds(327, 13, housewidth_h1, househeight_h1);
house_jl[4][3].setBounds(317, 13, housewidth_h2, househeight_h2);
house_jl[4][4].setBounds(307, 13, housewidth_h3, househeight_h3);
house_jl[6][1].setBounds(462, 13, housewidth_h1, househeight_h1);
house_jl[6][2].setBounds(457, 13, housewidth_h1, househeight_h1);
house_jl[6][3].setBounds(447, 13, housewidth_h2, househeight_h2);
house_jl[6][4].setBounds(437, 13, housewidth_h3, househeight_h3);
house_jl[8][1].setBounds(581, 180, housewidth_v1, househeight_v1);
house_jl[8][2].setBounds(576, 180, housewidth_v1, househeight_v1);
house_jl[8][3].setBounds(576, 170, housewidth_v2, househeight_v2);
house_jl[8][4].setBounds(576, 160, housewidth_v3, househeight_v3);
house_jl[9][1].setBounds(581, 276, housewidth_v1, househeight_v1);
house_jl[9][2].setBounds(576, 276, housewidth_v1, househeight_v1);
house_jl[9][3].setBounds(576, 266, housewidth_v2, househeight_v2);
house_jl[9][4].setBounds(576, 256, housewidth_v3, househeight_v3);
house_jl[11][1].setBounds(462, 443, housewidth_h1, househeight_h1);
house_jl[11][2].setBounds(457, 443, housewidth_h1, househeight_h1);
house_jl[11][3].setBounds(447, 443, housewidth_h2, househeight_h2);
house_jl[11][4].setBounds(437, 443, housewidth_h3, househeight_h3);
house_jl[13][1].setBounds(332, 443, housewidth_h1, househeight_h1);
house_jl[13][2].setBounds(327, 443, housewidth_h1, househeight_h1);
house_jl[13][3].setBounds(317, 443, housewidth_h2, househeight_h2);
house_jl[13][4].setBounds(307, 443, housewidth_h3, househeight_h3);
house_jl[14][1].setBounds(267, 443, housewidth_h1, househeight_h1);
house_jl[14][2].setBounds(262, 443, housewidth_h1, househeight_h1);
house_jl[14][3].setBounds(252, 443, housewidth_h2, househeight_h2);
house_jl[14][4].setBounds(242, 443, housewidth_h3, househeight_h3);
house_jl[16][1].setBounds(137, 443, housewidth_h1, househeight_h1);
house_jl[16][2].setBounds(132, 443, housewidth_h1, househeight_h1);
house_jl[16][3].setBounds(122, 443, housewidth_h2, househeight_h2);
house_jl[16][4].setBounds(112, 443, housewidth_h3, househeight_h3);
house_jl[18][1].setBounds(17, 276, housewidth_v1, househeight_v1);
house_jl[18][2].setBounds(12, 276, housewidth_v1, househeight_v1);
house_jl[18][3].setBounds(12, 266, housewidth_v2, househeight_v2);
house_jl[18][4].setBounds(12, 256, housewidth_v3, househeight_v3);
house_jl[19][1].setBounds(17, 180, housewidth_v1, househeight_v1);
house_jl[19][2].setBounds(12, 180, housewidth_v1, househeight_v1);
house_jl[19][3].setBounds(12, 170, housewidth_v2, househeight_v2);
house_jl[19][4].setBounds(12, 160, housewidth_v3, househeight_v3);
}
@Override
public void actionPerformed(ActionEvent evt) {
//點開始遊戲按鈕
if(evt.getSource() == start_jb) {
start_jb.setVisible(false);
classic_jb.setVisible(true);
prop_jb.setVisible(true);
}
//點經典模式按鈕
if(evt.getSource() == classic_jb) {
isclassic = true;
gameinfo_jl.setVisible(false);
classic_jb.setVisible(false);
prop_jb.setVisible(false);
for (int i = 0; i < 4; i++) {
money[i] = 5000;
}
}
//點道具模式按鈕
if(evt.getSource() == prop_jb) {
isprop = true;
gameinfo_jl.setVisible(false);
classic_jb.setVisible(false);
prop_jb.setVisible(false);
for (int i = 0; i < 4; i++) {
money[i] = 15000;
}
}
//點遊戲規則按鈕
if(evt.getSource() == rule_jb) {
if(!rule_jl.isVisible()) {
String rulebt_path = "images/back_button.png";
ImageIcon rulebtImage = new ImageIcon(rulebt_path);
rule_jb.setIcon(rulebtImage);
rule_jb.setBounds(800,650,100,50);
rule_jl.setVisible(true);
}else{
rule_jl.setVisible(false);
String rulebt_path = "images/rule_button.png";
ImageIcon rulebtImage = new ImageIcon(rulebt_path);
rule_jb.setIcon(rulebtImage);
rule_jb.setBounds(630, 20, 100, 50);
}
}
//點骰子按鈕
if(evt.getSource() == dice_jb) {
isrolldice = true;
dice_jb.setVisible(false);
dice_path = "images/dice.gif";
diceImage = new ImageIcon(dice_path);//骰子Icon
dice_jl.setIcon(diceImage);
dice_num = (int)(Math.random()*6+1);
dice_path = String.format("images/dice_%d.png",dice_num);
diceImage = new ImageIcon(dice_path);//骰子Icon
if(isdicethreetimes) {
isdicethreetimes = false;
dice_num *= 3;
}
t.schedule(new dice_timerTask(), 1000);
chess_move();
}
//點確認按鈕
if(evt.getSource() == accept_jb) {
isaccept = true;
accept_jb.setVisible(false);
cancel_jb.setVisible(false);
}
//點取消按鈕
if(evt.getSource() == cancel_jb) {
iscancel = true;
cancel_jb.setVisible(false);
accept_jb.setVisible(false);
if(isprop) {
exchange_jb.setVisible(false);
}
}
//點交換道具按鈕
if(evt.getSource() == exchange_jb) {
if(money[currentRole_ID] >= 3000) {
money[currentRole_ID] -= 3000;
prop();
}else {
alert_jl.setText("你的錢不夠買呦!");
}
isexchange = true;
cancel_jb.setVisible(false);
exchange_jb.setVisible(false);
}
//點繼續按鈕
if(evt.getSource() == continue_jb) {
iscontinue = true;
continue_jb.setVisible(false);
}
//點切換按鈕
if(evt.getSource() == switch_jb) {
switch(page){
case 1:
rank_jl.setVisible(false);
rest_jl.setVisible(false);
ownership_jl.setVisible(true);
lap_jl.setVisible(false);
page = 2;
break;
case 2:
rank_jl.setVisible(false);
rest_jl.setVisible(false);
ownership_jl.setVisible(false);
lap_jl.setVisible(true);
page = 3;
break;
case 3:
rank_jl.setVisible(true);
rest_jl.setVisible(true);
ownership_jl.setVisible(false);
lap_jl.setVisible(false);
page = 1;
break;
}
}
}
class dice_timerTask extends TimerTask{
@Override
public void run() {
dice_jl.setIcon(diceImage);
}
}
class print_rank_timerTask extends TimerTask{
@Override
public void run() {
rank();
}
}
class print_rest_timerTask extends TimerTask{
@Override
public void run() {
rest();
}
}
class print_ownership_timerTask extends TimerTask{
@Override
public void run() {
ownership();
}
}
class print_lap_timerTask extends TimerTask{
@Override
public void run() {
lap();
}
}
public void initPosition() {
for (int i = 0; i < 4; i++) {
chessposition[i] = 0;
}
chessposition_x[0] = 48;
chessposition_y[0] = 54;
chessposition_x[1] = 78;
chessposition_y[1] = 54;
chessposition_x[2] = 48;
chessposition_y[2] = 90;
chessposition_x[3] = 78;
chessposition_y[3] = 90;
for(int i = 0; i < chess_jl.length; i++) {
chess_jl[i].setBounds(chessposition_x[i], chessposition_y[i], role[i].getIconWidth(), role[i].getIconHeight());
}
}
public void init_info() {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (j == 0) {
player_information[i][j] = "無";
}
if (j == 1) {
player_information[i][j] = "無";
}
if (j == 2) {
player_information[i][j] = "無";
}
if (j == 3) {
player_information[i][j] = "無";
}
}
}
for (int i = 0; i < 4; i++) {
chessposition[i] = 0;
rest[i] = 0;
isout[i] = false;
}
for (int i = 0; i < 20; i++) {
house[i] = -1;
}
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 20; k++) {
houserank[i][j][k] = "";
}
}
}
}
public void chess_move() {
//currentRole_ID:玩家順序 0是玩家1,1是玩家2,2是玩家3,3是玩家4
chessposition[currentRole_ID] += dice_num;
//chessposition(棋子位置):0~19,如果超過19就要-20
if (chessposition[currentRole_ID] > 19) {
chessposition[currentRole_ID] -=20 ;
lap[currentRole_ID]++;
money[currentRole_ID] += 3000;
}
t.schedule(new move_timerTask(), 1700);
}
class move_timerTask extends TimerTask{
@Override
public void run() {
//4個角落的棋子座標
if(chessposition[currentRole_ID] >= 1 && chessposition[currentRole_ID] <= 7){
int outbound = chessposition[currentRole_ID] - 0; //超過Start幾格
chessposition_x[currentRole_ID] = start_x[currentRole_ID] + outbound*65;
chessposition_y[currentRole_ID] = start_y[currentRole_ID];
chess_jl[currentRole_ID].setBounds(chessposition_x[currentRole_ID], chessposition_y[currentRole_ID], role[currentRole_ID].getIconWidth(), role[currentRole_ID].getIconHeight());
}
else if(chessposition[currentRole_ID] >= 8 && chessposition[currentRole_ID] <= 10) {
int outbound = chessposition[currentRole_ID] - 7; //超過Prison幾格
chessposition_x[currentRole_ID] = prison_x[currentRole_ID];
chessposition_y[currentRole_ID] = prison_y[currentRole_ID] + outbound*96;
chess_jl[currentRole_ID].setBounds(chessposition_x[currentRole_ID], chessposition_y[currentRole_ID], role[currentRole_ID].getIconWidth(), role[currentRole_ID].getIconHeight());
}
else if(chessposition[currentRole_ID] >= 11 && chessposition[currentRole_ID] <= 17) {
int outbound = chessposition[currentRole_ID] - 10; //超過BackToStart幾格
chessposition_x[currentRole_ID] = backtostart_x[currentRole_ID] - outbound*65;
chessposition_y[currentRole_ID] = backtostart_y[currentRole_ID];
chess_jl[currentRole_ID].setBounds(chessposition_x[currentRole_ID], chessposition_y[currentRole_ID], role[currentRole_ID].getIconWidth(), role[currentRole_ID].getIconHeight());
}
else if(chessposition[currentRole_ID] == 18 || chessposition[currentRole_ID] == 19 || chessposition[currentRole_ID] == 0) {
if(chessposition[currentRole_ID] == 0) {
chessposition_x[currentRole_ID] = start_x[currentRole_ID];
chessposition_y[currentRole_ID] = start_y[currentRole_ID];
}else {
int outbound = chessposition[currentRole_ID] - 17; //超過Park幾格
chessposition_x[currentRole_ID] = park_x[currentRole_ID];
chessposition_y[currentRole_ID] = park_y[currentRole_ID] - outbound*96;
}
chess_jl[currentRole_ID].setBounds(chessposition_x[currentRole_ID], chessposition_y[currentRole_ID], role[currentRole_ID].getIconWidth(), role[currentRole_ID].getIconHeight());
}
chess_action();
}
}
public void chess_action() {
if (chessposition[currentRole_ID] == 0 || chessposition[currentRole_ID] == 7 || chessposition[currentRole_ID] == 10 || chessposition[currentRole_ID] == 17) {
//4個角落的
if (chessposition[currentRole_ID] == 0 ) {
alert_jl.setText("走回起點了!獲得3000元");
}
if (chessposition[currentRole_ID] == 7 ) {
alert_jl.setText("走到監獄,休息1回合");
rest[currentRole_ID] = 1;
}
if (chessposition[currentRole_ID] == 10 ) {
alert_jl.setText("走到返回起點");
chessposition[currentRole_ID] = 0;
chessposition_x[currentRole_ID] = start_x[currentRole_ID];
chessposition_y[currentRole_ID] = start_y[currentRole_ID];
chess_jl[currentRole_ID].setBounds(chessposition_x[currentRole_ID], chessposition_y[currentRole_ID], role[currentRole_ID].getIconWidth(), role[currentRole_ID].getIconHeight());
}
if (chessposition[currentRole_ID] == 17 ) {
alert_jl.setText("走到公園,休息2回合");
rest[currentRole_ID] = 2;
}
continue_jb.setVisible(true);
while(true) {
sleep(100);
if(iscontinue) {
iscontinue = false;
break;
}
}
print_player_informaiton();
}
else if (chessposition[currentRole_ID] == 5 || chessposition[currentRole_ID] == 15) {
//機會
alert_jl.setText("走到機會格了!點擊按鈕翻開機會卡!");
String continuebt_path = "images/open_button.png";
ImageIcon continuebtImage = new ImageIcon(continuebt_path);
continue_jb.setIcon(continuebtImage);
continue_jb.setVisible(true);
while(true) {
sleep(100);
if(iscontinue) {
iscontinue = false;
break;
}
}
chance_cards(); //機會函式
continuebt_path = "images/continue_button.png";
continuebtImage = new ImageIcon(continuebt_path);
continue_jb.setIcon(continuebtImage);
continue_jb.setVisible(true);
while(true) {
sleep(100);
if(iscontinue) {
iscontinue = false;
break;
}
}
print_player_informaiton(); //print玩家資訊
}
else if (chessposition[currentRole_ID] == 2 || chessposition[currentRole_ID] == 12) {
//命運
alert_jl.setText("走到命運格了!點擊按鈕翻開命運卡!");
String continuebt_path = "images/open_button.png";
ImageIcon continuebtImage = new ImageIcon(continuebt_path);
continue_jb.setIcon(continuebtImage);
continue_jb.setVisible(true);
while(true) {
sleep(100);
if(iscontinue) {
iscontinue = false;
break;
}
}
community_chest_cards(); //命運函式
continuebt_path = "images/continue_button.png";
continuebtImage = new ImageIcon(continuebt_path);
continue_jb.setIcon(continuebtImage);
continue_jb.setVisible(true);
while(true) {
sleep(100);
if(iscontinue) {
iscontinue = false;
break;
}
}
print_player_informaiton(); //print玩家資訊
}
else {
//檢查能不能買土地或蓋房子
boolean has_house_been_bought = check_house(); //檢查土地擁有權
if (has_house_been_bought == true && house_jl[chessposition[currentRole_ID]][4].isVisible() == false) {
country_cost_path = String.format("images/cost_%d.png",chessposition[currentRole_ID]); //國家花費卡路徑
country_fee_path = String.format("images/fee_%d.png",chessposition[currentRole_ID]); //國家過路費卡路徑
country_costImage = new ImageIcon(country_cost_path);
country_feeImage = new ImageIcon(country_fee_path);
countrycost_jl.setIcon(country_costImage);
countryfee_jl.setIcon(country_feeImage);
countrycost_jl.setVisible(true);
countryfee_jl.setVisible(true);
alert_jl.setText("請問是否要購買土地or蓋房子?");
accept_jb.setVisible(true);
cancel_jb.setVisible(true);
isaccept = false;
iscancel = false;
while(true) {
sleep(100);
if (isaccept || iscancel) {
iscancel = false;
countrycost_jl.setVisible(false);
countryfee_jl.setVisible(false);
break;
}
}
if(isaccept) {
buy_house();
}
}
else {
//付過路費
alert_jl.setText("哎呀!走到別人的土地了!");
sleep(1500);
if(rest[house[chessposition[currentRole_ID]]] == 0) {
country_fee_path = String.format("images/fee_%d.png",chessposition[currentRole_ID]); //國家過路費卡路徑
country_feeImage = new ImageIcon(country_fee_path);
countryfee_jl.setIcon(country_feeImage);
countryfee_jl.setVisible(true);
for (int i = 1; i <= 4; i++) {
if(house_jl[chessposition[currentRole_ID]][i].isVisible() == true) {
alert_jl.setText("你要付" + countryinformation[i+3][chessposition[currentRole_ID]] + "元給玩家" + ((house[chessposition[currentRole_ID]])+1)); //如果house[chessposition[currentRole_ID]] = 0代表是玩家1的,所以要+1(0+1=玩家1)
money[currentRole_ID] -= countryinformation[i+3][chessposition[currentRole_ID]];
money[(house[chessposition[currentRole_ID]])] += countryinformation[i+3][chessposition[currentRole_ID]];
}
}
}else {
alert_jl.setText("玩家" + ((house[chessposition[currentRole_ID]])+1) + "休息中,無須付過路費");
}
continue_jb.setVisible(true);
while(true) {
sleep(100);
if(iscontinue) {
countryfee_jl.setVisible(false);
iscontinue = false;
break;
}
}
}
print_player_informaiton(); //print玩家資訊
}
isroundover = true;
}
public void print_player_informaiton() {
alert_jl.setText("<html>"
+ "<body><span>你現在所持有的金額:"+ money[currentRole_ID] +"</span><br/>"
+ "<span>你現在所持有的土地:"+ player_information[currentRole_ID][0] +"</span><br/>"
+ "<span>你現在蓋一棟房子的國家:"+ player_information[currentRole_ID][1] +"</span><br/>"
+ "<span>你現在蓋二棟房子的國家:"+ player_information[currentRole_ID][2] +"</span><br/>"
+ "<span>你現在蓋三棟房子的國家:"+ player_information[currentRole_ID][3] +"</span><br/>"
+ "</body>"
+ "</html>");
}
//國家土地和房子費用及過路費
public void country_information() {
/*[0][i]買土地的錢 [4][i]買土地的過路費
*[1][i]蓋一棟房子的錢 [5][i]蓋一棟房子的過路費
*[2][i]蓋兩棟房子的錢 [6][i]蓋兩棟房子的過路費
*[3][i]蓋三棟房子的錢 [7][i]蓋三棟房子的過路費
*/
//start
countryinformation[0][0] = 1500;
//KOR
//cost
countryinformation[0][1] = 2200;
countryinformation[1][1] = 800;
countryinformation[2][1] = 1500;
countryinformation[3][1] = 3000;
//fee
countryinformation[4][1] = 880;
countryinformation[5][1] = 1280;
countryinformation[6][1] = 1630;
countryinformation[7][1] = 2380;
//JPN
//cost
countryinformation[0][3] = 2400;
countryinformation[1][3] = 1000;
countryinformation[2][3] = 1800;
countryinformation[3][3] = 3500;
//fee
countryinformation[4][3] = 960;
countryinformation[5][3] = 1460;
countryinformation[6][3] = 1860;
countryinformation[7][3] = 2710;
//MEX
//cost
countryinformation[0][4] = 3000;
countryinformation[1][4] = 1300;
countryinformation[2][4] = 2400;
countryinformation[3][4] = 4200;
//fee
countryinformation[4][4] = 1200;
countryinformation[5][4] = 1850;
countryinformation[6][4] = 2400;
countryinformation[7][4] = 3300;
//NZL
//cost
countryinformation[0][6] = 3600;
countryinformation[1][6] = 1500;
countryinformation[2][6] = 2800;
countryinformation[3][6] = 5500;
//fee
countryinformation[4][6] = 1440;
countryinformation[5][6] = 2190;
countryinformation[6][6] = 2840;
countryinformation[7][6] = 4190;
//USA
//cost
countryinformation[0][8] = 2200;
countryinformation[1][8] = 800;
countryinformation[2][8] = 1500;
countryinformation[3][8] = 3000;
//fee
countryinformation[4][8] = 880;
countryinformation[5][8] = 1280;
countryinformation[6][8] = 1630;
countryinformation[7][8] = 2380;
//RUS
//cost
countryinformation[0][9] = 1000;
countryinformation[1][9] = 500;
countryinformation[2][9] = 800;
countryinformation[3][9] = 1500;
//fee
countryinformation[4][9] = 400;
countryinformation[5][9] = 650;
countryinformation[6][9] = 800;
countryinformation[7][9] = 1150;
//SGP
//cost
countryinformation[0][11] = 3000;
countryinformation[1][11] = 1300;
countryinformation[2][11] = 2400;
countryinformation[3][11] = 4200;
//fee
countryinformation[4][11] = 1200;
countryinformation[5][11] = 1900;
countryinformation[6][11] = 2400;
countryinformation[7][11] = 3300;
//ESP
//cost
countryinformation[0][13] = 1600;
countryinformation[1][13] = 900;
countryinformation[2][13] = 1900;
countryinformation[3][13] = 3700;
//fee
countryinformation[4][13] = 640;
countryinformation[5][13] = 1090;
countryinformation[6][13] = 1590;
countryinformation[7][13] = 2490;
//THA
//cost
countryinformation[0][14] = 2000;
countryinformation[1][14] = 700;
countryinformation[2][14] = 1400;
countryinformation[3][14] = 2900;
//fee
countryinformation[4][14] = 800;
countryinformation[5][14] = 1150;
countryinformation[6][14] = 1500;
countryinformation[7][14] = 2250;
//AUS
//cost
countryinformation[0][16] = 2400;
countryinformation[1][16] = 1000;
countryinformation[2][16] = 1800;
countryinformation[3][16] = 3500;
//fee
countryinformation[4][16] = 960;
countryinformation[5][16] = 1460;
countryinformation[6][16] = 1860;
countryinformation[7][16] = 2710;
//TUR
//cost
countryinformation[0][18] = 2200;
countryinformation[1][18] = 800;
countryinformation[2][18] = 1500;
countryinformation[3][18] = 3000;
//fee
countryinformation[4][18] = 880;
countryinformation[5][18] = 1280;
countryinformation[6][18] = 1630;
countryinformation[7][18] = 2300;
//TWN
//cost
countryinformation[0][19] = 4000;
countryinformation[1][19] = 1800;
countryinformation[2][19] = 3200;
countryinformation[3][19] = 6000;
//fee
countryinformation[4][19] = 1600;
countryinformation[5][19] = 2500;
countryinformation[6][19] = 3200;
countryinformation[7][19] = 4600;
}
public boolean check_house() {
//如果土地是自己的,boolean值為true
boolean has_house_been_bought = true;