Skip to content

Commit e3f0374

Browse files
committed
init
1 parent 36816e1 commit e3f0374

148 files changed

Lines changed: 4449 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package oop.enemyversion1;
2+
3+
public class Enemy {
4+
5+
/*
6+
Goal: Show public interface for class.
7+
- Talk about Abstraction
8+
- Display Zombie walking, speaking and attacking.
9+
*/
10+
11+
String typeOfEnemy;
12+
int healthPoints = 10;
13+
int attackDamage = 1;
14+
15+
public void talk() {
16+
System.out.println("I am a " + typeOfEnemy + " Be prepared to fight!");
17+
}
18+
19+
public void walkForward() {
20+
System.out.println(typeOfEnemy + " moves closer to you");
21+
}
22+
23+
public void attack() {
24+
System.out.println(typeOfEnemy + " attacks for " + attackDamage + " damage");
25+
}
26+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package oop.enemyversion1;
2+
3+
public class Implementation {
4+
5+
public static void main(String[] args) {
6+
Enemy zombie = new Enemy();
7+
8+
zombie.typeOfEnemy = "Zombie";
9+
10+
System.out.println(zombie.typeOfEnemy + " has " + zombie.healthPoints +
11+
" health points and can do attack of " + zombie.attackDamage);
12+
13+
zombie.talk();
14+
zombie.walkForward();
15+
zombie.attack();
16+
}
17+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package oop.enemyversion2;
2+
3+
public class Enemy {
4+
5+
/*
6+
Goal: Show Encapsulation
7+
- Display Zombie walking, speaking and attacking.
8+
- Display Zombie getting their health and attacking
9+
- Create a new Enemy Ogre who needs more attack than the Zombie
10+
- Use setter to set Ogre health and attack
11+
- What happens if you forget to add one of them? We can prevent this by creating a constructor
12+
- Create second Ogre object referencing
13+
- Create constructor
14+
*/
15+
16+
// Look into typeOfEnemy
17+
private String typeOfEnemy;
18+
private int healthPoints;
19+
private int attackDamage;
20+
21+
public Enemy(String typeOfEnemy, int healthPoints, int attackDamage) {
22+
this.typeOfEnemy = typeOfEnemy;
23+
this.healthPoints = healthPoints;
24+
this.attackDamage = attackDamage;
25+
}
26+
27+
public void talk() {
28+
System.out.println("I am a " + typeOfEnemy + " Be prepared to fight!");
29+
}
30+
31+
public void walkForward() {
32+
System.out.println(typeOfEnemy + " moves closer to you");
33+
}
34+
35+
public void attack() {
36+
System.out.println(typeOfEnemy + " attacks for " + attackDamage + " damage");
37+
}
38+
39+
public int getHealthPoints() {
40+
return healthPoints;
41+
}
42+
43+
public void setHealthPoints(int healthPoints) {
44+
this.healthPoints = healthPoints;
45+
}
46+
47+
public int getAttackDamage() {
48+
return attackDamage;
49+
}
50+
51+
public void setAttackDamage(int attackDamage) {
52+
this.attackDamage = attackDamage;
53+
}
54+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package oop.enemyversion2;
2+
3+
public class Implementation {
4+
5+
public static void main(String[] args){
6+
// Enemy zombie = new Enemy();
7+
// zombie.setHealthPoints(10);
8+
// zombie.setAttackDamage(1);
9+
// System.out.println("Zombie has " + zombie.getHealthPoints() +
10+
// " health points and can do attack of " + zombie.getAttackDamage());
11+
//
12+
// zombie.talk();
13+
// zombie.walkForward();
14+
// zombie.attack();
15+
//
16+
// System.out.println("----");
17+
/**-----------------------*/
18+
// Enemy ogre = new Enemy();
19+
// ogre.setHealthPoints(20);
20+
// ogre.setAttackDamage(3);
21+
//
22+
// System.out.println("Ogre has " + ogre.getHealthPoints() +
23+
// " health points and can do attack of " + ogre.getAttackDamage());
24+
//
25+
// ogre.talk();
26+
// ogre.walkForward();
27+
// ogre.attack();
28+
/**-----------------------*/
29+
// Enemy ogre = new Enemy(20, 3);
30+
//
31+
// System.out.println("Ogre has " + ogre.getHealthPoints() +
32+
// " health points and can do attack of " + ogre.getAttackDamage());
33+
//
34+
// ogre.talk();
35+
// ogre.walkForward();
36+
// ogre.attack();
37+
/**-----------------------*/
38+
Enemy ogre1 = new Enemy("Ogre", 20, 3);
39+
40+
Enemy ogre2 = ogre1;
41+
42+
ogre1.setHealthPoints(15);
43+
44+
System.out.println(ogre1.getHealthPoints());
45+
System.out.println(ogre2.getHealthPoints());
46+
47+
}
48+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package oop.enemyversion3;
2+
3+
public class Enemy {
4+
5+
/*
6+
Goal: Show Inheritance
7+
- Implement Zombie object
8+
- Explain Superclass / super()
9+
- Override talk function
10+
- Create SpreadDisease that Parent does not have
11+
- Create Ogre class
12+
- Implement Smash
13+
- Explain Static
14+
- Static get all enemies
15+
- Static get id for each enemy
16+
-@Override
17+
*/
18+
19+
private int id;
20+
private int healthPoints;
21+
private int attackDamage;
22+
private static int numberOfEnemies;
23+
24+
public Enemy(int healthPoints, int attackDamage) {
25+
this.healthPoints = healthPoints;
26+
this.attackDamage = attackDamage;
27+
numberOfEnemies++;
28+
this.id = numberOfEnemies;
29+
}
30+
31+
public void talk() {
32+
System.out.println("Be prepared to fight!");
33+
}
34+
35+
public void walkForward() {
36+
System.out.println("Monster moves closer to you");
37+
}
38+
39+
public void attack() {
40+
System.out.println("Monster attacks for " + attackDamage + " damage");
41+
}
42+
43+
public int getHealthPoints() {
44+
return healthPoints;
45+
}
46+
47+
public void setHealthPoints(int healthPoints) {
48+
this.healthPoints = healthPoints;
49+
}
50+
51+
public int getAttackDamage() {
52+
return attackDamage;
53+
}
54+
55+
public void setAttackDamage(int attackDamage) {
56+
this.attackDamage = attackDamage;
57+
}
58+
59+
public int getId() {return id;}
60+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package oop.enemyversion3;
2+
3+
public class Implementation {
4+
5+
public static void main(String[] args){
6+
Zombie zombie = new Zombie(5, 1);
7+
8+
zombie.talk();
9+
zombie.walkForward();
10+
System.out.println(zombie.getHealthPoints());
11+
zombie.spreadDisease();
12+
/** ------------- Does not work with Enemy object */
13+
// Enemy zombie2 = new Enemy(5, 10);
14+
// zombie2.spreadDisease();
15+
16+
17+
Ogre ogre = new Ogre(20, 5);
18+
ogre.talk();
19+
ogre.walkForward();
20+
System.out.println(ogre.getHealthPoints());
21+
22+
23+
System.out.println(zombie.getId());
24+
System.out.println(ogre.getId());
25+
26+
}
27+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package oop.enemyversion3;
2+
3+
public class Ogre extends Enemy {
4+
public Ogre(int healthPoints, int attackDamage) {
5+
super(healthPoints, attackDamage);
6+
}
7+
8+
@Override
9+
public void talk() {
10+
System.out.println("Ogre is slamming hands all around!");
11+
}
12+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package oop.enemyversion3;
2+
3+
public class Zombie extends Enemy {
4+
public Zombie(int healthPoints, int attackDamage) {
5+
super(healthPoints, attackDamage);
6+
}
7+
8+
@Override
9+
public void talk() {
10+
System.out.println("*Grumbling...*");
11+
}
12+
13+
public void spreadDisease() {
14+
System.out.println("The zombie is trying to spread infection");
15+
}
16+
}
17+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package oop.enemyversion4;
2+
3+
public class Enemy {
4+
5+
/*
6+
Goal: Show Polymorphism
7+
*/
8+
9+
private int id;
10+
private int healthPoints;
11+
private int attackDamage;
12+
private static int numberOfEnemies;
13+
14+
public Enemy(int healthPoints, int attackDamage) {
15+
this.healthPoints = healthPoints;
16+
this.attackDamage = attackDamage;
17+
numberOfEnemies++;
18+
this.id = numberOfEnemies;
19+
}
20+
21+
public void talk() {
22+
System.out.println("Be prepared to fight!");
23+
}
24+
25+
public void walkForward() {
26+
System.out.println("Monster moves closer to you");
27+
}
28+
29+
public void attack() {
30+
System.out.println("Monster attacks for " + attackDamage + " damage");
31+
}
32+
33+
public int getHealthPoints() {
34+
return healthPoints;
35+
}
36+
37+
public void setHealthPoints(int healthPoints) {
38+
this.healthPoints = healthPoints;
39+
}
40+
41+
public int getAttackDamage() {
42+
return attackDamage;
43+
}
44+
45+
public void setAttackDamage(int attackDamage) {
46+
this.attackDamage = attackDamage;
47+
}
48+
49+
public int getId() {return id;}
50+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package oop.enemyversion4;
2+
3+
public class Implementation {
4+
5+
public static void main(String[] args) {
6+
Zombie zombie = new Zombie(10, 1);
7+
zombie.spreadDisease();
8+
Ogre ogre = new Ogre(20, 3);
9+
10+
battle(zombie);
11+
battle(ogre);
12+
}
13+
14+
public static void battle(Enemy e) {
15+
e.talk();
16+
e.attack();
17+
}
18+
}

0 commit comments

Comments
 (0)