Example #1
0
        private void TmControl_Tick(object sender, EventArgs e)
        {
            tmControl.Stop();
            tmControl.Interval = _snake.Speed;

            _snake = MapHelper.MoveSnakeOnMap(palMap, _map, _snake, _direction);

            if (ConfigHelper.SnakeClimbNum == 0)
            {
                _map = MapHelper.ShowBonus(palMap, _map, _snake, ConfigHelper.BeanColor);
            }
            else if (ConfigHelper.SnakeClimbNum == ConfigHelper.BeanShowTime)
            {
                _map = MapHelper.HideBonus(palMap, _map);
                ConfigHelper.SnakeClimbNum = -1;
            }

            ConfigHelper.SnakeClimbNum++;

            ConfigHelper.i_playtime++;
            if (ConfigHelper.i_playtime == 500)
            {
                MessageBox.Show("Hi,young man, too long you have played !");
                ConfigHelper.i_playtime = 0;
            }



            tmControl.Start();
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="panel"></param>
        /// <param name="map"></param>
        /// <param name="snake"></param>
        /// <returns></returns>
        public static ModelMapSnake DrawSnakeOnMap(Panel panel, ModelMap map, ModelMapSnake snake)
        {
            snake = GenSnakeOnMap(map, snake);
            foreach (var b in snake.Body)
            {
                DrawMapBox(panel, snake.Color, b.Abscissa, b.Ordinate, map.Box.Width, map.Box.Height);
            }


            return(snake);
        }
Example #3
0
        public static ModelMap ShowBonus(Panel panel, ModelMap map, ModelMapSnake snake, Color color)
        {
            var b = NewBonus(map.Row - 1, map.Column - 1);

            while (snake.Body.Count(s => s.Equals(b)) > 0)
            {
                b = NewBonus(map.Row - 1, map.Column - 1);
            }
            var m = map.Body.SingleOrDefault(t => t.Abscissa == b.Abscissa && t.Ordinate == b.Ordinate);

            if (m != null)
            {
                //DrawMapBox(panel, color, m.Abscissa, m.Ordinate, map.Box.Width, map.Box.Height);
                DrawMapBean(panel, color, m.Abscissa, m.Ordinate, map.Box.Width, map.Box.Height);
                m.Bean = true;
            }
            return(map);
        }
Example #4
0
        /// <summary>
        /// using a grid (two groups of coordinate) represents a body of snake
        /// </summary>
        /// <param name="map"></param>
        /// <param name="snake"></param>
        /// <returns></returns>
        public static ModelMapSnake GenSnakeOnMap(ModelMap map, ModelMapSnake snake)
        {
            var sk      = snake;
            var centerX = map.Row / 2;
            var centerY = map.Column / 2;

            sk.Body = new List <ModelElement>
            {
                new ModelElement
                {
                    Abscissa = centerX,
                    Ordinate = centerY
                },
                new ModelElement
                {
                    Abscissa = centerX,
                    Ordinate = centerY - 1
                }
            };
            return(sk);
        }
Example #5
0
        private void BtnIniSnake_Click_1(object sender, EventArgs e)
        {
            if (ConfigHelper.b_debug)
            {
                MessageBox.Show("snake");
            }

            if (b_initSnake && b_startMove)
            {
                return;
            }

            if (!b_initMap)
            {
                MessageBox.Show("There is no Map, Please click initMap firstly");
                return;
            }
            b_initSnake = true;


            _snake     = MapHelper.GenSnake(ConfigHelper.Speed, ConfigHelper.SnakeColor);
            _snake     = MapHelper.DrawSnakeOnMap(palMap, _map, _snake);
            _direction = _snake.Direction;
        }
Example #6
0
        /// <summary>
        /// 蛇身在移动图上移动  moving snake
        /// </summary>
        /// <param name="panel"></param>
        /// <param name="map"></param>
        /// <param name="snake"></param>
        /// <param name="direction"></param>
        /// <param name="enableBack"></param>
        /// <param name="dead"></param>
        /// <returns></returns>
        public static ModelMapSnake MoveSnakeOnMap(Panel panel, ModelMap map, ModelMapSnake snake, ModelEnum.Direction direction)
        {
            if (direction.Equals(ModelEnum.Direction.Up) && snake.Direction.Equals(ModelEnum.Direction.Down))
            {
                direction = snake.Direction;
            }
            else if (direction.Equals(ModelEnum.Direction.Down) && snake.Direction.Equals(ModelEnum.Direction.Up))
            {
                direction = snake.Direction;
            }
            else if (direction.Equals(ModelEnum.Direction.Left) && snake.Direction.Equals(ModelEnum.Direction.Right))
            {
                direction = snake.Direction;
            }
            else if (direction.Equals(ModelEnum.Direction.Right) && snake.Direction.Equals(ModelEnum.Direction.Left))
            {
                direction = snake.Direction;
            }


            var head = new ModelElement
            {
                Abscissa = snake.Body[0].Abscissa,
                Ordinate = snake.Body[0].Ordinate
            };

            switch (direction)
            {
            case ModelEnum.Direction.Left:
                head.Abscissa--;
                break;

            case ModelEnum.Direction.Right:
                head.Abscissa++;
                break;

            case ModelEnum.Direction.Up:
                head.Ordinate--;
                break;

            case ModelEnum.Direction.Down:
                head.Ordinate++;
                break;
            }
            if (head.Abscissa < 0)
            {
                head.Abscissa = map.Column - 1;
            }
            else if (head.Abscissa == map.Column)
            {
                head.Abscissa = 0;
            }
            if (head.Ordinate < 0)
            {
                head.Ordinate = map.Row - 1;
            }
            else if (head.Ordinate == map.Row)
            {
                head.Ordinate = 0;
            }



            var tail = snake.Body[snake.Body.Count - 1];
            var m    = map.Body.SingleOrDefault(t => t.Bean && t.Abscissa == tail.Abscissa && t.Ordinate == tail.Ordinate);

            if (m == null)
            {
                DrawMapBox(panel, map.Color, tail.Abscissa, tail.Ordinate, map.Box.Width, map.Box.Height);
                snake.Body.Remove(tail);
            }
            else
            {
                DrawMapBox(panel, snake.Color, head.Abscissa, head.Ordinate, map.Box.Width, map.Box.Height);
                m.Bean = false;
                //eat bean...
                //length of snake
                ConfigHelper.lengthSnake = snake.Body.Count();
            }

            DrawMapBox(panel, snake.Color, head.Abscissa, head.Ordinate, map.Box.Width, map.Box.Height);
            snake.Body.Insert(0, head);
            snake.Direction = direction;

            return(snake);
        }