I want to generate a pokemon with strength(random number 1-1000) and name(random name) in 2 textboxes and all while doing this making the pokemon into an object then i want the option to add the generated pokemon object to a listbox. I want to use 2 buttons one for generating objects the other for adding the generated pokemon to a listbox.
I have tried with various things like trying to call the button 2 method but gotten nowhere since it just wont accept the code im writing and could’nt find information on how you use 1 button to generate objects then add that generated object using another one. Please help this is just for fun.
This is what i tried.
namespace PokemonRNGG
{
public partial class Form1 : Form
{
Random rnd = new Random();
List pokemon = new List();
public Form1()
{
InitializeComponent();
}
class Pokemon
{
public int strength;
public string name;
}
public void button1_Click(object sender, EventArgs e)
{
Pokemon pkmn = new Pokemon();
pkmn.strength = rnd.Next(1, 100);
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
public void button2_Click(object sender, EventArgs e)
{
listBox1.Items.Add(new Pokemon());
}
}
}
hearthbeat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.