Beispiel #1
0
  @Override
  public String visitGameend(@NotNull DiceGameParser.GameendContext ctx) {
    if (ctx.MULTI != null) {
      return "print('Die Spieler '+','.join([self.name for self in game.players if "
          + ctx.COND.accept(this)
          + "])+' haben gewonnen!')";
    }

    if (ctx.SINGLE != null) {
      return "print([self.name for self in game.players if "
          + ctx.COND.accept(this)
          + "][0]+' hat gewonnen!')";
    }

    if (ctx.MOST != null) {
      return "print(str([player.name for player in game.players if player."
          + ctx.VAR.getText()
          + " == (max([self."
          + ctx.VAR.getText()
          + " for self in game.players]))][0]) +' hat gewonnen!')";
    }

    if (ctx.LEAST != null) {
      return "print(str([player.name for player in game.players if player."
          + ctx.VAR.getText()
          + " == (min([self."
          + ctx.VAR.getText()
          + " for self in game.players]))][0]) +' hat gewonnen!')";
    }

    return "visitGameend";
  }
Beispiel #2
0
  @Override
  public String visitLoop(@NotNull DiceGameParser.LoopContext ctx) {

    if (ctx.FORLOOP != null) {
      StringBuilder forLoop = new StringBuilder();
      if (ctx.POs != null) {
        forLoop.append("for self." + ctx.VAR.getText() + " in " + ctx.POs.accept(this) + ":\n");
      }
      if (ctx.DOs != null) {
        forLoop.append("for self." + ctx.VAR.getText() + " in " + ctx.DOs.accept(this) + ":\n");
      }
      forLoop.append(indent(ctx.ACTION.accept(this)));
      return forLoop.toString();
    }
    if (ctx.NLOOP != null) {
      StringBuilder loop = new StringBuilder();
      loop.append("for i in range(" + ctx.VALUE.getText() + "):\n");
      loop.append(indent(ctx.ACTION.accept(this)));
      return loop.toString();
    }
    return "visitLoop";
  }
Beispiel #3
0
  @Override
  public String visitVariable(@NotNull DiceGameParser.VariableContext ctx) {
    if (ctx.VAR != null) {
      return "self." + ctx.VAR.getText();
    }
    if (ctx.DO != null) {
      return ctx.DO.accept(this) + ".value";
    }
    if (ctx.PO != null) {
      return ctx.PO.accept(this);
    }
    if (ctx.INST != null) {
      return ctx.INST.accept(this) + "." + ctx.IVAR.getText();
    }

    return "visitVariable";
  }