Android Open Source - game_guess_lib Guess Question






From Project

Back to project page game_guess_lib.

License

The source code is released under:

MIT License

If you think the Android project game_guess_lib listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.wkmf.guess.lib.structure;
/*w  w  w .  j  ava  2  s .  c om*/
import android.app.ProgressDialog;

import com.wkmf.guess.lib.common.async.DownloadTask;
import com.wkmf.guess.lib.impl.GuessGameImageDownload;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;

import java.text.Collator;
import java.util.List;
import java.util.Random;
import java.util.UUID;

/**
 * Created by ernestofndz on 9/02/14.
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class GuessQuestion {

    public static final int TAGS_MAX = 3;
    private static final String IMG_EXT = ".png"; // extensin de las imgenes
    private static final String EMPTY = "";
    @JsonProperty("id")
    private String id;
    @JsonProperty("img_src")
    private String imageURL;
    @JsonProperty("img_path")
    private String imagePath;
    @JsonProperty("answer")
    private String answer;
    @JsonProperty("tags")
    private List<String> tags;
    @JsonProperty("tags_added")
    private int tagsAdded = 0;
    @JsonProperty("completed")
    private boolean completed = false;
    @JsonProperty("part_of_answer")
    private String partOfAnswer = EMPTY;

    // constructor
    public GuessQuestion(String id, String imageURL, String imagePath, String answer, List<String> tags, int tagsAdded, boolean completed, String partOfAnswer) {
        this.id = id;
        this.imageURL = imageURL;
        this.imagePath = imagePath;
        this.answer = answer;
        this.tags = tags;
        this.tagsAdded = tagsAdded;
        this.completed = completed;
        this.partOfAnswer = partOfAnswer;
    }

    public GuessQuestion() {
    }

    // descargamos la imagen
    public void downloadImage(GuessGameImageDownload callback, ProgressDialog pd) {
        new DownloadTask(callback, this.imageURL, pd).execute();
    }

    // generar la ruta al fichero
    public void generateImagePath() {
        this.imagePath = String.valueOf(UUID.randomUUID()).concat(IMG_EXT);
    }

    // comprobar una respuesta
    public boolean checkAnswer(String answer) {
        Collator collator = Collator.getInstance();
        collator.setStrength(Collator.PRIMARY);
        // comparamos, limpiamos tanto la respuesta correcta como el intento del usuario
        return collator.compare(clean(this.answer), clean(answer)) == 0;
    }

    // limpiar la respuesta
    private String clean(String str) {
        return str.trim().replaceAll("[^\\w\\s]", EMPTY).replaceAll(" ", EMPTY);
    }

    // aadir un tag
    public void addTag() {
        this.tagsAdded++;
    }

    // revelar parte de la respuesta
    public void revealPartOfAnswer() {
        int revealed = 0;
        int size = this.answer.length();
        int numLetters = size / 2; // obtenemos la 4ta parte
        char[] answer = this.answer.toCharArray();
        char[] partOfAnswer = (this.answer.replaceAll("[^\\d]", "_")).toCharArray();
        while (revealed < numLetters) {
            for (int i = 0; i < size; i++) {
                if (answer[i] == ' ' || partOfAnswer[i] == '_' && (new Random().nextBoolean() && new Random().nextBoolean())) {
                    if (answer[i] != ' ') revealed++;
                    partOfAnswer[i] = answer[i];
                }
                if (revealed == numLetters) break;
            }
        }
        // seteamos el valor
        this.partOfAnswer = String.valueOf(partOfAnswer);
    }

    // comprobar si ya tiene solicitado parte de la respuesta
    public boolean hasPartOfAnswer() {
        return !this.partOfAnswer.isEmpty();
    }

    // get/set
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getImageURL() {
        return imageURL;
    }
    public void setImageURL(String imageURL) {
        this.imageURL = imageURL;
    }
    public String getAnswer() {
        return answer;
    }
    public void setAnswer(String answer) {
        this.answer = answer;
    }
    public List<String> getTags() {
        return tags;
    }
    public void setTags(List<String> tags) {
        this.tags = tags;
    }
    public boolean isCompleted() {
        return completed;
    }
    public void setCompleted(boolean completed) {
        this.completed = completed;
    }
    public String getImagePath() {
        return imagePath;
    }
    public void setImagePath(String imagePath) {
        this.imagePath = imagePath;
    }
    public int getTagsAdded() {
        return tagsAdded;
    }
    public void setTagsAdded(int tagsAdded) {
        this.tagsAdded = tagsAdded;
    }
    public String getPartOfAnswer() {
        return partOfAnswer;
    }
}




Java Source Code List

com.android.vending.billing.util.Base64DecoderException.java
com.android.vending.billing.util.Base64.java
com.android.vending.billing.util.IabException.java
com.android.vending.billing.util.IabHelper.java
com.android.vending.billing.util.IabResult.java
com.android.vending.billing.util.Inventory.java
com.android.vending.billing.util.Purchase.java
com.android.vending.billing.util.Security.java
com.android.vending.billing.util.SkuDetails.java
com.wkmf.guess.lib.common.Constants.java
com.wkmf.guess.lib.common.ads.GuessGameAdsListener.java
com.wkmf.guess.lib.common.ads.GuessGameAds.java
com.wkmf.guess.lib.common.api.GuessApi.java
com.wkmf.guess.lib.common.api.GuessRestApi.java
com.wkmf.guess.lib.common.async.DownloadTask.java
com.wkmf.guess.lib.common.dialog.DialogElement.java
com.wkmf.guess.lib.common.dialog.DialogModalListAdapter.java
com.wkmf.guess.lib.common.dialog.DialogModal.java
com.wkmf.guess.lib.data.GuessGameBDDHandler.java
com.wkmf.guess.lib.data.GuessSQL.java
com.wkmf.guess.lib.impl.GuessGameBaseApp.java
com.wkmf.guess.lib.impl.GuessGameImageDownload.java
com.wkmf.guess.lib.impl.GuessGameInterface.java
com.wkmf.guess.lib.purchase.items.GuessGameItems.java
com.wkmf.guess.lib.screen.GuessLevelScreen.java
com.wkmf.guess.lib.screen.GuessMainScreen.java
com.wkmf.guess.lib.screen.GuessQuestionScreen.java
com.wkmf.guess.lib.screen.adapter.LevelsAdapter.java
com.wkmf.guess.lib.screen.adapter.QuestionsAdapter.java
com.wkmf.guess.lib.service.GuessGameService.java
com.wkmf.guess.lib.service.GuessGameUpdater.java
com.wkmf.guess.lib.service.ServiceStarter.java
com.wkmf.guess.lib.structure.GuessConfig.java
com.wkmf.guess.lib.structure.GuessDrawable.java
com.wkmf.guess.lib.structure.GuessGame.java
com.wkmf.guess.lib.structure.GuessLevelType.java
com.wkmf.guess.lib.structure.GuessLevel.java
com.wkmf.guess.lib.structure.GuessQuestion.java