Commits

Nikolaos Margaris  committed e89d3bf

...restructuring

  • Participants
  • Parent commits 8ce0f79

Comments (0)

Files changed (3)

File src/com/nima/Game.java

 	 * 		keep game's current status
 	 */
 	
-	private Player[] players;
+	private List<Player> players = new ArrayList<Player>();
+	private int numberOfPlayers;
 	private GameBoard board = new GameBoard();
-	private Quest quest;
-	private List<Monster> monsters = new ArrayList<Monster>();	
+	private Quest quest;	
+	
+	private int currentPlayerIndex;
 	private int currentTurn = 0;
 	private boolean gameEnded = false;
 	private int maxNumberOfHeroes;
 	
 	public Game(int numberOfPlayers){
-		this.players = new Player[numberOfPlayers];
+		this.numberOfPlayers = numberOfPlayers;
+		playerJoined(new Xargon());	// ... add the evil guy!!!
 	}
 	
 	public void startQuest(Properties questProps) throws Exception{
 		return maxNumberOfHeroes;
 	}
 	
-	public void begin(){		
+	public void playerJoined(Player player){
+		this.players.add(player);
+	}
+	
+	public void begin(){
+		//for now traverse through the array of players as is
+		this.currentPlayerIndex = 0;
+		this.players.get(0).activateNextPawn();
+	}
+	
+	public Pawn getCurrentPawn(){
+		return players.get(currentPlayerIndex).getActivePawn();
 	}
 	
 	public void end(){
 		return gameEnded;
 	}
 	
-	public Pawn whoIsNext(){
+	public Pawn next(){
 		return null;
 	}
+	
+	public void endCurrentTurn(){
+		this.currentTurn += 1;
+	}
+	
+	public int getCurrentTurn(){
+		return currentTurn;
+	}
 
 	public String getBoard(){
 		return board.export();
 	}
+	
+	public void rollTurns(){
+		//TBD
+	}
+	
 	public void createPlayers(){
 		//commit from android
 	}

File src/com/nima/HeroQuest.java

 		System.out.println();
 		
 		//create new game
-		int numberOfPlayers = 2;
+		int numberOfPlayers = 1;
 		Game game = new Game(numberOfPlayers);
-		Player player;
+		HumanPlayer 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"));
+			player = new HumanPlayer(getProperties("src/com/nima/player.hq"));
+			
+			// add player to game
+			game.playerJoined(player);
+			
 			System.out.println(game.getBoard());
 			
-			Hero hero = player.getActiveHero();
+			Pawn pawn = player.getActivePawn();
 			//position hero to board
-			hero.setPosx(12);
-			hero.setPosy(0);
+			pawn.setPosx(12);
+			pawn.setPosy(0);
 			
 			// Need to write down what each class should do from now on ... !!!
 			
 			
 			//simple logic to be implemented and tested
 			
+			game.begin();
+			
 			//1) check if game ended
-			//2) who is next?			
+			while(!game.isGameEnded()){				
+			
+			//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
 			//4) move monster to closest hero
 			//5) if not close then goto :7
 			//6) attack adjacent hero
-			//7) if monsters available then goto :3
-			
+			//7) if monsters available then goto :3				
+				game.end();
+				game.endCurrentTurn();
+			}
 			
 		}catch(Exception e){
 			e.printStackTrace();

File src/com/nima/Player.java

 package com.nima;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-
-public class Player {
-	private String name;
-	private List<Hero> heroesOwned = new ArrayList<Hero>();
-	private int activeHero = -1;
-	private int gold;
-	
+public abstract class Player {
 	public enum Action {
 		ATTACK, CAST_SPELL, SEARCH_TREASURE, SEARCH_SECRET,
 		SEARCH_TRAP, DISARM_TRAP, NONE
 	}
-
-	private Action currentAction = Action.NONE;
-	private Object currentMovePoints = 0;
-	private int rankPoints = 0;
-	
-	public Player(String name){	
-		this.name = name;
-	}
 	
-	public Player(Properties props){
-		this.name = props.getProperty("name");
-		this.gold = Integer.valueOf(props.getProperty("gold"));
-		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;
-		}
-	}
+	protected Action currentAction = Action.NONE;
+	protected int activePawn = -1;
+	protected String name;
 	
-	public void addHero(Hero hero){
-		if(hero == null) return;
-		this.heroesOwned.add(hero);
-		this.activeHero = this.heroesOwned.size() - 1;
-	}
-
 	public Action getCurrentAction() {
 		return currentAction;
 	}
-
-	public Object getCurrentMovePoints() {
-		return currentMovePoints;
-	}
-
-	public int getRankPoints() {
-		return rankPoints;
-	}
-	
 	public String getName(){
 		return name;
 	}
 	
-	public int wealth(){
-		return gold;
-	}
-	
-	public void earnGold(int earnings){
-		if(earnings < 0) return;
-		this.gold += earnings;
-	}
-	
-	public void loseGold(int loss){
-		if(loss < 0) return;
-		this.gold -= loss;
-	}
-	
-	public Hero getActiveHero() {
-		if(activeHero < 0){
-			return null;
-		}
-		return heroesOwned.get(activeHero);
-	}
-}
+	/*
+	 * Abstract Section
+	 */
+	public abstract Pawn getActivePawn();
+	public abstract void activateNextPawn();
+}