Commit 365a676e authored by Luboš Horáček's avatar Luboš Horáček

Merge branch 'feature-potme' into 'devel'

Feature potme

See merge request !49
parents 5e2d33f1 86ea441c
......@@ -49,7 +49,7 @@
android:value="Tablexia.db" />
<meta-data
android:name="AA_DB_VERSION"
android:value="7" />
android:value="8" />
<meta-data
android:name="AA_SERIALIZERS"
android:value="cz.nic.tablexia.menu.MenuEnumSerializer" />
......
......@@ -79,7 +79,7 @@ import cz.nic.tablexia.game.games.potme.map.mapobject.MapObjectType;
import cz.nic.tablexia.game.games.potme.map.tile.Tile;
import cz.nic.tablexia.game.games.potme.map.widget.MapWidget;
import cz.nic.tablexia.game.games.potme.map.widget.MapWidget.TileMapClickListener;
import cz.nic.tablexia.game.manager.GameManager;
import cz.nic.tablexia.menu.usermenu.User;
/**
* Activity for "Potmě" game
......@@ -368,6 +368,17 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
protected void onCreateTablexiaScene() {
scene.setBackground(new Background(BACKGROUND_COLOR));
}
@Override
protected void gameComplete() {
if (getPotmeDifficulty() == PotmeDifficulty.TUTORIAL) {
User selectedUser = getTablexiaContext().getSelectedUser();
if (selectedUser != null) {
selectedUser.markTutorialAsPlayed(getGameDefinition());
}
}
super.gameComplete();
}
@Override
protected void resetGame() {
......@@ -936,7 +947,8 @@ public class PotmeActivity extends GameActivity implements TileMapClickListener
public PotmeDifficulty getPotmeDifficulty() {
if (potmeDifficulty == null) {
boolean firstPlay = currentFirstPlay && (getTablexiaContext().getSelectedUser() != null) && (GameManager.getLastGameManagerRegardlessFinishing(getTablexiaContext().getSelectedUser(), getGameDefinition()) == null);
User selectedUser = getTablexiaContext().getSelectedUser();
boolean firstPlay = currentFirstPlay && (selectedUser != null && !selectedUser.wasGameTutorialPlayed(getGameDefinition()));
potmeDifficulty = PotmeDifficulty.getPotmeDifficultyForGameDifficulty(getDifficulty(), firstPlay);
}
return potmeDifficulty;
......
......@@ -26,8 +26,36 @@ import com.activeandroid.annotation.Table;
import com.activeandroid.query.Select;
import com.google.gson.annotations.Expose;
import cz.nic.tablexia.game.games.GamesDefinition;
@Table(name = "Users")
public class User extends Model {
public static class UserTutorial extends Model {
@Column(name = "User")
private User user;
@Column(name = "Game")
private int game;
private UserTutorial setUser(User user) {
this.user = user;
return this;
}
private UserTutorial setGame(GamesDefinition gamesDefinition) {
this.game = gamesDefinition.getPosition();
return this;
}
public static void createUserTutorialRecord(User user, GamesDefinition gamesDefinition) {
(new UserTutorial().setUser(user).setGame(gamesDefinition)).save();
}
public static boolean existsUserTutorialRecord(User user, GamesDefinition gamesDefinition) {
return new Select().from(UserTutorial.class).where("User = ? AND Game = ?", user.getId(), gamesDefinition.getPosition()).executeSingle() != null;
}
}
@Expose
@Column(name = "NickName")
......@@ -64,9 +92,12 @@ public class User extends Model {
@Column(name = "ConsecutivelyAllGames3Stars")
private boolean consecutivelyAllGames3Stars;
@Column(name = "PlayCountHallOfFame") private Integer playCountHallOfFame = 0;
@Column(name = "PlayCountStatistics") private Integer playCountStatistics = 0;
@Column(name = "PlayCountEncyclopedia") private Integer playCountEncyclopedia = 0;
@Column(name = "PlayCountHallOfFame")
private Integer playCountHallOfFame = 0;
@Column(name = "PlayCountStatistics")
private Integer playCountStatistics = 0;
@Column(name = "PlayCountEncyclopedia")
private Integer playCountEncyclopedia = 0;
public User() {
super();
......@@ -214,6 +245,14 @@ public class User extends Model {
public static List<User> getAllUsers() {
return new Select().from(User.class).where("deleted = 0").execute();
}
public void markTutorialAsPlayed(GamesDefinition gamesDefinition) {
UserTutorial.createUserTutorialRecord(this, gamesDefinition);
}
public boolean wasGameTutorialPlayed(GamesDefinition gamesDefinition) {
return UserTutorial.existsUserTutorialRecord(this, gamesDefinition);
}
@Override
public boolean equals(Object obj) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment