|
Hi,
1.
you can't change the signature of a .NET delegate, so a Control.Click event will trigger a void XXX_Click(object sender, System.EventArgs e) and nothing else.
Now your problem seems to be you want to share the click handler for all PBs so you need to identify which PB got clicked. That is what the "object sender" is for: cast it to a PB and you have the reference to the PB.
2.
I do have a lot of suggestions for you:
2a. if ((i % 2 == 0 && j % 2 == 0) || (i % 2 == 1 && j % 2 == 1)) ... can be simplified to if ((i+j) % 2 == 0) ...
2b. checkers_board.GetLength(0) is a bit ugly; why not define a constant, say const int BOARDSIZE=8; and then use that everywhere (in the array declarations, and in all the for loops).
2c. I don't see how checkers_value is going to be useful.
2d. I would separate the game logic from the UI, i.e. keep the board state in one data structure (maybe an array of ints), let the game run without caring about the UI, then have a Paint method that takes the board and paint it. That way, if you decide to do the UI differently, you don't have to change all the code everywhere ("separation of concerns").
2d. you might consider a little enum with four values: WHITE, BLACK, EMPTY, UNUSED (and probably have four images to reflect that). Testing a square for a particular int or enum value will be easier and faster than comparing colors all the time.
3.
Some more advanced stuff:
3a. I avoid using two-dimensional arrays; a chess/checkerlike game can be handled perfectly well using a one-dimensional array. The benefit is less code, faster execution, at the expense of some getting used to. Checkerlike moves are then executed by adding +9, +7, -7 or -9 to the current position instead of (+1,+1), (+1,-1), (-1,+1), (-1,-1).
3b. I tend to add extra squares around the border, with a special value, so the squares next to the border (where moves are limited) don't need special code: just checking the destination square is EMPTY will prevent a piece to wrap from one side to the other.
3c. Very advanced: There are special gaming techniques, often called "bit vectors", where all squares are represented by the individual bits of a single variable (ideal for chess, 64 bits fit in a long). This prohibits the virtual border squares but OTOH it makes it possible to generate a lot of moves in parallel (by performing shift and AND operations). Not beginners stuff though, needed however if you want to achieve the game strength of commercial games.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I am using an unmanaged DLL which will be accessed from a Windows application.
After I have first called a function within it, will it stay in memory until the form closes?
There are a number of variables within it I need to be able ot rely on.
Thanks.
Elaine
modified on Thursday, May 21, 2009 2:18 PM
|
|
|
|
|
It'll stay in memory as part of your app's process until the app closes, not the form.
|
|
|
|
|
Thanks Dave, that is what I was hoping for.
|
|
|
|
|
Apparently someone didn't agree with you, you got my 5 to compensate a bit.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
And mine just to spite the uni-voter
|
|
|
|
|
Ditto
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi
i want to create a sequantial workflow app (without wf), i'm looking for what tables is needed to implement this, for example we need some tables like workflowTypes, workflowSteps, workflowActivities, ... .
can anybody help me and have experience in this issue ?
thanks
|
|
|
|
|
Hi I was just wondering I made a component off an example on this site. Now I wish to post it for everyone to use. But how would I do that. I’m not that talkative person so I can’t really write about it so much. What would be the best cause of action???
|
|
|
|
|
Writing an article is about the best option you have. Or post it on your own personal blog.
|
|
|
|
|
If you want, have a go at writing an article in plain text, then drop me an email from the link at the bottom of this message. I'll mail you back and you can send me the code and text. I'll see if there's anything I can do to make it 'article worthy' for you.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
thank you i will see if i have time for it tomorrow.. do i need to post a link in the article that helped me?
|
|
|
|
|
I wouldn't post a link in the other article's forum as it might be seen as a 'hijacking' attempt, unless the other article is no longer supported by the author and you are offering to take over support.
Definately make sure there's in link in your article to the original and explain what's different/improvements etc.
Drop the author of the other article a private email letting him know what you've done so he can edit his article to link to yours if he wants.
These aren't rules, just my personal opinion.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hello I'm using the below code to color a picture but it is pretty slow is there a way to do it faster?
Thanks in advance.
<br />
Bitmap Turn(Bitmap pic)<br />
{<br />
Bitmap newpic = new Bitmap(pic.Width, pic.Height);<br />
for (int i = 0; i < pic.Width; i++)<br />
{<br />
for (int j = 0; j < pic.Height; j++)<br />
{<br />
Color color = pic.GetPixel(i, j);<br />
newpic.SetPixel(i, j, Color.FromArgb(123, 46, 125));<br />
}<br />
}<br />
return newpic;<br />
}<br />
|
|
|
|
|
Why are you retrieving the color from pic when you don't use it?
Here
Color color = pic.GetPixel(i, j); <=============================== this never gets used.
newpic.SetPixel(i, j, Color.FromArgb(123, 46, 125));
But if your newpic is to be all one color, look up the Graphics class, and the Fill method of that class.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Search the articles for "Image processing for dummies" and you'll find a series of articles that covers just what you're looking for.
|
|
|
|
|
Hi,
1.
an easy win is to replace pic.Height by a variable that gets initialized only once.
2.
for a fixed color, there are better ways, as Henry already mentioned. Here is one:
Graphics g=Graphics.FromImage(newpic);
g.FillRectangle(...);
g.Dispose();
3. the general solution for maximum performance is using pointers, avoiding GetPixel/SetPixel since these methods will perform boundary checks and coordinate conversions for each individual pixel.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I have realised that I made a typo, had a brain fart, in my previous post.
I should have said
If it is going to be one color investigate the Graphics class and the Clear method of that class. Although the various Fill methods are good to know.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thank you all for your good answers.
|
|
|
|
|
Hi,
Pop3 and Smtp work the sameway.. one sends a string message to the server (eg: HELO, USER user, PASS pass) and the server responses (eg. 250 Hello and welcome)
Is there any standard class for this type of communication? something simple like
+Connect()
+Write(s)
+LastResponse()
Because i'm not getting good results ..though i'm trying to communicate with gmail's pop and smtp, so maybe i'm failing with the SSL thing..
I'm having trouble with the Writing and Response,
public string SendMessage(string message)
{
ASCIIEncoding asciiEncoder = new ASCIIEncoding();
byte[] WriteBuffer = new byte[1024]; // 1 KB
WriteBuffer = asciiEncoder.GetBytes(message);
NetworkStream stream = cl.GetStream(); // cl is a TcpClient
stream.Write(WriteBuffer, 0, WriteBuffer.Length);
// Get response after message
return Response();
}
And my response method is:
public string Response()
{
byte[] serverbuffer = new Byte[1024]; //1 KB
int count = ns.Read(serverbuffer, 0, 1024);
if (count == 0)
{
return "";
}
return Encoding.ASCII.GetString(serverbuffer, 0, count);
}
|
|
|
|
|
Hi All,
My break points doesnt not work.I break on a certain part of my code and when i run the code it doesnt stop at the break point.
Could you please advice?
Thank you in Advance.
Many thanks
|
|
|
|
|
This often means that a piece of code that you expected to be called isn't, for some reason. Usually, because of an error in coding, or it is with me.
What I do is to place a break point in the calling code for your original break, and keep moving up the calling chain until something bites.
When that happens, step through until you discover the error.
If that doesn't work, I go for a cup of coffee and a lie down.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
If that doesn't work, I go for a cup of coffee and a lie down Hahahahahah.....
Thanks very much Henry.Its Much appreciated.The problem with my debugging is even i start a new project that doesnt have any code in it and i place a break point it doesnt stop at it.Any idea?
Thank you.
|
|
|
|
|
If your new project doesn't have any code, how do you set a breakpoint?
You can only set a breakpoint on a line of reachable code, without getting a warning.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thank you once again.I just declared a variable and assign a value to it.
|
|
|
|