public static void main(String[] args) { // Create players Player p1 = new Player("Ivano", 10); Player p2 = new Player("Maria", 10); // set ships System.out.println("Player 1 place shipment"); p1.setShips(); System.out.println("Player 2 place shipment"); p2.setShips(); // start game while (p1.isAlive() && p2.isAlive()) { // P1 Turn playTurn(p1, p2); // P2 Turn playTurn(p2, p1); } // somebody won if (p1.isAlive()) { System.out.println("PLAYER 1 WON!!!\nCongratulations!!"); } else { System.out.println("PLAYER 2 WON!!!\nCongratulations!!"); } }
public static void main(String[] args) { // TODO Auto-generated method stub Player p1 = new Player("Bob"); System.out.println(p1.name + ", You came across an item. +10 health!"); p1.boostHealth(100); System.out.println("Your health is now " + p1.health); System.out.println(p1.strength); Item i1 = new Item("sword", 0, 10); i1.boost(p1); System.out.println(p1.strength); Poison i2 = new Poison(); System.out.println("You came across Poison!"); i2.boost(p1); System.out.println(p1.health); System.out.println(p1.isAlive()); // Instant kill the player System.out.println("You stepped on a snake!"); p1.health = p1.health - p1.health; System.out.println(p1.isAlive()); System.out.println("You are dead!"); clearscreen(); System.out.println("You are a clear screen"); p1.health += 100; Enemy e1 = new Enemy("qoB"); Shirt s1 = new Shirt(); s1.boost(p1); // e1.fight(p1); // make empty array Enemy[] enemyArray = new Enemy[5]; // Array holds 5 enemies // fills the enemy array for (int i = 0; i < enemyArray.length; i++) { enemyArray[i] = new Enemy("qoB" + i); } // fight every single enemy in this array for (int i = 0; i < enemyArray.length; i++) { enemyArray[i].fight(p1); p1.obliterateNum += 5; } }
protected GameState updateThis(float et) { music.update(et); factory.update(et, player.getSpeed()); field.update(et); tunnel.update(et); float offset = -getNearClippingPlane() - player.getL() / 2; totalDistance += -player.getZ() + offset; distortion.translateZ(player, offset, player.getSpeed()); tunnel.translateZ(player, offset); field.translateZ(player, offset); if (player.isAlive()) { return this; } else if (fadeOut > 0) { fadeOut -= FADE_OUT_RATE * et; return this; } else { // TODO: Better end-of-game System.out.println("Game over!"); System.out.println("Your score: " + score); System.out.println("Your speed: " + player.getSpeed()); System.out.println("Your distance: " + totalDistance); return null; } }
private static String isLivingBoldState(Player player) { if (player.isAlive()) { return ""; } else { return Colors.BOLD; } }
/** Restart the game (for starting a new round) */ private void restart() { timePassed = 0.0f; Random r = new Random(); player.setCoords(10 + r.nextInt(GRIDSIZE - 20), 10 + r.nextInt(GRIDSIZE - 20), r.nextInt(3)); player.isAlive = true; grid = new Grid(GRIDSIZE, this); }
@Override protected void doAction() { boolean hasHuman = false; boolean hasMutant = false; boolean hasResistant = false; boolean hasHumanDoctor = false; int nbMutants = 0; Iterator<Player> itPlayer = game.playerIterator(); while (itPlayer.hasNext()) { Player player = itPlayer.next(); if (!player.isAlive()) continue; if (player.getState() == State.HUMAN) { hasHuman = true; } else { hasMutant = true; nbMutants++; } if (player.getGenome() == Genome.RESISTANT) hasResistant = true; if (player.getRole() == Role.DOCTOR && player.getState() == State.HUMAN) hasHumanDoctor = true; } if (!hasHuman && !hasMutant) { game.end(new EndGame(EndGame.Winner.DRAW, EndGame.Reason.ANNIHILATION)); return; } if (!hasHuman) { game.end(new EndGame(EndGame.Winner.MUTANTS, EndGame.Reason.ANNIHILATION)); return; } if (!hasMutant) { game.end(new EndGame(EndGame.Winner.HUMANS, EndGame.Reason.ANNIHILATION)); return; } if (!hasHumanDoctor) { int threshold = 1 + (mutantsAreNextToPlay ? 0 : 1) + (hasResistant ? 1 : 0); if (nbMutants >= threshold) game.end(new EndGame(EndGame.Winner.MUTANTS, EndGame.Reason.ASSURED_VICTORY)); } }
/** * Permet de supprimer proprement le dernier fichier wav et pho utilisé * * @author Justal "Latsuj" Kevin * @email [email protected] */ public void closeCurrentThreadPlayer() { if (player != null) { logger.info("JukeBox.Class : Fermeture du fichier " + player.getPath()); player.stopSong(); player.interrupt(); while (player.isAlive()) { // On attend que le thread soit ferme pour avancer } if (!isRessources(player.getPath())) { File pho = new File(previousSong + ".pho"); File wav = new File(previousSong + ".wav"); pho.delete(); wav.delete(); } else { logger.info("JukeBox.Class : Non suppression du fichier " + player.getPath()); } } }
// tests the player class @Test public void PlayerTest() throws Exception { Player player = new Player(2); assert !player.getShips().isEmpty(); assert player.getShips().size() == player.getNumShips(); assert player.getNumShipsArranged() == player.getShips().size() - player.getNumShips(); assert player.canAddCell(); Cell cell1 = new Cell(1, Cell.Status.HIT); player.addCell(cell1); player.addCell(cell1); assert player.getNumShipsArranged() == 1; assert player.canAttack(); player.attackCell(cell1); player.upgrade(); player.resetNumsAttacksMade(); assert !player .canAttack(); // even though we reset attacks, player should not be able to attack because // we fired on ourselves and destroyed our own ship assert player.getNumShipsAlive() == 0; // we only had one ship, and it's dead assert !player.isAlive(); // player has no living ships }
/** * Go through each player and check what action they are doing. Also, go through each tile and * update it. */ public void tick() { // System.out.println(game.getPlayer().getUsername() + "'s game"); // for (Player p : players) // System.out.println(p.getUsername() + "is in: " + // p.getRoom().getName()); // Go through players for (Player p : players) { if (!p.isAlive()) { game.r_removeModel(p.getUsername()); } // Only render the player if they are alive if (readyToRender && p.isAlive()) { // If the player is in the same room as the player on this // computer, add them to the renderer if (p.getRoom().equals(game.getPlayer().getRoom())) { if (game.r_addModel(p.getModel())) { // System.out.println("Adding " + p.getUsername() // + "'s model in " // + game.getPlayer().getUsername() + "'s game"); } } // If the player is not in the same room as the // player on this computer, remove them from the // renderer else if (!p.getRoom().equals(game.getPlayer().getRoom())) { game.r_removeModel(p.getUsername()); } // Update the room if (!p.isRoomLoaded() && p.equals(game.getPlayer())) { if (p.getOldRoom() != null) p.getOldRoom().removeTiles(game.getRenderer()); p.getRoom().initTiles(game.getRenderer()); p.setRoomLoaded(true); } // Update player p.tick(); // Packet to be sent to the server Packet packet = null; // Player shooting if (p.isShooting()) { packet = new Packet03Engage(p.getUsername()); // packet.writeData(game.getClient()); } // Player interacting // Check if player is interacting with a tile if (p.isInteracting() && p.getRoom() != null && p.equals(game.getPlayer()) && p.getRoom().validPosition(p, p.getX(), p.getY())) { Tile tile = p.getRoom().getTile(p, p.getX(), p.getY()); // isInteracting = false; // tile.onInteract(p); // Find the type of interaction switch (p.getInteraction()) { case CHEST: case DOOR: case TERMINAL: packet = new Packet06Interact(p.getUsername(), tile.getID()); break; case NONE: default: break; } // Interact with the tile tile.onInteract(p); // Reset the interaction back to NONE p.resetInteraction(); p.setInteracting(false); if (packet != null) packet.writeData(game.getClient()); } // Check health if (!p.getUsername().equals(game.getPlayer().getUsername())) { Player pl = getPlayer(game.getPlayer().getUsername()); if (pl.getRoom().equals(p.getRoom()) && pl.getSide() == Team.GUARD && p.getSide() == Team.SPY && pl.inRange(p.getX(), p.getY())) { // getPlayer(game.getPlayer().getUsername()) // .takeDamage(0.1); packet = new Packet04Damage(p.getUsername(), p.getUsername(), 0.5); packet.writeData(game.getClient()); } } // Player moving if (p.isMoving()) { packet = new Packet02Move( p.getUsername(), ((PlayerMP) p).getID(), p.getX(), p.getY(), p.getZ(), true, p.getRotation()); packet.writeData(game.getClient()); } // Player picking up item if (p.itemPickedUp()) { Tile tile = p.getRoom().getTile(p, p.getX(), p.getY()); Item last = p.getLastItem(); p.setItemPickedUp(false); packet = new Packet10Pickup(p.getUsername(), tile.getID(), last.getID()); packet.writeData(game.getClient()); } // Finally tick through the room that the player is in p.getRoom().tick(game.getRenderer(), game.getPlayer()); } } }
/** * Handles a damage packet from the server. The method then gives the appropriate amount of damage * to the appropriate player. * * @param username - username of player affected * @param damage - amount of damage to deal */ public void handleDamage(String username, double damage) { Player player = getPlayer(username); if (player.isAlive()) player.takeDamage(damage); else if (!player.isAlive()) game.getRenderer().deleteModel(username); }