Permalink
Browse files

added better card displaying

  • Loading branch information...
Patys committed Mar 15, 2017
1 parent d38c09d commit 5bcecfe560fba18ead7961a82207327c261f8534
Showing with 77 additions and 37 deletions.
  1. +77 −37 core/src/com/patys/llgame/UserInterface/MainView.java
@@ -16,6 +16,7 @@
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.patys.llgame.Card;
import com.patys.llgame.MetaGame;

public class MainView extends Table{
@@ -70,49 +71,88 @@ private void createGame() {
}

private void startGame() {
String mainCard = MetaGame.cardManager.getRandomCard().word;
String meaning_one = MetaGame.cardManager.getCardByWord(mainCard).meaning;
String meaning_two = MetaGame.cardManager.getRandomCard().meaning;
String meaning_three = MetaGame.cardManager.getRandomCard().meaning;
while(meaning_one.equals(meaning_two)){
meaning_two = MetaGame.cardManager.getRandomCard().meaning;

Card mainCard = MetaGame.cardManager.getRandomCard();
Card card1 = MetaGame.cardManager.getCardByWord(mainCard.word);
Card card2 = MetaGame.cardManager.getRandomCard();
Card card3 = MetaGame.cardManager.getRandomCard();

while(card1.meaning.equals(card2.meaning)){
card2 = MetaGame.cardManager.getRandomCard();
}
while(meaning_one.equals(meaning_three) && meaning_two.equals(meaning_three)){
meaning_three = MetaGame.cardManager.getRandomCard().meaning;
while(card1.meaning.equals(card3.meaning) || card2.meaning.equals(card3.meaning)){
card3 = MetaGame.cardManager.getRandomCard();
}

Label.LabelStyle label1Style = new Label.LabelStyle();
BitmapFont myFont = skin.getFont("default");
label1Style.font = myFont;
label1Style.fontColor = Color.RED;
this.add();
this.add(getPreparedCardWithWord(mainCard)).space(5).center();
this.row();
addCardsToTableInRandomWay(this, card1, card2, card3);
}

Table getPreparedCardWithWord(Card card) {
Table graphicalCard = new Table();
graphicalCard.background(new TextureRegionDrawable(new TextureRegion(new Texture("data/card_blue.png"))));

Label mainCardLabel = new Label(mainCard, label1Style);
Label meaningOneLabel = new Label(meaning_one, label1Style);
Label meaningTwoLabel = new Label(meaning_two, label1Style);
Label meaningThreeLabel = new Label(meaning_three, label1Style);
Label meaning = new Label(card.word, getLabelStyle());

graphicalCard.add(meaning).spaceBottom(50).center();

Table cardMain = new Table();
cardMain.background(new TextureRegionDrawable(new TextureRegion(new Texture("data/card_blue.png"))));
cardMain.add(mainCardLabel).center();

Table cardLeft = new Table();
cardLeft.background(new TextureRegionDrawable(new TextureRegion(new Texture("data/card_blue.png"))));
cardLeft.add(meaningOneLabel).center();

Table cardCenter = new Table();
cardCenter.background(new TextureRegionDrawable(new TextureRegion(new Texture("data/card_blue.png"))));
cardCenter.add(meaningTwoLabel).center();

Table cardRight = new Table();
cardRight.background(new TextureRegionDrawable(new TextureRegion(new Texture("data/card_blue.png"))));
cardRight.add(meaningThreeLabel).center();
return graphicalCard;
}

Table getPreparedCardWithMeaning(Card card) {
Table graphicalCard = new Table();
graphicalCard.background(new TextureRegionDrawable(new TextureRegion(new Texture("data/card_blue.png"))));

this.add();
this.add(cardMain).space(5).center();
this.row();
this.add(cardLeft).space(5).left();
this.add(cardCenter).space(5).center();
this.add(cardRight).space(5).right();
Label meaning = new Label(card.meaning, getLabelStyle());
Label good = new Label("Dobrze: " + Float.toString(card.good), getLabelStyle());
Label wrong = new Label("Zle: " + Float.toString(card.wrong), getLabelStyle());

graphicalCard.add(meaning).spaceBottom(50).center();
graphicalCard.row();
graphicalCard.add(good).left().padLeft(15).expandX();
graphicalCard.row();
graphicalCard.add(wrong).left().padLeft(15).expandX();

return graphicalCard;
}

void addCardsToTableInRandomWay(Table table, Card card1, Card card2, Card card3) {
// simple randomize
Boolean addedCardOne = false;
Boolean addedCardTwo = false;
Boolean addedCardThree = false;
while(!addedCardOne || !addedCardTwo || !addedCardThree ){
int random = (int )(Math.random() * 3 + 1);
switch(random) {
case 1:
if(!addedCardOne){
addedCardOne = true;
this.add(getPreparedCardWithMeaning(card1)).space(5).left();
}
break;
case 2:
if(!addedCardTwo) {
addedCardTwo = true;
this.add(getPreparedCardWithMeaning(card2)).space(5).left();
}
break;
case 3:
if(!addedCardThree) {
addedCardThree = true;
this.add(getPreparedCardWithMeaning(card3)).space(5).left();
}
break;
}
}
}

Label.LabelStyle getLabelStyle() {
Label.LabelStyle label1Style = new Label.LabelStyle();
BitmapFont myFont = skin.getFont("default");
label1Style.font = myFont;
label1Style.fontColor = Color.DARK_GRAY;
return label1Style;
}
}

0 comments on commit 5bcecfe

Please sign in to comment.