diff --git a/Die.java b/Die.java index 591298d..01f1296 100644 --- a/Die.java +++ b/Die.java @@ -1,14 +1,7 @@ import java.util.Random; public class Die{ - - public static int rolld(int sides){ - Random roller=new Random(); - return (roller.nextInt(sides)+1); - } - - // public static int d6(){ -// return (new Random().nextInt(6)+1); - // } - + public static int rolld(int sides){ + return (new Random().nextInt(sides)+1); } +} diff --git a/Figure.java b/Figure.java index a967d33..93d3d44 100644 --- a/Figure.java +++ b/Figure.java @@ -6,21 +6,22 @@ public abstract class Figure{ public int maxHealth; public int health; public int fightDice; - public Square location; //maybe just coordinates? - //and then Square location = Board.squareAt(int x, int y) ? - + public Square location; boolean moveThrough[]; - public void moveTo(byte direction){ - byte dir = (byte)(direction -1); + public void moveTo(int direction){ + + int dir = ((direction--)%9); while(! this.moveThrough[this.location.edge[dir]]){ System.out.println("Try again"); - dir = (byte)(new Scanner(System.in).nextByte()-1); + dir = (int)(new Scanner(System.in).nextByte()-1); } this.location = this.location.inDir(dir); + } public int[] fightRoll(){ + System.out.print(this.name + " rolls:"); int[] dice = Dice.rolld(6,this.fightDice); for(int i=0;i zd[0]) || ( (hd[0] > zd[0]) && this.winOnTie) ){ - System.out.println(this.name + " wins!"); - if( Dice.hasDoubles(hd) ){ - undead.wound(); + public boolean winOnTie; + public boolean student; + public boolean female; + + Hero(String moniker, boolean kid, boolean xx, int healthBoxes, Square start){ + + this.name = moniker; + this.health = this.maxHealth = healthBoxes; + this.fightDice = 2; + this.moveThrough = Hero.throughness(); + this.student = kid; + this.female = xx; + this.location = start; + start.herolist.add(this); + + } + + public static boolean[] throughness(){ + boolean answer = {true,true,true,false,false}; + return answer; } - } - else { - this.wound(); - } - } + public void die(){ + System.out.println(this.name + " dies..."); + new ZombieHero(this); + } + + public void fight(Zombie undead){ + + int[] hd = this.fightRoll(); + int[] zd = undead.fightRoll(); + + if( (hd[0] > zd[0]) || ( (hd[0] == zd[0]) && this.winOnTie) ){ + System.out.println(this.name + " wins!"); + if( Dice.hasDoubles(hd) ){ + undead.wound(); + } + } + else { + this.wound(); + } + } } diff --git a/README b/README new file mode 100644 index 0000000..ae8882a --- /dev/null +++ b/README @@ -0,0 +1,20 @@ +lastnight emulates the board game "Last Night on Earth, the Zombie Game", created by Jason C. Hill and produced by Flying Frog. + +v0.0 + +2011.11.19: +formatted nicely. +Board contains a rectangular grid of Squares, constructors create empty boards. +Building does nothing. has a name and belongs to a Board. +charlist contains a list of the characters that must be included as heroes. +Card,Deck nonexistent, will create decks of cards used in game. +Ell has many Squares and a list of Buildings. Not yet implemented. Will create corners of the board: + 6x6 grid less a 3x3 corner. Random Buildings from cards selected by Ell. +Figure has basics of figures( zombies and heros ): movement, wound taking, rolling dice in fights, + information={name, health, fightDice, location. +Hero extends figure to model human characters. Contains extra information, constructor, fight method. +Square is one of the squares in the Board. contains coordinates, lists of heros and zombies in Square, + connections to neighboring squares. claims a Board and a Building to belong to. +TestDice,TestFight,TestMove, for testing aspects of the game. +Zombie extends figure to model zombies. has constructor... +ZombieHero extends Zombie to model ex-Heroes who are zombified. Constructor from Hero. diff --git a/Square.java b/Square.java index 42e6964..7a7c563 100644 --- a/Square.java +++ b/Square.java @@ -10,22 +10,9 @@ public class Square { java.util.ArrayList herolist; java.util.ArrayList zombielist; - byte[] edge; /* - stores connections to squares: - - 6 7 8 - 3 4 5 edge[4] is the square itself; - 0 1 2 - - edge[i]=0 -> i=4 - edge[i]=1 -> i is open edge - edge[i]=2 -> i is a door(in wall) - edge[i]=3 -> i is wall - edge[i]=4 -> i is board edge - - */ + int[] edge; - public Square(int x, int y, byte[] edges, int building, Board gameBoard){ + public Square(int x, int y, int[] edges, int building, Board gameBoard){ this.x = x; this.y = y; this.building = building; @@ -35,7 +22,7 @@ public Square(int x, int y, byte[] edges, int building, Board gameBoard){ this.zombielist = new java.util.ArrayList(); } - public Square inDir(byte dir){ + public Square inDir(int dir){ if(dir == 0) return this.town.squareAt(this.x-1, this.y-1); else if (dir == 1) @@ -57,30 +44,5 @@ else if (dir == 8) else return this; } -/* - public void fight(Hero living, Zombie undead){ - int[] hd = Dice.rolld(6, living.fightDice); - System.out.print(living.name + " rolls: "); - for(int i=0; izdMax) || ((hdMax == zdMax) && (living.winOnTie))) { - System.out.println(living.name + " won the fight!"); - if(Dice.hasDoubles(hd)){ - System.out.println(living.name + " wounds "+ undead.name); - undead.wound(); - } - } - else { - System.out.println(living.name + " lost the fight..."); - living.wound(); - } - } -*/ + } diff --git a/TestFight.java b/TestFight.java index 2adf43e..92887c6 100644 --- a/TestFight.java +++ b/TestFight.java @@ -2,22 +2,23 @@ public class TestFight { public static void main(String args[]){ - - Square testSquare = new Square(0,0,new byte[9],0,new Board(1)); - Hero hero0 = new Hero("Clumsy",false,false,3,testSquare); - - while(hero0.health > 0){ - testSquare.fight(hero0, new Zombie(testSquare)); + + Square testSquare = new Square(0,0,new int[9],0,new Board(1)); + Hero[] heroes = new Hero[2]; + + heroes[0] = new Hero("Clumsy",false,false,3,testSquare); + heroes[1] = new Hero("Sammy",false,false,4,testSquare); + + for(int i=0; i<(2*Die.rolld(3)); i++){ + new Zombie(testSquare); } - - ZombieHero zh0 = new ZombieHero(hero0); - hero0 = new Hero("Sammy",false,false,4,testSquare); - - while((hero0.health>0) && (zh0.health>0)){ - testSquare.fight(hero0,zh0); - testSquare.fight(hero0, new Zombie(testSquare)); + + for(int i=0; (testSquare.herolist.size() > 0 && testSquare.zombielist.size() > 0);i++){ + System.out.println("\nRound " + i + ":"); + for(int j=0; j