<p>
This draft's last change is:
<strong>
- trolls can be of different races.
+ troll pants' color can be chosen.
</strong>
</p>
</div>
--- /dev/null
+/*
+ * This file is almost CG's toggle module from the SDK. I'd have
+ * subclassed it if it were an option.
+ */
+
+package com.codingame.game;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.codingame.gameengine.core.AbstractPlayer;
+import com.codingame.gameengine.core.GameManager;
+import com.codingame.gameengine.core.Module;
+import com.codingame.gameengine.module.entities.Entity;
+import com.codingame.gameengine.module.entities.GraphicEntityModule;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+/**
+ * @author Jean Porée, JBM
+ *
+ * This module allows you to display or hide elements of the GraphicEntityModule using the viewer's options menu.
+ *
+ */
+@Singleton
+public class PantsModule implements Module {
+
+ GameManager<AbstractPlayer> gameManager;
+ @Inject GraphicEntityModule entityModule;
+ Map<Integer, Object> registered, newRegistration;
+
+ class Toggle {
+ public String name;
+ public boolean state = true;
+
+ public Toggle(String name, boolean state) {
+ this.name = name;
+ this.state = state;
+ }
+ }
+
+ class Pants {
+ String name = "pants";
+ int state = 1;
+ Pants(int state) { this.state = state; }
+ }
+
+ @Inject
+ PantsModule(GameManager<AbstractPlayer> gameManager) {
+ this.gameManager = gameManager;
+ gameManager.registerModule(this);
+ registered = new HashMap<>();
+ newRegistration = new HashMap<>();
+ }
+
+ @Override
+ public void onGameInit() {
+ sendFrameData();
+ }
+
+ @Override
+ public void onAfterGameTurn() {
+ sendFrameData();
+ }
+
+ @Override
+ public void onAfterOnEnd() {}
+
+ private void sendFrameData() {
+ Object[] data = { newRegistration };
+ gameManager.setViewData("toggles", data);
+
+ newRegistration.clear();
+ }
+ /**
+ * Will display the entity only when the toggle state matches the state you set
+ *
+ * @param entity which will be displayed
+ * @param toggle the name of the toggle you want to use
+ * @param state the state of the toggle where the entity will be displayed at
+ */
+ public void displayOnToggleState(Entity<?> entity, String toggle, boolean state) {
+ int id = entity.getId();
+ Toggle associatedToggle = new Toggle(toggle, state);
+ if (!associatedToggle.equals(registered.get(id))) {
+ newRegistration.put(id, associatedToggle);
+ registered.put(id, associatedToggle);
+ }
+ }
+
+ public void displayOnPantsState(Entity<?> entity, int state) {
+ int id = entity.getId();
+ Pants associatedPants = new Pants(state);
+ if (!associatedPants.equals(registered.get(id))) {
+ newRegistration.put(id, associatedPants);
+ registered.put(id, associatedPants);
+ }
+ }
+}
import com.codingame.gameengine.module.entities.TextBasedEntity;
import com.codingame.gameengine.module.entities.Group;
import com.codingame.gameengine.module.entities.Curve;
-import com.codingame.gameengine.module.toggle.ToggleModule;
import com.google.inject.Inject;
class View {
@Inject private MultiplayerGameManager<com.codingame.game.Player> gameManager;
@Inject private GraphicEntityModule graphicEntityModule;
- @Inject ToggleModule toggleModule;
+ @Inject PantsModule pantsModule;
enum Dir {
LEFT("walks left.", 0),
.setFillColor(0xff0080)
.setAnchorX(p0 ? 0 : 1)
.setAnchorY(0.5);
- toggleModule.displayOnToggleState(stoneReminder, "debug", true);
+ pantsModule.displayOnToggleState(stoneReminder, "debug", true);
}
void updateStoneCounter() {
.setAnchorX(0.5)
.setAnchorY(1)
.setTint(trollRace.tint);
- Sprite trollPants = graphicEntityModule.createSprite()
+ Sprite trollPantsRed = graphicEntityModule.createSprite()
.setImage("pants_red.png")
.setAnchorX(0.5)
.setAnchorY(1);
- troll = graphicEntityModule.createGroup(trollBody, trollPants)
+ pantsModule.displayOnPantsState(trollPantsRed, 1);
+ Sprite trollPantsGreen = graphicEntityModule.createSprite()
+ .setImage("pants_green.png")
+ .setAnchorX(0.5)
+ .setAnchorY(1);
+ pantsModule.displayOnPantsState(trollPantsGreen, 2);
+ Sprite trollPantsBlue = graphicEntityModule.createSprite()
+ .setImage("pants_blue.png")
+ .setAnchorX(0.5)
+ .setAnchorY(1);
+ pantsModule.displayOnPantsState(trollPantsBlue, 3);
+ Sprite trollPantsPerv = graphicEntityModule.createSprite()
+ .setImage("pants_perv.png")
+ .setAnchorX(0.5)
+ .setAnchorY(1);
+ pantsModule.displayOnPantsState(trollPantsPerv, 4);
+ troll = graphicEntityModule
+ .createGroup(trollBody, trollPantsRed,
+ trollPantsGreen, trollPantsBlue, trollPantsPerv)
.setX(1920/2)
.setY(880)
.setScaleX(random.nextInt(2) == 0 ? 1 : -1)
.setStrokeColor(0xFFFF00)
.setFillColor(0xFFFF00)
.setFontSize(40);
- toggleModule.displayOnToggleState(trollMessage, "verboseTrolling", true);
+ pantsModule.displayOnToggleState(trollMessage, "verboseTrolling", true);
}
private void moveTroll() {
.setY(60)
.setAnchorX(0.5)
.setLoop(true);
- toggleModule.displayOnToggleState(debugMode, "debug", true);
+ pantsModule.displayOnToggleState(debugMode, "debug", true);
turnCounter = graphicEntityModule.createText()
.setAnchorX(0.5)
.setFontFamily("monospace")
.setFontWeight(Text.FontWeight.BOLD)
.setFontSize(100);
- toggleModule.displayOnToggleState(turnCounter, "debug", true);
+ pantsModule.displayOnToggleState(turnCounter, "debug", true);
animateTurnCounter();
}
}
obj['default'] = def;
if (def == undefined) {
- if (values.length > 2) {
- obj['default'] = values.length * Math.floor(2 * Math.random());
+ if (obj['values'].length > 2) {
+ obj['default'] = obj['values'].length * Math.floor(2 * Math.random());
}
else {
obj['default'] = Math.random() < 0.5;
}
export const options = [
+ // TODO: detroll this a bit
+ trollToggle('konami', 'unused', undefined,
+ '←', 0, '↓', 1, '↑', 2, '→', 3, 'B', 4, 'A', 5),
+ trollToggle('pants', 'pants', 1 + Math.floor(3 * Math.random()),
+ 'red', 1, 'green', 2, 'blue', 3, 'you perv', 4),
trollToggle('verboseTrolling', 'Verbose Trolling', true,
'on', true, 'off', false),
trollToggle('debug', 'Detroll Mode', false,
'on', true, 'off', false)
];
+
+for (var i = options.length-1; i > 1; i--) {
+ var s = Math.floor((i+1) * Math.random());
+ var selected = options[s];
+ options[s] = options[i];
+ options[i] = selected;
+}