Right I have this problem in my forum game i'm making, I have stats and everything working right, it's a battle arena where you have your char and he fights in an arena and levels up .etc buys equipment. Semi text based but with button pressing.
Right I have come to a problem, I want randomly generated armor name and stats that's put into a list box so when a user clicks on an item it will display said item and their randomly generated stats.
Something like when the armory is visited via a button it generates a random number of objects aka armor and weapons, so each new visit is all new equipment. the equation is simple it goes something like: StrengthStat * characterlvl + offsetnumber, this would be applied for intellect/health or any type of stat, because the level would scale wilt he gear being generated there for i would only have to generate the name which I have set up.
My real problem is when I click on said item, the stats need to hold for that particular item, then transfer over to the characters inventory. How would I go about this? I can't do an array because i'd have 50 million arrays x amount for x amount of stats, there has to be a better way.
Here's my code:
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 Armor_Generator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public string Name1;
public string Name2;
public string Name3;
public int Namesel;
public int Namesel2;
public int armorgen;
private void btnGen_Click(object sender, EventArgs e)
{
if (lisarmor.selected == null)
{
txtArmor.text == "Please select and item";
}
else
{
// Randoms the generator
Random rand = new Random((int)DateTime.Now.Ticks);
Namesel = rand.Next(1, 4);
Namesel2 = rand.Next(1, 4);
// Picks the names
name1part();
name2part();
// Displays the names
lisArmor.Items.Add(Name1 + " of " + Name2);
}
}
public void name1part()
{
if (Namesel == 1)
{
Name1 = "Smashies armor";
}
if (Namesel == 2)
{
Name1 = "Black armor";
}
if (Namesel == 3)
{
Name1 = "Breakable";
}
}
public void name2part()
{
if (Namesel2 == 1)
{
Name2 = "Desperation";
}
if (Namesel2 == 2)
{
Name2 = "Breakdown";
}
if (Namesel2 == 3)
{
Name2 = "the Zombie";
}
}
private void btnEq_Click(object sender, EventArgs e)
{
lisEq.Items.Add(lisArmor.SelectedItem);
lisArmor.Items.Remove(lisArmor.SelectedItem);
}
private void btnUEq_Click(object sender, EventArgs e)
{
lisArmor.Items.Add(lisEq.SelectedItem);
lisEq.Items.Remove(lisEq.SelectedItem);
}
}
}
I have 2 list boxes "lisEq" and "lisArmor"
i have 1 text box txtArmor is the out put for the stats.etc
I have 3 buttons:
btnEq which transfers over an item from lis armor to make it like it equips
btnUEq which transfers the selected item back to unequip status
btnGen which generates the armor word do far...
Alrighty i'll be watching this thread...I was thinking an array list and have item 1 generate 1 array with index 0 being the name 1 being the str the item has, 2 for being the int 3 for hp and so on, and to clear it if index 0,1,2,3 had a 0 value you'd clear the name and it would look like that item doesn't have it.
Sorry for the lengthy post!
Edit: Also I was also thinking some type of group array like 0, 1, 2, 3
is reserved for item 1 4, 5, 6, 7 is for item 2 and hold the values in
there or something.
Loading
frostyraverPosted Apr 28, 2009, 3:51 PM
:D
Main code:
/* Created by Mark Elliott
* Contact information:-
*
* MSN: [email protected]
*
*/
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 Armor_Generator
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
// Declair the ints
public string Name1;
public string Name2;
public string Name3;
public int Namesel;
public int Namesel2;
public int armorgen;
// When you click the Generating button
private void btnGen_Click(object sender, EventArgs e)
{
// Randoms the generator both name selects
Random rand = new Random((int)DateTime.Now.Ticks);
Namesel = rand.Next(1, 4);
Namesel2 = rand.Next(1, 4);
// Picks the names
name1part();
name2part();
// Displays the names
lisArmor.Items.Add(Name1 + " of " + Name2);
}
// List of the first names to generate
public void name1part()
{
if (Namesel == 1)
{
Name1 = "Smashies armor";
}
if (Namesel == 2)
{
Name1 = "Black armor";
}
if (Namesel == 3)
{
Name1 = "Breakable";
}
}
// List of the second names to generate
public void name2part()
{
if (Namesel2 == 1)
{
Name2 = "the bear";
}
if (Namesel2 == 2)
{
Name2 = "the turtle";
}
if (Namesel2 == 3)
{
Name2 = "the tiger";
}
}
// If the equipment button is clicked
private void btnEq_Click(object sender, EventArgs e)
{
// If the Selected item in list armor is selected
if (lisArmor.SelectedItem != null)
{
// Add the selected item to the listArmor
lisEq.Items.Add(lisArmor.SelectedItem);
// Remove the previous Selected Item
lisArmor.Items.Remove(lisArmor.SelectedItem);
// Display this when it's not selected
txtArmor.Text = "Select an Item/Generate armor." + lisArmor.SelectedItem;
}
}
// When the unequip button is pressed
private void btnUEq_Click(object sender, EventArgs e)
{
// If the item is selected
if (lisEq.SelectedItem != null)
{
// Add the lisArmor to the LisEq
lisArmor.Items.Add(lisEq.SelectedItem);
// Remove the previous item
lisEq.Items.Remove(lisEq.SelectedItem);
// Put the base stats in
baseStats();
// Convert them
lblHP.Text = Convert.ToString(Vars.hpEQ);
lblStr.Text = Convert.ToString(Vars.strEQ);
lblInt.Text = Convert.ToString(Vars.intEQ);
}
}
// When you click the Armor List
private void lisArmor_SelectedIndexChanged(object sender, EventArgs e)
{
// Converts the level text into the int
Vars.level = Convert.ToInt16(txtLevel.Text);
// Do the lisArmorList String
string lisArmorList = (string)lisArmor.SelectedItem;
// If there is a selection
if (this.lisArmor.SelectedIndex != null)
{
// If armor list is selected
if (lisArmorList != null)
{
// If it contains the bear
if (lisArmorList.Contains("the bear"))
{
// Make the HP Show the correct amount
bearStats();
}
// If it contains the turtle
else if (lisArmorList.Contains("the turtle"))
{
// Make the HP Show the correct amount
turtleStats();
}
// If it contains the tiger
else if (lisArmorList.Contains("the tiger"))
{
// Make the HP Show the correct amount
tigerStats();
}
// Adds the stats and show it in the text
Vars.HP = Vars.HP + Vars.level;
Vars.strr = Vars.strr + Vars.level;
Vars.intell = Vars.intell + Vars.level;
txtArmor.Text = "> " + lisArmor.SelectedItem + Environment.NewLine +
"HP Amount: " + Vars.HP + Environment.NewLine +
"Str Amount: " + Vars.strr + Environment.NewLine +
"Int Amount: " + Vars.intell + Environment.NewLine +
"Level: " + Vars.level;
// Move the list to the top
lisEq.TopIndex = 0;
}
}
}
// Equipment List is selected
private void lisEq_SelectedIndexChanged(object sender, EventArgs e)
{
// Converts the level text into the int
Vars.level = Convert.ToInt16(txtLevel.Text);
// Declair the start stuff
Vars.HP = Convert.ToInt16(lblHP.Text);
// Do the lisArmorList String
Vars.EquippedItem = (string)lisEq.SelectedItem;
// Declair
baseStats();
noStats();
// Run the checker
if (lisEq.SelectedItem != null)
{
// If 'of the bear' is selected then do the checker
// Else revert the stat
if (Vars.EquippedItem.Contains("the bear"))
{
bearStats();
Vars.LastItem = "the bear";
}
// If 'of the boar' is selected then do the checker
// Else revert the stat
else if (Vars.EquippedItem.Contains("the turtle"))
{
turtleStats();
Vars.LastItem = "the turtle";
}
// If 'of the tiger' is selected then do the checker
// Else revert the stat
else if (Vars.EquippedItem.Contains("the tiger"))
{
tigerStats();
Vars.LastItem = "the tiger";
}
// Adds the stats
Vars.HP = Vars.HP + Vars.hpEQ + Vars.level;
Vars.strr = Vars.strr + Vars.strEQ + Vars.level;
Vars.intell = Vars.intell + Vars.intEQ + Vars.level;
lblHP.Text = Convert.ToString(Vars.HP);
lblStr.Text = Convert.ToString(Vars.strr);
lblInt.Text = Convert.ToString(Vars.intell);
}
}
// Does the minus stats
private void minusStats()
{
Vars.HP = Vars.HP - Vars.level;
Vars.strr = Vars.strr - Vars.level;
Vars.intell = Vars.intell - Vars.level;
}
// Base Stats declaired here
private void baseStats()
{
Vars.hpEQ = 1;
Vars.strEQ = 1;
Vars.intEQ = 1;
}
// No Stats
private void noStats()
{
Vars.HP = 0;
Vars.strr = 0;
Vars.intell = 0;
}
// Of the bear stats
private void bearStats()
{
Vars.HP = 1;
Vars.strr = 2;
Vars.intell = 3;
}
// Of the turtle stats
private void turtleStats()
{
Vars.HP = 4;
Vars.strr = 5;
Vars.intell = 6;
}
// Of the tiger stats
private void tigerStats()
{
Vars.HP = 7;
Vars.strr = 8;
Vars.intell = 9;
}
}
}
Yep as you can see this CAN BE DONE! Soooo happy i found a work around.
Thank you all for your help.
Let me know if you find better code, code error, bugs or anything of help.
http://www.dreamincode.net/forums/index.php?showtopic=100771 Download is at this other coder forum :).
EDIT: Fixed the level part of the code, you can now icrease the levels without a problem :).
frostyraverPosted Apr 23, 2009, 4:59 AM
StefanPosted Apr 22, 2009, 11:43 AM
I think so. I also think it would be much easier, and a lot less to code...
frostyraverPosted Apr 22, 2009, 12:31 AM
StefanPosted Apr 21, 2009, 5:08 PM
frostyraverPosted Apr 21, 2009, 4:19 PM
// Setup the randomizer for stats
Random rand = new Random();
string item = list1[rand.Next(0, 10)] + list2[rand.Next(0, 10)] + list3[rand.Next(1, 10)];
// Out puts the whole text...
x = lisArmory.selected.index
txtArmory = "Name: " + name1 + " of " + name 2" + neweventline
"Str: " + list1[x] + neweventline +
"HP: " + list2[x] + neweventline +
"Int: " + list3[x];
As you can see x is the selected index and this will be coordinated accordingly, something like this would be sufficent to store the array, you click and it generates, then how does it store it? into another array? then how does it delete? clear said array line from the selected index?
My brains a bit fuzzeled atm.
StefanPosted Apr 21, 2009, 2:06 PM
Ex:
Random rand = new Random();
string item = list1[rand.Next(0, 10)] + list2[rand.Next(0, 10)] + list3[rand.Next(1, 10)];
Just replace the "10"s with the number of items in the list. The resulting string will be made up of one random value from each list.
Hope this helps!