Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Tutto e di + - Progetto MonsterOrganizer
Forum - Tutto e di + - Progetto MonsterOrganizer

Avatar
Fharamir (Normal User)
Rookie


Messaggi: 21
Iscritto: 06/05/2011

Segnala al moderatore
Postato alle 8:51
Mercoledì, 19/09/2012
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
Codice sorgente - presumibilmente C++

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace MonsterOrganizer
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         DataOrganizer DO;
  15.  
  16.         public Form1()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.        
  21.         private void esciToolStripMenuItem_Click(object sender, EventArgs e)
  22.         {
  23.             this.Close();
  24.         }
  25.  
  26.         //Evento legato alla voce del menu: Carica File
  27.         //Da questo evento inizia tutta la procedura del caricamento dati e della visualizzazione
  28.         private void caricaFileToolStripMenuItem_Click(object sender, EventArgs e)
  29.         {
  30.             OpenFileDialog D = new OpenFileDialog();
  31.             D.Filter = "File Excel (.xls)|*.xls";
  32.             DialogResult result = D.ShowDialog();
  33.             if (result == DialogResult.OK)
  34.                 if (!DO.Load(D.FileName, this))
  35.                     MessageBox.Show("Errore nel file selzionato. Seleziona un altro File");
  36.                 else
  37.                 {
  38.                     DO.AddControls(this);
  39.                 }
  40.         }
  41.  
  42.         private void Form1_Load(object sender, EventArgs e)
  43.         {
  44.             DO = new DataOrganizer();
  45.         }
  46.  
  47.         //Semplici MessageBox per visualizzare risposte a possibili FAQ
  48.         //Vedi Menu -> Help per le domande
  49.         private void InizFail_Click(object sender, EventArgs e)
  50.         {
  51.             MessageBox.Show("Hai messo un valore di iniziativa nella tabella ma te ne compare un altro?\n" +
  52.                             "Tutto normale: il valore che vedi è il risultato di un tiro.\n" +
  53.                             "Iniziativa + 1d20 Così non devi tirare tu e ricordarti i risultati.");
  54.         }
  55.  
  56.         private void SchedePiccole_Click(object sender, EventArgs e)
  57.         {
  58.             MessageBox.Show("Non riesci la leggere?\n" +
  59.                             "Purtroppo lo spazio è quello... Se aumenti il numero di schede queste si rimpiccioliscono.\n" +
  60.                             "Posso consigliarti di mettere meno schede in una sola schermata," +
  61.                             "e magari aprire più schermate diverse.");
  62.         }
  63.  
  64.         private void nonVedoTutteLeSchedeToolStripMenuItem_Click(object sender, EventArgs e)
  65.         {
  66.             MessageBox.Show("Hai messo delle schede che non vedi nella schermata?\n" +
  67.                             "Il numero massimo di schede è 12.\n" +
  68.                             "Se nel file excel metti più di 12 schede non le vedrai tutte.");
  69.         }
  70.  
  71.         private void ImmFail_Click(object sender, EventArgs e)
  72.         {
  73.             MessageBox.Show("Alcune schede (o tutte) in alto a sinistra hanno un quadrato bianco?\n" +
  74.                             "Il quadrato contiene un'immagine: l'immagine della scheda.\n" +
  75.                             "Se lo vedi bianco significa che il nome del personaggio/mostro non è stato\n" +
  76.                             "riconosciuto dal programma. Controlla il file excel per vedere quali nomi sono riconosciuti.");
  77.         }
  78.  
  79.         private void HowTo_Click(object sender, EventArgs e)
  80.         {
  81.             MessageBox.Show("Prima volta che usi questo software?\n" +
  82.                             "Per poter usare il programma ti serve un file .xls (editabile sia con MSExcel che con OpenOffice).\n" +
  83.                             "Riempi questo file con le caratteristiche dei tuoi personaggi/mostri a partire dalla 2a riga in poi.\n" +
  84.                             "Creato e salvato il file, clicca sul tasto CaricaFile in alto a sinistra e seleziona il file .xls\n" +
  85.                             "Tutto qui! :)");
  86.         }
  87.         //-------------------------
  88.     }
  89. }



