-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShopForm.cs
142 lines (138 loc) · 4.63 KB
/
ShopForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Space_Conqueror
{
public partial class ShopForm : Form
{
PlayingForm PForm;
Weapon? Weapon;
Armor? Armor;
public ShopForm(PlayingForm pform)
{
InitializeComponent();
CenterFormToScreen();
PForm = pform;
DefineSW();
DefineSA();
DefineSD();
this.BackColor = pform.BackColor;
this.ForeColor = pform.ForeColor;
sfpdl.ForeColor = pform.pfdl.ForeColor;
sfwb.BackColor = pform.pffb.BackColor;
sfpb.BackColor = pform.pffb.BackColor;
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
PForm.UpdatePlayingFormLabels();
}
protected void CenterFormToScreen()
{
Screen screen = Screen.FromControl(this);
Rectangle workingArea = screen.WorkingArea;
this.Location = new Point(
Math.Max(workingArea.X, workingArea.X + (workingArea.Width - this.Width) / 2),
Math.Max(workingArea.Y, workingArea.Y + (workingArea.Height - this.Height) / 2)
);
}
private void sfwb_Click(object sender, EventArgs e)
{
if (Weapon != null && PForm.P.Dollars >= Weapon.Price)
{
PForm.P.Dollars -= Weapon.Price;
PForm.P.PShip.EquipWeapon(Weapon);
DefineSW();
DefineSD();
this.Enabled = false;
MessageBox.Show("Thank You For Your Purchase!");
this.Enabled = true;
}
else
{
this.Enabled = false;
MessageBox.Show("You Can't Afford That!");
this.Enabled = true;
}
}
private void sfpb_Click(object sender, EventArgs e)
{
if (Armor != null && PForm.P.Dollars >= Armor.Price)
{
PForm.P.Dollars -= Armor.Price;
PForm.P.PShip.EquipArmor(Armor);
DefineSA();
DefineSD();
this.Enabled = false;
MessageBox.Show("Thank You For Your Purchase!");
this.Enabled = true;
} else
{
this.Enabled = false;
MessageBox.Show("You Can't Afford That!");
this.Enabled = true;
}
}
private void DefineSW()
{
int i;
for (i = 0; i < 10; i++)
{
if (Program.Weapons[i].Id > PForm.P.PShip.Arm.Id)
{
sfwpb.Image = Program.Weapons[i].PNG;
sfwnl.Text = Program.Weapons[i].Name;
sfwpl.Text = String.Format("{0:C}", Program.Weapons[i].Price);
sfdl.Text = Program.Weapons[i].Dam.ToString("N0");
Weapon = Program.Weapons[i];
break;
}
}
if (i == 10)
{
sfwpb.Image = Properties.Resources.NoItemWeapon;
sfwnl.Text = "Bought Out!";
sfwpl.Text = "null";
sfdl.Text = "null";
Weapon = null;
sfwb.Hide();
}
return;
}
private void DefineSA()
{
int i;
for (i = 0; i < 10; i++)
{
if (Program.Armors[i].Id > PForm.P.PShip.Plate.Id)
{
sfppb.Image = Program.Armors[i].PNG;
sfpnl.Text = Program.Armors[i].Name;
sfppl.Text = String.Format("{0:C}", Program.Armors[i].Price);
sfpl.Text = Program.Armors[i].Plating.ToString("N0");
Armor = Program.Armors[i];
break;
}
}
if(i==10)
{
sfppb.Image = Properties.Resources.NoItemArmor;
sfpnl.Text = "Bought Out!";
sfppl.Text = "null";
sfpl.Text = "null";
Armor = null;
sfpb.Hide();
}
return;
}
private void DefineSD()
{
sfpdl.Text = String.Format("{0:C}", PForm.P.Dollars);
}
}
}