package th; // Scores file manager // this is a hideous kludge. language designers need to wake up // and realize that *printf is The One True Way of Text Formatting :) // Even LISP realizes this, and the designers of Common Lisp appear to // have crafted "format" in the image of "printf". printf had typing issues // and people blame it for a deficency in C. Pity. // Viva printf! import java.io.*; public class Hsn { static void writeout(Mon player) throws IOException { FileWriter file = new FileWriter("scores.txt", true); PrintfFormat fmt = new PrintfFormat("%8d %3d %3d %3d %3d\t%s the level %d %s,\n\t%s %s in %s %s%s%s\n"); PrintfFormat line2 = new PrintfFormat("\tHP: %d/%d, ST: %d/%d, IN: %d/%d, DX: %d/%d, AR: %d, RG: 1/%d\n\tPlayed from:%s\n"); int score = (player.level+1) * (player.vanquished+1) + player.xp; score -= 2 * player.peacefuls + 10 * player.murders + 50 * player.canibal; score += g.bonus; if (player.hp > 0) { if (g.vegetarian == 0) score += 500; if (g.vegan == 0) score += 1000; if (g.food == 0) score += 3000; if (g.pets_lost == 0) score += 500; if (g.used_wand == 0) score += 1000; if (g.used_weapon == 0) score += 5000; if (g.illiterate == 0) score += 500; if (g.killed_zeius != 0) score += 500; if (g.teleported == 0) score += 500; if (g.polymorphed == 0) score += 500; if (g.controlled_polymorph == 0) score += 1500; } // hp > 0 Object stuff[] = { score, player.vanquished, player.peacefuls, player.murders, player.canibal, player.name, player.level, player.species.name, (player.hp > 0? "" : "killed by"), player.last_damage, (player.here.unique? "the" : "a"), player.here.name, (player.stunned != 0? ",\n\tWhile stunned by " + player.stunner + ".": "."), (player.inventory.contains(g.artifact)? "\n\t(Had the " + g.artifact.kind.name + "!)" :"") }; Object stuff2[] = { player.hp, player.mhp, player.st, player.mst, player.in, player.min, player.dx, player.mdx, player.armor, player.species.regeneration, g.from }; file.write(fmt.sprintf(stuff)); file.write(line2.sprintf(stuff2)); file.write(conducts(player)+"\n"); file.close(); }; static String conducts(Mon player) { String tmp = ""; if (g.vegetarian == 0) tmp += "\t* +500 Followed a vegetarian diet.\n"; if (g.vegan == 0) tmp += "\t* +1500 Followed a vegan diet.\n"; if (g.food == 0) tmp += "\t* +3000 Went without food.\n"; if (g.pets_lost == 0) tmp += "\t* +500 Never lost a pet.\n"; else tmp += "\tX Allowed " + g.pets_lost + " pet"+(g.pets_lost == 1? "" : "s" )+" to die.\n"; if (g.used_wand == 0) tmp += "\t* +1000 Never used an electric wand.\n"; if (g.used_weapon == 0) tmp += "\t* +5000 Never hit with a wielded weapon.\n"; if (g.illiterate == 0) tmp += "\t* +500 Never read or wrote.\n"; if (g.killed_zeius != 0) tmp += "\t* +500 Defeated Suzie in honorable melee combat.\n"; if (g.teleported == 0) tmp += "\t* +500 Never teleported.\n"; if (g.polymorphed == 0) tmp += "\t* +500 Never changed form.\n"; if (g.controlled_polymorph == 0) tmp += "\t* +1500 Never used a controlled polymorph.\n"; else tmp += "\tX Used controlled polymorph.\n"; if (player.peacefuls == 0) tmp += "\t* Never attacked a peaceful creature.\n"; else tmp += "\tX Attacked peaceful creatures " + player.peacefuls + " times.\n"; if (player.murders == 0) tmp += "\t* Never murdered anyone in a way that a jury would believe.\n"; else tmp += "\tX Murdered " + player.murders + " people.\n"; if (player.murders > g.allow_murder) tmp += "\t (Convicted of " + (player.murders - g.allow_murder) + " them.)\n"; if (player.canibal != 0) tmp += "\t X Resorted to cannibalism " + player.canibal + " times!\n"; for (Object merit: g.special_merits) tmp += "\t "+((String)merit)+"\n"; return tmp; } }