Classe DataOrganizer.cs:
Codice sorgente - presumibilmente C++

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. using System.Windows.Forms;
  7.  
  8. /*
  9.  * DataOrganizer è una classe intermediaria tra i tre elementi del software:
  10.  * 1: Il form
  11.  * 2: Il file Excel
  12.  * 3: Le schede visualizzate sul form
  13.  *
  14.  * gestisce il caricamento dei dati dal file excel
  15.  *
  16.  * */
  17.  
  18. namespace MonsterOrganizer
  19. {
  20.     class DataOrganizer
  21.     {
  22.         int total = 0;
  23.         Carta[] Carte;
  24.  
  25.         //Metodo principale di caricamento dati e inizializzazione di Carte
  26.         public Boolean Load(string path, Form F)
  27.         {
  28.             if (total > 0) { RemControls(F); total = 0; }
  29.  
  30.             Carte = new Carta[12];
  31.  
  32.             if (File.Exists(path))
  33.             {
  34.                 System.Data.OleDb.OleDbConnection Cn;
  35.                 System.Data.DataSet DtSet;
  36.                 System.Data.OleDb.OleDbDataAdapter Cmd;
  37.                 Cn = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='" +
  38.                     path + "';Extended Properties=Excel 8.0;");
  39.                 Cmd = new System.Data.OleDb.OleDbDataAdapter("select * from [Foglio1$]", Cn);
  40.                 Cmd.TableMappings.Add("Nome", "HP");
  41.                 DtSet = new System.Data.DataSet();
  42.                 Cmd.Fill(DtSet);
  43.                
  44.                 Cn.Close();
  45.  
  46.                 try
  47.                 {
  48.                     System.Data.DataTable dt = DtSet.Tables[0];
  49.                     Random R = new Random();
  50.  
  51.                     total = 0;
  52.                     while (dt.Rows[total][0].ToString() != "")
  53.                     {
  54.                         total++;
  55.                     }
  56.  
  57.                     for (int a = 0; a < total; a++)
  58.                     {
  59.                         Carte[a] = new Carta(a, total);
  60.                         Carte[a].SetName(dt.Rows[a][0].ToString());
  61.                         Carte[a].SetHP(Convert.ToInt16(dt.Rows[a][1].ToString()));
  62.                         Carte[a].CA.Text = dt.Rows[a][2].ToString();
  63.                         Carte[a].BAB.Text = dt.Rows[a][3].ToString();
  64.                         int rd = (int)R.Next(1, 21);
  65.                         Carte[a].Ini.Text = (rd +
  66.                             Convert.ToInt16(dt.Rows[a][4].ToString())).ToString();
  67.                         Carte[a].Tag.Text = dt.Rows[a][5].ToString();
  68.                         Carte[a].Arma1.Text = dt.Rows[a][6].ToString();
  69.                         Carte[a].Danno1.Text = dt.Rows[a][7].ToString();
  70.                         Carte[a].Arma2.Text = dt.Rows[a][8].ToString();
  71.                         Carte[a].Danno2.Text = dt.Rows[a][9].ToString();
  72.                         Carte[a].Arma3.Text = dt.Rows[a][10].ToString();
  73.                         Carte[a].Danno3.Text = dt.Rows[a][11].ToString();
  74.                         Carte[a].Vel.Text = dt.Rows[a][12].ToString();
  75.                         Carte[a].Cap.Text = dt.Rows[a][13].ToString();
  76.                         Carte[a].Tpc.Text = dt.Rows[a][14].ToString();
  77.                     }
  78.  
  79.                     return true;
  80.                 }
  81.                 catch { return false; }
  82.             }
  83.  
  84.             else return false;
  85.         }
  86.  
  87.         public void AddControls(Form F)
  88.         {
  89.             for (int x = 0; x < total; x++)
  90.                 Carte[x].AddControls(F);
  91.             return;
  92.         }
  93.  
  94.         private void RemControls(Form F)
  95.         {
  96.             for (int x = 0; x < total; x++)
  97.                 Carte[x].DelControls(F);
  98.             return;
  99.         }
  100.     }
  101. }



