Last active
August 29, 2015 13:56
-
-
Save Bjacksonshorts/8861370 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 AwkwardCritter extends Critter { | |
public AwkwardCritter(String s, int h, int a, int l,String n){ | |
super(s,h,a,l,n); | |
} | |
public void passDay(int days){ | |
status = name + " 's age is " + days; | |
if(healthChecker()){ | |
System.out.println(name + " = DEAD"); | |
}else{ | |
if (calculateChances(85) ){ | |
eat(); | |
status = status + " and it ate"; | |
} else { | |
health = health - 20; | |
} | |
if(health > 80 && luck > 7){ | |
yodel(); | |
status = status + " and yodelled"; | |
} | |
if(calculateChances(50)){ | |
snooze(); | |
status = status + " and slept"; | |
}else{ | |
health = health - 2; | |
} | |
if(calculateChances(50)){ | |
meditate(); | |
status = status + " and meditated" ; | |
}else{ | |
health = health - 7; | |
} | |
System.out.println( status + " and it's health is "+ health); | |
} | |
} | |
public void eat(){ | |
health = Math.min(health + 2, 100); | |
} | |
public void yodel(){ | |
if(luck > 7){ | |
health = Math.min(health + 3, 100); | |
}else if(luck <=7){ | |
health = Math.min(health + 2, 100); | |
} | |
} | |
public void snooze(){ | |
health = Math.min(health + 9, 100); | |
} | |
public void meditate(){ | |
health = Math.min(health + 2, 100); | |
} | |
public boolean healthChecker(){ | |
if (health < 1){ | |
return true; | |
}else{ | |
return false; | |
} | |
} | |
} |
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.util.Random; | |
public abstract class Critter { | |
protected String status; | |
protected int health; | |
protected int age; | |
protected double luck; | |
protected String name; | |
public Critter(String s, int h, int a, double l,String n){ | |
status= s; | |
name = n; | |
health = h; | |
age = a; | |
luck = l; | |
} | |
public String toString(){ | |
return "lee"; | |
} | |
public boolean calculateChances(int pct){ | |
Random p = new Random(); | |
int pp = p.nextInt(100); | |
if(pp + getLuck() < pct){ | |
return true; | |
}else{ | |
return false; | |
} | |
} | |
abstract public void passDay(int days); | |
public void setHealth(int h){ | |
h = health; | |
} | |
public int getHealth(){ | |
return health; | |
} | |
public void setLuck( double l){ | |
l = luck; | |
luck = Math.random(); | |
} | |
public double getLuck(){ | |
return luck; | |
} | |
} |
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 Environment { | |
private SmellyCritter sc; | |
private UglyCritter ug; | |
private AwkwardCritter ac; | |
private Critter[] critterArray; | |
//private int counter; | |
public static void main( String[] args) { | |
Environment e = new Environment(); | |
for (int idx = 1; idx <= 30; ++idx){ | |
e.status(idx); | |
} | |
System.out.println(""); | |
System.out.println(""); | |
} | |
public Environment(){ | |
critterArray = new Critter[15]; | |
for(int i = 0; i < 5; i++) { //health,age,luck | |
critterArray[3 * i] = new AwkwardCritter("",100,0,10,"AC " + (i + 1)); | |
critterArray[(3 * i) + 1] = new SmellyCritter("",100,0,10, "SC " + (i + 1)); | |
critterArray[(3 * i) + 2] = new UglyCritter("", 100,0,10, "UG " + (i + 1)); | |
} | |
} | |
public void status(int days){ | |
for( int i = 0; i < critterArray.length; i++){ | |
critterArray[i].passDay(days); | |
} | |
} | |
} |
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 SmellyCritter extends Critter { | |
public SmellyCritter(String s, int h, int a, int l, String n){ | |
super(s, h,a,l,n); | |
} | |
public void passDay( int days){ | |
status = name + " 's age is " + days; | |
if(healthChecker()){ | |
System.out.println( name + " = DEAD"); | |
}else{ | |
if(calculateChances(40)){ | |
eat(); | |
status = status + " and it ate"; | |
}else{ | |
health = health - 10; | |
} | |
if(calculateChances(80)){ | |
snooze(); | |
status = status + " and snoozed"; | |
}else{ | |
health = health - 1; | |
} | |
if( days > 15){ | |
dance(); | |
status = status + " and decided to dance"; | |
} | |
System.out.println( status + " and it's health is "+ health); | |
} | |
} | |
public void eat(){ | |
health = Math.min(health + 6,100); | |
} | |
public void dance(){ | |
health = Math.min(health + 1, 100); | |
} | |
public void snooze(){ | |
health = Math.min(health + 2, 100); | |
} | |
public boolean healthChecker(){ | |
if (health < 1){ | |
return true; | |
}else{ | |
return false; | |
} | |
} | |
} |
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 UglyCritter extends Critter { | |
public UglyCritter(String s,int h, int a, int l, String n){ | |
super(s,h,a,l,n); | |
} | |
public void passDay(int days){ | |
status = name + " 's age is " + days; | |
if(healthChecker()){ | |
System.out.println(name + " = DEAD"); | |
}else{ | |
if(calculateChances(70)){ | |
eat(); | |
status = status + " and it ate"; | |
}else{ | |
health = health - 15; | |
} | |
if(calculateChances(50)){ | |
snooze(); | |
status = status + " and snoozed"; | |
} | |
else{ | |
health = health - 2; | |
} | |
System.out.println( status + " and it's health is "+ health); | |
} | |
} | |
public void eat(){ | |
health = Math.min(health + 4, 100); | |
} | |
public void snooze(){ | |
health = Math.min(health + 9, 100); | |
} | |
public boolean healthChecker(){ | |
if (health < 1){ | |
return true; | |
}else{ | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment