Skip to content

Commit

Permalink
Initial cleanup, introduced Action interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
skiwi2 committed Sep 1, 2014
1 parent 8311526 commit 68efa97
Show file tree
Hide file tree
Showing 12 changed files with 758 additions and 753 deletions.
12 changes: 12 additions & 0 deletions cardshifter-core/src/main/java/com/cardshifter/core/Action.java
@@ -0,0 +1,12 @@

package com.cardshifter.core;

/**
*
* @author Frank van Heeswijk
*/
public interface Action {
boolean isAllowed();

void perform();
}
69 changes: 34 additions & 35 deletions cardshifter-core/src/main/java/com/cardshifter/core/CardAction.java
@@ -1,35 +1,34 @@
package com.cardshifter.core;

import java.util.Objects;

import org.luaj.vm2.LuaValue;
import org.luaj.vm2.lib.jse.CoerceJavaToLua;

public class CardAction extends UsableAction {

private final Card card;

public CardAction(final Card card, final String name, final LuaValue allowedFunction, final LuaValue actionFunction) {
super(name, allowedFunction, actionFunction);
this.card = Objects.requireNonNull(card, "card");
}

public Card getCard() {
return card;
}

@Override
public String toString() {
return "{Action " + getName() + " on card " + card + "}";
}

@Override
protected LuaValue methodArg() {
return CoerceJavaToLua.coerce(card);
}

@Override
protected Game getGame() {
return card.getGame();
}
}
package com.cardshifter.core;

import java.util.Objects;

import org.luaj.vm2.LuaValue;
import org.luaj.vm2.lib.jse.CoerceJavaToLua;

public class CardAction extends UsableAction {
private final Card card;

public CardAction(final Card card, final String name, final LuaValue allowedFunction, final LuaValue actionFunction) {
super(name, allowedFunction, actionFunction);
this.card = Objects.requireNonNull(card, "card");
}

public Card getCard() {
return card;
}

@Override
protected LuaValue methodArg() {
return CoerceJavaToLua.coerce(card);
}

@Override
protected Game getGame() {
return card.getGame();
}

@Override
public String toString() {
return "{Action " + getName() + " on card " + card + "}";
}
}
@@ -1,23 +1,21 @@
package com.cardshifter.core;

import java.util.Random;

import com.beust.jcommander.Parameter;

public class CommandLineOptions {

@Parameter(names = { "--file", "-f" }, description = "Script file to run")
private String script;

@Parameter(names = { "--seed", "-s" }, description = "Set random seed")
private Integer seed;

public Random getRandom() {
return seed == null ? new Random() : new Random(seed);
}

public String getScript() {
return script;
}

}
package com.cardshifter.core;

import java.util.Random;

import com.beust.jcommander.Parameter;

public class CommandLineOptions {
@Parameter(names = { "--file", "-f" }, description = "Script file to run")
private String script;

@Parameter(names = { "--seed", "-s" }, description = "Set random seed")
private Integer seed;

public Random getRandom() {
return (seed == null) ? new Random() : new Random(seed);
}

public String getScript() {
return script;
}
}

0 comments on commit 68efa97

Please sign in to comment.