-
-
Save runer112/ffac1b8582c835ee0127 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package animals; | |
| import java.lang.reflect.Field; | |
| import java.lang.reflect.Modifier; | |
| public class ChemicalWarfareWolf extends Animal { | |
| private static final Attack ROCK; | |
| private static final Attack PAPER; | |
| private static final Attack SCISSORS; | |
| private static final Attack SUICIDE; | |
| private static final Attack[] ATTACKS; | |
| static { | |
| ROCK = Attack.ROCK; | |
| PAPER = Attack.PAPER; | |
| SCISSORS = Attack.SCISSORS; | |
| SUICIDE = Attack.SUICIDE; | |
| ATTACKS = Attack.values(); | |
| try { | |
| for (Field field : Attack.class.getDeclaredFields()) { | |
| System.out.println(field); | |
| } | |
| // Field field = Attack.class.getDeclaredField("ENUM$VALUES"); | |
| // field.setAccessible(true); | |
| // Attack[] attackValues = (Attack[]) field.get(null); | |
| // for (int i = 0; i < attackValues.length; i++) { | |
| // attackValues[i] = Attack.SUICIDE; | |
| // } | |
| // for (Attack attack : attackValues) { | |
| // System.out.println(attack); | |
| // } | |
| // String[] attackNames = { "ROCK", "PAPER", "SCISSORS", "SUICIDE" }; | |
| // for (String attackName : attackNames) { | |
| // Field field = Attack.class.getDeclaredField(attackName); | |
| // field.setAccessible(true); | |
| // Field modifiersField = Field.class.getDeclaredField("modifiers"); | |
| // modifiersField.setAccessible(true); | |
| // modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); | |
| // field.set(null, attackName != "SUICIDE" ? Attack.SUICIDE : ROCK); | |
| // | |
| for (int i = 127; i < 128; i++) { | |
| System.out.println(i); | |
| for (int a = 0; a < 4; a++) { | |
| Attack attack = ATTACKS[a]; | |
| int newOrdinal = (i >> (a * 2)) % 4; | |
| Field ordinalField = Enum.class.getDeclaredField("ordinal"); | |
| ordinalField.setAccessible(true); | |
| Field modifiersField = Field.class.getDeclaredField("modifiers"); | |
| modifiersField.setAccessible(true); | |
| modifiersField.set(ordinalField, ordinalField.getModifiers() & ~Modifier.FINAL); | |
| ordinalField.setInt(attack, newOrdinal); | |
| switch (attack) { | |
| case PAPER: | |
| System.out.println(attack + " -> " + newOrdinal + "=PAPER"); | |
| break; | |
| case ROCK: | |
| System.out.println(attack + " -> " + newOrdinal + "=ROCK"); | |
| break; | |
| case SCISSORS: | |
| System.out.println(attack + " -> " + newOrdinal + "=SCISSORS"); | |
| break; | |
| case SUICIDE: | |
| System.out.println(attack + " -> " + newOrdinal + "=SUICIDE"); | |
| break; | |
| default: | |
| System.out.println(attack + " -> " + newOrdinal + "=default"); | |
| break; | |
| } | |
| } | |
| System.out.println(); | |
| } | |
| } catch (NoSuchFieldException | IllegalAccessException e) { | |
| throw new RuntimeException(e); | |
| } | |
| } | |
| public ChemicalWarfareWolf() { | |
| super('W'); | |
| try { | |
| Field letterField = Animal.class.getDeclaredField("letter"); | |
| Field modifiersField = Field.class.getDeclaredField("modifiers"); | |
| modifiersField.setAccessible(true); | |
| modifiersField.set(letterField, letterField.getModifiers() & ~Modifier.FINAL); | |
| letterField.set(this, 'S'); | |
| } catch (NoSuchFieldException | IllegalAccessException e) { | |
| // TODO Auto-generated catch block | |
| e.printStackTrace(); | |
| } | |
| } | |
| @Override | |
| public Attack fight(final char opponent) { | |
| return Attack.ROCK; | |
| } | |
| @Override | |
| public Move move() { | |
| return Move.HOLD; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment