Skip to content

Commit cf8f797

Browse files
committed
Merge branch 'issue11' #11
2 parents 0f136b2 + 5161a76 commit cf8f797

File tree

18 files changed

+547
-17
lines changed

18 files changed

+547
-17
lines changed

nbproject/build-impl.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
1919
-->
2020
<project xmlns:webproject1="http://www.netbeans.org/ns/web-project/1" xmlns:webproject2="http://www.netbeans.org/ns/web-project/2" xmlns:webproject3="http://www.netbeans.org/ns/web-project/3" basedir=".." default="default" name="Jogo_de_Whist-impl">
21+
<import file="rest-build.xml"/>
2122
<import file="ant-deploy.xml"/>
2223
<fail message="Please build using Ant 1.7.1 or higher.">
2324
<condition>
@@ -1004,6 +1005,9 @@ exists or setup the property manually. For example like this:
10041005
<copyfiles files="${libs.PostgreSQLDriver.classpath}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
10051006
<copyfiles files="${file.reference.jandex-2.0.2.Final.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
10061007
<copyfiles files="${libs.jstl.classpath}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
1008+
<copyfiles files="${libs.restapi.classpath}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
1009+
<copyfiles files="${libs.restlib.classpath}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
1010+
<copyfiles files="${file.reference.json-1.5-20090211.jar}" iftldtodir="${build.web.dir}/WEB-INF" todir="${dist.ear.dir}/lib"/>
10071011
<mkdir dir="${build.web.dir}/META-INF"/>
10081012
<manifest file="${build.web.dir}/META-INF/MANIFEST.MF" mode="update"/>
10091013
</target>
@@ -1015,6 +1019,9 @@ exists or setup the property manually. For example like this:
10151019
<copyfiles files="${libs.PostgreSQLDriver.classpath}" todir="${build.web.dir}/WEB-INF/lib"/>
10161020
<copyfiles files="${file.reference.jandex-2.0.2.Final.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
10171021
<copyfiles files="${libs.jstl.classpath}" todir="${build.web.dir}/WEB-INF/lib"/>
1022+
<copyfiles files="${libs.restapi.classpath}" todir="${build.web.dir}/WEB-INF/lib"/>
1023+
<copyfiles files="${libs.restlib.classpath}" todir="${build.web.dir}/WEB-INF/lib"/>
1024+
<copyfiles files="${file.reference.json-1.5-20090211.jar}" todir="${build.web.dir}/WEB-INF/lib"/>
10181025
</target>
10191026
<target depends="init" if="dist.ear.dir" name="-clean-webinf-lib">
10201027
<delete dir="${build.web.dir}/WEB-INF/lib"/>

nbproject/genfiles.properties

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
build.xml.data.CRC32=788d88e7
1+
build.xml.data.CRC32=d3ce7f16
22
build.xml.script.CRC32=6c8676ee
33
build.xml.stylesheet.CRC32=[email protected]
44
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
55
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
6-
nbproject/build-impl.xml.data.CRC32=788d88e7
7-
nbproject/build-impl.xml.script.CRC32=4aa5a2f1
6+
nbproject/build-impl.xml.data.CRC32=d3ce7f16
7+
nbproject/build-impl.xml.script.CRC32=6e9de954
88
nbproject/build-impl.xml.stylesheet.CRC32=[email protected]
9+
nbproject/rest-build.xml.data.CRC32=cddf6025
10+
nbproject/rest-build.xml.script.CRC32=9716e867
11+
nbproject/rest-build.xml.stylesheet.CRC32=[email protected]

