//Constructors public Merchant(string name, Texture2D cardTexture, Texture2D cardBack, Dictionary <string, Button> buttons, Dictionary <string, Texture2D> dieTextures) : base(name, cardTexture, cardBack, buttons) { merchantTurnState = new MerchantTurnState(); CurrentButtons = new List <Button>(); }
//---------------------- METHODS ----------------------------- /// <summary> /// NEED TO ADD SPELL CODE LATER /// </summary> /// <param name="player"></param> /// <returns></returns> public override bool HandleCard(Player player, MouseState current, MouseState previous, float xPos, float yPos) { XPos = xPos; YPos = yPos; CurrentMouseState = current; PreviousMouseState = previous; switch (merchantTurnState) { case MerchantTurnState.BUYSELL: LoadMerchantButtons(); HandleButtons(player); return(false); case MerchantTurnState.INSUFFICENTFUNDS: //Thread.Sleep(500); merchantTurnState = MerchantTurnState.BUYSELL; return(false); case MerchantTurnState.BUYSPELL: LoadSpellsButtons(); HandleButtons(player); return(false); case MerchantTurnState.SELLSPELL: LoadSpellsButtons(); HandleButtons(player); return(false); case MerchantTurnState.CONFIRMBUY: HandleButtons(player); if (player.Gold < 0) { return(true); } else { return(false); } case MerchantTurnState.CONFIRMSELL: HandleButtons(player); return(false); case MerchantTurnState.COMPLETE: return(true); default: return(false); } }
/// <summary> /// Handle Buttons Method /// </summary> /// <param name="player"></param> public void HandleButtons(Player player) { // If player clicks left mouse button. if (SingleMouseClick()) { switch (merchantTurnState) { // ------- BUY / SELL STATE ------- case MerchantTurnState.BUYSELL: if (XPos > 770 && XPos < 1018 && YPos > 600 && YPos < 672) { merchantTurnState = MerchantTurnState.COMPLETE; } if (XPos > 600 && XPos < 848 && YPos > 150 && YPos < 222) { if (player.Food < 6 && player.Gold >= 1) { Selection = "Buy Ration"; merchantTurnState = MerchantTurnState.CONFIRMBUY; } } if (XPos > 600 && XPos < 848 && YPos > 230 && YPos < 302) { if (player.Health < 20 && player.Gold >= 1) { Selection = "Buy Potion"; merchantTurnState = MerchantTurnState.CONFIRMBUY; } } if (XPos > 600 && XPos < 848 && YPos > 310 && YPos < 382) { if (player.Health < 20 && player.Gold >= 3) { Selection = "Buy Big Potion"; merchantTurnState = MerchantTurnState.CONFIRMBUY; } } if (XPos > 600 && XPos < 848 && YPos > 390 && YPos < 462) { if (player.Armor < 5 && player.Gold >= 6) { Selection = "Buy Armor"; merchantTurnState = MerchantTurnState.CONFIRMBUY; } } if (XPos > 600 && XPos < 848 && YPos > 470 && YPos < 542) { if (player.Gold >= 8 && player.Spells.Count < 2) { merchantTurnState = MerchantTurnState.BUYSPELL; } } if (XPos > 900 && XPos < 1148 && YPos > 150 && YPos < 222) { if (player.Armor > 0) { Selection = "Sell Armor"; merchantTurnState = MerchantTurnState.CONFIRMSELL; } } if (XPos > 900 && XPos < 1148 && YPos > 230 && YPos < 302) { if (player.Spells.Count > 0) { merchantTurnState = MerchantTurnState.SELLSPELL; } } break; // ------- CONFIRM BUY STATE ------- case MerchantTurnState.CONFIRMBUY: if (XPos > 600 && XPos < 850 && YPos > 420 && YPos < 490) { switch (Selection) { case "Buy Ration": if (player.SpendGold(1)) { player.Food++; merchantTurnState = MerchantTurnState.BUYSELL; } else { merchantTurnState = MerchantTurnState.INSUFFICENTFUNDS; } break; case "Buy Potion": if (player.SpendGold(1)) { player.Health++; merchantTurnState = MerchantTurnState.BUYSELL; } else { merchantTurnState = MerchantTurnState.INSUFFICENTFUNDS; } break; case "Buy Big Potion": if (player.SpendGold(3)) { player.Health += 4; merchantTurnState = MerchantTurnState.BUYSELL; } else { merchantTurnState = MerchantTurnState.INSUFFICENTFUNDS; } break; case "Buy Armor": if (player.SpendGold(6)) { player.Armor += 1; merchantTurnState = MerchantTurnState.BUYSELL; } else { merchantTurnState = MerchantTurnState.INSUFFICENTFUNDS; } break; case "Buy Fire Spell": if (player.SpendGold(8)) { player.AddSpell("Fire"); merchantTurnState = MerchantTurnState.BUYSELL; } else { merchantTurnState = MerchantTurnState.INSUFFICENTFUNDS; } break; case "Buy Ice Spell": if (player.SpendGold(8)) { player.AddSpell("Ice"); merchantTurnState = MerchantTurnState.BUYSELL; } else { merchantTurnState = MerchantTurnState.INSUFFICENTFUNDS; } break; case "Buy Poison Spell": if (player.SpendGold(8)) { player.AddSpell("Poison"); merchantTurnState = MerchantTurnState.BUYSELL; } else { merchantTurnState = MerchantTurnState.INSUFFICENTFUNDS; } break; case "Buy Healing Spell": if (player.SpendGold(8)) { player.AddSpell("Healing"); merchantTurnState = MerchantTurnState.BUYSELL; } else { merchantTurnState = MerchantTurnState.INSUFFICENTFUNDS; } break; default: break; } } if (XPos > 890 && XPos < 1138 && YPos > 420 && YPos < 490) { merchantTurnState = MerchantTurnState.BUYSELL; } break; // ------- BUY SPELL STATE ------- case MerchantTurnState.BUYSPELL: if (XPos > 770 && XPos < 1018 && YPos > 200 && YPos < 272) { Selection = "Buy Fire Spell"; merchantTurnState = MerchantTurnState.CONFIRMBUY; } if (XPos > 770 && XPos < 1018 && YPos > 280 && YPos < 352) { Selection = "Buy Ice Spell"; merchantTurnState = MerchantTurnState.CONFIRMBUY; } if (XPos > 770 && XPos < 1018 && YPos > 360 && YPos < 432) { Selection = "Buy Poison Spell"; merchantTurnState = MerchantTurnState.CONFIRMBUY; } if (XPos > 770 && XPos < 1018 && YPos > 440 && YPos < 512) { Selection = "Buy Healing Spell"; merchantTurnState = MerchantTurnState.CONFIRMBUY; } if (XPos > 770 && XPos < 1018 && YPos > 600 && YPos < 672) { merchantTurnState = MerchantTurnState.BUYSELL; } break; // ------- SELL SPELL STATE ------- // if there is no second spell but someone clicks the x&y space an out of bounds exception exists case MerchantTurnState.SELLSPELL: if (player.Spells.Count >= 1) { if (XPos > 1130 && XPos < 1175 && YPos > 20 && YPos < 65) { SpellIndex = 0; merchantTurnState = MerchantTurnState.CONFIRMSELL; Selection = "Sell Spell"; } } if (player.Spells.Count == 2) { if (XPos > 1180 && XPos < 1225 && YPos > 20 && YPos < 65) { SpellIndex = 1; merchantTurnState = MerchantTurnState.CONFIRMSELL; Selection = "Sell Spell"; } } //if (XPos > 1130 && XPos < 1175 && YPos > 20 && YPos < 65) //{ // SpellIndex = 0; // merchantTurnState = MerchantTurnState.CONFIRMSELL; // Selection = "Sell Spell"; //} //if (player.Spells.Count == 2) //{ // if (XPos > 1180 && XPos < 1225 && YPos > 20 && YPos < 65) // { // SpellIndex = 1; // merchantTurnState = MerchantTurnState.CONFIRMSELL; // Selection = "Sell Spell"; // } //} break; // ------- CONFIRM SALE STATE ------- case MerchantTurnState.CONFIRMSELL: if (XPos > 600 && XPos < 850 && YPos > 420 && YPos < 490) { switch (Selection) { case "Sell Armor": if (player.RemoveArmor()) { player.Gold += 3; merchantTurnState = MerchantTurnState.BUYSELL; } else { merchantTurnState = MerchantTurnState.INSUFFICENTFUNDS; } break; case "Sell Spell": player.RemoveSpell(SpellIndex); player.Gold += 4; merchantTurnState = MerchantTurnState.BUYSELL; break; } } if (XPos > 890 && XPos < 1138 && YPos > 420 && YPos < 490) { merchantTurnState = MerchantTurnState.BUYSELL; } break; // ------- COMPLETE ------- case MerchantTurnState.COMPLETE: break; default: break; } } }