Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 13th, 2007, 10:52 PM   #1
Jarod Silverstar
Newbie
 
Join Date: Dec 2006
Posts: 7
Rep Power: 0 Jarod Silverstar is on a distinguished road
Cannot assign 'Add' because it is a 'method group'

Beating my head against the wall on this one. Trying to write a simplified version of a combat routine (to make sure I have all the basic pieces working).

But getting stuck with just getting the basics done and drawing a blank on what I can do to solve this last issue. And hoping I can get some help.

To start with, I have a windows form where some info is entered:
namespace BasicCombatForm
{
    public partial class DataEntry : Form
    {
        int[] fighter1 = new int[2];
        int[] fighter2 = new int[2];
        
        public DataEntry()
        {
            InitializeComponent();
        }

        private void btnBegin_Click(object sender, EventArgs e)
        {
            string nameFighter1 = txtFighter1Name.Text;
            string nameFighter2 = txtFighter2Name.Text;
            fighter1[0] = Convert.ToInt16(txtFighter1Atk.Text);
            fighter1[1] = Convert.ToInt16(txtFighter1Def.Text);
            fighter2[0] = Convert.ToInt16(txtFighter2Atk.Text);
            fighter2[1] = Convert.ToInt16(txtFighter2Def.Text);

            Fight war = new Fight();
            Display show = new Display();
            show.showFight(war.newFight(nameFighter1, nameFighter2, fighter1, fighter2));
        }
    }
}

Next I have the class that handles the combat routine:
namespace BasicCombatForm
{
    public class Fight
    {
        
        public string[] newFight(string nameFighter1, string nameFighter2, int[] fighter1, int[] fighter2)
        {
            Random objRan = new Random();
            int roll1 = objRan.Next(1, 21);
            int roll2 = objRan.Next(1, 21);

            int fighter1Atk = fighter1[0] + roll1;
            int fighter1Def = fighter1[1] + roll1;
            int fighter2Atk = fighter2[0] + roll2;
            int fighter2Def = fighter2[1] + roll2;

            string[] result = new string[2];

            if (fighter1Atk > fighter2Def)
                result[0] = nameFighter1 + " scores a hit on " + nameFighter2;
            else
                result[0] = nameFighter1 + " misses " + nameFighter2;

            if (fighter2Atk > fighter1Def)
                result[1] = nameFighter2 + " scorese a hit on " + nameFighter1;
            else
                result[1] = nameFighter2 + " misses " + nameFighter1;

            return result;
        }

    }
}

And last I have a simple output form I want to write the results to:
namespace BasicCombatForm
{
    public partial class Display : Form
    {
        public Display()
        {
            InitializeComponent();
        }

        public object showFight(string[] result)
        {
           lstDisplayFight.Items.ToString = result[0];
           lstDisplayFight.Items.Equals = result[1];
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

After all is said and done, the last issue I am having is at the writing to the lstDisplayFight listbox. I keep coming back to the compile error that tells me that .Add or .Equals or any other function I try, cannot assign because it is a 'method group'. And I have not been able to find anything that helps clear up exactly what my issue is.

Am I just going about this the wrong way? Or is there something else I can do? (Of course, I don't even know if the rest of this is going to work either...)

Thanks all.
Jarod
Jarod Silverstar is offline   Reply With Quote
Old Oct 13th, 2007, 11:14 PM   #2
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 3 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
You use the Items property and then the Add method.
ListBox b = new ListBox();
b.Items.Add(new string("wtf?!?!");
You can also use the Items property as an indexer. To retrieve the items.
ListBox b = new ListBox();
...after doing w/e to the listbox
int length = b.Count;
string strArray = new string[length]
for(int x = 0; x < length; x++)
    strArray[x] = b.Items[x]; //gets item in list at index x
For an array, iterate through the array and add then to the listbox.
ListBox b = new ListBox();
string[] strArray = new string[10];
...
foreach(string str in strArray)
    b.Items.Add(str);

Hope this helps. Holla if you don't understand.
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Method not returning string csrocker101 C# 1 Apr 6th, 2007 6:45 PM
How to invoke static method from a Class object? smith.norton Java 1 Oct 5th, 2006 3:00 AM
DiveLog.java tutorial help Arenlor Java 2 Apr 26th, 2006 10:11 AM
Median/Mode in arrays? {Need help} Java|Tera Java 27 Nov 29th, 2005 10:50 AM
Debug recursion method() pr0gm3r Java 3 Oct 11th, 2005 12:33 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:40 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC