コード例 #1
0
        public static void Obstacle_Initialize(Obstacle_Info oe_indo)
        {
            //bmp_id:0 dot树 1 crossbar草丛 2cross山 3around海
            //XYAround 0左上,1右上,2左下,3为右下
            Random rd = new Random();

            if (oe_indo.Around_IF == true)
            {
                for (int i = 0; i < M_x; i++)
                {
                    Coordinate_date[1, i, 0]       = (int)oe_indo.Bmp_ID[3];
                    Coordinate_date[1, i, M_y - 1] = (int)oe_indo.Bmp_ID[3];
                }
                for (int i = 0; i < M_y; i++)
                {
                    Coordinate_date[1, 0, i]       = (int)oe_indo.Bmp_ID[3];
                    Coordinate_date[1, M_x - 1, i] = (int)oe_indo.Bmp_ID[3];
                }
            }
            else
            {
                for (int i = 0; i < oe_indo.XYAround[0]; i++)
                {
                    if (i < M_y)
                    {
                        Coordinate_date[1, 0, i] = (int)oe_indo.Bmp_ID[3];
                    }

                    if (i < M_x)
                    {
                        Coordinate_date[1, i, 0] = (int)oe_indo.Bmp_ID[3];
                    }
                }
                for (int i = 0; i < oe_indo.XYAround[1]; i++)
                {
                    if (i < M_y)
                    {
                        Coordinate_date[1, M_x - 1, i] = (int)oe_indo.Bmp_ID[3];
                    }

                    if (i < M_x)
                    {
                        Coordinate_date[1, M_x - 1 - i, 0] = (int)oe_indo.Bmp_ID[3];
                    }
                }
                for (int i = 0; i < oe_indo.XYAround[2]; i++)
                {
                    if (i < M_y)
                    {
                        Coordinate_date[1, 0, M_y - 1 - i] = (int)oe_indo.Bmp_ID[3];
                    }

                    if (i < M_x)
                    {
                        Coordinate_date[1, i, M_y - 1] = (int)oe_indo.Bmp_ID[3];
                    }
                }
                for (int i = 0; i < oe_indo.XYAround[3]; i++)
                {
                    if (i < M_y)
                    {
                        Coordinate_date[1, M_x - 1, M_y - 1 - i] = (int)oe_indo.Bmp_ID[3];
                    }

                    if (i < M_x)
                    {
                        Coordinate_date[1, M_x - 1 - i, M_y - 1] = (int)oe_indo.Bmp_ID[3];
                    }
                }
            }
            for (int i = 0; i < oe_indo.Cross_Num; i++)
            {
                int x = rd.Next(7, M_x - 7);
                int y = rd.Next(7, M_y - 7);
                for (int a = 0; a < 3; a++)
                {
                    if (Coordinate_date[1, x + a, y] == -1 && Coordinate_date[1, x + a + 1, y] == -1)
                    {
                        Coordinate_date[1, x + a, y] = (int)oe_indo.Bmp_ID[2];
                    }
                    if (Coordinate_date[1, x, y + a] == -1 && Coordinate_date[1, x, y + a + 1] == -1)
                    {
                        Coordinate_date[1, x, y + a] = (int)oe_indo.Bmp_ID[2];
                    }
                    if (Coordinate_date[1, x, y - a] == -1 && Coordinate_date[1, x, y - a - 1] == -1)
                    {
                        Coordinate_date[1, x, y - a] = (int)oe_indo.Bmp_ID[2];
                    }
                    if (Coordinate_date[1, x - a, y] == -1 && Coordinate_date[1, x - a - 1, y] == -1)
                    {
                        Coordinate_date[1, x - a, y] = (int)oe_indo.Bmp_ID[2];
                    }
                }
            }
            for (int i = 0; i < oe_indo.Cross_Bar_Num; i++)
            {
                int x       = rd.Next(7, M_x - 7);
                int y       = rd.Next(7, M_y - 7);
                int pd_flag = rd.Next(1, 1000);
                if (pd_flag < 500)
                {
                    for (int a = 0; a < 5; a++)
                    {
                        if (Coordinate_date[1, x + a, y] == -1 && Coordinate_date[1, x + a + 1, y] == -1)
                        {
                            Coordinate_date[1, x + a, y] = (int)oe_indo.Bmp_ID[1];
                        }
                    }
                }
                else
                {
                    for (int a = 0; a < 5; a++)
                    {
                        if (Coordinate_date[1, x, y + a] == -1 && Coordinate_date[1, x, y + a + 1] == -1)
                        {
                            Coordinate_date[1, x, y + a] = (int)oe_indo.Bmp_ID[1];
                        }
                    }
                }
            }

            for (int i = 0; i < oe_indo.Dor_Num; i++)
            {
                int x = rd.Next(7, M_x - 7);
                int y = rd.Next(7, M_y - 7);
                if (Coordinate_date[1, x, y] == -1)
                {
                    Coordinate_date[1, x, y] = (int)oe_indo.Bmp_ID[0];
                }
            }
        }
コード例 #2
0
        public static void Game_InFo_UpDate(Snake_Info snake, Game_Info info, Food_Info food, Obstacle_Info oe_indo)//游戏信息更新
        {
            X_Y_K xyz;

            xyz = (X_Y_K)Snake_AL[0];
            //bmp_id:0 dot树 1 crossbar草丛 2cross山 3around海
            //XYAround 0左上,1右上,2左下,3为右下

            if (Coordinate_date[1, xyz.X, xyz.Y] != -1) //判断是否碰到障碍物
            {
                if (Coordinate_date[1, xyz.X, xyz.Y] == (int)oe_indo.Bmp_ID[0])
                {
                    snake.PH = snake.PH - 10;
                }
                else if (Coordinate_date[1, xyz.X, xyz.Y] == (int)oe_indo.Bmp_ID[1])
                {
                    snake.PH = snake.PH - 20;
                }
                else if (Coordinate_date[1, xyz.X, xyz.Y] == (int)oe_indo.Bmp_ID[2])
                {
                    snake.PH = snake.PH - 15;
                }
                else if (Coordinate_date[1, xyz.X, xyz.Y] == (int)oe_indo.Bmp_ID[3])
                {
                    snake.PH = snake.PH - 30;
                }
            }
            if (Coordinate_date[2, xyz.X, xyz.Y] != -1)//判断是否碰到蛇身
            {
                snake.PH = snake.PH - 5;
            }
            if (Coordinate_date[3, xyz.X, xyz.Y] != -1) //判断是吃到食物
            {
                Coordinate_date[3, xyz.X, xyz.Y] = -1;
                food.Need_Add();
                info.Game_Mark++;
                snake.WaitAdd_Body++;
                snake.PH = snake.PH + 1;
            }
        }