Classe Carta.cs
Codice sorgente - presumibilmente C++

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using System.Drawing;
  7.  
  8. namespace MonsterOrganizer
  9. {
  10.     public class Carta
  11.     {
  12.         //Struttura
  13.         public PictureBox Sfondo;
  14.         public PictureBox Img;
  15.  
  16.         //Dati
  17.         private Label Nome;
  18.         private Label HP_title;
  19.         private Label HP;
  20.         private PictureBox HP_red;
  21.         private PictureBox HP_green;
  22.         private NumericUpDown HP_control;
  23.         private Label CA_title;
  24.         public Label CA;
  25.         private Label BAB_title;
  26.         public Label BAB;
  27.         private Label Ini_title;
  28.         public Label Ini;
  29.         private Label Tag_title;
  30.         public Label Tag;
  31.         private Label Arma1_title;
  32.         public Label Arma1;
  33.         public Label Danno1;
  34.         private Label Arma2_title;
  35.         public Label Arma2;
  36.         public Label Danno2;
  37.         private Label Arma3_title;
  38.         public Label Arma3;
  39.         public Label Danno3;
  40.         private Label Vel_title;
  41.         public Label Vel;
  42.         private Label Cap_title;
  43.         public Label Cap;
  44.         public TextBox Tpc;
  45.         private Button Tpc_Thrown;
  46.  
  47.         private double div = 1;
  48.  
  49.         public Carta(int num, int tot)
  50.         {
  51.             SetUpStructure(num, tot);
  52.         }
  53.  
  54.         //Posiziona tutti gli elementi all'interno della scheda con riferimento all'angolo in alto a sinistra dello sfondo
  55.         //e assegna ad ognuno un valore fittizio prima che vengano caricati i dati
  56.         private void SetUpStructure(int num, int tot)
  57.         {
  58.             short x = 326;
  59.             short y = 530;
  60.             short xl = 12;
  61.             short yl = 27;
  62.             switch (tot)
  63.             {
  64.                 case 1:
  65.                     {
  66.                         xl = Convert.ToInt16((1014 - x) / 2);
  67.                         break;
  68.                     }
  69.                 case 2:
  70.                     {
  71.                         xl = Convert.ToInt16((1014 / 2 - 6 - x) + ((x + 6) * num));
  72.                         break;
  73.                     }
  74.                 case 3:
  75.                     {
  76.                         xl = Convert.ToInt16(12 + ((x + 6) * num));
  77.                         break;
  78.                     }
  79.                 case 4:
  80.                     {
  81.                         div = 1.342;
  82.                         xl = Convert.ToInt16(12 + ((x / div + 6) * num));
  83.                         yl = Convert.ToInt16(27 + (y - y / div) / 2);
  84.                         break;
  85.                     }
  86.                 case 5:
  87.                     {
  88.                         div = 1.689;
  89.                         xl = Convert.ToInt16(12 + ((x / div + 6) * num));
  90.                         yl = Convert.ToInt16(27 + (y - y / div) / 2);
  91.                         break;
  92.                     }
  93.                 case 6:
  94.                     {
  95.                         div = 2.037;
  96.                         xl = Convert.ToInt16(12 + ((x / div + 6) * num));
  97.                         yl = Convert.ToInt16(27 + (y - y / div) / 2);
  98.                         break;
  99.                     }
  100.                 case 7:
  101.                 case 8:
  102.                 case 9:
  103.                 case 10:
  104.                 case 11:
  105.                 case 12:
  106.                     {
  107.                         int down = 0;
  108.                         if (num >= 6) down = 1;
  109.                         div = 2.037;
  110.                         xl = Convert.ToInt16(12 + ((x / div + 6) * (num - (down * 6))));
  111.                         yl = Convert.ToInt16(27 + ((y / div + 6) * down));
  112.                         break;
  113.                     }
  114.             };
  115.             x = Convert.ToInt16(x / div);
  116.             y = Convert.ToInt16(y / div);
  117.             Sfondo = new PictureBox();
  118.             Sfondo.Size = new Size(x, y);
  119.             Sfondo.Location = new Point(xl, yl);
  120.             Sfondo.SizeMode = PictureBoxSizeMode.StretchImage;
  121.             Sfondo.Image = Properties.Resources.ResourceManager.GetObject("Carta") as Image;
  122.             Sfondo.Enabled = true;
  123.             Sfondo.Visible = true;
  124.  
  125.             Img = new PictureBox();
  126.             Img.Size = new Size(Convert.ToInt16(120 / div), Convert.ToInt16(120 / div));
  127.             Img.SizeMode = PictureBoxSizeMode.StretchImage;
  128.             Img.Location = new Point(Sfondo.Location.X + (int)(Math.Round(6 / div)),
  129.                 Sfondo.Location.Y + (int)(Math.Round(6 / div)));
  130.             Img.Image = GetImage();
  131.  
  132.             Nome = new Label();
  133.             Nome.AutoSize = true;
  134.             Nome.Location = new Point(Sfondo.Location.X + (int)(Math.Round(12 / div)) + Img.Width,
  135.                 Sfondo.Location.Y + (int)(Math.Round(6 / div)));
  136.             Nome.Font = new Font("Calibri", (int)(Math.Round(20 / div)));
  137.             Nome.ForeColor = Color.Purple;
  138.             Nome.Text = "Name";
  139.             Nome.BackColor = Color.FromArgb(221, 238, 239);
  140.  
  141.             CA_title = new Label();
  142.             CA_title.AutoSize = true;
  143.             CA_title.Location = new Point(Sfondo.Location.X + (int)(Math.Round(12 / div)) + Img.Width,
  144.                 Sfondo.Location.Y + (int)(Math.Round(50 / div)));
  145.             CA_title.Font = new Font("Calibri", (int)(Math.Round(14 / div)));
  146.             CA_title.ForeColor = Color.Black;
  147.             CA_title.Text = "CA:";
  148.             CA_title.BackColor = Color.FromArgb(221, 238, 239);
  149.  
  150.             CA = new Label();
  151.             CA.AutoSize = true;
  152.             CA.Location = new Point(CA_title.Location.X + (int)(Math.Round(92 / div)),
  153.                 CA_title.Location.Y);
  154.             CA.Font = new Font("Calibri", (int)(Math.Round(14 / div)));
  155.             CA.ForeColor = Color.Red;
  156.             CA.Text = "10";
  157.             CA.BackColor = Color.FromArgb(221, 238, 239);
  158.  
  159.             Vel_title = new Label();
  160.             Vel_title.AutoSize = true;
  161.             Vel_title.Location = new Point(Sfondo.Location.X + (int)(Math.Round(12 / div)) + Img.Width,
  162.                 (int)(Math.Round(30 / div)) + CA.Location.Y);
  163.             Vel_title.Font = new Font("Calibri", (int)(Math.Round(14 / div)));
  164.             Vel_title.ForeColor = Color.Black;
  165.             Vel_title.Text = "Velocità:";
  166.             Vel_title.BackColor = Color.FromArgb(221, 238, 239);
  167.  
  168.             Vel = new Label();
  169.             Vel.AutoSize = true;
  170.             Vel.Location = new Point(Vel_title.Location.X + (int)(Math.Round(86 / div)) + (int)(Math.Round(6 / div)),
  171.                 Vel_title.Location.Y);
  172.             Vel.Font = new Font("Calibri", (int)(Math.Round(14 / div)));
  173.             Vel.ForeColor = Color.Red;
  174.             Vel.Text = "9 m";
  175.             Vel.BackColor = Color.FromArgb(221, 238, 239);
  176.  
  177.             Tag_title = new Label();
  178.             Tag_title.AutoSize = true;
  179.             Tag_title.Location = new Point(Sfondo.Location.X + (int)(Math.Round(12 / div)) + Img.Width,
  180.                 (int)(Math.Round(60 / div)) + CA.Location.Y);
  181.             Tag_title.Font = new Font("Calibri", (int)(Math.Round(14 / div)));
  182.             Tag_title.ForeColor = Color.Black;
  183.             Tag_title.Text = "Taglia:";
  184.             Tag_title.BackColor = Color.FromArgb(221, 238, 239);
  185.  
  186.             Tag = new Label();
  187.             Tag.AutoSize = true;
  188.             Tag.Location = new Point(Tag_title.Location.X + (int)(Math.Round(86 / div)) + (int)(Math.Round(6 / div)),
  189.                 Tag_title.Location.Y);
  190.             Tag.Font = new Font("Calibri", (int)(Math.Round(14 / div)));
  191.             Tag.ForeColor = Color.Red;
  192.             Tag.Text = "Media";
  193.             Tag.BackColor = Color.FromArgb(221, 238, 239);
  194.  
  195.             HP_title = new Label();
  196.             HP_title.AutoSize = true;
  197.             HP_title.Location = new Point(Sfondo.Location.X + (int)(Math.Round(10 / div)),
  198.                 Sfondo.Location.Y + (int)(Math.Round(20 / div)) + Img.Height);
  199.             HP_title.Font = new Font("Calibri", (int)(Math.Round(14 / div)));
  200.             HP_title.ForeColor = Color.Black;
  201.             HP_title.Text = "HP:";
  202.             HP_title.BackColor = Color.FromArgb(221, 238, 239);
  203.  
  204.             HP = new Label();
  205.             HP.AutoSize = true;
  206.             HP.Location = new Point(HP_title.Location.X + (int)(Math.Round(50 / div)),
  207.                 HP_title.Location.Y);
  208.             HP.Font = new Font("Calibri", (int)(Math.Round(14 / div)), FontStyle.Bold);
  209.             HP.ForeColor = Color.Red;
  210.             HP.Text = "10";
  211.             HP.BackColor = Color.FromArgb(221, 238, 239);
  212.  
  213.             HP_control = new NumericUpDown();
  214.             HP_control.Size = new Size(18, 20);
  215.             HP_control.Minimum = 0;
  216.             HP_control.Maximum = 10;
  217.             HP_control.Value = 10;
  218.             HP_control.Location = new Point(HP_title.Location .X, HP_title .Location .Y + (int)(Math.Round(40 / div)));
  219.             HP_control.ValueChanged += new System.EventHandler(NUP_Value_Changed);
  220.  
  221.             HP_green = new PictureBox();
  222.             HP_green.BackColor = Color.Green;
  223.             HP_green.Size = new Size((int)(Math.Round(250 / div)), 30);
  224.             HP_green.Location = new Point(HP_control.Location.X + (int)(Math.Round(40 / div)),
  225.                 HP_control.Location.Y - (int)((HP_green.Height - HP_control.Height) / 2));
  226.  
  227.             HP_red = new PictureBox();
  228.             HP_red.BackColor = Color.Red;
  229.             HP_red.Size = new Size(0, 30);
  230.             HP_red.Location = new Point(HP_green.Location.X + HP_green.Width, HP_green.Location.Y);
  231.  
  232.             BAB_title = new Label();
  233.             BAB_title.AutoSize = true;
  234.             BAB_title.Location = new Point(Sfondo.Location.X + (int)(Math.Round(190 / div)),
  235.                 Sfondo.Location.Y + (int)(Math.Round(20 / div)) + Img.Height);
  236.             BAB_title.Font = new Font("Calibri", (int)(Math.Round(14 / div)));
  237.             BAB_title.ForeColor = Color.Black;
  238.             BAB_title.Text = "BAB:";
  239.             BAB_title.BackColor = Color.FromArgb(221, 238, 239);
  240.  
  241.             BAB = new Label();
  242.             BAB.AutoSize = true;
  243.             BAB.Location = new Point(BAB_title.Location.X + (int)(Math.Round(50 / div)),
  244.                 BAB_title.Location.Y);
  245.             BAB.Font = new Font("Calibri", (int)(Math.Round(14 / div)));
  246.             BAB.ForeColor = Color.Red;
  247.             BAB.Text = "3";
  248.             BAB.BackColor = Color.FromArgb(221, 238, 239);
  249.  
  250.             Arma1_title = new Label();
  251.             Arma1_title.AutoSize = true;
  252.             Arma1_title.Location = new Point(Sfondo.Location.X + (int)(Math.Round(10 / div)),
  253.                  Sfondo.Location.Y + (int)(Math.Round(110 / div)) + Img.Height);
  254.             Arma1_title.Font = new Font("Calibri", (int)(Math.Round(14 / div)));
  255.             Arma1_title.ForeColor = Color.Black;
  256.             Arma1_title.Text = "Arma 1:";
  257.             Arma1_title.BackColor = Color.FromArgb(221, 238, 239);
  258.  
  259.             Arma1 = new Label();
  260.             Arma1.AutoSize = true;
  261.             Arma1.Location = new Point(Arma1_title.Location.X,
  262.                 Arma1_title.Location.Y + (int)(Math.Round(20 / div)));
  263.             Arma1.Font = new Font("Calibri", (int)(Math.Round(12 / div)));
  264.             Arma1.ForeColor = Color.Red;
  265.             Arma1.Text = "Questa è l'arma con cui ti picchio";
  266.             Arma1.BackColor = Color.FromArgb(221, 238, 239);
  267.  
  268.             Danno1 = new Label();
  269.             Danno1.AutoSize = true;
  270.             Danno1.Location = new Point(Arma1.Location.X,
  271.                 Arma1.Location.Y + (int)(Math.Round(20 / div)));
  272.             Danno1.Font = new Font("Calibri", (int)(Math.Round(12 / div)));
  273.             Danno1.ForeColor = Color.Red;
  274.             Danno1.Text = "E ti faccio tanto male";
  275.             Danno1.BackColor = Color.FromArgb(221, 238, 239);
  276.  
  277.             Arma2_title = new Label();
  278.             Arma2_title.AutoSize = true;
  279.             Arma2_title.Location = new Point(Sfondo.Location.X + (int)(Math.Round(10 / div)),
  280.                  Sfondo.Location.Y + (int)(Math.Round(170 / div)) + Img.Height);
  281.             Arma2_title.Font = new Font("Calibri", (int)(Math.Round(14 / div)));
  282.             Arma2_title.ForeColor = Color.Black;
  283.             Arma2_title.Text = "Arma 2:";
  284.             Arma2_title.BackColor = Color.FromArgb(221, 238, 239);
  285.  
  286.             Arma2 = new Label();
  287.             Arma2.AutoSize = true;
  288.             Arma2.Location = new Point(Arma2_title.Location.X,
  289.                 Arma2_title.Location.Y + (int)(Math.Round(20 / div)));
  290.             Arma2.Font = new Font("Calibri", (int)(Math.Round(12 / div)));
  291.             Arma2.ForeColor = Color.Red;
  292.             Arma2.Text = "Questa è l'arma con cui ti picchio";
  293.             Arma2.BackColor = Color.FromArgb(221, 238, 239);
  294.  
  295.             Danno2 = new Label();
  296.             Danno2.AutoSize = true;
  297.             Danno2.Location = new Point(Arma2.Location.X,
  298.                 Arma2.Location.Y + (int)(Math.Round(20 / div)));
  299.             Danno2.Font = new Font("Calibri", (int)(Math.Round(12 / div)));
  300.             Danno2.ForeColor = Color.Red;
  301.             Danno2.Text = "E ti faccio tanto male";
  302.             Danno2.BackColor = Color.FromArgb(221, 238, 239);
  303.  
  304.             Arma3_title = new Label();
  305.             Arma3_title.AutoSize = true;
  306.             Arma3_title.Location = new Point(Sfondo.Location.X + (int)(Math.Round(10 / div)),
  307.                  Sfondo.Location.Y + (int)(Math.Round(230 / div)) + Img.Height);
  308.             Arma3_title.Font = new Font("Calibri", (int)(Math.Round(14 / div)));
  309.             Arma3_title.ForeColor = Color.Black;
  310.             Arma3_title.Text = "Arma 3:";
  311.             Arma3_title.BackColor = Color.FromArgb(221, 238, 239);
  312.  
  313.             Arma3 = new Label();
  314.             Arma3.AutoSize = true;
  315.             Arma3.Location = new Point(Arma3_title.Location.X,
  316.                 Arma3_title.Location.Y + (int)(Math.Round(20 / div)));
  317.             Arma3.Font = new Font("Calibri", (int)(Math.Round(12 / div)));
  318.             Arma3.ForeColor = Color.Red;
  319.             Arma3.Text = "Questa è l'arma con cui ti picchio";
  320.             Arma3.BackColor = Color.FromArgb(221, 238, 239);
  321.  
  322.             Danno3 = new Label();
  323.             Danno3.AutoSize = true;
  324.             Danno3.Location = new Point(Arma3.Location.X,
  325.                 Arma3.Location.Y + (int)(Math.Round(20 / div)));
  326.             Danno3.Font = new Font("Calibri", (int)(Math.Round(12 / div)));
  327.             Danno3.ForeColor = Color.Red;
  328.             Danno3.Text = "E ti faccio tanto male";
  329.             Danno3.BackColor = Color.FromArgb(221, 238, 239);
  330.  
  331.             Cap_title = new Label();
  332.             Cap_title.AutoSize = true;
  333.             Cap_title.Location = new Point(Sfondo.Location.X + (int)(Math.Round(10 / div)),
  334.                  Sfondo.Location.Y + (int)(Math.Round(300 / div)) + Img.Height);
  335.             Cap_title.Font = new Font("Calibri", (int)(Math.Round(14 / div)));
  336.             Cap_title.ForeColor = Color.Black;
  337.             Cap_title.Text = "Capacità:";
  338.             Cap_title.BackColor = Color.FromArgb(221, 238, 239);
  339.  
  340.             Cap = new Label();
  341.             Cap.AutoSize = true;
  342.             Cap.Location = new Point(Cap_title.Location.X,
  343.                 Cap_title.Location.Y + (int)(Math.Round(20 / div)));
  344.             Cap.Font = new Font("Calibri", (int)(Math.Round(12 / div)));
  345.             Cap.ForeColor = Color.Red;
  346.             Cap.Text = "Ho anche questa capacità quindi ti powno";
  347.             Cap.BackColor = Color.FromArgb(221, 238, 239);
  348.  
  349.             Ini_title = new Label();
  350.             Ini_title.AutoSize = true;
  351.             Ini_title.Location = new Point(Sfondo.Location.X + (int)(Math.Round(200 / div)),
  352.                  Sfondo.Location.Y + (int)(Math.Round(360 / div)) + Img.Height);
  353.             Ini_title.Font = new Font("Calibri", (int)(Math.Round(14 / div)));
  354.             Ini_title.ForeColor = Color.Black;
  355.             Ini_title.Text = "Iniziativa:";
  356.             Ini_title.BackColor = Color.FromArgb(221, 238, 239);
  357.  
  358.             Ini = new Label();
  359.             Ini.AutoSize = true;
  360.             Ini.Location = new Point(Ini_title.Location.X + (int)(Math.Round(90 / div)),
  361.                 Ini_title.Location.Y);
  362.             Ini.Font = new Font("Calibri", (int)(Math.Round(14 / div)));
  363.             Ini.ForeColor = Color.Red;
  364.             Ini.Text = "17";
  365.             Ini.BackColor = Color.FromArgb(221, 238, 239);
  366.  
  367.             Tpc = new TextBox();
  368.             Tpc.Size = new Size(22, 31);
  369.             Tpc.Location = new Point(Sfondo.Location.X + (int)(Math.Round(10 / div)),
  370.                  Sfondo.Location.Y + (int)(Math.Round(340 / div)) + Img.Height);
  371.             Tpc.Font = new Font("Calibri", 10);
  372.             Tpc.Text = "0";
  373.  
  374.             Tpc_Thrown = new Button();
  375.             Tpc_Thrown.Size = new Size(70, 24);
  376.             Tpc_Thrown.Location = new Point(Tpc.Location.X + (int)(Math.Round(42 / div)),
  377.                 Tpc.Location.Y);
  378.             Tpc_Thrown.Font = new Font("Calibri", 11);
  379.             Tpc_Thrown.Text = "Tira! - 0";
  380.             Tpc_Thrown.Click += new System.EventHandler(ThrowDice);
  381.         }
  382.        
  383.         //Imposta l'immagine in alto a sinistra della scheda a seconda del nome
  384.         private Image GetImage()
  385.         {
  386.             Image I = Properties.Resources.ResourceManager.GetObject("Noimage") as Image;
  387.  
  388.             try
  389.             {
  390.                 I = Properties.Resources.ResourceManager.GetObject(Nome.Text) as Image;
  391.             }
  392.             catch
  393.             {
  394.                 return I;
  395.             }
  396.  
  397.             return I;
  398.         }
  399.  
  400.         //metodo pubblico per poter impostare il nome e contemporaneamente l'immagine
  401.         public void SetName(string nome)
  402.         {
  403.             Nome.Text = nome;
  404.             Img.Image = GetImage();
  405.             return;
  406.         }
  407.  
  408.         //Impostando gli HP tramite un metodo è possibile impostare contemporaneamente i valori per
  409.         //le barre verdi e rosse e le freccette per regolarli
  410.         public void SetHP(int Hp)
  411.         {
  412.             HP.Text = Convert.ToString(Hp);
  413.             HP_control.Maximum = Hp;
  414.             HP_control.Value = Hp;
  415.             return;
  416.         }
  417.  
  418.         //Inserisce i controlli nel form F
  419.         public void AddControls(Form F)
  420.         {
  421.             F.Controls.Add(Nome);
  422.             F.Controls.Add(Sfondo);
  423.             F.Controls.Add(Img);
  424.             F.Controls.Add(CA_title);
  425.             F.Controls.Add(CA);
  426.             F.Controls.Add(Vel_title);
  427.             F.Controls.Add(Vel);
  428.             F.Controls.Add(Tag_title);
  429.             F.Controls.Add(Tag);
  430.             F.Controls.Add(HP_title);
  431.             F.Controls.Add(HP);
  432.             F.Controls.Add(HP_control);
  433.             F.Controls.Add(HP_green);
  434.             F.Controls.Add(HP_red);
  435.             F.Controls.Add(BAB_title);
  436.             F.Controls.Add(BAB);
  437.             F.Controls.Add(Arma1_title);
  438.             F.Controls.Add(Arma1);
  439.             F.Controls.Add(Danno1);
  440.             F.Controls.Add(Arma2_title);
  441.             F.Controls.Add(Arma2);
  442.             F.Controls.Add(Danno2);
  443.             F.Controls.Add(Arma3_title);
  444.             F.Controls.Add(Arma3);
  445.             F.Controls.Add(Danno3);
  446.             F.Controls.Add(Cap_title);
  447.             F.Controls.Add(Cap);
  448.             F.Controls.Add(Ini_title);
  449.             F.Controls.Add(Ini);
  450.             F.Controls.Add(Tpc);
  451.             F.Controls.Add(Tpc_Thrown);
  452.  
  453.             Sfondo.SendToBack();
  454.             Img.BringToFront();
  455.             HP_red.BringToFront();
  456.             return;
  457.         }
  458.  
  459.         //Rimuove i controlli dal form in caso di caricamento di un nuovo file
  460.         public void DelControls(Form F)
  461.         {
  462.             F.Controls.Remove(Nome);
  463.             F.Controls.Remove(Sfondo);
  464.             F.Controls.Remove(Img);
  465.             F.Controls.Remove(CA_title);
  466.             F.Controls.Remove(CA);
  467.             F.Controls.Remove(Vel_title);
  468.             F.Controls.Remove(Vel);
  469.             F.Controls.Remove(Tag_title);
  470.             F.Controls.Remove(Tag);
  471.             F.Controls.Remove(HP_title);
  472.             F.Controls.Remove(HP);
  473.             F.Controls.Remove(HP_control);
  474.             F.Controls.Remove(HP_green);
  475.             F.Controls.Remove(HP_red);
  476.             F.Controls.Remove(BAB_title);
  477.             F.Controls.Remove(BAB);
  478.             F.Controls.Remove(Arma1_title);
  479.             F.Controls.Remove(Arma1);
  480.             F.Controls.Remove(Danno1);
  481.             F.Controls.Remove(Arma2_title);
  482.             F.Controls.Remove(Arma2);
  483.             F.Controls.Remove(Danno2);
  484.             F.Controls.Remove(Arma3_title);
  485.             F.Controls.Remove(Arma3);
  486.             F.Controls.Remove(Danno3);
  487.             F.Controls.Remove(Cap_title);
  488.             F.Controls.Remove(Cap);
  489.             F.Controls.Remove(Ini_title);
  490.             F.Controls.Remove(Ini);
  491.             F.Controls.Remove(Tpc);
  492.             F.Controls.Remove(Tpc_Thrown);
  493.  
  494.             return;
  495.         }
  496.  
  497.         //Evento della modifica degli hp, per far operare le barre rosse e verdi
  498.         private void NUP_Value_Changed(object sender, EventArgs e)
  499.         {
  500.             short max_hp = Convert.ToInt16(HP_control.Maximum);
  501.             short max_width = Convert.ToInt16(HP_green.Width);
  502.  
  503.             HP_red.Width = max_width - (int)Math.Round(max_width * HP_control.Value / max_hp);
  504.             HP_red.Location = new Point(HP_green.Location.X + HP_green.Width - HP_red.Width, HP_red.Location.Y);
  505.             HP.Text = HP_control.Value.ToString ();
  506.  
  507.             return;
  508.         }
  509.  
  510.         //Evento del bottone "Tira!" per ottenere un numero casuale
  511.         private void ThrowDice(object sender, EventArgs e)
  512.         {
  513.             short a = 0;
  514.             try
  515.             {
  516.                 a = Convert.ToInt16(Tpc.Text);
  517.             }
  518.             catch { }
  519.             Random R = new Random();
  520.             Tpc_Thrown.Text = "Tira! - " + (a + R.Next(1, 21));
  521.  
  522.             return;
  523.         }
  524.     }
  525. }



Grazie in anticipo per qualsiasi consiglio :)

PM Quote