ストアをフィーチャーしたゲームを作成しています。ボタンが選択されると、購入するために押されたボタンに応じて特定のメッセージが返される必要があります。私は今、以下のコードを持っています。正しいメッセージが返されるようにするにはどうすればよいですか (武器の場合、武器のメッセージ、保護の場合、保護のメッセージ)。
ラジオボタンを1つだけ選択可能にする方法を探していましたが、もっと簡単だと確信しています。ヘルプは本当にありがたいです、ありがとう!
コントローラ:
if (WeaponType != 0) { // buying weapon
if (IsItemAllowed((int)WeaponType, gangster)) {
if (gangster.Cash < WeaponPrice(WeaponType)) {
ViewBag.Message = "You don't have enough cash to buy this weapon";
return View();
}
gangster.Cash -= WeaponPrice(WeaponType);
gangster.Weapon++;
ViewBag.Message = "You have succesfully purchased this weapon";
} else {
ViewBag.Message = "You can't buy this weapon yet";
}
} else if (ProtectionType != 0) { // buying protection
if (IsItemAllowed((int)ProtectionType, gangster)) {
if (gangster.Cash < ProtectionPrice(ProtectionType)) {
ViewBag.Message = "You don't have enough cash to buy this protection";
return View();
}
gangster.Cash -= ProtectionPrice(ProtectionType);
gangster.Protection++;
ViewBag.Message = "You have succesfully purchased this protection";
} else {
ViewBag.Message = "You can't buy this protection yet";
}
}
見る:
<div class="row-fluid" style="margin-top: 20px">
@using (Html.BeginForm("Index")) {
@Html.Button("WeaponType", LocalStoreModel.StoreWeapon.Weapon01, false)@: .38 S&W Model 12<br>
@Html.RadioButton("WeaponType", LocalStoreModel.StoreWeapon.Weapon02, false)@: .45 M1911<br>
@Html.RadioButton("WeaponType", LocalStoreModel.StoreWeapon.Weapon03, false)@: Remington Model 11<br>
@Html.RadioButton("WeaponType", LocalStoreModel.StoreWeapon.Weapon04, false)@: .351 Winchester SL<br>
@Html.RadioButton("WeaponType", LocalStoreModel.StoreWeapon.Weapon05, false)@: Thompson Model 1921 <br>
@Html.RadioButton("WeaponType", LocalStoreModel.StoreWeapon.Weapon06, false)@: Browning Automatic Rifle <br>
@Html.RadioButton("WeaponType", LocalStoreModel.StoreWeapon.Weapon07, false)@: Browning M2<br>
<br>
<input class="btn btn-large btn-primary" type="submit" value="Buy Weapon" />
<br>
@Html.RadioButton("ProtectionType", LocalStoreModel.StoreProtection.Protection01, false)@: Layered Fabric Vest<br>
@Html.RadioButton("ProtectionType", LocalStoreModel.StoreProtection.Protection02, false)@: Metal Plate Vest<br>
@Html.RadioButton("ProtectionType", LocalStoreModel.StoreProtection.Protection03, false)@: Ceramic Plate Vest<br>
@Html.RadioButton("ProtectionType", LocalStoreModel.StoreProtection.Protection04, false)@: Armoured T-Ford<br>
@Html.RadioButton("ProtectionType", LocalStoreModel.StoreProtection.Protection05, false)@: Armored Car (Custom)<br>
<br>
<input class="btn btn-large btn-primary" type="submit" value="Buy Protection" />
<br>
}