Commits

Anonymous committed 828cd44

...moving on with map

Comments (0)

Files changed (13)

bin/com/nima/conf.hq

 item.rack=1
 item.fireplace=1
 item.weapons_rack=1
-item.cupboard=1
+item.cupboard=1
+board.default=---------------------------\n|                         |\n|                         |

bin/com/nima/quest1.hq

 name=A Growl of Thunder
-map=eeeeeeeeeeemeteeeeeeeeeeeetuuuufeeeeeemeuuuuuuuuuuueeuuuueeeeeeeeeuuuuuuuuuuuteuuuueeeeeeeeeuuuuuuuuuuuteuuuueeeeeeeeeuuuuuuuuuuuteuuuuemeeeeeeeuuuemeeeeeeeeuuuueeeeeeeeeeeeeeemeeeeeeuuuumemeeeeeeeeeemeeeeeeeeuuuueeeeeeeeeffeeemeeeeeeeeeeeeeeeeeeeeffeeeeeeeetetemeeuuuueeeeeffeuuuueeeeeemeemuuuueeeeeeeeuuuueeeeeeeeeeuuuueeeeeeeeuuuueeeeeefffeemeeuuuetemeeuuueeeeeeuuuueeemuuueemffmemeeeeeeeuuuumeeeuuueeeffeeeeeeeeeeuuuuemeeuuueemffeeeeeeteeeuuuueeeeuuuteeemeemeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
+map=eeeeeeeeeeemeteeeeeeeeeeeetuuuufeeeeeemeuuuuuuuuuuueeuuuueeeeeeeeeuuuuuuuuuuuteuuuueeeeeeeeeuuuuuuuuuuueeuuuueeeeeeeeeuuuuuuuuuuueeuuuuemeeeeeeeuuuemeeeeeeeeuuuueeeeeeeeeeeeeeemeeeeeeuuuumemeeeeeeeeeemeeeeeeeeuuuueeeeeeeeeffeeemeeeeeeeeeeeeeeeeeeeeffeeeeeeeetetemeeuuuueeeeeffeuuuueeeeeemeemuuuueeeeeeeeuuuueeeeeeeeeeuuuueeeeeeeeuuuueeeeeefffeemeeuuuetemeeuuueeeeeeuuuueeemuuueemffmemeeeeeeeuuuumeeeuuueeeffeeeeeeeeeeuuuuemeeuuueemffeeeeeeteeeuuuueeeeuuuteeemeemeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
 text=You have traveled far and wide...
 notes=Empty for now...
 max_heroes=2
+<?xml version="1.0"?>
+
+<project name="HeroQuest" default="compile">
+	
+	<property name="src.dir" location="src"/>
+	<property name="dst.dir" location="bin"/>
+	
+	<target name="compile">
+		<echo level="info" message="Building HeroQuest Game Engine" />
+		<javac srcdir="${src.dir}" destdir="${dst.dir}" 
+			includeantruntime="false" failonerror="true">
+		</javac>
+	</target>
+	
+	<target name="run">
+		<java classpath="bin" classname="com.nima.HeroQuest" />
+	</target>
+</project>

src/com/nima/Game.java

 	private Quest quest;
 	private List<Monster> monsters = new ArrayList<Monster>();	
 	private int currentTurn = 0;
