Skip to content

Instantly share code, notes, and snippets.

@sprengerjo
Created June 24, 2013 20:32
Show Gist options
  • Save sprengerjo/5853372 to your computer and use it in GitHub Desktop.
Save sprengerjo/5853372 to your computer and use it in GitHub Desktop.
bowling game generated java source
package de.sprengerjo.game.xtend;
import java.util.ArrayList;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.ExclusiveRange;
import org.eclipse.xtext.xbase.lib.Functions.Function0;
@SuppressWarnings("all")
public class Game {
private ArrayList<Integer> _scores = new Function0<ArrayList<Integer>>() {
public ArrayList<Integer> apply() {
ArrayList<Integer> _newArrayList = CollectionLiterals.<Integer>newArrayList(Integer.valueOf(0));
return _newArrayList;
}
}.apply();
public ArrayList<Integer> getScores() {
return this._scores;
}
public void setScores(final ArrayList<Integer> scores) {
this._scores = scores;
}
public boolean roll(final int i) {
ArrayList<Integer> _scores = this.getScores();
boolean _add = _scores.add(Integer.valueOf(i));
return _add;
}
public int score() {
int _xblockexpression = (int) 0;
{
int score = 0;
int roll = 1;
ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, 10, true);
for (final Integer i : _doubleDotLessThan) {
boolean _isStrike = this.isStrike(roll);
if (_isStrike) {
int _strikeBonus = this.strikeBonus(roll);
int _plus = (score + _strikeBonus);
score = _plus;
int _plus_1 = (roll + 1);
roll = _plus_1;
} else {
boolean _isSpare = this.isSpare(roll);
if (_isSpare) {
int _plus_2 = (score + 10);
ArrayList<Integer> _scores = this.getScores();
int _plus_3 = (roll + 2);
Integer _get = _scores.get(_plus_3);
int _plus_4 = (_plus_2 + (_get).intValue());
score = _plus_4;
int _plus_5 = (roll + 2);
roll = _plus_5;
} else {
ArrayList<Integer> _scores_1 = this.getScores();
Integer _get_1 = _scores_1.get(roll);
int _plus_6 = (score + (_get_1).intValue());
ArrayList<Integer> _scores_2 = this.getScores();
int _plus_7 = (roll + 1);
Integer _get_2 = _scores_2.get(_plus_7);
int _plus_8 = (_plus_6 + (_get_2).intValue());
score = _plus_8;
int _plus_9 = (roll + 2);
roll = _plus_9;
}
}
}
_xblockexpression = (score);
}
return _xblockexpression;
}
public boolean isSpare(final int roll) {
ArrayList<Integer> _scores = this.getScores();
Integer _get = _scores.get(roll);
ArrayList<Integer> _scores_1 = this.getScores();
int _plus = (roll + 1);
Integer _get_1 = _scores_1.get(_plus);
int _plus_1 = ((_get).intValue() + (_get_1).intValue());
boolean _equals = (10 == _plus_1);
return _equals;
}
public boolean isStrike(final int roll) {
ArrayList<Integer> _scores = this.getScores();
Integer _get = _scores.get(roll);
boolean _equals = (10 == (_get).intValue());
return _equals;
}
public int strikeBonus(final int roll) {
ArrayList<Integer> _scores = this.getScores();
int _plus = (roll + 1);
Integer _get = _scores.get(_plus);
int _plus_1 = (10 + (_get).intValue());
ArrayList<Integer> _scores_1 = this.getScores();
int _plus_2 = (roll + 2);
Integer _get_1 = _scores_1.get(_plus_2);
int _plus_3 = (_plus_1 + (_get_1).intValue());
return _plus_3;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment