コード例 #1
0
        private void HireFire(object sender, System.EventArgs e)
        {
            if (selectedCrewMember != null && btnHireFire.Visible)
            {
                if (game.Commander.Ship.HasCrew(selectedCrewMember.Id))
                {
                    if (FormAlert.Alert(AlertType.CrewFireMercenary, this, selectedCrewMember.Name) == DialogResult.Yes)
                    {
                        game.Commander.Ship.Fire(selectedCrewMember.Id);

                        UpdateAll();
                        game.ParentWindow.UpdateAll();
                    }
                }
                else
                {
                    if (game.Commander.Ship.FreeCrewQuarters == 0)
                    {
                        FormAlert.Alert(AlertType.CrewNoQuarters, this, selectedCrewMember.Name);
                    }
                    else
                    {
                        game.Commander.Ship.Hire(selectedCrewMember);

                        UpdateAll();
                        game.ParentWindow.UpdateAll();
                    }
                }
            }
        }
コード例 #2
0
        public static bool SaveFile(string fileName, object toSerialize, System.Windows.Forms.IWin32Window owner)
        {
            FileStream outStream = null;
            bool       saveOk    = false;

            try
            {
                outStream = new FileStream(fileName, FileMode.Create);
                (new BinaryFormatter()).Serialize(outStream, toSerialize);

                outStream.Close();
                outStream = null;

                saveOk = true;
            }
            catch (IOException ex)
            {
                FormAlert.Alert(AlertType.FileErrorSave, owner, fileName, ex.Message);
            }
            finally
            {
                if (outStream != null)
                {
                    outStream.Close();
                }
            }

            return(saveOk);
        }
コード例 #3
0
		private void Sell()
		{
			if (selectedEquipment != null && sellSideSelected)
			{
				if (FormAlert.Alert(AlertType.EquipmentSell, this) == DialogResult.Yes)
				{
					// The slot is the selected index. Two of the three list boxes will have selected indices of -1, so adding
					// 2 to the total cancels those out.
					int				slot	= lstSellWeapon.SelectedIndex + lstSellShield.SelectedIndex + lstSellGadget.SelectedIndex + 2;
					Commander	cmdr	= game.Commander;

					if (selectedEquipment.EquipmentType == EquipmentType.Gadget &&
						(((Gadget)selectedEquipment).Type == GadgetType.ExtraCargoBays ||
						((Gadget)selectedEquipment).Type == GadgetType.HiddenCargoBays) &&
						cmdr.Ship.FreeCargoBays < 5)
					{
						FormAlert.Alert(AlertType.EquipmentExtraBaysInUse, this);
					}
					else
					{
						cmdr.Cash	+= selectedEquipment.SellPrice;
						cmdr.Ship.RemoveEquipment(selectedEquipment.EquipmentType, slot);

						UpdateSell();
						game.ParentWindow.UpdateAll();
					}
				}
			}
		}
コード例 #4
0
		private void Buy()
		{
			if (selectedEquipment != null && !sellSideSelected)
			{
				Commander			cmdr			= game.Commander;
				EquipmentType	baseType	= selectedEquipment.EquipmentType;

				if (baseType == EquipmentType.Gadget && cmdr.Ship.HasGadget(((Gadget)selectedEquipment).Type) &&
					((Gadget)selectedEquipment).Type != GadgetType.ExtraCargoBays)
					FormAlert.Alert(AlertType.EquipmentAlreadyOwn, this);
				else if (cmdr.Debt > 0)
					FormAlert.Alert(AlertType.DebtNoBuy, this);
				else if (selectedEquipment.Price > cmdr.CashToSpend)
					FormAlert.Alert(AlertType.EquipmentIF, this);
				else if ((baseType == EquipmentType.Weapon && cmdr.Ship.FreeSlotsWeapon == 0) ||
					(baseType == EquipmentType.Shield && cmdr.Ship.FreeSlotsShield == 0) ||
					(baseType == EquipmentType.Gadget && cmdr.Ship.FreeSlotsGadget == 0))
					FormAlert.Alert(AlertType.EquipmentNotEnoughSlots, this);
				else if (FormAlert.Alert(AlertType.EquipmentBuy, this, selectedEquipment.Name,
					Functions.FormatNumber(selectedEquipment.Price)) == DialogResult.Yes)
				{
					cmdr.Ship.AddEquipment(selectedEquipment);
					cmdr.Cash	-= selectedEquipment.Price;

					DeselectAll();
					UpdateSell();
					game.ParentWindow.UpdateAll();
				}
			}
		}
