课上无聊和OS.Giftia用C艹写了一个(简易的)1010!游戏。
还是一个简单的程序,每次有三个选项,可以放到8×8大小的棋盘上。
但是判断机制应该是完美无缺了(我觉得),所以里面的一些东西也许对你们有用(我希望)。
不管怎样,反正是无聊的时候写的,所以别指望啥升级之类的东西。
源码如下:
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 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
#include <iostream> #include <cstring> #include <algorithm> #include <time.h> using namespace std; bool become[10][10]; bool image[3][3]; bool gameOver = false; bool ifCanPut(bool image[3][3]) { for (int i = 0; i < 6; ++i) { for (int j = 0; j < 6; ++j) { if (become[i][j] == 1) { continue; } bool fault = false; for (int a = 0; a < 3; ++a) { for (int b = 0; b < 3; ++b) { if (become[i + a][j + b] == 1 && image[a][b] == 1) { fault = true; break; } } if (fault) { break; } } if (fault) { continue; } return true; } } return false; } void show() { bool canPutFinal = false; bool imagetemp[3][3][3]; srand((unsigned)time(NULL)); for (int cnt = 0; cnt < 3; ++cnt) { for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { int sec = rand() % 2; imagetemp[cnt][i][j] = sec; } } bool image_decide[3][3]; memset(image_decide, 0, sizeof(image_decide)); int x = 0,y = 0; for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { if (imagetemp[cnt][i][j] == 0) { continue; } else if (imagetemp[cnt][i][j] == 1) { image_decide[x][y++] = imagetemp[cnt][i][j]; } } y = 0; x++; } memset(imagetemp[cnt], 0, sizeof(imagetemp[cnt])); x = 0; y = 0; for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { if (image_decide[j][i] == 0) { continue; } else if (image_decide[j][i] == 1) { imagetemp[cnt][y++][x] = image_decide[j][i]; } } y = 0; x++; } if (ifCanPut(imagetemp[cnt])) { canPutFinal = true; } } cout << "No.1: No.2: No.3:" << endl; for (int i = 0; i < 3; ++i) { for (int pri = 0; pri < 3; ++pri) { for (int j = 0; j < 3; ++j) { if (imagetemp[pri][i][j] == 1) { cout << "* "; } else if (imagetemp[pri][i][j] == 0) { cout << " "; } } cout << " "; } cout << endl; } cout << endl; if (!canPutFinal) { gameOver = true; return ; } int select; cout << "Please enter your select image: "; cin >> select; memset(image, false, sizeof(image)); memcpy(image, imagetemp[select - 1], sizeof(imagetemp[select - 1])); return ; } void checkDisap() { for (int i = 0; i < 8; ++i) { bool flag = true; if (become[i][0] == 1) { for (int a = 0; a < 8; ++a) { if (become[i][a] != 1) { flag = false; break; } } if (flag == true) { for (int a = 0; a < 8; ++a) { become[i][a] = 0; } } } } for (int i = 0; i < 8; ++i) { bool flag = true; if (become[0][i] == 1) { for (int a = 0; a < 8; ++a) { if (become[a][i] != 1) { flag = false; break; } } if (flag == true) { for (int a = 0; a < 8; ++a) { become[a][i] = 0; } } } } } bool singleCanPut(int x, int y, bool image[3][3]) { for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { if (become[x + i][y + j] == 1 && image[i][j] == 1) { return false; } } } return true; } void printSurface() { system("cls"); cout << " 0 1 2 3 4 5 6 7" << endl; for (int i = 0; i < 8; ++i) { cout << i << " "; for (int j = 0; j < 8; ++j) { if (become[i][j] == 0) { cout << ". "; } else { cout << "# "; } } cout << endl; } cout << endl << endl; return ; } void setSurface(int x, int y, bool image[3][3]) { for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { if(image[i][j] == 1) { become[x + i][y + j] = 1; } } } return ; } int main() { printSurface(); show(); enter: cout << "Please enter the left corner coordinate (e.g. 0 0):"; int x, y; cin >> x >> y; for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { if ((x + i > 7 && image[i][j] == 1) || (y + j > 7 && image[i][j] == 1)) { cout << "You have entered a wrong coordinate!" << endl; goto enter; } } } if (!singleCanPut(x, y, image)) { cout << "You can't put it there!" << endl; goto enter; } run: setSurface(x, y, image); printSurface(); checkDisap(); printSurface(); show(); if (gameOver) { goto end; } goto enter; end: cout << "Game Over!" << endl; return 0; } |
●▽●
=w=
小u小u
求友链~
https://blog.zhouys.ac.cn
欸,网站上没有东西啊……
博客文章被我清了呢…现在改用Ghost了~
没有缩进?