19/09/12 6:51
Fharamir
Salve a tutti,
ho creato un progetto in C# di un software per il gioco da tavolo di D&D (Dungeons & Dragons).
Il progetto è finito e lo sto postando qui per poter avere qualche consiglio sulle soluzioni scelte e la qualità del codice.
Il software serve all'organizzatore del gioco (Dungeon Master) per organizzare gli incontri e/o scontri all'interno di una partita. Il Master potrà preparare anticipatamente le schede dei personaggi su un file .xls
e il programma leggerà il file e visualizzerà le schede con un minimo di interfaccia grafica.
Vi posto il codice:
Form1.cs
Classe DataOrganizer.cs:
Classe Carta.cs
Grazie in anticipo per qualsiasi consiglio
ho creato un progetto in C# di un software per il gioco da tavolo di D&D (Dungeons & Dragons).
Il progetto è finito e lo sto postando qui per poter avere qualche consiglio sulle soluzioni scelte e la qualità del codice.
Il software serve all'organizzatore del gioco (Dungeon Master) per organizzare gli incontri e/o scontri all'interno di una partita. Il Master potrà preparare anticipatamente le schede dei personaggi su un file .xls
e il programma leggerà il file e visualizzerà le schede con un minimo di interfaccia grafica.
Vi posto il codice:
Form1.cs
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace MonsterOrganizer { public partial class Form1 : Form { DataOrganizer DO; public Form1() { InitializeComponent(); } private void esciToolStripMenuItem_Click(object sender, EventArgs e) { this.Close(); } //Evento legato alla voce del menu: Carica File //Da questo evento inizia tutta la procedura del caricamento dati e della visualizzazione private void caricaFileToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog D = new OpenFileDialog(); D.Filter = "File Excel (.xls)|*.xls"; DialogResult result = D.ShowDialog(); if (result == DialogResult.OK) if (!DO.Load(D.FileName, this)) MessageBox.Show("Errore nel file selzionato. Seleziona un altro File"); else { DO.AddControls(this); } } private void Form1_Load(object sender, EventArgs e) { DO = new DataOrganizer(); } //Semplici MessageBox per visualizzare risposte a possibili FAQ //Vedi Menu -> Help per le domande private void InizFail_Click(object sender, EventArgs e) { MessageBox.Show("Hai messo un valore di iniziativa nella tabella ma te ne compare un altro?\n" + "Tutto normale: il valore che vedi è il risultato di un tiro.\n" + "Iniziativa + 1d20 Così non devi tirare tu e ricordarti i risultati."); } private void SchedePiccole_Click(object sender, EventArgs e) { MessageBox.Show("Non riesci la leggere?\n" + "Purtroppo lo spazio è quello... Se aumenti il numero di schede queste si rimpiccioliscono.\n" + "Posso consigliarti di mettere meno schede in una sola schermata," + "e magari aprire più schermate diverse."); } private void nonVedoTutteLeSchedeToolStripMenuItem_Click(object sender, EventArgs e) { MessageBox.Show("Hai messo delle schede che non vedi nella schermata?\n" + "Il numero massimo di schede è 12.\n" + "Se nel file excel metti più di 12 schede non le vedrai tutte."); } private void ImmFail_Click(object sender, EventArgs e) { MessageBox.Show("Alcune schede (o tutte) in alto a sinistra hanno un quadrato bianco?\n" + "Il quadrato contiene un'immagine: l'immagine della scheda.\n" + "Se lo vedi bianco significa che il nome del personaggio/mostro non è stato\n" + "riconosciuto dal programma. Controlla il file excel per vedere quali nomi sono riconosciuti."); } private void HowTo_Click(object sender, EventArgs e) { MessageBox.Show("Prima volta che usi questo software?\n" + "Per poter usare il programma ti serve un file .xls (editabile sia con MSExcel che con OpenOffice).\n" + "Riempi questo file con le caratteristiche dei tuoi personaggi/mostri a partire dalla 2a riga in poi.\n" + "Creato e salvato il file, clicca sul tasto CaricaFile in alto a sinistra e seleziona il file .xls\n" + "Tutto qui! :)"); } //------------------------- } }
Classe DataOrganizer.cs:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Windows.Forms; /* * DataOrganizer è una classe intermediaria tra i tre elementi del software: * 1: Il form * 2: Il file Excel * 3: Le schede visualizzate sul form * * gestisce il caricamento dei dati dal file excel * * */ namespace MonsterOrganizer { class DataOrganizer { int total = 0; Carta[] Carte; //Metodo principale di caricamento dati e inizializzazione di Carte public Boolean Load(string path, Form F) { if (total > 0) { RemControls(F); total = 0; } Carte = new Carta[12]; if (File.Exists(path)) { System.Data.OleDb.OleDbConnection Cn; System.Data.DataSet DtSet; System.Data.OleDb.OleDbDataAdapter Cmd; Cn = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + path + "';Extended Properties=Excel 8.0;"); Cmd = new System.Data.OleDb.OleDbDataAdapter("select * from [Foglio1$]", Cn); Cmd.TableMappings.Add("Nome", "HP"); DtSet = new System.Data.DataSet(); Cmd.Fill(DtSet); Cn.Close(); try { System.Data.DataTable dt = DtSet.Tables[0]; Random R = new Random(); total = 0; while (dt.Rows[total][0].ToString() != "") { total++; } for (int a = 0; a < total; a++) { Carte[a] = new Carta(a, total); Carte[a].SetName(dt.Rows[a][0].ToString()); Carte[a].SetHP(Convert.ToInt16(dt.Rows[a][1].ToString())); Carte[a].CA.Text = dt.Rows[a][2].ToString(); Carte[a].BAB.Text = dt.Rows[a][3].ToString(); int rd = (int)R.Next(1, 21); Carte[a].Ini.Text = (rd + Convert.ToInt16(dt.Rows[a][4].ToString())).ToString(); Carte[a].Tag.Text = dt.Rows[a][5].ToString(); Carte[a].Arma1.Text = dt.Rows[a][6].ToString(); Carte[a].Danno1.Text = dt.Rows[a][7].ToString(); Carte[a].Arma2.Text = dt.Rows[a][8].ToString(); Carte[a].Danno2.Text = dt.Rows[a][9].ToString(); Carte[a].Arma3.Text = dt.Rows[a][10].ToString(); Carte[a].Danno3.Text = dt.Rows[a][11].ToString(); Carte[a].Vel.Text = dt.Rows[a][12].ToString(); Carte[a].Cap.Text = dt.Rows[a][13].ToString(); Carte[a].Tpc.Text = dt.Rows[a][14].ToString(); } return true; } catch { return false; } } else return false; } public void AddControls(Form F) { for (int x = 0; x < total; x++) Carte[x].AddControls(F); return; } private void RemControls(Form F) { for (int x = 0; x < total; x++) Carte[x].DelControls(F); return; } } }
Classe Carta.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using System.Drawing; namespace MonsterOrganizer { public class Carta { //Struttura public PictureBox Sfondo; public PictureBox Img; //Dati private Label Nome; private Label HP_title; private Label HP; private PictureBox HP_red; private PictureBox HP_green; private NumericUpDown HP_control; private Label CA_title; public Label CA; private Label BAB_title; public Label BAB; private Label Ini_title; public Label Ini; private Label Tag_title; public Label Tag; private Label Arma1_title; public Label Arma1; public Label Danno1; private Label Arma2_title; public Label Arma2; public Label Danno2; private Label Arma3_title; public Label Arma3; public Label Danno3; private Label Vel_title; public Label Vel; private Label Cap_title; public Label Cap; public TextBox Tpc; private Button Tpc_Thrown; private double div = 1; public Carta(int num, int tot) { SetUpStructure(num, tot); } //Posiziona tutti gli elementi all'interno della scheda con riferimento all'angolo in alto a sinistra dello sfondo //e assegna ad ognuno un valore fittizio prima che vengano caricati i dati private void SetUpStructure(int num, int tot) { short x = 326; short y = 530; short xl = 12; short yl = 27; switch (tot) { case 1: { xl = Convert.ToInt16((1014 - x) / 2); break; } case 2: { xl = Convert.ToInt16((1014 / 2 - 6 - x) + ((x + 6) * num)); break; } case 3: { xl = Convert.ToInt16(12 + ((x + 6) * num)); break; } case 4: { div = 1.342; xl = Convert.ToInt16(12 + ((x / div + 6) * num)); yl = Convert.ToInt16(27 + (y - y / div) / 2); break; } case 5: { div = 1.689; xl = Convert.ToInt16(12 + ((x / div + 6) * num)); yl = Convert.ToInt16(27 + (y - y / div) / 2); break; } case 6: { div = 2.037; xl = Convert.ToInt16(12 + ((x / div + 6) * num)); yl = Convert.ToInt16(27 + (y - y / div) / 2); break; } case 7: case 8: case 9: case 10: case 11: case 12: { int down = 0; if (num >= 6) down = 1; div = 2.037; xl = Convert.ToInt16(12 + ((x / div + 6) * (num - (down * 6)))); yl = Convert.ToInt16(27 + ((y / div + 6) * down)); break; } }; x = Convert.ToInt16(x / div); y = Convert.ToInt16(y / div); Sfondo = new PictureBox(); Sfondo.Size = new Size(x, y); Sfondo.Location = new Point(xl, yl); Sfondo.SizeMode = PictureBoxSizeMode.StretchImage; Sfondo.Image = Properties.Resources.ResourceManager.GetObject("Carta") as Image; Sfondo.Enabled = true; Sfondo.Visible = true; Img = new PictureBox(); Img.Size = new Size(Convert.ToInt16(120 / div), Convert.ToInt16(120 / div)); Img.SizeMode = PictureBoxSizeMode.StretchImage; Img.Location = new Point(Sfondo.Location.X + (int)(Math.Round(6 / div)), Sfondo.Location.Y + (int)(Math.Round(6 / div))); Img.Image = GetImage(); Nome = new Label(); Nome.AutoSize = true; Nome.Location = new Point(Sfondo.Location.X + (int)(Math.Round(12 / div)) + Img.Width, Sfondo.Location.Y + (int)(Math.Round(6 / div))); Nome.Font = new Font("Calibri", (int)(Math.Round(20 / div))); Nome.ForeColor = Color.Purple; Nome.Text = "Name"; Nome.BackColor = Color.FromArgb(221, 238, 239); CA_title = new Label(); CA_title.AutoSize = true; CA_title.Location = new Point(Sfondo.Location.X + (int)(Math.Round(12 / div)) + Img.Width, Sfondo.Location.Y + (int)(Math.Round(50 / div))); CA_title.Font = new Font("Calibri", (int)(Math.Round(14 / div))); CA_title.ForeColor = Color.Black; CA_title.Text = "CA:"; CA_title.BackColor = Color.FromArgb(221, 238, 239); CA = new Label(); CA.AutoSize = true; CA.Location = new Point(CA_title.Location.X + (int)(Math.Round(92 / div)), CA_title.Location.Y); CA.Font = new Font("Calibri", (int)(Math.Round(14 / div))); CA.ForeColor = Color.Red; CA.Text = "10"; CA.BackColor = Color.FromArgb(221, 238, 239); Vel_title = new Label(); Vel_title.AutoSize = true; Vel_title.Location = new Point(Sfondo.Location.X + (int)(Math.Round(12 / div)) + Img.Width, (int)(Math.Round(30 / div)) + CA.Location.Y); Vel_title.Font = new Font("Calibri", (int)(Math.Round(14 / div))); Vel_title.ForeColor = Color.Black; Vel_title.Text = "Velocità:"; Vel_title.BackColor = Color.FromArgb(221, 238, 239); Vel = new Label(); Vel.AutoSize = true; Vel.Location = new Point(Vel_title.Location.X + (int)(Math.Round(86 / div)) + (int)(Math.Round(6 / div)), Vel_title.Location.Y); Vel.Font = new Font("Calibri", (int)(Math.Round(14 / div))); Vel.ForeColor = Color.Red; Vel.Text = "9 m"; Vel.BackColor = Color.FromArgb(221, 238, 239); Tag_title = new Label(); Tag_title.AutoSize = true; Tag_title.Location = new Point(Sfondo.Location.X + (int)(Math.Round(12 / div)) + Img.Width, (int)(Math.Round(60 / div)) + CA.Location.Y); Tag_title.Font = new Font("Calibri", (int)(Math.Round(14 / div))); Tag_title.ForeColor = Color.Black; Tag_title.Text = "Taglia:"; Tag_title.BackColor = Color.FromArgb(221, 238, 239); Tag = new Label(); Tag.AutoSize = true; Tag.Location = new Point(Tag_title.Location.X + (int)(Math.Round(86 / div)) + (int)(Math.Round(6 / div)), Tag_title.Location.Y); Tag.Font = new Font("Calibri", (int)(Math.Round(14 / div))); Tag.ForeColor = Color.Red; Tag.Text = "Media"; Tag.BackColor = Color.FromArgb(221, 238, 239); HP_title = new Label(); HP_title.AutoSize = true; HP_title.Location = new Point(Sfondo.Location.X + (int)(Math.Round(10 / div)), Sfondo.Location.Y + (int)(Math.Round(20 / div)) + Img.Height); HP_title.Font = new Font("Calibri", (int)(Math.Round(14 / div))); HP_title.ForeColor = Color.Black; HP_title.Text = "HP:"; HP_title.BackColor = Color.FromArgb(221, 238, 239); HP = new Label(); HP.AutoSize = true; HP.Location = new Point(HP_title.Location.X + (int)(Math.Round(50 / div)), HP_title.Location.Y); HP.Font = new Font("Calibri", (int)(Math.Round(14 / div)), FontStyle.Bold); HP.ForeColor = Color.Red; HP.Text = "10"; HP.BackColor = Color.FromArgb(221, 238, 239); HP_control = new NumericUpDown(); HP_control.Size = new Size(18, 20); HP_control.Minimum = 0; HP_control.Maximum = 10; HP_control.Value = 10; HP_control.Location = new Point(HP_title.Location .X, HP_title .Location .Y + (int)(Math.Round(40 / div))); HP_control.ValueChanged += new System.EventHandler(NUP_Value_Changed); HP_green = new PictureBox(); HP_green.BackColor = Color.Green; HP_green.Size = new Size((int)(Math.Round(250 / div)), 30); HP_green.Location = new Point(HP_control.Location.X + (int)(Math.Round(40 / div)), HP_control.Location.Y - (int)((HP_green.Height - HP_control.Height) / 2)); HP_red = new PictureBox(); HP_red.BackColor = Color.Red; HP_red.Size = new Size(0, 30); HP_red.Location = new Point(HP_green.Location.X + HP_green.Width, HP_green.Location.Y); BAB_title = new Label(); BAB_title.AutoSize = true; BAB_title.Location = new Point(Sfondo.Location.X + (int)(Math.Round(190 / div)), Sfondo.Location.Y + (int)(Math.Round(20 / div)) + Img.Height); BAB_title.Font = new Font("Calibri", (int)(Math.Round(14 / div))); BAB_title.ForeColor = Color.Black; BAB_title.Text = "BAB:"; BAB_title.BackColor = Color.FromArgb(221, 238, 239); BAB = new Label(); BAB.AutoSize = true; BAB.Location = new Point(BAB_title.Location.X + (int)(Math.Round(50 / div)), BAB_title.Location.Y); BAB.Font = new Font("Calibri", (int)(Math.Round(14 / div))); BAB.ForeColor = Color.Red; BAB.Text = "3"; BAB.BackColor = Color.FromArgb(221, 238, 239); Arma1_title = new Label(); Arma1_title.AutoSize = true; Arma1_title.Location = new Point(Sfondo.Location.X + (int)(Math.Round(10 / div)), Sfondo.Location.Y + (int)(Math.Round(110 / div)) + Img.Height); Arma1_title.Font = new Font("Calibri", (int)(Math.Round(14 / div))); Arma1_title.ForeColor = Color.Black; Arma1_title.Text = "Arma 1:"; Arma1_title.BackColor = Color.FromArgb(221, 238, 239); Arma1 = new Label(); Arma1.AutoSize = true; Arma1.Location = new Point(Arma1_title.Location.X, Arma1_title.Location.Y + (int)(Math.Round(20 / div))); Arma1.Font = new Font("Calibri", (int)(Math.Round(12 / div))); Arma1.ForeColor = Color.Red; Arma1.Text = "Questa è l'arma con cui ti picchio"; Arma1.BackColor = Color.FromArgb(221, 238, 239); Danno1 = new Label(); Danno1.AutoSize = true; Danno1.Location = new Point(Arma1.Location.X, Arma1.Location.Y + (int)(Math.Round(20 / div))); Danno1.Font = new Font("Calibri", (int)(Math.Round(12 / div))); Danno1.ForeColor = Color.Red; Danno1.Text = "E ti faccio tanto male"; Danno1.BackColor = Color.FromArgb(221, 238, 239); Arma2_title = new Label(); Arma2_title.AutoSize = true; Arma2_title.Location = new Point(Sfondo.Location.X + (int)(Math.Round(10 / div)), Sfondo.Location.Y + (int)(Math.Round(170 / div)) + Img.Height); Arma2_title.Font = new Font("Calibri", (int)(Math.Round(14 / div))); Arma2_title.ForeColor = Color.Black; Arma2_title.Text = "Arma 2:"; Arma2_title.BackColor = Color.FromArgb(221, 238, 239); Arma2 = new Label(); Arma2.AutoSize = true; Arma2.Location = new Point(Arma2_title.Location.X, Arma2_title.Location.Y + (int)(Math.Round(20 / div))); Arma2.Font = new Font("Calibri", (int)(Math.Round(12 / div))); Arma2.ForeColor = Color.Red; Arma2.Text = "Questa è l'arma con cui ti picchio"; Arma2.BackColor = Color.FromArgb(221, 238, 239); Danno2 = new Label(); Danno2.AutoSize = true; Danno2.Location = new Point(Arma2.Location.X, Arma2.Location.Y + (int)(Math.Round(20 / div))); Danno2.Font = new Font("Calibri", (int)(Math.Round(12 / div))); Danno2.ForeColor = Color.Red; Danno2.Text = "E ti faccio tanto male"; Danno2.BackColor = Color.FromArgb(221, 238, 239); Arma3_title = new Label(); Arma3_title.AutoSize = true; Arma3_title.Location = new Point(Sfondo.Location.X + (int)(Math.Round(10 / div)), Sfondo.Location.Y + (int)(Math.Round(230 / div)) + Img.Height); Arma3_title.Font = new Font("Calibri", (int)(Math.Round(14 / div))); Arma3_title.ForeColor = Color.Black; Arma3_title.Text = "Arma 3:"; Arma3_title.BackColor = Color.FromArgb(221, 238, 239); Arma3 = new Label(); Arma3.AutoSize = true; Arma3.Location = new Point(Arma3_title.Location.X, Arma3_title.Location.Y + (int)(Math.Round(20 / div))); Arma3.Font = new Font("Calibri", (int)(Math.Round(12 / div))); Arma3.ForeColor = Color.Red; Arma3.Text = "Questa è l'arma con cui ti picchio"; Arma3.BackColor = Color.FromArgb(221, 238, 239); Danno3 = new Label(); Danno3.AutoSize = true; Danno3.Location = new Point(Arma3.Location.X, Arma3.Location.Y + (int)(Math.Round(20 / div))); Danno3.Font = new Font("Calibri", (int)(Math.Round(12 / div))); Danno3.ForeColor = Color.Red; Danno3.Text = "E ti faccio tanto male"; Danno3.BackColor = Color.FromArgb(221, 238, 239); Cap_title = new Label(); Cap_title.AutoSize = true; Cap_title.Location = new Point(Sfondo.Location.X + (int)(Math.Round(10 / div)), Sfondo.Location.Y + (int)(Math.Round(300 / div)) + Img.Height); Cap_title.Font = new Font("Calibri", (int)(Math.Round(14 / div))); Cap_title.ForeColor = Color.Black; Cap_title.Text = "Capacità:"; Cap_title.BackColor = Color.FromArgb(221, 238, 239); Cap = new Label(); Cap.AutoSize = true; Cap.Location = new Point(Cap_title.Location.X, Cap_title.Location.Y + (int)(Math.Round(20 / div))); Cap.Font = new Font("Calibri", (int)(Math.Round(12 / div))); Cap.ForeColor = Color.Red; Cap.Text = "Ho anche questa capacità quindi ti powno"; Cap.BackColor = Color.FromArgb(221, 238, 239); Ini_title = new Label(); Ini_title.AutoSize = true; Ini_title.Location = new Point(Sfondo.Location.X + (int)(Math.Round(200 / div)), Sfondo.Location.Y + (int)(Math.Round(360 / div)) + Img.Height); Ini_title.Font = new Font("Calibri", (int)(Math.Round(14 / div))); Ini_title.ForeColor = Color.Black; Ini_title.Text = "Iniziativa:"; Ini_title.BackColor = Color.FromArgb(221, 238, 239); Ini = new Label(); Ini.AutoSize = true; Ini.Location = new Point(Ini_title.Location.X + (int)(Math.Round(90 / div)), Ini_title.Location.Y); Ini.Font = new Font("Calibri", (int)(Math.Round(14 / div))); Ini.ForeColor = Color.Red; Ini.Text = "17"; Ini.BackColor = Color.FromArgb(221, 238, 239); Tpc = new TextBox(); Tpc.Size = new Size(22, 31); Tpc.Location = new Point(Sfondo.Location.X + (int)(Math.Round(10 / div)), Sfondo.Location.Y + (int)(Math.Round(340 / div)) + Img.Height); Tpc.Font = new Font("Calibri", 10); Tpc.Text = "0"; Tpc_Thrown = new Button(); Tpc_Thrown.Size = new Size(70, 24); Tpc_Thrown.Location = new Point(Tpc.Location.X + (int)(Math.Round(42 / div)), Tpc.Location.Y); Tpc_Thrown.Font = new Font("Calibri", 11); Tpc_Thrown.Text = "Tira! - 0"; Tpc_Thrown.Click += new System.EventHandler(ThrowDice); } //Imposta l'immagine in alto a sinistra della scheda a seconda del nome private Image GetImage() { Image I = Properties.Resources.ResourceManager.GetObject("Noimage") as Image; try { I = Properties.Resources.ResourceManager.GetObject(Nome.Text) as Image; } catch { return I; } return I; } //metodo pubblico per poter impostare il nome e contemporaneamente l'immagine public void SetName(string nome) { Nome.Text = nome; Img.Image = GetImage(); return; } //Impostando gli HP tramite un metodo è possibile impostare contemporaneamente i valori per //le barre verdi e rosse e le freccette per regolarli public void SetHP(int Hp) { HP.Text = Convert.ToString(Hp); HP_control.Maximum = Hp; HP_control.Value = Hp; return; } //Inserisce i controlli nel form F public void AddControls(Form F) { F.Controls.Add(Nome); F.Controls.Add(Sfondo); F.Controls.Add(Img); F.Controls.Add(CA_title); F.Controls.Add(CA); F.Controls.Add(Vel_title); F.Controls.Add(Vel); F.Controls.Add(Tag_title); F.Controls.Add(Tag); F.Controls.Add(HP_title); F.Controls.Add(HP); F.Controls.Add(HP_control); F.Controls.Add(HP_green); F.Controls.Add(HP_red); F.Controls.Add(BAB_title); F.Controls.Add(BAB); F.Controls.Add(Arma1_title); F.Controls.Add(Arma1); F.Controls.Add(Danno1); F.Controls.Add(Arma2_title); F.Controls.Add(Arma2); F.Controls.Add(Danno2); F.Controls.Add(Arma3_title); F.Controls.Add(Arma3); F.Controls.Add(Danno3); F.Controls.Add(Cap_title); F.Controls.Add(Cap); F.Controls.Add(Ini_title); F.Controls.Add(Ini); F.Controls.Add(Tpc); F.Controls.Add(Tpc_Thrown); Sfondo.SendToBack(); Img.BringToFront(); HP_red.BringToFront(); return; } //Rimuove i controlli dal form in caso di caricamento di un nuovo file public void DelControls(Form F) { F.Controls.Remove(Nome); F.Controls.Remove(Sfondo); F.Controls.Remove(Img); F.Controls.Remove(CA_title); F.Controls.Remove(CA); F.Controls.Remove(Vel_title); F.Controls.Remove(Vel); F.Controls.Remove(Tag_title); F.Controls.Remove(Tag); F.Controls.Remove(HP_title); F.Controls.Remove(HP); F.Controls.Remove(HP_control); F.Controls.Remove(HP_green); F.Controls.Remove(HP_red); F.Controls.Remove(BAB_title); F.Controls.Remove(BAB); F.Controls.Remove(Arma1_title); F.Controls.Remove(Arma1); F.Controls.Remove(Danno1); F.Controls.Remove(Arma2_title); F.Controls.Remove(Arma2); F.Controls.Remove(Danno2); F.Controls.Remove(Arma3_title); F.Controls.Remove(Arma3); F.Controls.Remove(Danno3); F.Controls.Remove(Cap_title); F.Controls.Remove(Cap); F.Controls.Remove(Ini_title); F.Controls.Remove(Ini); F.Controls.Remove(Tpc); F.Controls.Remove(Tpc_Thrown); return; } //Evento della modifica degli hp, per far operare le barre rosse e verdi private void NUP_Value_Changed(object sender, EventArgs e) { short max_hp = Convert.ToInt16(HP_control.Maximum); short max_width = Convert.ToInt16(HP_green.Width); HP_red.Width = max_width - (int)Math.Round(max_width * HP_control.Value / max_hp); HP_red.Location = new Point(HP_green.Location.X + HP_green.Width - HP_red.Width, HP_red.Location.Y); HP.Text = HP_control.Value.ToString (); return; } //Evento del bottone "Tira!" per ottenere un numero casuale private void ThrowDice(object sender, EventArgs e) { short a = 0; try { a = Convert.ToInt16(Tpc.Text); } catch { } Random R = new Random(); Tpc_Thrown.Text = "Tira! - " + (a + R.Next(1, 21)); return; } } }
Grazie in anticipo per qualsiasi consiglio
aaa