I wanted to learn more about programing and wanted to create something that been made a million times over but I want to understand it better.
I am trying to create a combat system using randomly generated enemies and the player.
I created a Abstract Entity class that encases all the shared attributes and then created two class "Enemy" "Player" and those inherit all of the attributes.
My issue is I keep getting an error about the int damageDealt = rand.nextint(god.attackDamage); and it does not explain the issue. Anytime I try to consolidate attributes and methods into a class and then create and instance of that class I have issues when trying to work with that object. Maybe I'm not understanding something correctly but could anyone explain this process a little better. Im not interested in a link to someone who has completed the task, i would much rather understand how and why it works.
I know i didn't need to create class and objects here but i wanted to grow the project and make it as object oriented as possible. In my mind as modular as possible
basically...
Abstract class Entity(){
int currentHealth = 10;
int maxHealth = 50;
int attackDamage = 5;
}
public class devil extends Entity(){
}
public class god extends Entity(){
}
Main(){
Bool running = true;
Player god = new Player();
Enemy devil = new Enemy();
game:
while(running){
devil.currentHealth = rand.next(devil.maxHealth); //give the enemy rand hp
while(enemy.currentHealth > 0){
int damageDealt = rand.nextint(god.attackDamage);
int damageTaken = rand.nextint(devil.attackDamage);
devil.currentHealth -= god.attackDamage();
god.currentHealth -= devil.attackDamage();
if (devil.currentHealth = 0){
continue game;
}
if (god.currentHealth = 0 {
running = false
System.out.println("Thanks for watching the game fight itself..lol")
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire