1+ using System ;
2+ using System . Drawing ;
3+ using System . Windows . Forms ;
4+
5+ namespace WinFormsApp1 . Controls
6+ {
7+ public partial class CharacterStatsControl : UserControl
8+ {
9+ private TableLayoutPanel statsLayout ;
10+ private Label levelValueLabel ;
11+ private Label goldValueLabel ;
12+ private Label attackValueLabel ;
13+ private Label defenseValueLabel ;
14+ private Label expValueLabel ;
15+ private Label classValueLabel ;
16+ private Label weaponValueLabel ;
17+ private Label armorValueLabel ;
18+
19+ public CharacterStatsControl ( )
20+ {
21+ InitializeComponent ( ) ;
22+ }
23+
24+ private void InitializeComponent ( )
25+ {
26+ this . Size = new Size ( 300 , 250 ) ;
27+ this . BackColor = Color . Transparent ;
28+
29+ // Create scrollable panel for stats
30+ Panel scrollablePanel = new Panel
31+ {
32+ Dock = DockStyle . Fill ,
33+ AutoScroll = true ,
34+ BorderStyle = BorderStyle . None
35+ } ;
36+
37+ // Create stats layout
38+ statsLayout = new TableLayoutPanel
39+ {
40+ AutoSize = true ,
41+ AutoSizeMode = AutoSizeMode . GrowAndShrink ,
42+ ColumnCount = 2 ,
43+ RowCount = 8 ,
44+ Location = new Point ( 0 , 0 ) ,
45+ Padding = new Padding ( 5 )
46+ } ;
47+
48+ // Set column styles
49+ statsLayout . ColumnStyles . Add ( new ColumnStyle ( SizeType . AutoSize ) ) ;
50+ statsLayout . ColumnStyles . Add ( new ColumnStyle ( SizeType . AutoSize ) ) ;
51+
52+ CreateStatLabels ( ) ;
53+ AddLabelsToLayout ( ) ;
54+
55+ scrollablePanel . Controls . Add ( statsLayout ) ;
56+ this . Controls . Add ( scrollablePanel ) ;
57+ }
58+
59+ private void CreateStatLabels ( )
60+ {
61+ // Level
62+ var levelLabel = new Label { Text = "Level:" , AutoSize = true , Margin = new Padding ( 2 ) } ;
63+ levelValueLabel = new Label { Text = "1" , AutoSize = true , Font = new Font ( "Arial" , 8 , FontStyle . Bold ) , Margin = new Padding ( 2 ) } ;
64+
65+ // Gold
66+ var goldLabel = new Label { Text = "Gold:" , AutoSize = true , Margin = new Padding ( 2 ) } ;
67+ goldValueLabel = new Label { Text = "50" , AutoSize = true , Font = new Font ( "Arial" , 8 , FontStyle . Bold ) , ForeColor = Color . Goldenrod , Margin = new Padding ( 2 ) } ;
68+
69+ // Attack
70+ var attackLabel = new Label { Text = "Attack:" , AutoSize = true , Margin = new Padding ( 2 ) } ;
71+ attackValueLabel = new Label { Text = "15" , AutoSize = true , Font = new Font ( "Arial" , 8 , FontStyle . Bold ) , ForeColor = Color . Red , Margin = new Padding ( 2 ) } ;
72+
73+ // Defense
74+ var defenseLabel = new Label { Text = "Defense:" , AutoSize = true , Margin = new Padding ( 2 ) } ;
75+ defenseValueLabel = new Label { Text = "8" , AutoSize = true , Font = new Font ( "Arial" , 8 , FontStyle . Bold ) , ForeColor = Color . Blue , Margin = new Padding ( 2 ) } ;
76+
77+ // Experience
78+ var expLabel = new Label { Text = "Exp:" , AutoSize = true , Margin = new Padding ( 2 ) } ;
79+ expValueLabel = new Label { Text = "0" , AutoSize = true , Font = new Font ( "Arial" , 8 , FontStyle . Bold ) , ForeColor = Color . Purple , Margin = new Padding ( 2 ) } ;
80+
81+ // Class
82+ var classLabel = new Label { Text = "Class:" , AutoSize = true , Margin = new Padding ( 2 ) } ;
83+ classValueLabel = new Label { Text = "Warrior" , AutoSize = true , Font = new Font ( "Arial" , 8 , FontStyle . Bold ) , ForeColor = Color . DarkGreen , Margin = new Padding ( 2 ) } ;
84+
85+ // Weapon
86+ var weaponLabel = new Label { Text = "Weapon:" , AutoSize = true , Margin = new Padding ( 2 ) } ;
87+ weaponValueLabel = new Label { Text = "None" , AutoSize = true , Font = new Font ( "Arial" , 8 , FontStyle . Bold ) , ForeColor = Color . DarkOrange , Margin = new Padding ( 2 ) } ;
88+
89+ // Armor
90+ var armorLabel = new Label { Text = "Armor:" , AutoSize = true , Margin = new Padding ( 2 ) } ;
91+ armorValueLabel = new Label { Text = "None" , AutoSize = true , Font = new Font ( "Arial" , 8 , FontStyle . Bold ) , ForeColor = Color . DarkCyan , Margin = new Padding ( 2 ) } ;
92+ }
93+
94+ private void AddLabelsToLayout ( )
95+ {
96+ statsLayout . Controls . Add ( new Label { Text = "Level:" , AutoSize = true , Margin = new Padding ( 2 ) } , 0 , 0 ) ;
97+ statsLayout . Controls . Add ( levelValueLabel , 1 , 0 ) ;
98+
99+ statsLayout . Controls . Add ( new Label { Text = "Gold:" , AutoSize = true , Margin = new Padding ( 2 ) } , 0 , 1 ) ;
100+ statsLayout . Controls . Add ( goldValueLabel , 1 , 1 ) ;
101+
102+ statsLayout . Controls . Add ( new Label { Text = "Attack:" , AutoSize = true , Margin = new Padding ( 2 ) } , 0 , 2 ) ;
103+ statsLayout . Controls . Add ( attackValueLabel , 1 , 2 ) ;
104+
105+ statsLayout . Controls . Add ( new Label { Text = "Defense:" , AutoSize = true , Margin = new Padding ( 2 ) } , 0 , 3 ) ;
106+ statsLayout . Controls . Add ( defenseValueLabel , 1 , 3 ) ;
107+
108+ statsLayout . Controls . Add ( new Label { Text = "Exp:" , AutoSize = true , Margin = new Padding ( 2 ) } , 0 , 4 ) ;
109+ statsLayout . Controls . Add ( expValueLabel , 1 , 4 ) ;
110+
111+ statsLayout . Controls . Add ( new Label { Text = "Class:" , AutoSize = true , Margin = new Padding ( 2 ) } , 0 , 5 ) ;
112+ statsLayout . Controls . Add ( classValueLabel , 1 , 5 ) ;
113+
114+ statsLayout . Controls . Add ( new Label { Text = "Weapon:" , AutoSize = true , Margin = new Padding ( 2 ) } , 0 , 6 ) ;
115+ statsLayout . Controls . Add ( weaponValueLabel , 1 , 6 ) ;
116+
117+ statsLayout . Controls . Add ( new Label { Text = "Armor:" , AutoSize = true , Margin = new Padding ( 2 ) } , 0 , 7 ) ;
118+ statsLayout . Controls . Add ( armorValueLabel , 1 , 7 ) ;
119+ }
120+
121+ public void UpdateStats ( Player player )
122+ {
123+ if ( player == null ) return ;
124+
125+ levelValueLabel . Text = player . Level . ToString ( ) ;
126+ goldValueLabel . Text = player . Gold . ToString ( ) ;
127+ attackValueLabel . Text = player . GetTotalAttack ( ) . ToString ( ) ;
128+ defenseValueLabel . Text = player . GetTotalDefense ( ) . ToString ( ) ;
129+ expValueLabel . Text = $ "{ player . Experience } /{ player . ExperienceToNextLevel } ";
130+ classValueLabel . Text = player . CharacterClass . ToString ( ) ;
131+ weaponValueLabel . Text = player . EquippedWeapon ? . Name ?? "None" ;
132+ armorValueLabel . Text = player . EquippedArmor ? . Name ?? "None" ;
133+ }
134+
135+ public void ClearStats ( )
136+ {
137+ levelValueLabel . Text = "-" ;
138+ goldValueLabel . Text = "-" ;
139+ attackValueLabel . Text = "-" ;
140+ defenseValueLabel . Text = "-" ;
141+ expValueLabel . Text = "-" ;
142+ classValueLabel . Text = "-" ;
143+ weaponValueLabel . Text = "None" ;
144+ armorValueLabel . Text = "None" ;
145+ }
146+ }
147+ }
0 commit comments