コード例 #5
0
ファイル: Form_Options.cs プロジェクト: jatrocha/SpaceTrader
        public FormOptions()
        {
            InitializeComponent();

            if (game != null)
            {
                Options.CopyValues(game.Options);
            }
            else
            {
                Options.LoadFromDefaults(false, this);
                btnOk.Enabled = false;
                FormAlert.Alert(AlertType.OptionsNoGame, this);
            }

            UpdateAll();
        }
コード例 #6
0
        private void btnPayBack_Click(object sender, System.EventArgs e)
        {
            if (cmdr.Debt == 0)
            {
                FormAlert.Alert(AlertType.DebtNone, this);
            }
            else
            {
                FormPayBackLoan form = new FormPayBackLoan();
                if (form.ShowDialog(this) == DialogResult.OK)
                {
                    cmdr.Cash -= form.Amount;
                    cmdr.Debt -= form.Amount;

                    UpdateAll();
                    game.ParentWindow.UpdateAll();
                }
            }
        }
コード例 #7
0
        private void btnGetLoan_Click(object sender, System.EventArgs e)
        {
            if (cmdr.Debt >= MaxLoan)
            {
                FormAlert.Alert(AlertType.DebtTooLargeLoan, this);
            }
            else
            {
                FormGetLoan form = new FormGetLoan(MaxLoan - cmdr.Debt);
                if (form.ShowDialog(this) == DialogResult.OK)
                {
                    cmdr.Cash += form.Amount;
                    cmdr.Debt += form.Amount;

                    UpdateAll();
                    game.ParentWindow.UpdateAll();
                }
            }
        }
コード例 #8
0
        public FormShipList()
        {
            InitializeComponent();

            #region Array of controls
            lblPrice = new Label[]
            {
                lblPrice0,
                lblPrice1,
                lblPrice2,
                lblPrice3,
                lblPrice4,
                lblPrice5,
                lblPrice6,
                lblPrice7,
                lblPrice8,
                lblPrice9,
            };

            btnBuy = new Button[]
            {
                btnBuy0,
                btnBuy1,
                btnBuy2,
                btnBuy3,
                btnBuy4,
                btnBuy5,
                btnBuy6,
                btnBuy7,
                btnBuy8,
                btnBuy9,
            };
            #endregion

            UpdateAll();
            Info((int)game.Commander.Ship.Type);

            if (game.Commander.Ship.Tribbles > 0 && !game.TribbleMessage)
            {
                FormAlert.Alert(AlertType.TribblesTradeIn, this);
                game.TribbleMessage = true;
            }
        }
コード例 #9
0
        private void btnBuyInsurance_Click(object sender, System.EventArgs e)
        {
            if (cmdr.Insurance)
            {
                if (FormAlert.Alert(AlertType.InsuranceStop, this) == DialogResult.Yes)
                {
                    cmdr.Insurance = false;
                    cmdr.NoClaim   = 0;
                }
            }
            else if (!cmdr.Ship.EscapePod)
            {
                FormAlert.Alert(AlertType.InsuranceNoEscapePod, this);
            }
            else
            {
                cmdr.Insurance = true;
                cmdr.NoClaim   = 0;
            }

            UpdateAll();
            game.ParentWindow.UpdateAll();
        }
コード例 #10
0
        public static object LoadFile(string fileName, bool ignoreMissingFile, System.Windows.Forms.IWin32Window owner)
        {
            object     obj      = null;
            FileStream inStream = null;

            try
            {
                inStream = new FileStream(fileName, FileMode.Open);
                obj      = (new BinaryFormatter()).Deserialize(inStream);
                inStream.Close();
                inStream = null;
            }
            catch (FileNotFoundException ex)
            {
                if (!ignoreMissingFile)
                {
                    FormAlert.Alert(AlertType.FileErrorOpen, owner, fileName, ex.Message);
                }
            }
            catch (IOException ex)
            {
                FormAlert.Alert(AlertType.FileErrorOpen, owner, fileName, ex.Message);
            }
            catch (System.Runtime.Serialization.SerializationException)
            {
                FormAlert.Alert(AlertType.FileErrorOpen, owner, fileName, Strings.FileFormatBad);
            }
            finally
            {
                if (inStream != null)
                {
                    inStream.Close();
                }
            }

            return(obj);
        }
