C# Code behind
Min page:<body>
<form id="form1" runat="server">
<div>
<asp:Image runat="server" ID="imgSlot1" />
<asp:Image runat="server" ID="imgSlot2" />
<asp:Image runat="server" ID="imgSlot3" />
</div>
<div>
<asp:Button Text="HOLD" runat="server" ID="btnHold1" onclick="btnHold1_Click"/>
<asp:Button Text="HOLD" runat="server" ID="btnHold2" onclick="btnHold2_Click"/>
<asp:Button Text="HOLD" runat="server" ID="btnHold3" onclick="btnHold3_Click"/>
</div>
<div>
<asp:Label runat="server" ID="lblResult" />
</div>
<div>
<asp:Button Text="Pull" runat="server" ID="btnPull" onclick="btnPull_Click" />
</div>
<div>
Credits:
<asp:Label runat="server" ID="lblCredit" Text="50" />
</div>
</form>
</body>
Dertil har jeg noget Code Behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default6 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnPull_Click(object sender, EventArgs e)
{
int Credits = Convert.ToInt32(lblCredit.Text);
Credits -= 2;
Random r = new Random();
int First = r.Next(1, 6);
int Second = r.Next(1, 6);
int Third = r.Next(1, 6);
if (First == Second && Second == Third)
{
int Reward = 0;
switch (First.ToString())
{
case "1":
Reward = 10;
break;
case "2":
Reward = 30;
break;
case "3":
Reward = 50;
break;
case "4":
Reward = 200;
break;
case "5":
Reward = 100;
break;
default:
break;
}
lblResult.Text = "Du vandt " + Reward.ToString() + " credits!";
Credits = Credits + Reward;
lblCredit.Text = Credits.ToString();
}
imgSlot1.ImageUrl = "~/img/slot" + First + ".png";
imgSlot2.ImageUrl = "~/img/slot" + Second + ".png";
imgSlot3.ImageUrl = "~/img/slot" + Third + ".png";
lblCredit.Text = Credits.ToString();
}
protected void btnHold1_Click(object sender, EventArgs e)
{
}
protected void btnHold2_Click(object sender, EventArgs e)
{
}
protected void btnHold3_Click(object sender, EventArgs e)
{
}
}
Dette er en spillemaskine, hvor der skal være "HOLD" knapper til hhv. Slot1-2-3
Det jeg mangler er bare en måde at få min
"imgSlot1.ImageUrl = "~/img/slot" + First + ".png";"
til at undgå at generere en ny random hvis jeg har presset på "HOLD" knappen.
//Counx