Christophe Verré wrote:
If nobody answers, post the GameHelper code here.
[My Blog]
All roads lead to JavaRanch
Rubbal Bhusri wrote:
Oh ! I can't wait for so long, so I would rather write the whole code here to make the whole understanding process get going !
Here I am going to present the code before you.
The classes are as follows :
For each DotCom object call placeDotCom(3), to get the location of this DotCom.. Each DotCom covers 3 grid either horizontally or vertically...
I don't blame you for not getting this one. Well needed comments are missing, leaving just useless comments (// end of inner while loop)....
Programming is about thinking, NOT coding
Christophe Verré wrote:
This code generates locations for "dot coms (three letters word)" in a matrix of 7x7.
A row is identified by a number, a column by a letter.
"dot coms" will be placed vertically or horizontally.
"dot coms" cannot overlap, not being broken in several rows or columns.
The matrix is represented by a 49-sized array.
How could this form a Matrix of 7 x 7 ??
How could I visualize to place DotComs in vertical and horizontal positions ??
What does this argument in method placeDotCom(3) means ??
As far as I see, our DotCom is of String type and this grid is of type int , please explain this ??
What kind of input does user suppose to give ??
From here, the thing comes into my mind is that , there would be some String array, where we get just 3-places to keep our Dotcom.
now you tell me, Is it so ??
here alphaCells s a reference to the ArrayList object
May be e.g. alphacoords[0] = "Facebook"; alphacoords[1] = "."; alphacoords[2] = "com";
String temp = null; Don't know about this
coors, I don't know what it is for
Does 1 % 2 gives 1 ?
[My Blog]
All roads lead to JavaRanch
Rubbal Bhusri wrote:Please look at this code , where we called placeDotCom(3) for the first time.
What value is it returning here ??
I can see here the return type is an ArrayList<String>, which means return type is an object of ArrayList whch will be containing String object and newLocation is a reference to that object, which will be brought by helper.placeDotCom(3).
Is it so ? Right ?
I can see here the return type is an ArrayList<String>, which means return type is an object of ArrayList whch will be containing String object and newLocation is a reference to that object, which will be brought by helper.placeDotCom(3).
Are the locations(or postions) of this ArrayList contiguous ?? or Are they random ?
helper.placeDotCom(3) will be returning some String objects e.g. String a, String b, String c etc. hich wil be stored in ArrayList. Is it so ??
[My Blog]
All roads lead to JavaRanch
Christophe Verré wrote:
Rubbal Bhusri wrote:Does 1 % 2 gives 1 ?
Yes. (comCount % 2) == 1) is a trick to switch between vertical and horizontal positioning. "%" is called modulus. The value on the left will roll from 0 to 2(excluded) :
0%2=0
1%2=1
2%2=0
3%2=1
4%2=0
...
You can see that the result switches between 0 and 1. This can be used to switch between horizontal and vertical positioning.
[My Blog]
All roads lead to JavaRanch
Every-time the whole process of method takes a fresh start does all the things in the same way.
The thing which put me in doubt, which part of the code , restricts to book the already occupied places, I mean, where is the record kept of already occupied positions.
[My Blog]
All roads lead to JavaRanch
avoiding the 14th postion, why ?
[My Blog]
All roads lead to JavaRanch
Christophe Verré wrote:
Can you correct the program to check that the locations do not break vertically ?
Christophe Verré wrote:
"if (x > 0 && (location % gridLength == 0))" will check if the three locations of a "dot com" will break between different lines.
This works well horizontally:
......X
XX.....
.......
.......
.......
.......
.......
[My Blog]
All roads lead to JavaRanch