+	private boolean gameEnded = false;
 	private int maxNumberOfHeroes;
 	
 	public Game(int numberOfPlayers){
 	public void begin(){		
 	}
 	
-	public void end(){		
+	public void end(){
+		this.gameEnded = true;
+	}
+	
+	public boolean isGameEnded(){
+		return gameEnded;
 	}
 	
 	public Pawn whoIsNext(){
 		return null;
 	}
 
+	public String getBoard(){
+		return board.export();
+	}
 	public void createPlayers(){
 		//commit from android
 	}

src/com/nima/GameBoard.java

 	public static final int VMAX = 19;
 	
 	private GameTile[][] tiles = new GameTile[VMAX][HMAX];
-	
+		
 	public void configure(char[] bitmap) throws Exception{
 		if(bitmap.length != VMAX * HMAX){
 			throw new Exception();
-		}
+		}		
 		int row = 0, col = 0;		
 		for (char c : bitmap) {
 			this.tiles[row][col++] = new GameTile(c);
 	
 	public String export(){
 		StringBuilder sb = new StringBuilder();
-		
+		for(int row = 0; row < VMAX; row++){
+			for(int col = 0; col < HMAX; col++){
+				sb.append(tiles[row][col].getType().toChar());
+			}
+			sb.append("\n");
+		}		
 		return sb.toString();
 	}
 	

src/com/nima/GameTile.java

 				return EMPTY;		
 			}
 		}
+		
+		public char toChar(){
+			switch(this){
+				case UNUSED:
+					return 'x';					
+				case EMPTY:
+					return '.';
+				case BLOCKED:
+					return 'B';
+				case FURNITURE:
+					return 'F';
+				case TRAP:
+					return 'T';
+				case MONSTER:
+					return 'M';
+				case EXIT:
+					return 'X';
+				case ENTRY:
+					return 'I';
+				default:
+					return '.';
+			}
+		}
 	}
 	
 	public GameTile(char c){

src/com/nima/Hero.java

 		this.mindPoints = Integer.valueOf(props.getProperty(key + "base_mind"));
 		this.attackDice = Integer.valueOf(props.getProperty(key + "base_attack"));
 		this.defendDice = Integer.valueOf(props.getProperty(key + "base_defend"));
-		this.moveDice = Integer.valueOf(props.getProperty(key + "base_move"));
+		this.moveDice = Integer.valueOf(props.getProperty(key + "base_move"));		
 	}
 	
 	public boolean move(int movePoints) {

src/com/nima/HeroQuest.java

 package com.nima;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.FileReader;
 import java.io.IOException;
-import java.util.Enumeration;
+import java.io.InputStreamReader;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
 import java.util.Properties;
 
 public class HeroQuest {
 	public static void main(String[] args) {
 		System.out.println("Welcome to HeroQuest Engine!!!");
+				
 		
 		//read configuration file		
 		Properties config = getProperties("src/com/nima/conf.hq");
-
+		
+		try {
+			PrintStream ps = new PrintStream(System.out, true, "UTF-8");
+			ps.println(config.getProperty("board.default"));
+		} catch (UnsupportedEncodingException e) {			
+			e.printStackTrace();
+		}
+		
+		System.out.println();
 		//create new game
-		Game game = new Game(2);
+		int numberOfPlayers = 2;
+		Game game = new Game(numberOfPlayers);
+		Player player;
 		
 		//Prepare Board with a quest
 		try{			
 			game.startQuest(getProperties("src/com/nima/quest1.hq"));
+			
+			//create player
+			player = new Player(getProperties("src/com/nima/player.hq"));
+			System.out.println(game.getBoard());
+			
+			Hero hero = player.getActiveHero();
+			//position hero to board
+			hero.setPosx(12);
+			hero.setPosy(0);
+			
+			//simple logic to be implemented and tested
+			
+			//1) check if game ended
+			//2) who is next?
+			//3) if player then goto :5 
+			//4) zargon plays
+			//5) check if next player is alive: on.yes then 'play' else goto :2
+			
+			//DM's play
+			//1) find active monsters
+			//2) decide monster's turn
+			//3) find next monster's visible heroes
+			//4) move monster to closest hero
+			//5) if not close then goto :7
+			//6) attack adjacent hero
+			//7) if monsters available then goto :3
+			
+			
 		}catch(Exception e){
 			e.printStackTrace();
-		}
-		
+		}		
 		
 		System.out.println("Finished!!!");
 	}
 	
+	private static void cmdtest(Game game){
+		InputStreamReader isr = new InputStreamReader(System.in);
+		int input = ' ';
+		
+		while(input != 'x'){
+			showMenu();
+			try {
+				input = isr.read();
+			
+			
+			switch(input){
+			case 'b':
+				System.out.println(game.getBoard());
+				break;
+			case 'a':
+				break;
+			case 's':
+				break;
+			case 'd':
+				break;
+			case 'w':
+				break;
+			case 'i':
+				break;
+			case 'j':
+				break;
+			case 'k':
+				break;
+			case 'l':
+				break;
+			case 'r':					
+				break;
+				
+			}
+			
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+		}
+			
+			
+	}
+	
+	private static void showMenu(){
+		System.out.println("Menu\n====\n\nx: Exit\nb: Show Board\nr: Roll Move Dice\nw: Move Up\ns: Move Down\na: Move Left\nd: Move Right\ni: Attack Up\nj: Attack Left\nk: Attack Down\nl: Attack Right\n");
+		
+	}
+	
 	private static Properties getProperties(String fileName){
 		Properties props = new Properties();
 		File file = new File(fileName);
-		try {
-			FileReader fr = new FileReader(file);
-			props.load(fr);
-			fr.close();
+		try {			
+			FileInputStream fis = new FileInputStream(file);
+			props.load(new InputStreamReader(fis, "UTF-8"));			
 		} catch (FileNotFoundException e) {
 			e.printStackTrace();
 		} catch (IOException e) {

src/com/nima/Pawn.java

 	public enum STATE {
 		GOOD, DEAD, CURSED, PETRIFIED
 	}
-	private STATE currentState;
+	protected STATE currentState;
+	
+	protected int posx;	
+	protected int posy;
 	
 	protected String name;
 	protected int moveDice;
 	protected int bodyPoints;
 	protected int mindPoints;
 	
+	protected int availableMovePoints = 0; //initialize
+		
 	public abstract boolean move(int movePoints);
 	public abstract boolean attack(Pawn other);
 	
+	protected void rollMovement(){
+		RedDice rd = new RedDice();
+		for(int i = 0; i <moveDice; i++){
+			this.availableMovePoints += rd.roll().number(); 
+		}
+	}
+	
 	public STATE getCurrentState(){
 		return currentState;
 	}
 	public int getMoveDice() {
 		return moveDice;
 	}
-	public void setMoveDice(int moveDices) {
+	public void setMoveDice(int moveDice) {
 		this.moveDice = moveDice;
 	}
 	public int getAttackDice() {
 	public void setName(String name) {
 		this.name = name;
 	}
+	public int getPosx() {
+		return posx;
+	}
+	public void setPosx(int posx) {
+		this.posx = posx;
+	}
+	public int getPosy() {
+		return posy;
+	}
+	public void setPosy(int posy) {
+		this.posy = posy;
+	}
+	public int getMovePoints(){
+		return availableMovePoints;
+	}
 }

src/com/nima/Player.java

 public class Player {
 	private String name;
 	private List<Hero> heroesOwned = new ArrayList<Hero>();
+	private int activeHero = -1;
 	private int gold;
 	
 	public enum Action {
 		int heroes = Integer.valueOf(props.getProperty("heroes"));
 		while(heroes > 0){			
 			this.heroesOwned.add(new Hero("hero." + String.valueOf(heroes--) + ".", props));
+			this.activeHero = this.heroesOwned.size() - 1;
 		}
 	}
 	
 	public void addHero(Hero hero){
 		if(hero == null) return;
-		heroesOwned.add(hero);
+		this.heroesOwned.add(hero);
+		this.activeHero = this.heroesOwned.size() - 1;
 	}
-	
+
 	public Action getCurrentAction() {
 		return currentAction;
 	}
 		if(loss < 0) return;
 		this.gold -= loss;
 	}
+	
+	public Hero getActiveHero() {
+		if(activeHero < 0){
+			return null;
+		}
+		return heroesOwned.get(activeHero);
+	}
 }

src/com/nima/RedDice.java

 			return Side.FOUR;
 		}else if(rnd == 5) {
 			return Side.FIVE;
-		}
-		
+		}		
 		return Side.SIX;		
 	}
 }

src/com/nima/conf.hq

 item.rack=1
 item.fireplace=1
 item.weapons_rack=1
-item.cupboard=1
+item.cupboard=1
+board.default=---------------------------\n|                         |\n|                         |

src/com/nima/quest1.hq

 name=A Growl of Thunder
-map=eeeeeeeeeeemeteeeeeeeeeeeetuuuufeeeeeemeuuuuuuuuuuueeuuuueeeeeeeeeuuuuuuuuuuuteuuuueeeeeeeeeuuuuuuuuuuuteuuuueeeeeeeeeuuuuuuuuuuuteuuuuemeeeeeeeuuuemeeeeeeeeuuuueeeeeeeeeeeeeeemeeeeeeuuuumemeeeeeeeeeemeeeeeeeeuuuueeeeeeeeeffeeemeeeeeeeeeeeeeeeeeeeeffeeeeeeeetetemeeuuuueeeeeffeuuuueeeeeemeemuuuueeeeeeeeuuuueeeeeeeeeeuuuueeeeeeeeuuuueeeeeefffeemeeuuuetemeeuuueeeeeeuuuueeemuuueemffmemeeeeeeeuuuumeeeuuueeeffeeeeeeeeeeuuuuemeeuuueemffeeeeeeteeeuuuueeeeuuuteeemeemeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
+map=eeeeeeeeeeemeteeeeeeeeeeeetuuuufeeeeeemeuuuuuuuuuuueeuuuueeeeeeeeeuuuuuuuuuuuteuuuueeeeeeeeeuuuuuuuuuuueeuuuueeeeeeeeeuuuuuuuuuuueeuuuuemeeeeeeeuuuemeeeeeeeeuuuueeeeeeeeeeeeeeemeeeeeeuuuumemeeeeeeeeeemeeeeeeeeuuuueeeeeeeeeffeeemeeeeeeeeeeeeeeeeeeeeffeeeeeeeetetemeeuuuueeeeeffeuuuueeeeeemeemuuuueeeeeeeeuuuueeeeeeeeeeuuuueeeeeeeeuuuueeeeeefffeemeeuuuetemeeuuueeeeeeuuuueeemuuueemffmemeeeeeeeuuuumeeeuuueeeffeeeeeeeeeeuuuuemeeuuueemffeeeeeeteeeuuuueeeeuuuteeemeemeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
 text=You have traveled far and wide...
 notes=Empty for now...
 max_heroes=2