From a9d7a2e1960f9d7404d28feec6669d3b247098a4 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Mon, 4 Jun 2012 11:25:17 -0400 Subject: Added experience/levelling You get less experience for fighting the same mob when you increase a level. Also, your attack power is equal to your level. --- src/com/fourisland/frigidearth/Functions.java | 18 ++++++++ .../fourisland/frigidearth/MapViewGameState.java | 50 ++++++++++++++++---- src/com/fourisland/frigidearth/Mob.java | 3 +- src/com/fourisland/frigidearth/mobs/Mouse.java | 10 ++++ src/com/fourisland/frigidearth/mobs/Rat.java | 10 +++- src/com/fourisland/frigidearth/mobs/Spider.java | 54 ++++++++++++++++++++++ 6 files changed, 134 insertions(+), 11 deletions(-) create mode 100644 src/com/fourisland/frigidearth/mobs/Spider.java (limited to 'src') diff --git a/src/com/fourisland/frigidearth/Functions.java b/src/com/fourisland/frigidearth/Functions.java index 32943ce..f01f3a0 100644 --- a/src/com/fourisland/frigidearth/Functions.java +++ b/src/com/fourisland/frigidearth/Functions.java @@ -30,4 +30,22 @@ public class Functions return result; } + + public static String padLeft(String str, int length, char pad) + { + int padding = length - str.length(); + if (str.length() > length) + { + return str; + } + + StringBuilder sb = new StringBuilder(); + for (int i=0; i 1000) + { + level++; + experience -= 1000; + + printMessage("You grow to level " + level + "!"); + } } foundMob = true; @@ -827,10 +858,10 @@ public class MapViewGameState implements GameState // Also, if it is adjacent to the player, it should attack if ((mob.hostile) && (canSeePlayer(mob.x, mob.y))) { - if (arePointsAdjacent(playerx, playery, mob.x, mob.y)) + if (arePointsAdjacent(playerx, playery, mob.x, mob.y, false)) { // Attack! - health -= (mob.power - defense); + health -= (mob.getAttackPower() - defense); printMessage(mob.getBattleMessage()); } else { List path = findPath(mob.getPosition(), new Point(playerx, playery)); @@ -1095,22 +1126,22 @@ public class MapViewGameState implements GameState } } - private boolean arePointsAdjacent(int px, int py, int mx, int my) + private boolean arePointsAdjacent(int px, int py, int mx, int my, boolean includeDiagonals) { if (mx == (px-1)) { - if (my == (py-1)) return true; + if ((my == (py-1)) && (includeDiagonals)) return true; if (my == py) return true; - if (my == (py+1)) return true; + if ((my == (py+1)) && (includeDiagonals)) return true; } else if (mx == px) { if (my == (py-1)) return true; if (my == (py+1)) return true; } else if (mx == (px+1)) { - if (my == (py-1)) return true; + if ((my == (py-1)) && (includeDiagonals)) return true; if (my == py) return true; - if (my == (py+1)) return true; + if ((my == (py+1)) && (includeDiagonals)) return true; } return false; @@ -1228,6 +1259,7 @@ public class MapViewGameState implements GameState case 1: mobTypes.add(Mouse.class); mobTypes.add(Rat.class); + mobTypes.add(Spider.class); } try diff --git a/src/com/fourisland/frigidearth/Mob.java b/src/com/fourisland/frigidearth/Mob.java index c35b276..f3bfe6a 100644 --- a/src/com/fourisland/frigidearth/Mob.java +++ b/src/com/fourisland/frigidearth/Mob.java @@ -17,7 +17,6 @@ public abstract class Mob public int y; public int health; public boolean hostile; - public int power; public Mob(int x, int y) { @@ -41,4 +40,6 @@ public abstract class Mob public abstract Color getDisplayColor(); public abstract String getName(); public abstract String getBattleMessage(); + public abstract int getAttackPower(); + public abstract int getBaseExperience(); } diff --git a/src/com/fourisland/frigidearth/mobs/Mouse.java b/src/com/fourisland/frigidearth/mobs/Mouse.java index 17f5f94..6966764 100644 --- a/src/com/fourisland/frigidearth/mobs/Mouse.java +++ b/src/com/fourisland/frigidearth/mobs/Mouse.java @@ -40,4 +40,14 @@ public class Mouse extends Mob { return "The mouse bites you"; } + + public int getAttackPower() + { + return 0; + } + + public int getBaseExperience() + { + return 50; + } } diff --git a/src/com/fourisland/frigidearth/mobs/Rat.java b/src/com/fourisland/frigidearth/mobs/Rat.java index 0603bb1..f7277c6 100644 --- a/src/com/fourisland/frigidearth/mobs/Rat.java +++ b/src/com/fourisland/frigidearth/mobs/Rat.java @@ -20,7 +20,6 @@ public class Rat extends Mob health = Functions.rollDice(1, 4); hostile = true; - power = 1; } public char getDisplayCharacter() @@ -43,4 +42,13 @@ public class Rat extends Mob return "The rat bites you"; } + public int getAttackPower() + { + return 1; + } + + public int getBaseExperience() + { + return 100; + } } diff --git a/src/com/fourisland/frigidearth/mobs/Spider.java b/src/com/fourisland/frigidearth/mobs/Spider.java new file mode 100644 index 0000000..58a554b --- /dev/null +++ b/src/com/fourisland/frigidearth/mobs/Spider.java @@ -0,0 +1,54 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.fourisland.frigidearth.mobs; + +import com.fourisland.frigidearth.Functions; +import com.fourisland.frigidearth.Mob; +import java.awt.Color; + +/** + * + * @author hatkirby + */ +public class Spider extends Mob +{ + public Spider(int x, int y) + { + super(x, y); + + health = Functions.rollDice(2, 5); + hostile = true; + } + + public char getDisplayCharacter() + { + return 's'; + } + + public Color getDisplayColor() + { + return Color.BLACK; + } + + public String getName() + { + return "Spider"; + } + + public String getBattleMessage() + { + return "The spider bites you"; + } + + public int getAttackPower() + { + return 2; + } + + public int getBaseExperience() + { + return 200; + } +} -- cgit 1.4.1