Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Boggle game help
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
cycro1234




PostPosted: Thu Jan 19, 2006 5:52 pm   Post subject: Boggle game help

Hey all!

I'm making a boggle game for school and I need some help.

I have a 5 by 5 button grid and each button has a random letter on it. When the user clicks on a button, the letter on it is highlighted. In boggle, you can make words by connecting letters from adjacent squares. Here is an example of what I would have generated:

H R T S U
E N B W L
L C E C H
S L O W A
A R D I N

The word HELLO can be made by connecting the H in the upper left hand corner to the E underneath it, to the L underneath the E, then to the L digaonally down to the right from L, and finally to the O beside the L.

In my game, the user is able to click on any square and the corresponding letter gets highlighted. However, the user should ONLY be able to click on adjacent squares to their first click. So if the user clicks on H, they should ONLY be able to click on the adjacent R, N, and E.

I've thought of one method of solving this problem, but I can't seem to make it work. When the user clicks on a box, all 8 adjacent squares around it obtain the value of 2 and the box clicked gets a value of 1. Then the next box the user clicks on must be one with a value of 2, if not, then nothing happens. As well, if the user clicks on a box but then decides to deselect it, all numbers that were changed are reset to 0.

So if H is selected, this happens behind the scenes:

H 2 T S U
2 2 B W L
L C E C H
S L O W A
A R D I N
H is assigned a value of 1.

Any ideas on how I could do this? Are there any other ways? Help would be appreciated. Thanks in advance.

-Cycro
Sponsor
Sponsor
Sponsor
sponsor
rizzix




PostPosted: Thu Jan 19, 2006 6:10 pm   Post subject: (No subject)

In developing an algorithm to solve Minesweeper I created this: http://www.compsci.ca/v2/viewtopic.php?t=7755

...in BeanShell (a java-ish scripting language)

I used this method to gather neighbouring "cell". You can use a similar approach.

in particular:
Java:
    final int[][] cell = {
        {r + 1,  c    }//bottom
        {r    ,  c + 1}//right
        {r - 1,  c    }//top
        {r    ,  c - 1}//left
        {r + 1,  c + 1}//bottom-right
        {r + 1,  c - 1}//bottom-left
        {r - 1,  c - 1}//top-left
        {r - 1,  c + 1}   //top-right
    };
where (r,c) is your current Button's location
cycro1234




PostPosted: Thu Jan 19, 2006 6:21 pm   Post subject: (No subject)

Alright, I'll see what I can do.
cycro1234




PostPosted: Thu Jan 19, 2006 7:49 pm   Post subject: (No subject)

Thanks, but I still don't know what to do.

I need to somehow track the location of each click so I can compare the current click to the previous click.

So if the first click is on a box located at 3,3 the user can only click on the 8 boxes around it:

2,3
3,2
2,2
4,3
etc.

Then if the user click on another box, i need to get those coordinates and see if they match with the right ones.
rizzix




PostPosted: Thu Jan 19, 2006 8:41 pm   Post subject: (No subject)

let each button have a state. (extend JButton). Once it's clicked change it's state.. (flag it), check if surrounding buttons are flaged. if it is... then it's a valid move (make sure to unflag those buttons right afterward).. if not it isin't..

just remember, never unflag the current button, only the surrounding ones, unless it's an invalid move.
wtd




PostPosted: Thu Jan 19, 2006 8:48 pm   Post subject: (No subject)

Is that combination of logic and presentation, rizzix? Wink
evogre3n




PostPosted: Thu Jan 19, 2006 9:34 pm   Post subject: (No subject)

[mod:fbe74bf621="rizzix"]This is so not happening in my realm. Please do not provide him with an answer. Help him out but don't do the work for him.[/mod:fbe74bf621]
rizzix




PostPosted: Thu Jan 19, 2006 9:50 pm   Post subject: (No subject)

wtd wrote:
Is that combination of logic and presentation, rizzix? Wink


eh? True. One should always create a separate model class and a view. But seriously I don't expect him to do that =/. Java basics are hard as it is already.

In fact no one here programs in proper MVC. Most teacher's don't know the pattern themselves, to teach it. It's hopeless.
Sponsor
Sponsor
Sponsor
sponsor
evogre3n




PostPosted: Fri Jan 20, 2006 7:16 am   Post subject: (No subject)

Could you guys go into more detail abot this MVC and creating seperate model class and views... i dont quite understand what you guys mean..

thanks
MysticVegeta




PostPosted: Sat Jan 21, 2006 10:57 pm   Post subject: (No subject)

rizzix wrote:
In developing an algorithm to solve Minesweeper I created this: http://www.compsci.ca/v2/viewtopic.php?t=7755

...in BeanShell (a java-ish scripting language)

I used this method to gather neighbouring "cell". You can use a similar approach.

in particular:
Java:
    final int[][] cell = {
        {r + 1,  c    }//bottom
        {r    ,  c + 1}//right
        {r - 1,  c    }//top
        {r    ,  c - 1}//left
        {r + 1,  c + 1}//bottom-right
        {r + 1,  c - 1}//bottom-left
        {r - 1,  c - 1}//top-left
        {r - 1,  c + 1}   //top-right
    };
where (r,c) is your current Button's location

Yeah that minesweeper tick me off pretty hard but a nice recursion with a couple of if structures was enough.
It took me 1.5 hours to code it!!! lol I was ashamed of myself when I made a solution that worked

well Robert, you could either check each cell separately or a conventient method to do it is, hint: run a loop from -1 to 1 Wink
evogre3n




PostPosted: Sun Jan 22, 2006 8:42 am   Post subject: (No subject)

I already showed him that...

I told him to run a loop from -1 row and -1 col to +2row, +2col (getting the 9 squares around it)

That was simple enough.. thanks anyways
MysticVegeta




PostPosted: Sun Jan 22, 2006 1:34 pm   Post subject: (No subject)

But you have to check for ArraysOutOfBoundsException since if the cell is in the top corner, grid [x][y-1] doesnt exist.
evogre3n




PostPosted: Sun Jan 22, 2006 9:32 pm   Post subject: (No subject)

err?

may i introduce try catches to you?

Java:
int myInt [] [] = new int [5][5];

try
{
     // error generating code
     myInt [20][20] = 1;
}
catch (Exception e)
{
     //message for exception when caught
}


The preceding will not cause an exception to terminate the program (Y)
MysticVegeta




PostPosted: Mon Jan 23, 2006 11:26 pm   Post subject: (No subject)

Interesting concept, I didnt know it. Thanks. Rolling Eyes
evogre3n




PostPosted: Tue Jan 24, 2006 7:57 am   Post subject: (No subject)

err?

whats with the sarcasm...

Your previous post gives the impression you dont know it... sorry for trying to help. Surprised
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 15 Posts ]
Jump to:   


Style:  
Search: