Ejemplo n.º 1
0
        private void mazesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Chọn mê cung khác sẽ chơi lại từ đầu. Bạn chắc chắn chọn?"
                                , "My Snake", MessageBoxButtons.YesNo, MessageBoxIcon.Warning,
                                MessageBoxDefaultButton.Button1) == DialogResult.Yes)
            {
                OpenFileDialog open = new OpenFileDialog();
                open.Filter = "Level file (*.lev)|*.lev|All file (*.*)|*.*";
                if (open.ShowDialog() == DialogResult.OK)
                {
                    this.Reset();
                    vatCan.Clear(g);
                    vatCan = new Wall();
                    vatCan.ReadFromFile(open.FileName);
                    manHinh = new AI_Snake.Snake.Screen();
                    manHinh.ChangeTypeAll(vatCan.Walls, ScreenType.WALL);
                    manHinh.ChangeTypeAll(conRan.SnakeBody, ScreenType.SNAKE);
                    manHinh.ChangeTypeAll(ranThongMinh.SnakeBody, ScreenType.SNAKE);

                    thucAn.Clear(g);
                    thucAn = new Food();
                    do
                    {
                        thucAn.CreateFood();
                    } while (!manHinh.IsBlank(thucAn.Coordinates));
                    manHinh.ChangeTypeAt(thucAn.Coordinates, ScreenType.FOOD);

                    ranThongMinh.FindPath(thucAn.Coordinates, manHinh);
                    show_button.Text = "Show";

                    vatCan.Draw(g);
                    thucAn.Draw(g);
                }
            }
        }
Ejemplo n.º 2
0
        private void Reset()
        {
            g = panel1.CreateGraphics();

            manHinh = new AI_Snake.Snake.Screen();

            //khởi tạo vật cản
            vatCan = new Wall();
            vatCan.ReadFromFile("level1.lev");
            manHinh.ChangeTypeAll(vatCan.Walls, ScreenType.WALL);

            //khởi tạo con rắn
            conRan = new AI_Snake.Snake.Snake();
            manHinh.ChangeTypeAll(conRan.SnakeBody, ScreenType.SNAKE);
            timer_tocDo.Interval = conRan.Speed;
            timer_tocDo.Enabled  = false;
            camDi = Transfer.UP;

            //khởi tạo rắn thông minh
            ranThongMinh = new SmartSnake(Brushes.Blue, Brushes.LightSalmon, new Point(44, 5));
            manHinh.ChangeTypeAll(ranThongMinh.SnakeBody, ScreenType.SNAKE);
            ranThongMinh.Speed = conRan.Speed;

            //tạo thức ăn
            thucAn = new Food();
            do
            {
                thucAn.CreateFood();
            } while (!manHinh.IsBlank(thucAn.Coordinates));
            manHinh.ChangeTypeAt(thucAn.Coordinates, ScreenType.FOOD);

            //rắn thông minh tìm đường đi
            ranThongMinh.FindPath(thucAn.Coordinates, manHinh);
            show_button.Text = "Show";

            //trang trí
            player_lbl.Text   = "0";
            computer_lbl.Text = "1";

            play_button.Text    = "Play";
            play_button.Enabled = true;

            g.Clear(Color.White);
            vatCan.Draw(g);
            thucAn.Draw(g);
            conRan.Draw(g);
            ranThongMinh.Draw(g);

            gameOver          = false;
            player            = 0;
            computer          = 0;
            player_lbl.Text   = "0";
            computer_lbl.Text = "0";
            tocDo_lbl.Text    = "100";

            //âm thanh
            nhacnen = new SoundPlayer(@"nhac nen.wav");
            //nhacRanMay = new SoundPlayer(@"Sound\ran may.wav");
            //nhacRanNguoiChoi = new SoundPlayer(@"Sound\ran nguoi choi.wav");
            nhacnen.Stop();
        }