private void test(def.coordinate t) { if (nowa.x == -1 && nowa.y == -1) { nowa = t; addblackbackgroundimage(t.x * def.MAXEDGE + t.y, llk.getMap(t.x, t.y)); } else if (nowb.x == -1 && nowb.y == -1) { nowb = t; if (llk.delete(nowa, nowb)) { btnMap[nowa.x * def.MAXEDGE + nowa.y].Visible = false; btnMap[nowb.x * def.MAXEDGE + nowb.y].Visible = false; llk.addscore(); lblscore.Text = llk.getscore().ToString(); // to add Win; if (llk.getscore() == 320) { timer1.Enabled = false; StreamWriter pass = new StreamWriter("g_llk.dat"); pass.Close(); MessageBox.Show("你顺利地通过了此关^_^"); btnGameStart.Visible = true; } } btnMap[nowa.x * def.MAXEDGE + nowa.y].Enabled = true; btnMap[nowb.x * def.MAXEDGE + nowb.y].Enabled = true; addbackgroundimage(nowa.x * def.MAXEDGE + nowa.y, llk.getMap(nowa.x, nowa.y)); nowa.x = -1; nowa.y = -1; nowb.x = -1; nowb.y = -1; } }
public bool delete(def.coordinate a, def.coordinate b) { if (map[a.x, a.y] != map[b.x, b.y]) return false; def.queue[] que = new def.queue[def.MAXEDGE * def.MAXEDGE * 4]; def.coordinate c; int[,,] mark = new int[def.MAXEDGE, def.MAXEDGE, 4]; int f, r, i, j, k; int tmp; tmp = map[b.x, b.y]; map[b.x, b.y] = 0; for (i = 0; i < def.MAXEDGE; i++) for (j = 0; j < def.MAXEDGE; j++) for (k = 0; k < 4; k++) { mark[i, j, k] = 1; } f = 0; r = 0; for (i = 0; i < 4; i++) { c.x = a.x + move[i, 0]; c.y = a.y + move[i, 1]; if (c.x < 0 || c.y < 0 || c.x >= def.MAXEDGE || c.y >= def.MAXEDGE) continue; if (map[c.x, c.y] != 0) continue; mark[c.x, c.y, i] = 0; que[r].place = c; que[r].direct = i; que[r].turn = 0; r++; } while (f != r) { for (i = 0; i < 4; i++) { c.x = que[f].place.x + move[i, 0]; c.y = que[f].place.y + move[i, 1]; if (c.x < 0 || c.y < 0 || c.x >= def.MAXEDGE || c.y >= def.MAXEDGE) continue; if (mark[c.x, c.y, i] == 0) continue; if (map[c.x, c.y] != 0) continue; if (que[f].direct != i && que[f].turn == 2) continue; mark[c.x, c.y, i] = 0; que[r].place = c; que[r].direct = i; que[r].turn = que[f].turn; if (que[f].direct != i) que[r].turn++; r++; } f++; } for (k = 0; k < 4; k++) if (mark[b.x, b.y, k] == 0) { map[a.x, a.y] = 0; map[b.x, b.y] = 0; return true; } map[b.x, b.y] = tmp; return false; }