Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
Java_Yams
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
GPSE
4A
Java_Yams
Commits
3891903b
Commit
3891903b
authored
Jul 24, 2021
by
Weber Rodolphe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
final code
parent
621b4b46
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
37 deletions
+71
-37
SheetPlayer.java
src/SheetPlayer.java
+25
-17
Yams.java
src/Yams.java
+24
-15
YamsDices.java
src/YamsDices.java
+22
-5
No files found.
src/SheetPlayer.java
View file @
3891903b
...
...
@@ -25,11 +25,12 @@ public class SheetPlayer {
private
final
String
LINE
=
"--------------------"
;
private
final
char
[]
FIG_INDEX
=
{
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
,
'g'
,
'h'
,
'i'
,
'j'
,
'k'
,
'l'
,
'm'
};
private
final
String
[]
FIG_NAME
={
"Brelan"
,
"
Carré"
,
"Full
"
,
"Petite Suite"
,
"Grande Suite"
,
"Yams"
,
"Chance"
};
private
final
String
[]
FIG_NAME
={
"Brelan"
,
"
Full"
,
"Carré
"
,
"Petite Suite"
,
"Grande Suite"
,
"Yams"
,
"Chance"
};
private
String
playerName
;
/**< player name */
private
Integer
[]
scoring
=
new
Integer
[
13
];
/** scoring table */
private
int
totalScore
;
/**< final player score */
private
int
round
;
/**< count the number of round */
//private int totalScore; /**< final player score */
private
char
[]
figureIndex
;
/**< letters indicating the figure type */
//private int subTotalScore; /**< all number score */
//private int bonus; /**< bonus score */
...
...
@@ -43,10 +44,8 @@ public class SheetPlayer {
for
(
int
idx
=
0
;
idx
<
scoring
.
length
;
idx
++){
scoring
[
idx
]=
null
;
}
totalScore
=
0
;
figureIndex
=
FIG_INDEX
;
//subTotalScore=0;
//bonus=0;
round
=
1
;
}
/**
...
...
@@ -78,23 +77,31 @@ public class SheetPlayer {
return
(
int
)
total
;
}
public
int
totalScore
()
{
Integer
total
=
subTotalScore
()+
bonus
();
for
(
int
idx
=
6
;
idx
<
13
;
idx
++){
total
+=(
scoring
[
idx
]==
null
)?
0
:
scoring
[
idx
]
;
}
return
(
int
)
total
;
}
/**
* @brief print the scoring sheet
*/
public
void
printScore
(){
System
.
out
.
println
(
LINE
);
System
.
out
.
println
(
"Player: "
+
playerName
);
System
.
out
.
println
(
"Player: "
+
playerName
+
" round: "
+
round
);
System
.
out
.
println
(
LINE
);
for
(
int
idx
=
1
;
idx
<=
6
;
idx
++){
System
.
out
.
println
(
"["
+
figureIndex
[
idx
-
1
]
+
"] sum of "
+
idx
+
" : "
+
nullToMinus
(
scoring
[
idx
-
1
]));
}
System
.
out
.
println
(
"----subTotal: "
+
subTotalScore
()
+
" => bonus : "
+
bonus
());
for
(
int
idx
=
7
;
idx
<
13
;
idx
++){
System
.
out
.
println
(
"["
+
figureIndex
[
idx
-
1
]
+
"] "
+
FIG_NAME
[
idx
-
6
]
+
" : "
+
nullToMinus
(
scoring
[
idx
-
1
]));
for
(
int
idx
=
7
;
idx
<
=
13
;
idx
++){
System
.
out
.
println
(
"["
+
figureIndex
[
idx
-
1
]
+
"] "
+
FIG_NAME
[
idx
-
7
]
+
" : "
+
nullToMinus
(
scoring
[
idx
-
1
]));
}
System
.
out
.
println
(
"Total: "
+
totalScore
);
System
.
out
.
println
(
"Total: "
+
totalScore
()
);
System
.
out
.
println
(
LINE
);
round
=(
round
%
3
)+
1
;
}
/**
...
...
@@ -105,17 +112,18 @@ public class SheetPlayer {
figureIndex
[
index
]=
'x'
;
}
public
int
askFigure
(){
public
int
askFigure
(
Scanner
sc
){
String
letter
;
System
.
out
.
println
(
"Indicates the figure you want to play (a,b ...m):"
);
Scanner
sc
=
new
Scanner
(
"a"
);
do
{
System
.
out
.
println
(
"Indicates the figure you want to play (a,b ...m):"
);
letter
=
sc
.
nextLine
();
System
.
out
.
println
(
"-"
+
letter
+
"-"
);
}
while
(!
String
.
valueOf
(
figureIndex
).
contains
(
letter
)
||
(
letter
==
String
.
valueOf
(
'x'
)));
return
String
.
valueOf
(
figureIndex
).
indexOf
(
letter
);
}
}
while
(
letter
!=
"x"
);
sc
.
close
();
return
0
;
public
void
updateScoring
(
int
figureIndex
,
int
score
){
scoring
[
figureIndex
]=
score
;
this
.
figureIndex
[
figureIndex
]=
'x'
;
}
}
src/Yams.java
View file @
3891903b
...
...
@@ -17,7 +17,7 @@
*
* This java file represents a java lab for the 4th year students of Polytech Orleans.
*/
import
java.util.Scanner
;
public
class
Yams
{
...
...
@@ -29,20 +29,29 @@ public class Yams{
public
static
void
main
(
String
[]
args
)
{
YamsDices
myDice5
=
new
YamsDices
();
SheetPlayer
player1
=
new
SheetPlayer
(
"rodo"
);
clearScreen
();
player1
.
printScore
();
myDice5
.
printYams
();
myDice5
.
rollYams
(
myDice5
.
askDice
());
clearScreen
();
player1
.
printScore
();
myDice5
.
printYams
();
myDice5
.
rollYams
(
myDice5
.
askDice
());
myDice5
.
printYams
();
//System.out.println(player1.askFigure());
SheetPlayer
player1
=
new
SheetPlayer
(
"Player1"
);
Scanner
sc
=
new
Scanner
(
System
.
in
);
int
figureIndex
;
for
(
int
idx
=
0
;
idx
<
2
;
idx
++){
clearScreen
();
player1
.
printScore
();
myDice5
.
rollYams
(
"12345"
);
//1st roll
myDice5
.
printYams
();
myDice5
.
rollYams
(
myDice5
.
askDice
(
sc
));
//2nd roll
clearScreen
();
player1
.
printScore
();
myDice5
.
printYams
();
figureIndex
=
player1
.
askFigure
(
sc
);
myDice5
.
rollYams
(
myDice5
.
askDice
(
sc
));
//3rd roll
player1
.
updateScoring
(
figureIndex
,
myDice5
.
getScore
(
figureIndex
));
clearScreen
();
player1
.
printScore
();
myDice5
.
printYams
();
System
.
out
.
println
(
"press return"
);
sc
.
nextLine
();
//wait
}
sc
.
close
();
System
.
out
.
println
(
"Player1, your final score : "
+
player1
.
totalScore
());
}
}
...
...
src/YamsDices.java
View file @
3891903b
...
...
@@ -42,11 +42,9 @@ public class YamsDices {
System
.
out
.
println
(
" "
+
dice5
[
0
].
diceValue
+
' '
+
dice5
[
1
].
diceValue
+
' '
+
dice5
[
2
].
diceValue
+
' '
+
dice5
[
3
].
diceValue
+
' '
+
dice5
[
4
].
diceValue
+
' '
);
}
public
String
askDice
(){
public
String
askDice
(
Scanner
sc
){
System
.
out
.
println
(
"Indicates the dices you want to roll (12345):"
);
Scanner
sc
=
new
Scanner
(
System
.
in
);
String
position
=
sc
.
nextLine
();
sc
.
close
();
return
(
position
);
}
public
void
rollYams
(
String
position
){
// roll the selected dices
...
...
@@ -118,9 +116,9 @@ public class YamsDices {
boolean
ps1234
=
(
numberOf
[
0
]
!=
0
)
&&
(
numberOf
[
1
]
!=
0
)
&&
(
numberOf
[
2
]
!=
0
)
&&
(
numberOf
[
3
]
!=
0
);
boolean
ps2345
=
(
numberOf
[
1
]
!=
0
)
&&
(
numberOf
[
2
]
!=
0
)
&&
(
numberOf
[
3
]
!=
0
)
&&
(
numberOf
[
4
]
!=
0
);
boolean
ps3456
=
(
numberOf
[
2
]
!=
0
)
&&
(
numberOf
[
3
]
!=
0
)
&&
(
numberOf
[
4
]
!=
0
)
&&
(
numberOf
[
5
]
!=
0
);
return
(
ps1234
||
ps2345
||
ps3456
)?
4
0
:
0
;
return
(
ps1234
||
ps2345
||
ps3456
)?
3
0
:
0
;
}
public
int
checkGrandeSuite
()
{
int
[]
sortedDices
=
new
int
[
5
];
for
(
int
idx
=
0
;
idx
<
5
;
idx
++){
...
...
@@ -131,6 +129,25 @@ public class YamsDices {
return
(
Arrays
.
toString
(
sortedDices
).
equals
(
"[1, 2, 3, 4, 5]"
)||
Arrays
.
toString
(
sortedDices
).
equals
(
"[2, 3, 4, 5, 6]"
))?
40
:
0
;
}
public
int
getScore
(
int
figureIndex
){
int
score
=
0
;
switch
(
figureIndex
){
case
0
:
score
=
sumValDice
(
1
);
break
;
case
1
:
score
=
sumValDice
(
2
);
break
;
case
2
:
score
=
sumValDice
(
3
);
break
;
case
3
:
score
=
sumValDice
(
4
);
break
;
case
4
:
score
=
sumValDice
(
5
);
break
;
case
5
:
score
=
sumValDice
(
6
);
break
;
case
6
:
score
=
checkBrelan
();
break
;
case
7
:
score
=
checkFull
();
break
;
case
8
:
score
=
checkCarre
();
break
;
case
9
:
score
=
checkPetiteSuite
();
break
;
case
10
:
score
=
checkGrandeSuite
();
break
;
case
11
:
score
=
checkYams
();
break
;
case
12
:
score
=
sumDice
();
break
;
}
return
score
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment