FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaSweeper/src/JavaSweeper.java at master · pandim/JavaSweeper · GitHub
pandim
/
JavaSweeper
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaSweeper
/
src
/
JavaSweeper.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
119 lines (106 loc) · 3.63 KB
Breadcrumbs
JavaSweeper
/
src
/
JavaSweeper.java
Copy path
File metadata and controls
119 lines (106 loc) · 3.63 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
javax
.
swing
.*;
import
java
.
awt
.*;
import
java
.
awt
.
event
.
MouseAdapter
;
import
java
.
awt
.
event
.
MouseEvent
;
import
sweeper
.
Box
;
import
sweeper
.
Coord
;
import
sweeper
.
Game
;
import
sweeper
.
Ranges
;
public
class
JavaSweeper
extends
JFrame
{
private
Game
game
;
private
final
int
IMAGE_SIZE
=
50
;
private
JPanel
panel
;
private
JLabel
label
;
public
static
void
main
(
String
[]
args
) {
new
JavaSweeper
();
}
private
JavaSweeper
() {
int
COLS
=
9
;
int
ROWS
=
9
;
int
BOMBS
=
10
;
game
=
new
Game
(
COLS
,
ROWS
,
BOMBS
);
game
.
start
();
setImages
();
initPanel
();
initLabel
();
initFrame
();
}
private
void
initLabel
() {
label
=
new
JLabel
(
getMessage
());
Font
font
=
new
Font
(
"Tahoma"
,
Font
.
ITALIC
,
18
);
label
.
setFont
(
font
);
label
.
setHorizontalAlignment
(
JLabel
.
CENTER
);
add
(
label
,
BorderLayout
.
SOUTH
);
}
private
void
initPanel
() {
panel
=
new
JPanel
() {
@
Override
protected
void
paintComponent
(
Graphics
g
) {
super
.
paintComponent
(
g
);
for
(
Coord
coord
:
Ranges
.
getAllCoords
())
g
.
drawImage
((
Image
)
game
.
getBox
(
coord
).
image
,
coord
.
x
*
IMAGE_SIZE
,
coord
.
y
*
IMAGE_SIZE
,
this
);
}
};
panel
.
addMouseListener
(
new
MouseAdapter
() {
@
Override
public
void
mousePressed
(
MouseEvent
e
) {
int
x
=
e
.
getX
() /
IMAGE_SIZE
;
int
y
=
e
.
getY
() /
IMAGE_SIZE
;
Coord
coord
=
new
Coord
(
x
,
y
);
switch
(
e
.
getButton
()) {
case
MouseEvent
.
BUTTON1
:
game
.
pressLeftButton
(
coord
);
break
;
case
MouseEvent
.
BUTTON3
:
game
.
pressRightButton
(
coord
);
break
;
case
MouseEvent
.
BUTTON2
:
game
.
start
();
break
;
default
:
break
;
}
label
.
setText
(
getMessage
());
panel
.
repaint
();
}
});
panel
.
setPreferredSize
(
new
Dimension
(
Ranges
.
getSize
().
x
*
IMAGE_SIZE
,
Ranges
.
getSize
().
y
*
IMAGE_SIZE
));
add
(
panel
);
}
private
void
initFrame
() {
setDefaultCloseOperation
(
WindowConstants
.
EXIT_ON_CLOSE
);
setTitle
(
"Сапёр с Явы"
);
setResizable
(
false
);
pack
();
setLocationRelativeTo
(
null
);
setVisible
(
true
);
}
private
void
setImages
()
{
for
(
Box
box
:
Box
.
values
()) {
box
.
image
=
getImage
(
box
.
name
().
toLowerCase
());
}
setIconImage
(
getImage
(
"icon"
));
}
private
Image
getImage
(
String
name
) {
String
filename
=
"img/"
+
name
+
".png"
;
ImageIcon
icon
=
new
ImageIcon
(
getClass
().
getResource
(
filename
));
return
icon
.
getImage
();
}
private
String
getMessage
(){
switch
(
game
.
getState
()){
case
BOMBED
:
return
"Ба-да-бум !!! Вы проиграли!"
;
case
WINNER
:
return
"Вы выиграли! Поздравляем!"
;
case
PLAYED
:
default
:
if
(
game
.
getTotalFlaged
() ==
0
)
return
"Добро пожаловать!"
;
else
return
"Подумай дважды! Флажков "
+
game
.
getTotalFlaged
() +
" на "
+
game
.
getTotalBombs
() +
" бомб."
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL