Permalink
Browse files

added upper progress bar and refactored MainView

  • Loading branch information...
Patys committed Mar 17, 2017
1 parent 5bcecfe commit 03d707a931cb23adc148fe17f1fedccb94c92c8e
@@ -2,4 +2,8 @@

public class MetaGame {
public static CardManager cardManager;

public static int experience;
public static int level;
public static int points;
}
@@ -0,0 +1,29 @@
package com.patys.llgame.UserInterface;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;

public class DefaultSkin extends Skin {
public DefaultSkin() {
// Generate a 1x1 white texture and store it in the skin named "white".
Pixmap pixmap = new Pixmap(1, 1, Format.RGBA8888);
pixmap.setColor(Color.WHITE);
pixmap.fill();
this.add("white", new Texture(pixmap));

// Store the default libgdx font under the name "default".
this.add("default", new BitmapFont());


Label.LabelStyle label1Style = new Label.LabelStyle();
BitmapFont myFont = this.getFont("default");
label1Style.font = myFont;
label1Style.fontColor = Color.DARK_GRAY;
this.add("default", label1Style);
}
}
@@ -0,0 +1,95 @@
package com.patys.llgame.UserInterface;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.patys.llgame.Card;
import com.patys.llgame.MetaGame;

public class GameView extends Table{
private DefaultSkin skin;

public GameView() {
skin = new DefaultSkin();
}

public void startGame() {

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(card1.meaning.equals(card3.meaning) || card2.meaning.equals(card3.meaning)){
card3 = MetaGame.cardManager.getRandomCard();
}

this.add();
this.add(getPreparedCardWithWord(mainCard)).space(5).center();
this.row();
addCardsToTableInRandomWay(this, card1, card2, card3);
}

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

Label meaning = new Label(card.word, skin);

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

return graphicalCard;
}

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

Label meaning = new Label(card.meaning, skin);
Label good = new Label("Dobrze: " + Float.toString(card.good), skin);
Label wrong = new Label("Zle: " + Float.toString(card.wrong), skin);

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;
}

private 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;
}
}
}
}
@@ -0,0 +1,29 @@
package com.patys.llgame.UserInterface;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.utils.Align;
import com.patys.llgame.MetaGame;

public class LevelBar extends Table {

private DefaultSkin skin;

public LevelBar() {
skin = new DefaultSkin();

Label level = new Label("Poziom: " + Integer.toString(MetaGame.level), skin);
Label experience = new Label("Doœwiadczenie: " + Integer.toString(MetaGame.experience), skin);
Label points = new Label("Punkty: " + Integer.toString(MetaGame.points), skin);

int averge = (int) ((level.getWidth() + experience.getWidth())/2);
int space = Gdx.graphics.getWidth() - averge*3;

this.add(level).expandX().fill().align(Align.left);
this.add().spaceRight(space);
this.add(experience).expandX().fill().align(Align.right);
this.row();
this.add(points).expandX().fill().align(Align.right);
}
}
@@ -1,42 +1,22 @@
package com.patys.llgame.UserInterface;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
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{
private TextButton playButton;
private TextButton exitButton;
private Skin skin;
private DefaultSkin skin;

private GameView gameView;

public MainView() {
skin = new Skin();

// Generate a 1x1 white texture and store it in the skin named "white".
Pixmap pixmap = new Pixmap(1, 1, Format.RGBA8888);
pixmap.setColor(Color.WHITE);
pixmap.fill();
skin.add("white", new Texture(pixmap));
skin = new DefaultSkin();

// Store the default libgdx font under the name "default".
skin.add("default", new BitmapFont());


// Configure a TextButtonStyle and name it "default". Skin resources are stored by type, so this doesn't overwrite the font.
TextButtonStyle textButtonStyle = new TextButtonStyle();
textButtonStyle.up = skin.newDrawable("white", Color.DARK_GRAY);
@@ -53,6 +33,8 @@ public MainView() {
playButton.padBottom(5);
exitButton = new TextButton("Wyjœcie", skin);

gameView = new GameView();

this.add(playButton).space(10);
this.row();
this.add(exitButton);
@@ -67,92 +49,7 @@ public void changed (ChangeEvent event, Actor actor) {

private void createGame() {
this.reset();
startGame();
}

private void startGame() {

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(card1.meaning.equals(card3.meaning) || card2.meaning.equals(card3.meaning)){
card3 = MetaGame.cardManager.getRandomCard();
}

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 meaning = new Label(card.word, getLabelStyle());

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

return graphicalCard;
}

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

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;
gameView.startGame();
this.add(gameView);
}
}
@@ -7,6 +7,8 @@

public UserInterface(Table table) {
this.table = table;
this.table.add(new MainView()).expandX().expandY();
this.table.add(new LevelBar()).top().spaceBottom(20);
this.table.row();
this.table.add(new MainView()).expandX();
}
}

0 comments on commit 03d707a

Please sign in to comment.