2011-02-27 248 views
0

我希望你能幫助我!我正在嘗試製作一個類似於Candyland的遊戲。當用戶點擊按鈕時,我希望模具旋轉。選擇一個隨機數並根據該數字,骰子顯示該數字的圖像。這樣可行!然後,我希望我們的用戶能夠在我們的電路板上前進 - 基於他們所在的位置,它添加他們旋轉的任何東西,並且該位置上的圖像變得可見。在調試模式下,一切正常,但由於某種原因,棋子不會移動!你能告訴我爲什麼。我在下面附上我的代碼。非常感謝!圖片不顯示

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

什麼是Session [「Imagesrc」]? – 2011-02-27 21:08:53

+0

你在使用什麼框架? – Mark 2011-02-27 21:24:33

回答

0

我的猜測是你的'地方'變量是一個成員字段,它正在與每個頁面構造重新初始化。 chnge你的地方變量是viewstate或會話狀態像你的其他東西。