-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrid.java
More file actions
198 lines (176 loc) · 4.21 KB
/
Copy pathGrid.java
File metadata and controls
198 lines (176 loc) · 4.21 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
public class Grid {
private int size;
private int numColors;
private MyNode start;
public Grid(int size, int numColors){
this.size = size;
this.numColors = numColors;
this.start = new MyNode("black");
}
public Grid(int size, int numColors, MyNode start){
this.size = size;
this.numColors = numColors;
this.start = start;
}
public Grid sameGrid(Grid grid){
int size = grid.getSize();
int numColors = grid.getNumColors();
MyNode otherStart = grid.getStartNode();
MyNode secondStart = grid.getStartNode();
MyNode start = new MyNode(otherStart.getData());
MyNode topCorner = start;
for(int i = 0; i < size; i++){
MyNode current = start;
for(int j = 0; j < size; j++){
MyNode node = new MyNode(otherStart.getNext().getData());
current.setNext(node);
node.setPrev(current);
current = node;
otherStart = otherStart.getNext();
}
MyNode downNode = new MyNode(secondStart.getDown().getData());
start.setDown(downNode);
downNode.setUp(start);
start = downNode;
otherStart = secondStart.getDown();
secondStart = otherStart;
}
MyNode starty = topCorner;
int count = 0;
for(int i = 0; i < size-1; i++){
MyNode curr = starty;
MyNode currDown = starty.getDown();
for(int j = 0; j < size-1; j++){
count++;
System.out.println(count);
curr.getNext().setDown(currDown.getNext());
currDown.getNext().setUp(curr.getNext());
curr = curr.getNext();
currDown = currDown.getNext();
}
starty = starty.getDown();
}
return new Grid(size, numColors, topCorner);
}
public void createGrid(){
MyNode other = start;
for(int i = 0; i < size; i++){
MyNode current = other;
for(int j = 0; j < size; j++){
MyNode node = new MyNode(generateColor());
current.setNext(node);
node.setPrev(current);
current = node;
}
MyNode downNode = new MyNode(generateColor());
other.setDown(downNode);
downNode.setUp(other);
other = downNode;
}
MyNode starty = start;
int count = 0;
for(int i = 0; i < size-1; i++){
MyNode curr = starty;
MyNode currDown = starty.getDown();
for(int j = 0; j < size-1; j++){
count++;
System.out.println(count);
curr.getNext().setDown(currDown.getNext());
currDown.getNext().setUp(curr.getNext());
curr = curr.getNext();
currDown = currDown.getNext();
}
starty = starty.getDown();
}
}
public void changeSize(int size){
this.size = size;
MyNode other = start;
for(int i = 0; i < size; i++){
MyNode current = other;
for(int j = 0; j < size; j++){
MyNode node = new MyNode(generateColor());
current.setNext(node);
node.setPrev(current);
current = node;
}
MyNode downNode = new MyNode(generateColor());
other.setDown(downNode);
downNode.setUp(other);
other = downNode;
}
}
public void changeNumColors(int numColors){
this.numColors = numColors;
MyNode other = start;
for(int i = 0; i < size; i++){
MyNode current = other;
for(int j = 0; j < size; j++){
MyNode node = new MyNode(generateColor());
current.setNext(node);
node.setPrev(current);
current = node;
}
MyNode downNode = new MyNode(generateColor());
other.setDown(downNode);
downNode.setUp(other);
other = downNode;
}
}
public MyNode getStartNode(){
return start;
}
public int getSize(){
return size;
}
public int getNumColors(){
return numColors;
}
public String firstLine(){
String toReturn = "";
MyNode other = start;
for(int i = 0; i < size; i++){
toReturn += other.toString();
other = other.getNext();
}
return toReturn;
}
public String toString(){
String toReturn = "";
MyNode other = start;
for(int i = 0; i < size; i++){
MyNode current = other;
for(int j = 0; j < size; j++){
toReturn += " " + current.toString();
current = current.getNext();
}
toReturn += "\n";
other = other.getDown();
}
return toReturn;
}
public String generateColor(){
double random = Math.random() * numColors;
String color = "";
if(random < 1){
color = "red";
} else if(random < 2){
color = "green";
} else if(random < 3){
color = "blue";
} else if(random < 4){
color = "magenta";
} else if(random < 5){
color = "cyan";
} else if(random < 6){
color = "yellow";
} else if(random < 7){
color = "gray";
} else if(random < 8){
color = "orange";
} else if(random < 9){
color = "pink";
}
return color;
}
}