Created
February 17, 2014 05:26
-
-
Save ltagliaferri/9045191 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BlueRedTower extends Tower { | |
public BlueRedTower(){ | |
super(); | |
this.name = "Blue Red Tower"; | |
} | |
public int attackJelly() { | |
int pointValue = 1; | |
return pointValue; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BlueTower extends Tower { | |
public BlueTower(){ | |
super(); | |
this.name = "Blue Tower"; | |
} | |
public int attackJelly() { | |
int pointValue = 1; | |
return pointValue; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RedTower extends Tower { | |
public RedTower(){ | |
super(); | |
this.name = "Red Tower"; | |
} | |
public int attackJelly() { | |
int pointValue = 0; | |
return pointValue; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
public abstract class Tower { | |
public int pointValue; | |
public static final int LEVEL_1 = 1; | |
public static final int LEVEL_2 = 2; | |
public static final int LEVEL_3 = 3; | |
public static final int LEVEL_4 = 4; | |
protected int level; | |
protected String name; | |
public Tower(){ | |
this.level = LEVEL_1; | |
name = "Generic Tower"; | |
} | |
public void increaseLevel(){ | |
if (this.level != LEVEL_4) this.level++; | |
else System.out.println("Tower at maximum level"); | |
} | |
public void attackJelly(int pointValue){ | |
if (pointValue > 1) { | |
System.out.println(this.name + " attacks Jelly for " + pointValue + " points damage."); | |
System.out.println(); | |
} | |
else if (pointValue == 1) { | |
System.out.println(this.name + " attacks Jelly for " + pointValue + " point damage."); | |
System.out.println(); | |
} | |
else { | |
System.out.println(this.name + " did not effectively attack Jelly."); | |
System.out.println(); | |
} | |
} | |
/*public int compareTo(Tower arg0) { | |
if (this.level > arg0.level) return 1; | |
else return -1; | |
} | |
*/ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TowerTest { | |
public static void main (String[] args){ | |
BlueRedTower brt = new BlueRedTower(); | |
brt.attackJelly(1); | |
BlueTower bt = new BlueTower(); | |
bt.attackJelly(2); | |
bt.attackJelly(2); | |
RedTower rt = new RedTower(); | |
rt.attackJelly(2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment