-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTAM.java
More file actions
170 lines (132 loc) · 4.65 KB
/
Copy pathTAM.java
File metadata and controls
170 lines (132 loc) · 4.65 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
public class TAM {
public static void main(String[] args){
/* IMPORTANT NOTES:
*
* grid.length = gridHeight
* grid[0].length = gridWidth
* meaning:
* gridHeight = number of rows
* gridWidth = number of columns
* putting stuff in the array according to a cartesian coordinate plane has to be [y][x] aka row number and then column
*
*/
// variables
int gridHeight = 50; // grid height
int gridWidth = 50; // grid width
int bombs = (gridHeight * gridWidth)/10; // bomb number
char bomb = '+'; // bomb char
char flags = '#'; // flag char
// creating grid
char[][] grid = new char[gridHeight][gridWidth];
format(); // format method
populateGrid(gridHeight, gridWidth, grid); // populating empty grid
displayGrid(gridHeight, gridWidth, grid); // display grid
populateBombs(bombs, bomb, gridHeight, gridWidth, grid);// adding bombs
// spacer
System.out.println("\n" + spacer(gridWidth));
displayGrid(gridHeight, gridWidth, grid); // display grid
format();
numberGen(gridHeight, gridWidth, grid);
// spacer
System.out.println("\n" + spacer(gridWidth));
displayGrid(gridHeight, gridWidth, grid); // display grid
format();
}
// code to populate empty grid
public static void populateGrid(int tempGH, int tempGW, char[][] tempGrid){
for(int i = 0; i < tempGH; i++){
for(int l = 0; l < tempGW; l++){
tempGrid[i][l] = '.';
}
}
}
// code to display grid - works with numbers less than 20
public static void displayGrid(int tempGH, int tempGW, char[][] tempGrid){
for(int i = 0; i < tempGH; i++){
for(int l = 0; l < tempGW; l++){
System.out.print(tempGrid[i][l]);
System.out.print(" ");
}
System.out.print(i); // displays row number
System.out.println("");
}
// firstDigit = number/((int)(pow(10,(int)log(number))));
//fix doesn't work; run to test
// code to display column
for(int i = 0; i < tempGW; i++){
if(i < 10){
System.out.print("0");
System.out.print(" ");
} else if(i >= 10 && i < 20){
System.out.print("1");
System.out.print(" ");
} else if(i >= 20 && i < 30){
System.out.print("2");
System.out.print(" ");
} else if(i >= 30 && i < 40){
System.out.print("3");
System.out.print(" ");
} else if(i >= 40 && i < 50){
System.out.print("4");
System.out.print(" ");
} else if(i >= 50 && i < 60){
System.out.print("5");
System.out.print(" ");
}
}
System.out.println();
for(int i = 0; i < tempGW; i++){
System.out.print(i % 10);
System.out.print(" ");
}
}
// code to populate bombs
public static void populateBombs(int bombs, char bomb, int tempGH, int tempGW, char[][] tempGrid){
for(int i = 0; i < bombs; i++){
int x = 0;
int y = 0;
x = (int) (Math.random() * tempGH);
y = (int) (Math.random() * tempGW);
tempGrid[x][y] = bomb;
}
}
// number generation - needs work
public static void numberGen(int tempGH, int tempGW, char[][] tempGrid){
for(int i = 0; i < tempGH; i++){
for(int l = 0; l < tempGW; l++){
System.out.print(adjacent(i, l, tempGrid) + " ");
}
System.out.println();
}
}
public static int adjacent(int x, int y , char[][] arr){
int adj = 0;
for (int dx = (x > 0 ? -1 : 0); dx < (x < arr.length ? 1 : 0); dx++)
{
for (int dy = (y > 0 ? -1 : 0); dy < (y < arr[0].length ? 1 : 0); dy++)
{
if (dx != 0 || dy != 0)
{
if(arr[x + dx][y + dy] == '+'){
adj++;
}
}
}
}
return adj;
}
// format method for aesthetics/visuals
public static void format(){
for(int i = 0; i <= 25; i++){
System.out.println();
}
}
public static String spacer(int w){
String space = "";
w *= 2;
for(int i = 0; i <= w; i++){
space += '-';
}
return space;
}
}