nbproject/project.properties

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ endorsed.classpath=\
3030
${libs.javaee-endorsed-api-7.0.classpath}
3131
excludes=
3232
file.reference.jandex-2.0.2.Final.jar=/home/lucas/Downloads/jandex-2.0.2.Final.jar
33+
file.reference.jquery-ui-1.12.1.custom.zip=/home/lucas/Downloads/jquery-ui-1.12.1.custom.zip
34+
file.reference.json-1.5-20090211.jar=/home/lucas/Downloads/json-1.5-20090211.jar
35+
file.reference.le-frog-1.0.10.jar=/home/lucas/Downloads/le-frog-1.0.10.jar
3336
includes=**
3437
j2ee.compile.on.save=true
3538
j2ee.copy.static.files.on.save=true
@@ -45,7 +48,12 @@ javac.classpath=\
4548
${libs.hibernate4-persistence.classpath}:\
4649
${libs.PostgreSQLDriver.classpath}:\
4750
${file.reference.jandex-2.0.2.Final.jar}:\
48-
${libs.jstl.classpath}
51+
${libs.jstl.classpath}:\
52+
${file.reference.jquery-ui-1.12.1.custom.zip}:\
53+
${file.reference.le-frog-1.0.10.jar}:\
54+
${libs.restapi.classpath}:\
55+
${libs.restlib.classpath}:\
56+
${file.reference.json-1.5-20090211.jar}
4957
# Space-separated list of extra javac options
5058
javac.compilerargs=
5159
javac.debug=true
@@ -78,6 +86,7 @@ no.dependencies=false
7886
persistence.xml.dir=${conf.dir}
7987
platform.active=default_platform
8088
resource.dir=setup
89+
rest.config.type=ide
8190
run.test.classpath=\
8291
${javac.test.classpath}:\
8392
${build.test.classes.dir}

nbproject/project.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
<project xmlns="http://www.netbeans.org/ns/project/1">
33
<type>org.netbeans.modules.web.project</type>
44
<configuration>
5+
<buildExtensions xmlns="http://www.netbeans.org/ns/ant-build-extender/1">
6+
<extension file="rest-build.xml" id="rest.5"/>
7+
</buildExtensions>
58
<data xmlns="http://www.netbeans.org/ns/web-project/3">
69
<name>Jogo de Whist</name>
710
<minimum-ant-version>1.6.5</minimum-ant-version>
@@ -34,6 +37,24 @@
3437
<file>${libs.jstl.classpath}</file>
3538
<path-in-war>WEB-INF/lib</path-in-war>
3639
</library>
40+
<library dirs="200">
41+
<file>${file.reference.jquery-ui-1.12.1.custom.zip}</file>
42+
</library>
43+
<library dirs="200">
44+
<file>${file.reference.le-frog-1.0.10.jar}</file>
45+
</library>
46+
<library dirs="200">
47+
<file>${libs.restapi.classpath}</file>
48+
<path-in-war>WEB-INF/lib</path-in-war>
49+
</library>
50+
<library dirs="200">
51+
<file>${libs.restlib.classpath}</file>
52+
<path-in-war>WEB-INF/lib</path-in-war>
53+
</library>
54+
<library dirs="200">
55+
<file>${file.reference.json-1.5-20090211.jar}</file>
56+
<path-in-war>WEB-INF/lib</path-in-war>
57+
</library>
3758
</web-module-libraries>
3859
<web-module-additional-libraries/>
3960
<source-roots>

nbproject/rest-build.xml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
*** GENERATED - DO NOT EDIT ***
4+
-->
5+
<project name="Jogo_de_Whist-rest-build" basedir=".." xmlns:webproject3="http://www.netbeans.org/ns/web-project/3" xmlns:webproject2="http://www.netbeans.org/ns/web-project/2" xmlns:webproject1="http://www.netbeans.org/ns/web-project/1" xmlns:jaxrs="http://www.netbeans.org/ns/jax-rs/1">
6+
<target name="-check-trim">
7+
<condition property="do.trim">
8+
<and>
9+
<isset property="client.urlPart"/>
10+
<length string="${client.urlPart}" when="greater" length="0"/>
11+
</and>
12+
</condition>
13+
</target>
14+
<target name="-trim-url" if="do.trim">
15+
<pathconvert pathsep="/" property="rest.base.url">
16+
<propertyset>
17+
<propertyref name="client.url"/>
18+
</propertyset>
19+
<globmapper from="*${client.urlPart}" to="*/"/>
20+
</pathconvert>
21+
</target>
22+
<target name="-spare-url" unless="do.trim">
23+
<property name="rest.base.url" value="${client.url}"/>
24+
</target>
25+
<target name="test-restbeans" depends="run-deploy,-init-display-browser,-check-trim,-trim-url,-spare-url">
26+
<replace file="${restbeans.test.file}" token="${base.url.token}" value="${rest.base.url}||${rest.application.path}"/>
27+
<condition property="do.browse-url">
28+
<istrue value="${display.browser}"/>
29+
</condition>
30+
<antcall target="browse-url"/>
31+
</target>
32+
<target name="browse-url" if="do.browse-url">
33+
<nbbrowse url="${restbeans.test.url}"/>
34+
</target>
35+
</project>

