public static GameStateFactory getStateFactory() { if (_instance == null) { _instance = new GameStateFactory(); } return(_instance); }
public void endTurn() { /*foreach (Unit unit in current.units) * { * current.points += getPoints(unit); * }*/ Console.WriteLine("Le joueur " + current.name + " a fini de jouer son tour"); if (nbTurn == 0) { endGame(); } else { switchPlayer(); } nbTurn--; // Pour l'history if (nbTurn % 2 == 0) { Console.WriteLine("-stocjkage"); GameState gs = saveStates.stateToSave; List <Unit> lu = new List <Unit>(); lu.AddRange(UnitFactory.getUnitFactory().createArmy(current.race, current.units.Count)); int i = 0; while (i < lu.Count) { lu[i].pos = current.units[i].pos; i++; } Player p = PlayerFactory.getPlayerFactory().createPlayer(current.race, current.name, lu); gs.player1 = p; gs.nbTurn = nbTurn; gs.units = clone(map.units); saveStates.set(gs); saveStates.save(); saveStates.set(GameStateFactory.getStateFactory().createGameState()); } else { Console.WriteLine("-settage"); GameState gs = saveStates.stateToSave; List <Unit> lu = new List <Unit>(); lu.AddRange(UnitFactory.getUnitFactory().createArmy(current.race, current.units.Count)); int i = 0; while (i < lu.Count) { lu[i].pos = current.units[i].pos; i++; } Player p = PlayerFactory.getPlayerFactory().createPlayer(current.race, current.name, lu); gs.player2 = p; //saveStates.set(gs); } }
public GameState pop() { stateToSave = GameStateFactory.getStateFactory().createGameState(); if (states.Count != 0) { GameState g = states.Last(); states.RemoveAt(states.Count - 1); return(g); } else { return(null); } }
public static GameStateFactory getStateFactory() { if (_instance == null) _instance = new GameStateFactory(); return _instance; }
public Game build() { Random rnd = new Random(); Game game = new GameImpl(); // Creation de la carte de la taille voulue // ainsi que le nombre de tours associés MapStrategy mS; switch (this.sizeMap) { case GameBuilder.LitMap: mS = LitMapFactory.getMapStrategy(); game.nbTurn = LitTurn * 2; break; case GameBuilder.MidMap: mS = MidMapFactory.getMapStrategy(); game.nbTurn = MidTurn * 2; break; case GameBuilder.BigMap: mS = BigMapFactory.getMapStrategy(); game.nbTurn = BigTurn * 2; break; default: mS = LitMapFactory.getMapStrategy(); break; } PlayerFactory pF = PlayerFactory.getPlayerFactory(); RaceFactory rF = RaceFactory.getRaceFactory(); UnitFactory uF = UnitFactory.getUnitFactory(); game.map = mS.createMap(); Race p1Race = rF.getRace(player1Race); List <Unit> p1Army = uF.createArmy(p1Race, mS.getSizeArmy()); Player player1 = pF.createPlayer(p1Race, player1Name, p1Army); game.map.placeArmy(player1, 1); Race p2Race = rF.getRace(player2Race); List <Unit> p2Army = uF.createArmy(p2Race, mS.getSizeArmy()); Player player2 = pF.createPlayer(p2Race, player2Name, p2Army); game.map.placeArmy(player2, 2); List <Player> pl = new List <Player>(); pl.Add(player1); pl.Add(player2); game.players = pl; game.current = game.players[rnd.Next(0, 1)]; // game.nbTurn = 0; History h = HistoryFactory.getHistoryFactory().createHistory(); game.saveStates = h; GameState gs = GameStateFactory.getStateFactory().createGameState(); gs.player1 = game.players[0]; gs.player2 = game.players[1]; gs.nbTurn = game.nbTurn; gs.units = game.map.units; game.saveStates.set(gs); game.saveStates.save(); game.saveStates.set(GameStateFactory.getStateFactory().createGameState()); return(game); }
public void start() { saveStates.set(GameStateFactory.getStateFactory().createGameState()); beginTurn(); }