Posted: Sun Mar 19, 2006 1:38 pm Post subject: (No subject)
good pretty good for 1 month of programming. I would suggest:
- Use loops for checking who wins instead of "if" because take a look at the following code:
code:
for (int i =0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (your2DArray[i][j] != "X") return false;
}
}
return true;
You have just checked diagonally, but using the same loop you can check the inverse diagonal
And then you would need just 2 more loops, 1 of them for 2 horizontals, 1 of them for 2 verticals. What the code does is checks for "X"s. if the string is not "X" then it returns false because they are not in a row You can put al the cehcks in the same method and use it to check for both X and 0's. It will save you a lot of code.
- Error trapping, a char or string crahes the program