private boolean equip() { if (winner == null) { return false; } for (int i = 0; i < winner.getInventorySize(); i++) { if (input.equals("equip " + winner.getInventory(i).getType())) { winner.setEquipedWeapon(looser.getEquipedWeapon()); looser.removeInventory(looser.getEquipedWeapon()); winner.setTotalStrength(); textOut(winner.getEquipedWeapon().getType() + " equiped"); input = ""; } } return true; }
/** * First choose of random players to fight against each other then give a short message about * winner, looser and weapons If the search list is empty a message about the winner of the whole * game is sent to the console */ private void mainProgram() { if (searchList.size() > 1) { textOut.append("\n"); Player opponent1 = searchList.get(new Random().nextInt(searchList.size())); searchList.remove(opponent1); Player opponent2 = searchList.get(new Random().nextInt(searchList.size())); searchList.remove(opponent2); int opponent1Strength = opponent1.getTotalStrength(); int opponent2Strength = opponent2.getTotalStrength(); if (opponent1Strength > opponent2Strength) { winner = opponent1; looser = opponent2; } else if (opponent1Strength < opponent2Strength) { winner = opponent2; looser = opponent1; } else { if (new Random().nextBoolean() == true) { winner = opponent1; looser = opponent2; } else { winner = opponent2; looser = opponent1; } } textOut.append( winner.getName() + " killed " + looser.getName() + " with " + winner.getEquipedWeapon().getType() + " (" + winner.getEquipedWeapon().getStrength() + " ap). " + looser.getEquipedWeapon().getType() + " (" + looser.getEquipedWeapon().getStrength() + " ap) is now in " + winner.getName() + "´s inventory.\n"); searchList.add(winner); winner.addInventory(looser.getEquipedWeapon()); if (searchList.size() == 1) { textOut.append("\n"); textOut.append(winner.getName() + " won the game!!! Congrantiolations!\n"); } looser.setDead(); if (this.openInventory()) { } else if (this.equip()) { } else if (this.exit()) { } else if (this.restart()) { } else { } } }