Skip to content

Commit

Permalink
v0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jmein committed Nov 19, 2011
1 parent d9e57ca commit 621bc42
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 156 deletions.
13 changes: 3 additions & 10 deletions 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);
}
}
19 changes: 11 additions & 8 deletions Figure.java
Expand Up @@ -6,37 +6,40 @@ 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<fightDice;i++){
System.out.print(" " + dice[i]);
}
System.out.println();
return dice;

}

public void wound(){

System.out.println(this.name + " takes a wound");
this.health--;
if (this.health == 0)
if (this.health == 0){
this.die();

}

}

abstract void die();
Expand Down
97 changes: 40 additions & 57 deletions Hero.java
@@ -1,63 +1,46 @@
public class Hero extends Figure{

public boolean winOnTie = false;
public boolean student;
public boolean strange;
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;

}

public static boolean[] throughness(){
boolean[] answer = {true,true,true,false,false};
return answer;
}

public String answer(String question){

if(question == "Where are you?"){
return("I'm at "+this.location.x+","+this.location.y);
}
else if(question == "How well are you?"){
return ("I have "+this.health+"/"+this.maxHealth+" health.");
}
else
return "...";

}

public void die(){
System.out.println("\"Curse you, zombies!! Now you've taken everything from me!!\"");
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();
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();
}

}
}
20 changes: 20 additions & 0 deletions 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.
46 changes: 4 additions & 42 deletions Square.java
Expand Up @@ -10,22 +10,9 @@ public class Square {
java.util.ArrayList<Hero> herolist;
java.util.ArrayList<Zombie> 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;
Expand All @@ -35,7 +22,7 @@ public Square(int x, int y, byte[] edges, int building, Board gameBoard){
this.zombielist = new java.util.ArrayList<Zombie>();
}

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)
Expand All @@ -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; i<living.fightDice; i++){
System.out.print(hd[i]+" ");
}
int hdMax = Dice.max(hd);
int[] zd = Dice.rolld(6, undead.fightDice);
System.out.print(undead.name + " rolls: ");
for(int i=0; i<undead.fightDice; i++){
System.out.print(zd[i]+" ");
}int zdMax = Dice.max(zd);
if((hdMax>zdMax) || ((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();
}
}
*/

}
31 changes: 16 additions & 15 deletions TestFight.java
Expand Up @@ -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<testSquare.zombielist.size(); j++){
testSquare.herolist.get(j%testSquare.herolist.size()).fight(testSquare.zombielist.get(j));
}
}

}

}
2 changes: 1 addition & 1 deletion TestMove.java
Expand Up @@ -13,7 +13,7 @@ public static void main(String[] args){

while(true){
System.out.println("Which way do you want to go?");
clumsy.moveTo(in.nextByte());
clumsy.moveTo(in.nextInt());
System.out.println(clumsy.answer("Where are you?"));
}

Expand Down
40 changes: 17 additions & 23 deletions Zombie.java
@@ -1,28 +1,22 @@
public class Zombie extends Figure{

Zombie(Square pit){
this.name = "Zombie";
this.health = this.maxHealth = 1;
this.fightDice = 1;
this.moveThrough = /*{true,true,true,true,false};*/Zombie.throughness();
this.location = pit;
pit.zombielist.add(this);

}

public static boolean[] throughness(){
boolean[] answer = {true,true,true,true,false};
return answer;
}

void answer(String question){
System.out.println("Urgh....");
}
Zombie(Square pit){
this.name = "Zombie";
this.health = this.maxHealth = 1;
this.fightDice = 1;
this.moveThrough =/*{true,true,true,true,false}*/Zombie.throughness();
this.location = pit;
pit.zombielist.add(this);
}

void die(){

System.out.println(this.name+" dies!");
this.location.zombielist.remove(this);
}
public static boolean[] throughness(){
boolean[] answer = {true,true,true,true,false};
return answer;
}

void die(){
System.out.println(this.name + " dies!");
this.location.zombielist.remove(this);
}

}
2 changes: 2 additions & 0 deletions ZombieHero.java
Expand Up @@ -2,9 +2,11 @@
public class ZombieHero extends Zombie{

ZombieHero(Hero corpse){

super(corpse.location);
this.name=("Zombie " + corpse.name);
this.health = this.maxHealth = corpse.maxHealth;

}

}

0 comments on commit 621bc42

Please sign in to comment.