public void Timer_Elapsed(object source, System.Timers.ElapsedEventArgs e) { if (replay == true) { bs = GetSqureRandom(); bs.InitSqure(); bswait = GetSqureRandom(); bswait.InitSqure(); one = new BaseGround(25, 30); one.bswait = bswait; one.InitBackground(); one.Sum(bs); replay = false; } if (one.AutoChange(bs, 1)) { autodown = true; } if (one.changebool == true) { // Console.WriteLine("切换"); bs = bswait; bswait = GetSqureRandom();//下一个图形 bswait.InitSqure(); one.bswait = bswait; one.RemenberGround(); //记住背景坐标 one.Sum(bs); one.changebool = false; //判断置假 } }
public void Sum(BaseSqure bs) { x = 0; y = 0; for (int i = 0; i < 4; i++)//移动图形坐标 { for (int j = 0; j < 4; j++) { if (bs.str[i, j] == 1) { str[i + 1, 7 + j] = bs.str[i, j]; } } } Print();//填充图形 flag = 0; }
public void StartGame() { bs = GetSqureRandom(); bs.InitSqure(); bswait = GetSqureRandom(); bswait.InitSqure(); one = new BaseGround(25, 30); one.bswait = bswait; one.InitBackground(); one.Sum(bs); keyDownThread = new Thread(KeyDownThread); KeyDown += new KeyDownEventHander(KeyDownEnvent); keyDownThread.Start(); timer = new System.Timers.Timer(1000); //定时器 timer.Elapsed += Timer_Elapsed; timer.Start(); //1s一次 }
public bool AutoChange(BaseSqure bs, int a = 0) { if (flag == 2) { return(true); } else { flag = 1; HistryGround();//背景坐标 /* bs.y += bs.saveY; * bs.x += bs.saveX;*/ for (int i = 0; i < 4; i++)//移动图形坐标 { for (int j = 0; j < 4; j++) { if (bs.str[i, j] == 1) { str[i + 1 + this.x, 7 + j + this.y] = bs.str[i, j]; } } } if (a > 0) { for (int j = 1; j < Y / 2 + 1; j++) { for (int i = X - 2; i > 0; i--) { if (str[i, j] == 1 && str[i + 1, j] != 0) { this.x = 0; this.y = 0; changebool = true; // flag = 0; return(false); } else if (str[i, j] == 1 && str[i + 1, j] == 0) { break; } } } } this.x += a; HistryGround(); //背景坐标 for (int i = 0; i < 4; i++) //移动图形坐标 { for (int j = 0; j < 4; j++) { if (bs.str[i, j] == 1) { str[i + 1 + this.x, 7 + j + this.y] = bs.str[i, j]; } } } /* bs.saveY = 0; * bs.saveX = 0;*/ Print();//填充图形 flag = 0; return(false); } }
public void Change(BaseSqure bs, int a = 0, int b = 0) { if (flag == 1) { return; } else { flag = 2; HistryGround();//背景坐标 /* bs.y += bs.saveY; * bs.x += bs.saveX;*/ for (int i = 0; i < 4; i++)//移动图形坐标 { for (int j = 0; j < 4; j++) { if (bs.str[i, j] == 1) { str[i + 1 + this.x, 7 + j + this.y] = bs.str[i, j]; } } } if (b < 0) { for (int i = 1; i < X - 1; i++) { for (int j = 1; j < Y / 2 + 1; j++) { if (str[i, j] == 1 && str[i, j - 1] != 0) { flag = 0; return; } else if (str[i, j] == 1 && str[i, j - 1] == 0) { break; } } } } if (b > 0) { for (int i = 1; i < X; i++) { for (int j = Y / 2; j > 0; j--) { if (str[i, j] == 1 && str[i, j + 1] != 0) { flag = 0; return; } else if (str[i, j] == 1 && str[i, j + 1] == 0) { break; } } } } if (a > 0) { for (int j = 1; j < Y / 2 + 1; j++) { for (int i = X - 2; i > 0; i--) { if (str[i, j] == 1 && str[i + 1, j] != 0) { changebool = true; flag = 0; return; } else if (str[i, j] == 1 && str[i + 1, j] == 0) { break; } } } } this.x += a; this.y += b; HistryGround(); //背景坐标 for (int i = 0; i < 4; i++) //移动图形坐标 { for (int j = 0; j < 4; j++) { if (bs.str[i, j] == 1) { str[i + 1 + this.x, 7 + j + this.y] = bs.str[i, j]; } } } /* bs.saveY = 0; * bs.saveX = 0;*/ Print();//填充图形 flag = 0; } }