图像不显示

时间:2011-02-27 21:04:40

标签: c#

我希望你能帮助我!我正在尝试制作类似于candyland的游戏。我想在用户点击按钮时旋转模具。选择一个随机数,并根据该数字,骰子显示该数字的图像。这样可行!然后,我希望我们的用户能够在我们的电路板上向前移动 - 基于它们所在的位置,它添加了它们旋转的任何内容,并且该点上的图像变得可见。在调试模式下,一切都很完美,但由于某种原因,pawn永远不会移动!你能告诉我为什么吗?我在下面附上我的代码。非常感谢你!

protected void btnSpin_Click(object sender, EventArgs e)
    {
        Random randomNumber = new Random();
        int x = randomNumber.Next(1, 6);
        switch (x)
        {
            case 1:
                //imgDie.ImageUrl = "~/Images/dice1.jpg";
                Session["Die"] = "~/Images/dice1.jpg";
                break;
            case 2:
                Session["Die"] = "~/Images/dice2.jpg";
                break;
            case 3:
                Session["Die"] = "~/Images/dice3.jpg";
                break;
            case 4:
                Session["Die"] = "~/Images/dice4.jpg";
                break;
            case 5:
                Session["Die"] = "~/Images/dice5.jpg";
                break;
            case 6:
                Session["Die"] = "~/Images/dice6.jpg";
                break;
        }
        imgDie.ImageUrl = (string)Session["Die"];

        place = place + x;
        switch (place)
        {
            case 2:
                img2.Visible = true;
                img2.ImageUrl = (string)Session["Imagesrc"];

                break;
            case 3:
                img3.Visible = true;
                img3.ImageUrl = (string)Session["Imagesrc"];
                break;
            case 4:
                img4.Visible = true;
                img4.ImageUrl = (string)Session["Imagesrc"];

                break;
            case 5:
                img5.Visible = true;
                img5.ImageUrl = (string)Session["Imagesrc"];

                break;
            case 6:
                img6.Visible = true;
                img6.ImageUrl = (string)Session["Imagesrc"];

                break;
            case 7:
                img7.Visible = true;
                img7.ImageUrl = (string)Session["Imagesrc"];

                break;
            case 8:
                img8.ImageUrl = (string)Session["Imagesrc"];
                img8.Visible = true;
                break;

1 个答案:

答案 0 :(得分:0)

我的猜测是你的'place'变量是一个成员字段,它正在重新初始化每个页面结构。将您的地方变量变为视图状态或会话状态,就像其他东西一样。