Archived

This topic is now archived and is closed to further replies.

Word Game Soloution C#

This topic is 5017 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is extremely vague!

If the boxes are stored in a 2d array, then you can just check all 4 surrounding boxes and see if they are a ''not'' before allowing the player to move in that direction.

PS I dont understand what you are talking about so my advice may be wrong. Sorry

Share this post


Link to post
Share on other sites
You have the X and Y of the latest selected box. Now the next selected box can only be X-1,Y / X+1,Y / X,Y-1 / X,Y+1 (and probably not the one where you came from before).

Shouldn''t be too hard.

Share this post


Link to post
Share on other sites
I''ll explain more. Imagine you have a word search and the word is this

H <- notice this
W
O
R
D
S
E
A
R
C

Well at the moment they could make that word because they can select any box in a line. So what I want it to do is when U click O - C it disables the H picturebox so they cannot make word search. You get me? But of course there is going to be 49 boxes so I can use

private void Box3()
Box1.Enables = false; can I because the code would get far to big! So any ideas?

Share this post


Link to post
Share on other sites
Post some code. It sounds like you are about to do something like creating a variable for each cell:

Box1
Box2
Box3

barf-o-rama! Create an array for this. I don't know the VB syntax, but look up arrays. Then you just have one variable that has many cells and you access a particular cell by index, Something like this, again excuse the syntax:

Dim Box(32) as Integer 'creates an array of Integers with 32 elements

Box(0) = 2 'puts the value 2 in slot 0
Box(14) = 6 'puts the value 6 in slot 14
Box(3) = 5 'see the pattern yet?


EDIT: OK duh, read the title, C#

Arrays in C# are similar to VB:

int Box[] = new int[32]; //creates an array of 32 integers

Then you access each element like so:

Box[4] = 100;
int x = Box[8];

and so on.



[edited by - CodeMunkie on March 22, 2004 12:15:50 PM]

Share this post


Link to post
Share on other sites
The question is what exactly does this have to do with C# ? The title is misleading.

As for selection you can disable the ones that shouldn''t be able to be selected with an extended or drived class that has an additional property to help you decied if it is so. Throwing an exception in the code if its in "not" category. Catching it displaying a Error to the client, clearing the selection.

Share this post


Link to post
Share on other sites
Well, yes and no. I guess to keep it simple you could just make an array of PictureBoxes and use the Tag property to store info about the box. Not the most elegant solution, but simple enough. And afterburn said what he said because up til now you have not asked anything C# specific.

Share this post


Link to post
Share on other sites
Well maybe so but the question is not directly related to C#. Its related to data or object structure. The language is not relevent in this context.

As you can see this could be built in C++ or VB or any other language. so the constructs of the implementation is not relevent to what your problem is.

The problem is more related in How do I make sure they do not select certain boxes.... I know which ones are disabled but how do I go about coding the issue.


The real issue here can be solved with a 2d array.

PictureBox[][] aryPic = new PictureBox[7][7] //49 Picture Boxes
//not had to make a 2d array as of yet in C# so this might be incorrect syntax. Only used ArrayList and other collections.

You might also note that your image shows a row of 6. and a cols of 7. = 42 not 49.

if you derive your a class from the picture box you can extend so properties.

class MyPicBox: PictureBox
{
bool selectable;
public MyPicBox():base()
{
selectable = true;
}
public bool IsSelectable
{
get{
return selectable;
}
set{
selectable = value;
}
}
}

This way you can just add additional logic to the object that can also display data visually to the user. Otherwise your creating multiple objects like an array of items to hold your pictures and another to hold your "selectable" value;

Maybe you need to study the underlying principals concerning design OO. The idea is to encapsulate as much as possible.
While creating the fewest objects to handle such.

So look at your question again as you do not specify anything that is language specific...




[edited by - afterburn on March 22, 2004 1:15:35 PM]

[edited by - afterburn on March 22, 2004 1:16:27 PM]

Damn code smiles

[edited by - afterburn on March 22, 2004 1:17:59 PM]

Share this post


Link to post
Share on other sites