Making Magical Squares In Java
Author |
Message |
Banished_Outlaw
|
Posted: Sat Jan 19, 2008 2:46 am Post subject: Making Magical Squares In Java |
|
|
Hi,
I am new to Java language and am supposed to make a final program in Java. Our teacher gave us some options and I thought I would make magical squares in Java. I am thinking of starting out with a basic 3 x 3 grid.
I am unable to figure out how to do the following:
1. how do i make a table or a rectangle shape in Java, i googled my question and I found out a command 'draw3DRect' but the website I found it on doesn't explain it with any examples? do i need to import some graphics package before i can use this command? OR do i make a table in paint and upload the picture in Java, but if i do upload a picture how do i use it to display user input?
2. Is there any way I can make the user select the square he wants to fill in? Like use the mouse to select a square and type in a number. But I do not want the code to be too complex. OR should i make the program by using arrays and assigning and asking the user to type in a row and a column number, thus selecting the square he wants to fill in.
3. Can i make use of inheritance and polymorphism for making this program as I recently learned about them and it would be good if i can use them in my programs.
4. I also want to add a timer. I can make a counter that displays the correct solution but making a timer would look better?
I know my questions are abstract and not explained very well but Java seems like such a complex language after we did turing last year Another problem is that I have misplaced my Java textbook so all i have is my memory (which is not very good) and the internet to help me make this program...
I would really appreciate any help on this topic!! Thanks |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Banished_Outlaw
|
Posted: Sat Jan 19, 2008 1:54 pm Post subject: Re: Making Magical Squares In Java |
|
|
If no one can help me with these problems, can someone at least suggest an easy text based or low graphics game in Java? |
|
|
|
|
|
HeavenAgain
|
Posted: Sat Jan 19, 2008 2:01 pm Post subject: RE:Making Magical Squares In Java |
|
|
obviously you will require to use a 2-d array for your table. the drawing part isnt hard, you can have a 2-d boolean array to keep tracked of the square that is lite up (im not REALLY sure how the game works...)
for the drawing part, you just need 2 for loops, go through the 2-d boolean array, if it is false then draw not filled square, if it is true draw a filled square, etc etc?
nail down your problem first, one step at a time |
|
|
|
|
|
Banished_Outlaw
|
Posted: Sat Jan 19, 2008 2:12 pm Post subject: Re: Making Magical Squares In Java |
|
|
yeah thats a definite start. Magical squares consists of a sqaure 3 by 3 grid. This grid has to be filled with the numbers 1 to 9 such that all vertical, horizontal, and diagonal rows and columns add up to the same number. Every puzzle can have many solutions, which is y i am thinking of display a number in the center of the grid, which will limit the solutions to a few.
thanks a lot for your help HeavenAgain, I am gonna try making that 2-d boolean array and come back if i have more questions |
|
|
|
|
|
HellblazerX
|
Posted: Sat Jan 19, 2008 2:15 pm Post subject: Re: Making Magical Squares In Java |
|
|
1. draw3DRect is a method in the Graphics class, which is used to draw things on the screen. However, in order to use it, you need to pass it into a Container (aka window). I would suggest looking into Swing. Swing is the GUI in Java, and there are some nice tutorials on it:
http://compsci.ca/v3/viewtopic.php?t=1975
http://compsci.ca/v3/viewtopic.php?t=8107
2. Once again, Swing will come into to play. In order to detect mouse movements and mouse position, you'll need to look into the MouseListener class, which is part of Swing. Once you get the position, you can use the div function in Turing to get the row and column position of the mouse (in Java, you would divide normally, and typecast the result to int).
3. If you use Swing, you'll be using Inheritance. I'm not sure how you can use Polymorphism though.
4. If you want to use a timer, don't use counters, as they're not accurate chronologically. Try using the System.currentTimeMillis () |
|
|
|
|
|
Banished_Outlaw
|
Posted: Sat Jan 19, 2008 2:20 pm Post subject: Re: Making Magical Squares In Java |
|
|
Thanks a lot Hellblazerx, u pretty much answered all my questions, i havent learned these commands in school but the tutorial seems easy enough to understand.......lets hope i can learn this commands soon because the project is due in less than a week |
|
|
|
|
|
|
|