Prasanna Raman wrote:I am trying to learn object oriented programming design.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Winston Gutkowski wrote:
Prasanna Raman wrote:I am trying to learn object oriented programming design.
Prasanna,
Please DontWriteLongLines. It makes your thread very hard to read, and it's actually bad coding practice.
I've broken yours up this time, but for future reference, please remember:
80 characters max.
(the SSCCE page actually recommends 62)
Campbell Ritchie wrote:I like the last part, the enum.
I don't like any of the rest of it, I am afraid. It looks like the sort of code you get when you spend half an hour thinking and all day writing. It is supposed to be the other way round, as I told you this morning.
There is something very wrong with setting all the fields in a Player from an ID number. There is something wrong with such a large block of if‑elses.
Let's see your design first. You needn't expect to get decent code until you have got a decent design.
Take the enum. How can you get elements out of an enum in order? If you don't know, try the Java tutorials and the Java Language Specification. That means you can create exactly the same number of Player instances as there are elements in the enum.
That also means you have got about 5% of the problem solved. You still will have to work on the other 95%.
The one bit I said I liked, and you want to change that.Prasanna Raman wrote: . . . Thank you, Campbell. I will change the enum part first. . . .
I am at my wits' end trying to figure this out! Kindly let me know where I am going wrong.
Bear wrote:Develop the model of the game. That is, the classes that model the game, it's behavior and state.
Campbell wrote:You should spend all day thinking about the TicTacToe example. Once you have done so, you can write the entire model for a game in half an hour.
Winston wrote:But the main point, as everybody else has said, is to start simple.
Prasanna Raman wrote:So, just to confirm if my understanding is right, you first want me to list all the classes and just the method stubs inside it without any code?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Prasanna Raman wrote:Does this sound right? If yes, please suggest what my next step should be.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Important point there. It means you are not going to try to program game logic into the app. Makes it much easier.Prasanna Raman wrote: . . .
There are 2 human players playing against each other. One player will have his symbol as "X" and the other "O".
. . .
Getting better
Campbell Ritchie wrote:There is another way to verify each of those conditions. Probably several ways to do it. I challenge you to find another way for each.
Campbell Ritchie wrote: Also describe very simply how you intend to verify a row/column/diagonal.
Campbell Ritchie wrote:
You can check whether the game has been won by checking all three rows, all three columns and both diagonals. You can check whether the game has finished without a winner by counting nine moves.
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|