src/java/com/github/lucasgueiros/ifuwhist/partida/Partida.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import com.github.lucasgueiros.ifuwhist.partida.vaza.Naipe;
2626
import com.github.lucasgueiros.ifuwhist.partida.excecoes.CartaInvalidaException;
2727
import com.github.lucasgueiros.ifuwhist.partida.excecoes.CartaNaoEstaNaMaoException;
28+
import com.github.lucasgueiros.ifuwhist.webservice.aletoriedade.GeradorAleatorioJavaRandom;
29+
import com.github.lucasgueiros.ifuwhist.webservice.aletoriedade.GeradorAleatorioQrngAnu;
2830

2931
/**
3032
*
@@ -197,7 +199,7 @@ public void iniciar() {
197199
maos.get(po).clear();
198200
}
199201
// embaralhe e crie a bolsa
200-
bolsa = new EmbaralhadorSimples().embaralhar(dador);
202+
bolsa = new EmbaralhadorSimples().embaralhar(dador, new GeradorAleatorioQrngAnu());
201203
// distribua as cartas
202204
for (Posicao posicao : Posicao.values()) {
203205
maos.get(posicao).addAll(bolsa.getMao(posicao));

src/java/com/github/lucasgueiros/ifuwhist/partida/bolsa/Bolsa.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88
import com.github.lucasgueiros.ifuwhist.mesa.Posicao;
99
import com.github.lucasgueiros.ifuwhist.partida.vaza.Carta;
1010
import com.github.lucasgueiros.ifuwhist.partida.vaza.Naipe;
11+
import java.io.Serializable;
1112
import java.util.Collection;
1213
import java.util.LinkedList;
1314
import java.util.List;
15+
import javax.xml.bind.annotation.XmlElement;
16+
import javax.xml.bind.annotation.XmlRootElement;
17+
1418

1519
/**
1620
*
@@ -20,15 +24,21 @@
2024
*
2125
* @author lucas
2226
*/
23-
public class Bolsa {
27+
@XmlRootElement
28+
public class Bolsa implements Serializable {
2429

30+
private static final long serialVersionUID = 1L;
31+
2532
private Naipe trunfo;
2633
private Collection<Carta> norte;
2734
private Collection<Carta> sul;
2835
private Collection<Carta> leste;
2936
private Collection<Carta> oeste;
3037
private Posicao dealer;
3138

39+
public Bolsa() {
40+
}
41+
3242
private Bolsa(Naipe trunfo, Posicao dealer) {
3343
this.trunfo = trunfo;
3444
this.dealer = dealer;
@@ -60,14 +70,16 @@ public Naipe getTrunfo() {
6070
return trunfo;
6171
}
6272

73+
@XmlElement
6374
public void setTrunfo(Naipe trunfo) {
6475
this.trunfo = trunfo;
6576
}
6677

6778
public Posicao getDealer() {
6879
return dealer;
6980
}
70-
81+
82+
@XmlElement
7183
public void setDealer(Posicao dealer) {
7284
this.dealer = dealer;
7385
}
@@ -86,6 +98,7 @@ public Collection<Carta> getNorte() {
8698
return norte;
8799
}
88100

101+
@XmlElement (name="NORTH")
89102
public void setNorte(Collection<Carta> norte) {
90103
this.norte = norte;
91104
}
@@ -94,6 +107,7 @@ public Collection<Carta> getSul() {
94107
return sul;
95108
}
96109

110+
@XmlElement (name="SOUTH")
97111
public void setSul(Collection<Carta> sul) {
98112
this.sul = sul;
99113
}
@@ -102,6 +116,7 @@ public Collection<Carta> getLeste() {
102116
return leste;
103117
}
104118

119+
@XmlElement (name="EAST")
105120
public void setLeste(Collection<Carta> leste) {
106121
this.leste = leste;
107122
}
@@ -110,9 +125,15 @@ public Collection<Carta> getOeste() {
110125
return oeste;
111126
}
112127

128+
@XmlElement (name="WEST")
113129
public void setOeste(Collection<Carta> oeste) {
114130
this.oeste = oeste;
115131
}
132+
133+
@Override
134+
public String toString() {
135+
return "Bolsa{" + "trunfo=" + trunfo + ", norte=" + norte + ", sul=" + sul + ", leste=" + leste + ", oeste=" + oeste + ", dealer=" + dealer + '}';
136+
}
116137

117138

118139

src/java/com/github/lucasgueiros/ifuwhist/partida/bolsa/Embaralhador.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import com.github.lucasgueiros.ifuwhist.mesa.Posicao;
99
import com.github.lucasgueiros.ifuwhist.partida.vaza.Carta;
10+
import com.github.lucasgueiros.ifuwhist.webservice.aletoriedade.GeradorAleatorio;
1011

1112
/**
1213
*
@@ -18,7 +19,8 @@ public interface Embaralhador {
1819
* Gera um nova bolsa aleatoriamente, apenas define-se o "imaginável" dealer.
1920
*
2021
* @param posicao dealer
22+
* @param geradorAleatorio
2123
* @return
2224
*/
23-
public Bolsa embaralhar(Posicao posicao);
25+
public Bolsa embaralhar(Posicao posicao, GeradorAleatorio geradorAleatorio);
2426
}

src/java/com/github/lucasgueiros/ifuwhist/partida/bolsa/EmbaralhadorOestePorUltimo.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.github.lucasgueiros.ifuwhist.partida.vaza.ComparaCartas;
1111
import com.github.lucasgueiros.ifuwhist.partida.vaza.Naipe;
1212
import com.github.lucasgueiros.ifuwhist.partida.vaza.Simbolo;
13+
import com.github.lucasgueiros.ifuwhist.webservice.aletoriedade.GeradorAleatorio;
1314
import java.util.LinkedList;
1415
import java.util.List;
1516
import java.util.Random;
@@ -21,15 +22,15 @@
2122
public class EmbaralhadorOestePorUltimo implements Embaralhador {
2223

2324
@Override
24-
public Bolsa embaralhar(Posicao dealer) {
25+
public Bolsa embaralhar(Posicao dealer, GeradorAleatorio gerador) {
2526
List<Carta> maoDealer = new LinkedList<>();
2627
List<Carta> maoEsquerda = new LinkedList<>();
2728
List<Carta> maoDireita = new LinkedList<>();
2829
List<Carta> maoParceiro = new LinkedList<>();
2930

3031
for(Naipe su : Naipe.values()) {
3132
for(Simbolo sy : Simbolo.values()) {
32-
int random = (int) ( Math.random() * 3 ) ; // um número entre 0 e 3
33+
int random = gerador.get(1,0,3)[0] ; // um número entre 0 e 3
3334
loop:do {
3435
switch(random) {
3536
case 0: // NORTH

src/java/com/github/lucasgueiros/ifuwhist/partida/bolsa/EmbaralhadorSimples.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.github.lucasgueiros.ifuwhist.partida.vaza.ComparaCartas;
1111
import com.github.lucasgueiros.ifuwhist.partida.vaza.Naipe;
1212
import com.github.lucasgueiros.ifuwhist.partida.vaza.Simbolo;
13+
import com.github.lucasgueiros.ifuwhist.webservice.aletoriedade.GeradorAleatorio;
1314
import java.util.Arrays;
1415
import java.util.Collections;
1516
import java.util.LinkedList;
@@ -22,8 +23,8 @@
2223
public class EmbaralhadorSimples implements Embaralhador {
2324

2425
@Override
25-
public Bolsa embaralhar(Posicao dealer){
26-
long seed = (long) Math.random();
26+
public Bolsa embaralhar(Posicao dealer, GeradorAleatorio geradorAleatorio){
27+
//long seed = (long) Math.random();
2728

2829
Carta [] maoDealer = new Carta[13];
2930
Carta [] maoEsquerda = new Carta[13];
@@ -38,9 +39,16 @@ public Bolsa embaralhar(Posicao dealer){
3839
}
3940
}
4041

41-
Random r = new Random(seed);
42+
//Random r = new Random(seed);
4243
// embaralhe
43-
Collections.shuffle(set, r);
44+
Collections.shuffle(set, new Random(){
45+
private int [] alea = geradorAleatorio.get(52,0,51,-1);
46+
47+
@Override
48+
public int nextInt(int bound) {
49+
return alea[bound-1];
50+
}
51+
});
4452

4553
// distribua
4654
// até 13

0 commit comments

Comments
 (0)