-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinesweeperUtils.java
More file actions
104 lines (78 loc) · 3.11 KB
/
MinesweeperUtils.java
File metadata and controls
104 lines (78 loc) · 3.11 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
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Toolkit;
public class MinesweeperUtils {
private static final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
public static int roundToInt(double number){
int periodLocation = 0;
String numberString = "" + number;
for (int counter = 0; counter < numberString.length(); counter++){
if (numberString.charAt(counter) == '.'){
periodLocation = counter;
break;
}
}
String roundedNumString = numberString.substring(0, periodLocation);
int roundedNum = Integer.parseInt(roundedNumString);
if (Integer.parseInt("" + numberString.charAt(periodLocation + 1)) >= 5){
roundedNum++;
}
return roundedNum;
}
public static Dimension getSquareScreenSize(double ratio){
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
double screenWidth = dim.getWidth();
double screenHeight = dim.getHeight();
Dimension gameScreenSize = null;
if (screenWidth > screenHeight){
int gameScreenWidth = roundToInt(ratio * screenWidth);
gameScreenSize = new Dimension(gameScreenWidth, gameScreenWidth);
}
else {
int gameScreenHeight = roundToInt(ratio * screenHeight);
gameScreenSize = new Dimension(gameScreenHeight, gameScreenHeight);
}
return gameScreenSize;
}
public static Dimension getGameScreenSize(double widthRatio, double heightRatio){
double screenWidth = screenSize.getWidth();
double screenHeight = screenSize.getHeight();
int gameScreenWidth = roundToInt(widthRatio * screenWidth);
int gameScreenHeight = roundToInt(heightRatio * screenHeight);
Dimension gameScreenSize = new Dimension(gameScreenWidth, gameScreenHeight);
return gameScreenSize;
}
public static Dimension getGameScreenSize
(double widthRatio,
double heightRatio,
Dimension screenSize){
double screenWidth = screenSize.getWidth();
double screenHeight = screenSize.getHeight();
int gameScreenWidth = roundToInt(widthRatio * screenWidth);
int gameScreenHeight = roundToInt(heightRatio * screenHeight);
Dimension gameScreenSize = new Dimension(gameScreenWidth, gameScreenHeight);
return gameScreenSize;
}
public static Dimension getSquareScreenSize(double ratio, Dimension screenSize){
double screenWidth = screenSize.getWidth();
int gameScreenWidth = roundToInt(ratio * screenWidth);
Dimension gameScreenSize = new Dimension(gameScreenWidth, gameScreenWidth);
return gameScreenSize;
}
public static Point getCornerPoint(Dimension windowSize){
int windowWidthR = roundToInt(windowSize.getWidth());
int windowHeightR = roundToInt(windowSize.getHeight());
int x = (screenSize.width-windowWidthR) / 2;
int y = (screenSize.height-windowHeightR) / 2;
Point windowLocation = new Point(x, y);
return windowLocation;
}
public static Point getCornerPoint(double windowWidth, double windowHeight){
int windowWidthR = roundToInt(windowWidth);
int windowHeightR = roundToInt(windowHeight);
int x = (screenSize.width-windowWidthR) / 2;
int y = (screenSize.height-windowHeightR) / 2;
Point windowLocation = new Point(x, y);
return windowLocation;
}
}