Exemplo n.º 1
0
        //后退
        //将前面的走法存到一个栈里面;
        private void button3_Click(object sender, EventArgs e)
        {
            g_manager.keyDownOrreStep = false;
            if (g_manager.G_oldStep.Count > 0)
            {
                BackStep     oldStep = g_manager.G_oldStep.Pop();
                Keys         key     = (Keys)Enum.ToObject(typeof(Keys), oldStep.keyDown);
                KeyEventArgs ke      = new KeyEventArgs(key);
                g_manager.RoleTryTo(ke);

                g_manager.G_map.LogicMap[oldStep.curentLocation.X + oldStep.direct.Y
                                         , oldStep.curentLocation.Y + oldStep.direct.X] = oldStep.targetState;
                try
                {
                    g_manager.G_map.LogicMap[oldStep.curentLocation.X + oldStep.direct.Y * 2
                                             , oldStep.curentLocation.Y + oldStep.direct.X * 2] = oldStep.target_targetState;
                }
                catch (Exception)
                {
                }
            }
            //还原前一步的画布
            MapFactory.CreaImgByArray(g_manager.G_map, g_manager.G_map.LogicMap, g_manager.CurentBmp);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 目标位置可以到达,绘出相应的图片
        /// </summary>
        /// <param name="xx"></param>
        /// <param name="yy"></param>
        /// <param name="targetState"></param>
        /// <param name="direct"></param>
        public void DrawToCurentBmp(int xx, int yy, MapState targetState, Point direct)
        {
            //上一步的信息
            BackStep oldStep = new BackStep();

            oldStep.curentLocation = this.g_curentRolePosition;
            oldStep.keyDown        = g_keyDown;
            oldStep.targetState    = (char)targetState;
            oldStep.direct         = dir;
            //数组可能越界
            try
            {
                oldStep.target_targetState = g_map.LogicMap[xx + direct.Y * 2, yy + direct.X * 2];
            }
            catch (Exception)
            {
            }

            Bitmap   orImg   = g_map.Road;
            MapState orState = MapState.road;

            //判断当前位置的状态是否为‘^’
            if (g_map.LogicMap[xx, yy] == (char)MapState.target_role)
            {
                orImg   = g_map.Tatget;
                orState = MapState.target;
            }

            if (targetState == MapState.road)//路
            {
                //原始位置
                g_gra.DrawImage(orImg, yy * g_gezi, xx * g_gezi, g_gezi, g_gezi);
                //目标位置
                g_gra.DrawImage(g_map.Role, (yy + direct.X) * g_gezi, (xx + direct.Y) * g_gezi, g_gezi, g_gezi);
                _control.CreateGraphics().DrawImage(g_curentBmp, _control.ClientRectangle);
                //panel1.Invalidate();
                g_map.LogicMap[xx, yy] = (char)orState;
                g_map.LogicMap[xx + direct.Y, yy + direct.X] = (char)MapState.role;
                //改变角色所在位置;
                g_curentRolePosition = new Point(xx + direct.Y, yy + direct.X);
            }
            if (targetState == MapState.target)
            {
                g_gra.DrawImage(orImg, yy * g_gezi, xx * g_gezi, g_gezi, g_gezi);
                g_gra.DrawImage(g_map.Role, (yy + direct.X) * g_gezi, (xx + direct.Y) * g_gezi, g_gezi, g_gezi);
                _control.CreateGraphics().DrawImage(g_curentBmp, _control.ClientRectangle);
                //panel1.Invalidate();
                g_map.LogicMap[xx, yy] = (char)orState;
                g_map.LogicMap[xx + direct.Y, yy + direct.X] = (char)MapState.target_role;//
                g_curentRolePosition = new Point(xx + direct.Y, yy + direct.X);
            }
            if (targetState == MapState.box)
            {
                //越界
                try
                {
                    if (g_map.LogicMap[xx + direct.Y * 2, yy + direct.X * 2] == (char)MapState.wall)
                    {
                        return;
                    }
                }
                catch (Exception)
                {
                    return;
                }


                MapState nextNextState = MapState.box;
                //箱子到达的位置是目标位置;
                if (g_map.LogicMap[xx + direct.Y * 2, yy + direct.X * 2] == (char)MapState.target)
                {
                    nextNextState = MapState.taget_box;
                }

                g_gra.DrawImage(orImg, yy * g_gezi, xx * g_gezi, g_gezi, g_gezi);
                g_gra.DrawImage(g_map.Role, (yy + direct.X) * g_gezi, (xx + direct.Y) * g_gezi, g_gezi, g_gezi);
                g_gra.DrawImage(g_map.Box, (yy + direct.X * 2) * g_gezi, (xx + direct.Y * 2) * g_gezi, g_gezi, g_gezi);
                g_map.LogicMap[xx, yy] = (char)orState;
                g_map.LogicMap[xx + direct.Y, yy + direct.X]         = (char)MapState.role;
                g_map.LogicMap[xx + direct.Y * 2, yy + direct.X * 2] = (char)nextNextState;
                g_curentRolePosition = new Point(xx + direct.Y, yy + direct.X);
                _control.CreateGraphics().DrawImage(g_curentBmp, _control.ClientRectangle);
                //panel1.Invalidate();
            }
            if (targetState == MapState.taget_box)
            {
                try
                {
                    if (g_map.LogicMap[xx + direct.Y * 2, yy + direct.X * 2] == (char)MapState.wall)
                    {
                        return;
                    }
                }
                catch (Exception)
                {
                    return;
                }


                MapState nextNextState = MapState.box;
                //箱子到达的位置是目标位置;
                if (g_map.LogicMap[xx + direct.Y * 2, yy + direct.X * 2] == (char)MapState.target)
                {
                    nextNextState = MapState.taget_box;
                }


                g_gra.DrawImage(orImg, yy * g_gezi, xx * g_gezi, g_gezi, g_gezi);
                g_gra.DrawImage(g_map.Role, (yy + direct.X) * g_gezi, (xx + direct.Y) * g_gezi, g_gezi, g_gezi);
                g_gra.DrawImage(g_map.Box, (yy + direct.X * 2) * g_gezi, (xx + direct.Y * 2) * g_gezi, g_gezi, g_gezi);
                g_map.LogicMap[xx, yy] = (char)orState;
                //这里角色和目标重合
                g_map.LogicMap[xx + direct.Y, yy + direct.X] = (char)MapState.target_role;

                g_map.LogicMap[xx + direct.Y * 2, yy + direct.X * 2] = (char)nextNextState;
                g_curentRolePosition = new Point(xx + direct.Y, yy + direct.X);
                _control.CreateGraphics().DrawImage(g_curentBmp, _control.ClientRectangle);
                //panel1.Invalidate();
            }
            //用户按下按钮记录步数
            if (keyDownOrreStep)
            {
                g_oldStep.Push(oldStep);
            }
        }