berry-cs / csc121-project-bella-ian-nate

MIT License
0 stars 0 forks source link

Need better object-oriented organization of code #1

Open nadeemabdulhamid opened 3 weeks ago

nadeemabdulhamid commented 3 weeks ago

This code is very CSC 103-style, which is not necessarily robust and good Java coding style, and in the long run, becomes a big mess of unmanageable code. There's a lot of redundancy, and very little layering/modeling of classes appropriately. Also it uses mutation, which we have not learned about yet, and introduces a whole can of worms.

I suggest starting all over again, and rewrite your application to use classes to model each type of thing in the world. For example, if there are ships, aliens, and asteroids in the game, there should be 3 separate classes to model the characteristics and behaviors of each of those types of objects. Instead of 4 booleans to track movement directions (and having to worry about what if more that one boolean is true, or what if none are true, etc.) use a single posn to represent movement velocity (direction/speed).

The update method should be refactored, so that it delegates updates to each of the individual classes. That is, in the Space class, it should basically just delegate so that the method is simple and straightforward:

public IWorld update() {
    return new Space( ship.update(),  alien.update(), asteroid.update() );

Similarly with draw().

nadeemabdulhamid commented 3 weeks ago

... Also must have test cases. Which, as you've realized by not having any - you can't readily write with CSC 103-style code. That isn't acceptable in the real world; you can't write code that can't be unit tested.