public static void eliminateNoblelessFactions(Game game) { List<Unit> units = game.getUnits(); List<Structure> cities = game.getStructures(); // find out newly eliminated factions and set them to eliminated and // set their original assets to neutral/rebel faction boolean[] prev_no_nobles = new boolean[C.NR_HOUSES]; for (int i = 0; i < prev_no_nobles.length; i++) { prev_no_nobles[i] = game.getFaction(i).isEliminated(); } boolean[] no_nobles = {true, true, true, true, true}; for (Unit unit : units) { if (unit.type == C.NOBLE_UNIT_TYPE && C.HOUSE1 <= unit.prev_owner && unit.prev_owner <= C.HOUSE5) { no_nobles[unit.prev_owner] = false; } } for (int i = 0; i < no_nobles.length; i++) { if (no_nobles[i] ^ prev_no_nobles[i]) { game.getFaction(i).setEliminated(); for (Unit unit : units) { if (unit.prev_owner == i) { unit.prev_owner = C.NEUTRAL; unit.owner = C.NEUTRAL; } } for (Structure city : cities) { if (city.prev_owner == i) { city.prev_owner = C.NEUTRAL; city.owner = C.NEUTRAL; } } } } }
/** * Adjust unit loyalty, create rebels, place rebels. Note: AFAIK in all mods Naval move units can * only move on oceans, and non-Naval units can move on land, so rebels are placed with this * feature in mind. */ public void adjustUnitLoyalty() { List<Unit> units = game.getUnits(); LinkedList<Unit> rebels = new LinkedList<>(); for (Unit unit : units) { if (unit.owner == game.getTurn() && canRebel(unit)) { unit.loyalty = pay_rate * C.PAY_LOYALTY_HIT; if (!unit.in_space && unit.loyalty < C.LOYALTY_REBEL_LIMIT) { if (game.getRandom().nextFloat() < (1 - unit.loyalty / C.LOYALTY_REBEL_LIMIT) * C.LOYALTY_REBEL_HIGH_P) { rebels.add(unit); } } } } if (rebels.isEmpty()) { return; } rebels.sort(Comp.unit_xy); rebels.sort(Comp.unit_pidx); LinkedList<Unit> naval = new LinkedList<>(); LinkedList<Unit> non_naval = new LinkedList<>(); for (Unit rebel : rebels) { if (rebel.move_type == C.MoveType.NAVAL) { naval.add(rebel); } else { non_naval.add(rebel); } } placeRebels(naval, Util.FindHexesAround.Hextype.SEA); placeRebels(non_naval, Util.FindHexesAround.Hextype.LAND); }
public static void main(String[] args) { Game currentGame = new Game(); System.out.println( "Welcome to the guessing game. Think of a number between 1 and 100 and type 'ok' when ready."); System.out.println( "If the number it too high, type 'high'. If it is too low, type 'low'. If it is your number, type 'yes'"); Scanner sc = new Scanner(System.in); String inputString = sc.next(); int guess = 50; int currentHigh = 101; int currentLow = 1; int guessCount = 0; while (!inputString.equals("yes")) { if (inputString.equals("high")) { currentHigh = guess; } else if (inputString.equals("low")) { currentLow = guess; } guess = currentGame.generateGuess(guess, inputString, currentHigh, currentLow); guessCount++; System.out.println(guess); inputString = sc.next(); } System.out.println("I have guessed your number in: " + guessCount + " guesses!"); sc.close(); }
public static void main(String[] args) { Game game = Parser.parserFileMieux(new File("test.txt")); game.getActes().get(0).getScene(0).setCheminBackground("img/green_hallway_by_skimlines.jpg"); // game.getActes().get(0).getScene(1).setCheminBackground("img/green_stairs_by_skimlines.jpg"); Ecran screen = new Ecran(game); System.out.println(screen.toScript()); }
public void update() { if (!Sound.menuBackground.playing()) Sound.playAsBackground(Sound.menuBackground, 1); if (Game.INPUT.isKeyPressed(Input.KEY_W) || Game.INPUT.isKeyPressed(Input.KEY_UP)) { if (selectedIndex > 0) { selectedIndex -= 1; Sound.menuClick.playAsSoundEffect(1, 0.1f, false); } } if (Game.INPUT.isKeyPressed(Input.KEY_S) || Game.INPUT.isKeyPressed(Input.KEY_DOWN)) { if (selectedIndex < 2) { selectedIndex += 1; Sound.menuClick.playAsSoundEffect(1, 0.1f, false); } } if (Game.INPUT.isKeyPressed(Input.KEY_RETURN)) { switch (selectedIndex) { case 0: Game.setState(GameState.MAIN_MENU); case 1: Game.setState(GameState.LOADMENU); break; case 2: Game.exit(); break; default: break; } } }
public void OpenMenuPopup() { CloseMenuPopup(); Game game = Main.app.getStateManager().getState(Game.class); game.Pause(true); MenuPopup = nifty.createPopup("MenuPopup"); nifty.showPopup(screen, MenuPopup.getId(), null); }
public static void main(String[] args) { List<Dungeon> dungeons = new ArrayList<Dungeon>(); dungeons.add(new Dungeon(1)); dungeons.add(new Dungeon(2)); dungeons.add(new Dungeon(3)); Game game = new Game(dungeons); game.start(); }
@Override public void whatToDo(Character character) { Game game = Game.getInstance(); if (!game.getIsHaunt()) { character.incrementMight(); character.incrementSanity(); } }
public void onStartScreen() { System.out.println("GameScreen onStartScreen"); Game game = Main.app.getStateManager().getState(Game.class); game.setGameScreenController(this); timeLabel.setText(game.getTimeString()); GameCameraState Cam = Main.app.getStateManager().getState(GameCameraState.class); Cam.pointCameraAt(game.getMap().getMapCenter()); }
@Override public void onEnter() { final Game runningGame = GameInput.getRunningGame(); GameInput.setTargetCursor( TargetCursor.makeSquareTargeter( runningGame.getWorld(), runningGame.getActivePlayerActor().getCoordinate(), null)); pauseIfUnpaused(); }
@Override public void onEnter() { final Game runningGame = GameInput.getRunningGame(); GameInput.setTargetCursor( TargetCursor.makeListTargeter( runningGame.getWorld(), runningGame.getActivePlayerActor().getInventory().getItemsHeld().size())); pauseIfUnpaused(); }
public void paint(Graphics g, int x, int y) { int viewPointX, viewPointY; // attach health bar to top of unit that owns it viewPointX = Game.getGameInstance().getPlayer().getPlayerCamera().getViewPointX(); viewPointY = Game.getGameInstance().getPlayer().getPlayerCamera().getViewPointY(); g.setColor(Color.BLACK); g.drawRect(x - viewPointX, y - viewPointY, barWidth, barHeight); g.setColor(barColor); g.fillRect(x - viewPointX + 1, y - viewPointY + 1, (int) fillWidth - 1, barHeight - 1); }
public void update() { for (Updatable updatable : updatables.values()) { updatable.update(); } Game game = Main.app.getStateManager().getState(Game.class); timeLabel.setText(game.getTimeString()); // update pathfinding statistics PathManager pathFinding = PathManager.getSingleton(); NumberFormat numberFormat = NumberFormat.getIntegerInstance(); // comma seperated expandedNodesLabel.setText(numberFormat.format(-1)); graphReadsLabel.setText(numberFormat.format(-1)); }
@Override public void input(double delta) { if (game.keyboard.keyDownOnce(KeyEvent.VK_R)) { if (game.mouse instanceof RelativeMouseInput) game.setMouseController(new AbsoluteMouseInput(game)); else game.setMouseController(new RelativeMouseInput(game)); } if (game.keyboard.keyDownOnce(KeyEvent.VK_C)) { Game.window().setDisableCursor(!Game.window().isCursorDisabled()); } }
public void OpenPopulationPopup() { ClosePopulationPopup(); Game game = Main.app.getStateManager().getState(Game.class); game.Pause(true); // prevent mouse wheel interfering with scrolling a menu // TODO there may be a better way of doing this, e.g. nifty not passing the mousewheel event to // the game. disableMouseWheel(); PopulationPopup = nifty.createPopup("PopulationPopup"); nifty.showPopup(screen, PopulationPopup.getId(), null); }
private void changeMenu(int i) { Menu m = nxtMenu[currMenu.ordinal()][i]; if (m != Menu.NONE) { this.currMenu = m; subMenuVisible = false; // Animate boxes for (int n = 0; n < NUM_BOXES; n++) { boxs[n] .setPos(boxStartPos) .setText(txt[currMenu.ordinal()][n]); // .setSize(boxStartSize[1]); } } else { // TODO: put in special cases for things like 'quit' and options(sound, language etc.) here switch (currMenu) { case NONE: case MAIN: // When click on find opponent currSubMenu = currMenu; submenuSelected(0); break; case NEW_GAME: switch (i) { case 1: game.gameType = Game.SINGLE_PLY; game.startNewGame(); break; case 2: game.gameType = Game.LOCAL_MULTI; game.startNewGame(); break; } break; case FIND_OPPONENT: switch (i) { } break; case OPTIONS: changeSubmenu(Menu.GENERAL.ordinal(), i); break; case CHECK: switch (i) { case 1: System.exit(0); break; } break; } } SoundManager.MENUCLICK.play(); }
public static void main(String[] args) { Game game = new Game(4); for (int i = 0; i < args.length; i += 2) try { game.addOption(args[i], args[i + 1]); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("Arguments invalide."); } catch (IllegalArgumentException e) { System.out.println("Arguments invalide."); } if (!game.isStarted()) game.addOption(); game.addKeyListener(); }
/** * Place rebels, fill hexes starting from closest available hex. Return true if all rebels placed, * false if we run out of planet hexes before all rebels are placed. * * @param rebels list of units to place * @return true iff all rebels placed */ private boolean placeRebels(LinkedList<Unit> rebels, Util.FindHexesAround.Hextype type) { Hex center = null; Hex target = null; Hex prev_target = null; Util.FindHexesAround hex_finder = null; Point p = new Point(C.NEUTRAL, C.NEUTRAL); int p_idx = -1; int x = -1; int y = -1; while (!rebels.isEmpty()) { Unit unit = rebels.pop(); if (unit.y != y || unit.x != x || unit.p_idx != p_idx) { y = unit.y; x = unit.x; p_idx = unit.p_idx; addMessage( new Message( "Rebellion on " + game.getPlanet(p_idx).name + " " + x + "," + y + "!", C.Msg.REBELLION, game.getYear(), game.getPlanet(p_idx))); } Hex hex_tmp = game.getHexFromPXY(unit.p_idx, unit.x, unit.y); if (!hex_tmp.equals(center)) { center = hex_tmp; hex_finder = new Util.FindHexesAround(center, C.NEUTRAL, type, game.getPlanet(p_idx).tile_set_type); prev_target = target; target = hex_finder.next(); } while (target != null && Util.stackSize(target.getStack()) >= C.STACK_SIZE) { target = hex_finder.next(); } prev_target = spot(prev_target, target); if (target == null) { return false; } if (unit.carrier == null) { if (unit.type_data.cargo > 0 && unit.cargo_list.size() > 0) { List<Unit> tmp = new LinkedList<>(); tmp.addAll(unit.cargo_list); for (Unit u : tmp) { unit.disembark(u); center.addUnit(u); } } } else { Unit u = unit.carrier; u.disembark(unit); } center.getStack().remove(unit); game.changeOwnerOfUnit(p, unit); game.relocateUnit(false, unit.p_idx, target.getX(), target.getY(), unit); target.addUnit(unit); game.getUnits().add(unit); // Util.dP(" hex " + target.getX() + "," + target.getY()); } spot(target, prev_target); return true; }
public static int calculateCityLoyalty(int tax_rate, EfsIni efs_ini, Game game) { int excom_penalty = 0; // System.out.println(" state = " + game.getDiplomacy().getDiplomaticState(game.getTurn(), // C.THE_CHURCH)); if (game.getDiplomacy().getDiplomaticState(game.getTurn(), C.THE_CHURCH) == C.DS_WAR) { excom_penalty = game.getEfs_ini().excom_peasant_loyalty_hit; // System.out.println("WTF"); } // System.out.println("excom_peasant_loyalty_hit = " + // game.getEfs_ini().excom_peasant_loyalty_hit); // System.out.println("Excom penalty = " + excom_penalty); return FastMath.max( 0, FastMath.min( 100, 100 - (tax_rate - efs_ini.default_tax_rate) * C.TAX_LOYALTY_HIT - excom_penalty)); }
/** * Calculate faction Gross Domestic Product, that is the total firebirds produced by cities on * planets where you own the palace. */ public int calculateGDP() { int pop = 0; List<Structure> all_cities = game.getStructures(); boolean[] rules = new boolean[game.getPlanets().size()]; for (Structure s : all_cities) { if (s.type == C.PALACE && s.owner == game.getTurn()) { rules[s.p_idx] = true; } } for (Structure s : all_cities) { if (s.prev_owner == number && rules[s.p_idx]) { pop += s.health; } } return (int) FastMath.ceil(pop * CITY_GDP / 100); }
public SpriteEwin( final Game g, final Hero hero, final int x, final int y, final int w, final int h, final String name, final String image) { super( x, y, g.getPanel().getWidth(), g.getPanel().getHeight(), ImagesLoader.getInstance(), name, image); width = w; height = h; game = g; ewin = hero; // try { // player = new ImagesPlayer("run", g.getProgramPeriod(), // g.getPeriodBetween2Images(), true, // ImagesLoader.getInstance()); // } catch (final TooShortImagePeriodException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } }
/** * {@inheritDoc} * * @author holdawscot */ @Override public void loadXML(Game game, Element objectElement) { super.loadXML(game, objectElement); this.deadlyWeapon = (Weapon) game.getItem(objectElement.getChildText("deadlyWeapon")); this.soundEffect = objectElement.getChildText("soundEffect"); this.killMessage = objectElement.getChildText("killMessage"); }
public MenuSys(Game game, Dimension winSize) { this.game = game; this.currMenu = Menu.MAIN; this.currSubMenu = Menu.NONE; this.subMenuVisible = false; this.drawSubmenuScreen = -1; this.winSize = winSize; // TODO: Get country connected on and set language (default to English) this.txt = english; // this.txtOpt = englishOpt; // loadGraphics(); setupBoxes(); // Init mouse and key listeners game.addMouseListener(menuClickListener); game.addMouseMotionListener(menuMoveListener); }
/* * Setups up menus boxes in correct positions */ private void setupBoxes() { int yoffset = 90; this.boxs = new Box[NUM_BOXES]; this.subBoxs = new Box[NUM_BOXES]; this.subMenuBoxs = new Box[NUM_SUB_BOXES]; this.textFields = new TextField[NUM_TEXT_FIELDS]; boxStartPos = new Vector2D((winSize.width - Box.size) / 2, (winSize.height - Box.size) / 2 + yoffset); this.centralBox = new Box(boxStartPos, "").setColor(Color.DARK_GRAY, Color.BLACK).setImage(game.imgs[1]); // TODO: Change dimensions subBoxStartPos = new Vector2D(winSize.width / 2 - Box.size * 3, (winSize.height - Box.size) / 2); for (int i = 0; i < NUM_BOXES; i++) { boxs[i] = new Box() .setPos(boxStartPos) .setSizeBoth(Box.size, Box.size) .setText(txt[currMenu.ordinal()][i]); subBoxs[i] = new Box().setPos(subBoxStartPos).setSizeBoth(Box.subSizeW, Box.subSizeH); } for (int i = 0; i < NUM_SUB_BOXES; i++) { subMenuBoxs[i] = new Box().setColor(Color.BLACK, Color.WHITE).setSizeBoth(Box.iconSize, Box.iconSize); } for (int i = 0; i < NUM_TEXT_FIELDS; i++) { textFields[i] = new TextField(); textFields[i].setVisible(false); game.add(textFields[i]); } // Set positions to end in after animation boxs[0].setFinalPos( new Vector2D( (winSize.width - Box.size) / 2, (winSize.height - Box.size * 3) / 2 + yoffset)); boxs[1].setFinalPos( new Vector2D( (winSize.width - Box.size * 3) / 2, (winSize.height - Box.size) / 2 + yoffset)); boxs[2].setFinalPos( new Vector2D((winSize.width + Box.size) / 2, (winSize.height - Box.size) / 2 + yoffset)); boxs[3].setFinalPos( new Vector2D((winSize.width - Box.size) / 2, (winSize.height + Box.size) / 2 + yoffset)); // SubMenuBoxes[0] is always back button Vector2D p = centralBoxSubmenuPos = new Vector2D( boxs[0].getFinalPos().x - Box.size / 2, boxs[0].getFinalPos().y + Box.size / 2); subMenuBoxs[0] = new Box(new Vector2D(p.x + 2 * Box.size / 2 - 50, p.y + 2 * Box.size - 30), "BACK") .setSizeBoth(100, 30) .setColor(Color.BLACK, Color.WHITE); }
@Override public void happens() { Character character = Game.getInstance().getCurrentCharacter(); HumanStats currentExplorer = (HumanStats) character.getStats(); Trait chosenTrait = Game.getInstance().chooseATrait(); int rollResult = character.getTraitRoll(chosenTrait); if (rollResult >= 4) { Trait trait1 = Game.getInstance().chooseATrait(); character.incrementTrait(trait1, 1); } else if (rollResult >= 0 && rollResult <= 3) { boolean decremented = false; for (Trait trait : Trait.values()) { if (decremented) { break; } switch (trait) { case KNOWLEDGE: if (currentExplorer.getCurrentKnowledgeIndex() != 0) { currentExplorer.decrementKnowledge(currentExplorer.getCurrentKnowledgeIndex()); decremented = true; } break; case SANITY: if (currentExplorer.getCurrentSanityIndex() != 0) { currentExplorer.decrementSanity(currentExplorer.getCurrentSanityIndex()); decremented = true; } break; case MIGHT: if (currentExplorer.getCurrentMightIndex() != 0) { currentExplorer.decrementMight(currentExplorer.getCurrentMightIndex()); decremented = true; } break; case SPEED: if (currentExplorer.getCurrentSpeedIndex() != 0) { currentExplorer.decrementSpeed(currentExplorer.getCurrentSpeedIndex()); decremented = true; } break; } } } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.popup_scoring); setFinishOnTouchOutside(false); game = (Game) getIntent().getExtras().get(Keys.GAME); TextView bowlerNameView = (TextView) findViewById(R.id.bowlerName); TextView batsmanNameView = (TextView) findViewById(R.id.strikingBatsmanName); batsmanNameView.setText(game.getBattingTeam().getStriker().getName()); bowlerNameView.setText(game.getBowlingTeam().getCurrentBowler().getName()); extrasGroup = (RadioGroup) findViewById(R.id.radiogroup1); runGroup = (RadioGroup) findViewById(R.id.radiogroup2); }
@Override public void updateSpriteSpeed() { if (isActive) { dy += 10 * ((float) game.getProgramPeriod() / 200); if (isLooping) { player.updateTick(); } } }
/** * Calculate base unit pay. * * @return */ public int calculateUnitPay() { int pay = 0; List<Unit> all_units = game.getUnits(); for (Unit u : all_units) { if (u.prev_owner == number) { pay += u.type_data.crd_trn; } } return pay; }
private Hex spot(Hex prev_target, Hex target) { if (prev_target != null && !prev_target.equals(target)) { List<Unit> tmp = prev_target.getStack(); // Util.dP("spot " + prev_target.getX() + "," + prev_target.getY() + " " + tmp.size() + " " + // Util.getFactionName(tmp.get(0).owner)); game.getHexProc().spotProc(prev_target, tmp); prev_target = target; } return prev_target; }
public static void main(final String[] args) { game = new Game(); game.frame.add(game); game.frame.setResizable(false); game.frame.setTitle(Game.title); game.frame.pack(); game.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); game.frame.setLocationRelativeTo(null); game.frame.setVisible(true); game.start(); }