コード例 #11
0
        public bool TradeShip(ShipSpec specToBuy, int netPrice, string newShipName, IWin32Window owner)
        {
            bool traded = false;

            if (netPrice > 0 && Debt > 0)
            {
                FormAlert.Alert(AlertType.DebtNoBuy, owner);
            }
            else if (netPrice > CashToSpend)
            {
                FormAlert.Alert(AlertType.ShipBuyIF, owner);
            }
            else if (specToBuy.CrewQuarters < Ship.SpecialCrew.Length)
            {
                string passengers = Ship.SpecialCrew[1].Name;
                if (Ship.SpecialCrew.Length > 2)
                {
                    passengers += " and " + Ship.SpecialCrew[2].Name;
                }

                FormAlert.Alert(AlertType.ShipBuyPassengerQuarters, owner, passengers);
            }
            else if (specToBuy.CrewQuarters < Ship.CrewCount)
            {
                FormAlert.Alert(AlertType.ShipBuyCrewQuarters, owner);
            }
            else if (Ship.ReactorOnBoard)
            {
                FormAlert.Alert(AlertType.ShipBuyReactor, owner);
            }
            else
            {
                Equipment[] special = new Equipment[]
                {
                    Consts.Weapons[(int)WeaponType.MorgansLaser],
                    Consts.Weapons[(int)WeaponType.QuantumDistruptor],
                    Consts.Shields[(int)ShieldType.Lightning],
                    Consts.Gadgets[(int)GadgetType.FuelCompactor],
                    Consts.Gadgets[(int)GadgetType.HiddenCargoBays]
                };
                bool[] add       = new bool[special.Length];
                bool   addPod    = false;
                int    extraCost = 0;

                for (int i = 0; i < special.Length; i++)
                {
                    if (Ship.HasEquipment(special[i]))
                    {
                        if (specToBuy.Slots(special[i].EquipmentType) == 0)
                        {
                            FormAlert.Alert(AlertType.ShipBuyNoSlots, owner, newShipName, special[i].Name,
                                            Strings.EquipmentTypes[(int)special[i].EquipmentType]);
                        }
                        else
                        {
                            extraCost += special[i].TransferPrice;
                            add[i]     = true;
                        }
                    }
                }

                if (Ship.EscapePod)
                {
                    addPod     = true;
                    extraCost += Consts.PodTransferCost;
                }

                if (netPrice + extraCost > CashToSpend)
                {
                    FormAlert.Alert(AlertType.ShipBuyIFTransfer, owner);
                }

                extraCost = 0;

                for (int i = 0; i < special.Length; i++)
                {
                    if (add[i])
                    {
                        if (netPrice + extraCost + special[i].TransferPrice > CashToSpend)
                        {
                            FormAlert.Alert(AlertType.ShipBuyNoTransfer, owner, special[i].Name);
                        }
                        else if (FormAlert.Alert(AlertType.ShipBuyTransfer, owner, special[i].Name, special[i].Name.ToLower(),
                                                 Functions.FormatNumber(special[i].TransferPrice)) == DialogResult.Yes)
                        {
                            extraCost += special[i].TransferPrice;
                        }
                        else
                        {
                            add[i] = false;
                        }
                    }
                }

                if (addPod)
                {
                    if (netPrice + extraCost + Consts.PodTransferCost > CashToSpend)
                    {
                        FormAlert.Alert(AlertType.ShipBuyNoTransfer, owner, Strings.ShipInfoEscapePod);
                    }
                    else if (FormAlert.Alert(AlertType.ShipBuyTransfer, owner, Strings.ShipInfoEscapePod,
                                             Strings.ShipInfoEscapePod.ToLower(), Functions.FormatNumber(Consts.PodTransferCost)) == DialogResult.Yes)
                    {
                        extraCost += Consts.PodTransferCost;
                    }
                    else
                    {
                        addPod = false;
                    }
                }

                if (FormAlert.Alert(AlertType.ShipBuyConfirm, owner, Ship.Name, newShipName,
                                    (add[0] || add[1] || add[2] || addPod ? Strings.ShipBuyTransfer : "")) == DialogResult.Yes)
                {
                    CrewMember[] oldCrew = Ship.Crew;

                    Ship  = new Ship(specToBuy.Type);
                    Cash -= (netPrice + extraCost);

                    for (int i = 0; i < Math.Min(oldCrew.Length, Ship.Crew.Length); i++)
                    {
                        Ship.Crew[i] = oldCrew[i];
                    }

                    for (int i = 0; i < special.Length; i++)
                    {
                        if (add[i])
                        {
                            Ship.AddEquipment(special[i]);
                        }
                    }

                    if (addPod)
                    {
                        Ship.EscapePod = true;
                    }
                    else if (Insurance)
                    {
                        Insurance = false;
                        NoClaim   = 0;
                    }

                    traded = true;
                }
            }

            return(traded);
        }
コード例 #12
0
 private void btnTestAlert_Click(object sender, System.EventArgs e)
 {
     FormAlert.Alert(AlertType.Alert, this, "Result", "The result was " +
                     FormAlert.Alert((AlertType)selAlertType.SelectedItem,
                                     this, txtValue1.Text, txtValue2.Text, txtValue3.Text).ToString());
 }