private void timer1_Tick(object sender, EventArgs e) { LoadButton.Enabled = !game.IsActive; if (game.IsDead && !game.IsActive) { GameBox.Paint -= game.PaintOnControl; KeyDown -= game.ReceiveKey; ConfigureGame(game.Clone() as Game); } if (game.IsActive) { game.Tick(); Matrix <double> features = game.GetFeatures(); StringBuilder sb = new StringBuilder(); sb.AppendLine("======Features======"); for (int i = 0; i < features.Cells; i++) { sb.AppendLine($"{features[0, i]}"); } InfoBox.Text = sb.ToString(); if (checkBox1.Checked && loadedModel != null) { loadedModel.Predict(game); } } GameBox.Invalidate(); }
private void Draw() { BeginInvoke((Action)(() => { NetworkBox.Invalidate(); GameBox.Invalidate(); })); }
private void UpdateScreen(object sender, EventArgs e) { if (Settings.GameOver) { if (Input.KeyPressed(Keys.Enter)) { StartGame(); } } else { if (Input.KeyPressed(Keys.Right) && Settings.direction != Direction.Left) { Settings.direction = Direction.Right; } if (Input.KeyPressed(Keys.Up) && Settings.direction != Direction.Down) { Settings.direction = Direction.Up; } if (Input.KeyPressed(Keys.Left) && Settings.direction != Direction.Right) { Settings.direction = Direction.Left; } if (Input.KeyPressed(Keys.Down) && Settings.direction != Direction.Up) { Settings.direction = Direction.Down; } MovePlayer(); } GameBox.Invalidate(); }
private void MessUp_Click(object sender, EventArgs e) { gameStatus = GameStatus.Playing; map.MessUp(); prew = 0; preh = 0; messUpTime--; MessUp.Text = string.Format("打乱({0})", messUpTime); if (messUpTime == 0) { MessUp.Enabled = false; } GameBox.Invalidate(); }
private void Tip_Click(object sender, EventArgs e) { if (map.getTip(out tipaw, out tipah, out tipbw, out tipbh)) { gameStatus = GameStatus.OnHit; preh = 0; prew = 0; tipTime--; Tip.Text = string.Format("提示({0})", tipTime); if (tipTime == 0) { Tip.Enabled = false; } GameBox.Invalidate(); } }
private void update(object state) { Action <string> actionDelegate = (x) => { CountDown.Text = ((int)timeLeft).ToString(); }; CountDown.Invoke(actionDelegate, state); //CountDown.Text = ((int)timeLeft).ToString(); if (gameStatus != GameStatus.Paused) { int t1, t2, t3, t4; if (map.getTip(out t1, out t2, out t3, out t4) == false) { map.MessUp(); GameBox.Invalidate(); } timeLeft -= 0.5; if (timeLeft <= 0) { gameStatus = GameStatus.Fail; Lose(state); } } }
private void Boom(int ww, int hh, int w, int h, Point[] points) { Pen pen = new Pen(Color.Red); Graphics g = GameBox.CreateGraphics(); Image image; SoundPlayer player; player = new SoundPlayer(string.Format("Sound/exp{0}.wav", Ran.Next(1, 3))); player.Play(); for (int i = 1; i <= 6; ++i) { image = (Bitmap)rm.GetObject("B" + i); if (i <= 3) { g.DrawLines(pen, points); } g.DrawImage(image, Block.BlockWidth * ww, Block.BlockHeight * hh, Block.BlockWidth, Block.BlockHeight); g.DrawImage(image, Block.BlockWidth * w, Block.BlockHeight * h, Block.BlockWidth, Block.BlockHeight); Thread.Sleep(100); } GameBox.Invalidate(); }
private void GameBox_MouseClick(object sender, MouseEventArgs e) { gameStatus = GameStatus.Playing; GameBox.Invalidate(); int h = e.Y / Block.BlockHeight; int w = e.X / Block.BlockWidth; int aw, ah, bw, bh; if (map[h, w] == 0) { return; } if (h == preh && w == prew) { preh = 0; prew = 0; } else if (map[preh, prew] == map[h, w] && map.CanLink(prew, preh, w, h, out aw, out ah, out bw, out bh)) { timeLeft += 2; map.BlockNum -= 2; long timeNow = DateTime.Now.Ticks; Console.WriteLine(timeNow); if (timeNow - preHit <= 25000000) { combo++; } else { combo = 1; } preHit = timeNow; maxCombo = Math.Max(maxCombo, combo); // 直连 List <Point> points = new List <Point>(); points.Add(new Point(prew * Block.BlockWidth + Block.BlockWidth / 2, preh * Block.BlockHeight + Block.BlockHeight / 2)); if (aw != -1) { points.Add(new Point(aw * Block.BlockWidth + Block.BlockWidth / 2, ah * Block.BlockHeight + Block.BlockHeight / 2)); } if (bw != -1) { points.Add(new Point(bw * Block.BlockWidth + Block.BlockWidth / 2, bh * Block.BlockHeight + Block.BlockHeight / 2)); } points.Add(new Point(w * Block.BlockWidth + Block.BlockWidth / 2, h * Block.BlockHeight + Block.BlockHeight / 2)); map[preh, prew] = map[h, w] = 0; int hh = preh, ww = prew; // 本来应该写一个类用来保存状态的 但是 一开始不知道 也懒得改了 new Thread(() => Boom(ww, hh, w, h, points.ToArray())).Start(); preh = 0; prew = 0; score += 10; score += combo; Score.Text = score.ToString(); Combo.Text = string.Format("{0}/{1}", combo, maxCombo); //new Thread(PlayComboSound).Start(); PlayComboSound(); if (map.BlockNum == 0) { Win(); } } else { preh = h; prew = w; } GameBox.Invalidate(); }