Esempio n. 1
0
        private void tmr_Tick(object sender, EventArgs e)
        {
            this.Invalidate();
            if (this.Handle != GetForegroundWindow()) //持续使该窗体置为最前,屏蔽该行则单次置顶
            {
                SetForegroundWindow(this.Handle);
            }

            if (MainWays.IsEaten(snakes, f))
            {
                replayfoods = true;
            }

            if (MainWays.IsOver(snakes, this.Size))
            {
                tmr.Enabled = !tmr.Enabled;
                SoundPlayer sp = new SoundPlayer(Properties.Resources.game_over);
                sp.Play();
                if (MessageBox.Show("你是否再来一局!", "游戏结束", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                {
                    InitiSnake();
                }
                else
                {
                    Application.Exit();
                }
            }
        }
Esempio n. 2
0
 private void InitiSnake()
 {
     snakes.Clear();
     ocus.Clear();
     Snake.S     = null;
     replayfoods = true;
     foreach (Snake s in MainWays.InitiSnakes(new Point(600, 240), 10))
     {
         snakes.Add(s);
     }
     rand        = new Random();
     f           = new Foods(this.Size, rand);
     tmr.Enabled = true;
     //SoundPlayer sp = new SoundPlayer(Properties.Resources.gamebg);
     //sp.Play();
 }