-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Class Design #5
Comments
Could we make a parent character class to derive enemies and players from, instead of just an interface? In my experience, there is always a lot of similar code. Or we could do it through composition, either way, I think having concrete code rather than an interface makes sense maybe? |
At first, I was about to agree with @CoreyHendrey. On second thought, they have different logics, assuming the game is single player. Player character's movements and, where it places bombs will be controlled by the player. But bots' actions will be controlled by algorithms. So, it probably makes sense to make a separate interface for their actions but for their characteristics, isn't it better to make a parent class, e.g. Character, with common attributes like color(which they all have) and inheritance from that class? |
I think the algorithms should output which way to move, and the parent character class will take those as inputs to move the character. However the player will use the keyboard as the inputs. I don’t think the algorithm should actually move/translate an object directly. :) |
It's good to talk about though. Thinking about it more, it'd be better as a separate class entirely. We can then have things like friction (for sliding), velocity, gravity etc in a movement object. Then we can even use them for the bombs and whatever else needs to move. |
@CoreyHendrey, @lyx13710 Thanks for your feedback. What I am thinking, is having interface for the entities is because they may have common behavior that is moving, collision detection ect but I feel the way they implements/how they behave is different for example movement of two different enemies will be different. I agree there will be lot of common code like knowing the position of that entity or getting health for that entity. One approach is to have Static entity as interface which defines behavior and have a abstract class called Enemy which will have common state and behavior. But again the instance variables should be based on the behavior we want to provide not they other way round . By making a abstract class, we would inherit them all even if we don't need/use them. Hence I have my doubts with this approach. What do you guys think ? |
@ashish2199 Yeah. That's what and how I wanted to say. God damn it >_< |
Either way sounds fine. I’m just wondering how their movement will be different to the player though. I think my way may be a bit to convoluted. I was thinking the movement receives something like a 2D Vector, and moves based on that. How we generate that could be different for different entities. I’m very new to architecture so I could be way off, though. I’m happy with whatever you guys want to do :) |
@dostertag commented on Nov 17, 2017, 6:15 AM GMT+5:30:
First of all, Thanks for asking such question. It I feel it will be helpful to others too. First of all let me tell you what I mean by Entity. For me Entity is anything that is drawn inside gamescreen(the box that represents the area in which game is played) which affect the behaviour of player.For example a wall is a entity for us as it stops player from moving across it. First of all Entity is not a class, it is a interface ( that is it will only tell what behaviour i.e Methods the class that implement it will provide). Entity interface will be extended by two other interfaces that is StaticEntity and Moving Entity. Methods which EntityInterface might have are StaticEntity interface will provide the behavior for entities that donot move such as Stones as Bricks. It might include methods such as MovingEntity interface will provide the behaviour for entities that move across the gamescreen such as Player and various types of enemies. It will have methods like move(int steps, enum Direction), die() , getHealth() , reduceHealth(int damage) Now comes the actual class which will implement this interface that is Player Class class. Player class will have state that is instance variable such as positionX , positionY , health , playerName ect. Since it will implement MovingEntity interface which inturn extends the Entity interface so it will have methods from both the interfaces. Here will we provide the method body for these methods for example die() method will be implemented diffeent by enemy classes and player class. For enemeny class when die method is called we would simply just set isAlive boolean of that enemy to false, increment the score and remove it from the list of aliveEnemy which will present it from getting drawn on screen. |
Based on the current code, I think we should add a class for enemies... |
I am thinking of creating these classes under these packages.
Bomberman (Project Name)
Please provide your feedback
Update: Changed to exploding animation , also added multiple classes for vairous levels.
The text was updated successfully, but these errors were encountered: