Skip to content

Commit f4a0116

Browse files
committed
improved display
1 parent dedec37 commit f4a0116

File tree

2 files changed

+34
-33
lines changed

2 files changed

+34
-33
lines changed

15-Connect-Four-Game/script.js

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -158,24 +158,24 @@ function makeMove(button, buttonNo) {
158158

159159
}
160160
function colorButton(points) {
161-
var i = [];
162-
points.forEach(function (point) {
163-
i.push([toBtNo(point[0], point[1] - 1), point[2]]);
164-
})
165-
for (var j = 0; j < buttons.length; j++) {
166-
var mark = false;
167-
i.forEach(element => {
168-
if (element[0] === j) {
169-
buttons[j].innerHTML = element[1];
170-
buttons[j].style.color = "red";
171-
mark = true;
172-
}
173-
});
174-
if (!mark) {
175-
buttons[j].innerHTML = "";
176-
buttons[j].style.color = "transparent";
177-
}
178-
}
161+
// var i = [];
162+
// points.forEach(function (point) {
163+
// i.push([toBtNo(point[0], point[1] - 1), point[2]]);
164+
// })
165+
// for (var j = 0; j < buttons.length; j++) {
166+
// var mark = false;
167+
// i.forEach(element => {
168+
// if (element[0] === j) {
169+
// buttons[j].innerHTML = element[1];
170+
// buttons[j].style.color = "red";
171+
// mark = true;
172+
// }
173+
// });
174+
// if (!mark) {
175+
// buttons[j].innerHTML = "";
176+
// buttons[j].style.color = "transparent";
177+
// }
178+
// }
179179

180180
}
181181
var winMethod = 0;
@@ -517,6 +517,16 @@ function PCMove() {
517517
makeMove(buttons[r * columns + c], r * columns + c + 1);
518518
availableMoves = [];
519519
return;
520+
}else{
521+
for (var r = 0; r < rows; r++) {
522+
for (var c = 0; c < columns; c++) {
523+
if(filledGrid[r][c] === -1){
524+
makeMove(buttons[r * columns + c], r * columns + c + 1);
525+
availableMoves = [];
526+
return;
527+
}
528+
}
529+
}
520530
}
521531
availableMoves = [];
522532
}

15-Connect-Four-Game/style.css

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,29 +92,26 @@ fieldset {
9292
height: 80vmin;
9393
display: flex;
9494
flex-direction: column;
95-
justify-content: space-between;
95+
justify-content: stretch;
9696
}
9797

98-
/* Grid Row */
9998
.row {
10099
display: flex;
101-
justify-content: space-between;
102-
height: calc((80vmin - 6px - 12px) / 6); /* Subtracting padding and gaps */
100+
flex-grow: 1;
101+
margin: 0 -1px; /* 负边距可以帮助处理间隙问题 */
103102
}
104103

105-
/* Grid Column */
106104
.col {
105+
display: flex;
106+
flex-grow: 1;
107107
align-items: center;
108+
justify-content: center;
108109
background-color: #d5deff;
109110
border: 1px solid #4f3ff0;
110111
border-radius: 5px;
111-
display: flex;
112-
justify-content: center;
113-
width: calc((80vmin - 6px - 12px) / 7); /* Subtracting padding and gaps */
114112
margin: 1px;
115113
}
116114

117-
/* Buttons */
118115
.btn {
119116
background-color: transparent;
120117
border: none;
@@ -147,21 +144,15 @@ fieldset {
147144
/* Player - 1 Buttons */
148145
.btn-player-1 {
149146
background-color: #34c471;
150-
border: 2px solid #34c471;
151147
border-radius: 50%;
152148
color: red;
153-
height: 80%;
154-
width: 80%;
155149
}
156150

157151
/* Player - 2 Buttons */
158152
.btn-player-2 {
159153
background-color: #df3670;
160-
border: 2px solid #df3670;
161154
border-radius: 50%;
162155
color: red;
163-
height: 80%;
164-
width: 80%;
165156
}
166157

167158
/* Media Queries */

0 commit comments

Comments
 (0)