-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19af131
commit 359c698
Showing
8 changed files
with
121 additions
and
857 deletions.
There are no files selected for viewing
23 changes: 3 additions & 20 deletions
23
src/main/java/br/unicap/cardgame/controller/CardController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,10 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package br.unicap.cardgame.controller; | ||
|
||
import br.unicap.cardgame.model.Cards; | ||
import javax.persistence.EntityManager; | ||
import javax.persistence.PersistenceContext; | ||
|
||
/** | ||
* | ||
* @author gcaraciolo | ||
*/ | ||
public class CardController { | ||
|
||
@PersistenceContext(unitName = "cardgame") | ||
private EntityManager em; | ||
|
||
public int getCorretAnswer(int card_id) { | ||
Cards card = em.find(Cards.class, card_id); | ||
System.out.println(card); | ||
System.out.println(card.getQuestionId().getCorrectAnswerId().getId()); | ||
return 1; | ||
|
||
public int getCorretAnswer(Cards card) { | ||
return card.getQuestionId().getCorrectAnswerId().getId(); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/br/unicap/cardgame/controller/DeckController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package br.unicap.cardgame.controller; | ||
|
||
import br.unicap.cardgame.model.Cards; | ||
import br.unicap.cardgame.model.Users; | ||
import br.unicap.cardgame.util.Utils; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import javax.ejb.Stateless; | ||
import javax.persistence.EntityManager; | ||
import javax.persistence.PersistenceContext; | ||
|
||
@Stateless | ||
public class DeckController { | ||
|
||
@PersistenceContext(unitName = "cardgame") | ||
private EntityManager em; | ||
|
||
private List<Cards> userCards(Users u) { | ||
return em.createNativeQuery("select ca.id, ca.question_id, ca.attack, ca.defense, ca.life from users u, chars c, decks d, decks_cards dc, cards ca where \n" + | ||
"u.id = " + u.getId() + " and \n" + | ||
"u.char_id = c.id and \n" + | ||
"c.deck_id = d.id and \n" + | ||
"d.id = dc.deck_id and\n" + | ||
"dc.card_id = ca.id;", Cards.class).getResultList(); | ||
} | ||
|
||
public List<Cards> randonCards(Users u) { | ||
List<Cards> cards = userCards(u); | ||
if(cards.size() < 1) { | ||
return new ArrayList<Cards>(); | ||
} | ||
List<Cards> randon = new ArrayList<Cards>(); | ||
for(int i = 0; i < 3; i++) { | ||
randon.add(cards.get(Utils.getRandomNumber(0, cards.size()))); | ||
} | ||
return randon; | ||
} | ||
|
||
public Cards randonCard(Users u) { | ||
List<Cards> cards = userCards(u); | ||
if(cards.size() < 1) { | ||
return null; | ||
} | ||
return cards.get(Utils.getRandomNumber(0, cards.size())); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.