Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
poo2019numeric
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
steven.liatti
poo2019numeric
Commits
d59575d1
Commit
d59575d1
authored
5 years ago
by
david
Browse files
Options
Downloads
Patches
Plain Diff
ajout des fonctions hangman
parent
e74bc73d
No related branches found
No related tags found
2 merge requests
!2
Tanguy
,
!1
David
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/ch/hepia/hangman/hangman.java
+137
-0
137 additions, 0 deletions
src/main/java/ch/hepia/hangman/hangman.java
src/test/java/ch/hepia/hangman/AppTest.java
+27
-0
27 additions, 0 deletions
src/test/java/ch/hepia/hangman/AppTest.java
with
164 additions
and
0 deletions
src/main/java/ch/hepia/hangman/hangman.java
0 → 100644
+
137
−
0
View file @
d59575d1
package
ch.hepia.hangman
;
public
class
hangman
{
/*
currentWord = l'avancement actuel du mot ex : _a___ == David
guessWord = le mot rechercher ex David
letter = la lettre entrers
Ex :
currentWord = _____
guessWord = David
letter = 'a'
resultat = _a____
*/
public
static
String
check
(
String
currentWord
,
String
guessWord
,
char
letter
)
{
//les string sont immutable en java
//conversion en tableau de char
char
[]
tempArray
=
currentWord
.
toCharArray
();
for
(
int
i
=
0
;
i
<
guessWord
.
length
();
i
++)
{
if
(
guessWord
.
charAt
(
i
)==
letter
)
//a ajouter les test majuscule
{
tempArray
[
i
]=
letter
;
}
}
return
String
.
valueOf
(
tempArray
);
}
/*
guessWord = le mot a cacher
Ex :
guessWord = David
resultat = ______
*/
public
static
String
createWord
(
String
guessWord
)
{
char
tempArray
[]=
guessWord
.
toCharArray
();
for
(
int
i
=
0
;
i
<
guessWord
.
length
();
i
++)
{
tempArray
[
i
]=
'_'
;
}
return
String
.
valueOf
(
tempArray
);
}
/*
Affiche l'etat de la potence en fonction du nombre d'essai.
*/
public
static
void
showHangman
(
int
essai
)
{
System
.
out
.
println
(
"----------"
);
switch
(
essai
)
{
case
1
:
System
.
out
.
println
(
"|/"
);
for
(
int
i
=
0
;
i
<
6
;
i
++)
{
System
.
out
.
println
(
"|"
);
}
break
;
case
2
:
System
.
out
.
println
(
"|/ |"
);
for
(
int
i
=
0
;
i
<
6
;
i
++)
{
System
.
out
.
println
(
"|"
);
}
break
;
case
3
:
System
.
out
.
println
(
"|/ |"
);
System
.
out
.
println
(
"| (_)"
);
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
System
.
out
.
println
(
"|"
);
}
break
;
case
4
:
System
.
out
.
println
(
"|/ |"
);
System
.
out
.
println
(
"| (_)"
);
System
.
out
.
println
(
"| |"
);
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
System
.
out
.
println
(
"|"
);
}
break
;
case
5
:
System
.
out
.
println
(
"|/ |"
);
System
.
out
.
println
(
"| (_)"
);
System
.
out
.
println
(
"| /|"
);
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
System
.
out
.
println
(
"|"
);
}
break
;
case
6
:
System
.
out
.
println
(
"|/ |"
);
System
.
out
.
println
(
"| (_)"
);
System
.
out
.
println
(
"| /|\\"
);
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
System
.
out
.
println
(
"|"
);
}
break
;
case
7
:
System
.
out
.
println
(
"|/ |"
);
System
.
out
.
println
(
"| (_)"
);
System
.
out
.
println
(
"| /|\\"
);
System
.
out
.
println
(
"| | "
);
for
(
int
i
=
0
;
i
<
3
;
i
++)
{
System
.
out
.
println
(
"|"
);
}
break
;
case
8
:
System
.
out
.
println
(
"|/ |"
);
System
.
out
.
println
(
"| (_)"
);
System
.
out
.
println
(
"| /|\\"
);
System
.
out
.
println
(
"| | "
);
System
.
out
.
println
(
"| / "
);
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
System
.
out
.
println
(
"|"
);
}
break
;
case
9
:
System
.
out
.
println
(
"|/ |"
);
System
.
out
.
println
(
"| (_)"
);
System
.
out
.
println
(
"| /|\\"
);
System
.
out
.
println
(
"| | "
);
System
.
out
.
println
(
"| / \\"
);
for
(
int
i
=
0
;
i
<
2
;
i
++)
{
System
.
out
.
println
(
"|"
);
}
break
;
}
System
.
out
.
println
(
""
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/test/java/ch/hepia/hangman/AppTest.java
0 → 100644
+
27
−
0
View file @
d59575d1
package
ch.hepia.hangman
;
import
org.junit.jupiter.api.Test
;
import
java.util.List
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertTrue
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
class
HangmanTests
{
@Test
void
check_create
()
{
String
hiddenWord
=
hangman
.
createWord
(
"david"
);
assertEquals
(
hiddenWord
,
"_____"
);
}
@Test
void
check_test
()
{
String
hiddenWord
=
hangman
.
createWord
(
"david"
);
hiddenWord
=
hangman
.
check
(
hiddenWord
,
"david"
,
'd'
);
assertEquals
(
hiddenWord
,
"d___d"
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment