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
francois.hofer
poo2019numeric
Commits
e30233e7
Commit
e30233e7
authored
5 years ago
by
fefe
Browse files
Options
Downloads
Patches
Plain Diff
Forgot to push the last version of hangman
parent
a31926da
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/ch/hepia/Hangman/Hangman.class
+0
-0
0 additions, 0 deletions
src/main/java/ch/hepia/Hangman/Hangman.class
src/main/java/ch/hepia/Hangman/Hangman.java
+34
-5
34 additions, 5 deletions
src/main/java/ch/hepia/Hangman/Hangman.java
with
34 additions
and
5 deletions
src/main/java/ch/hepia/Hangman/Hangman.class
+
0
−
0
View file @
e30233e7
No preview for this file type
This diff is collapsed.
Click to expand it.
src/main/java/ch/hepia/Hangman/Hangman.java
+
34
−
5
View file @
e30233e7
import
java.util.Scanner
;
public
class
Hangman
{
private
String
secretWord
;
private
String
currWord
;
...
...
@@ -26,7 +27,7 @@ public class Hangman {
private
int
attemps
(){
return
this
.
attemp
;
}
p
rivate
String
secretWord
(){
p
ublic
String
secretWord
(){
return
this
.
secretWord
;
}
private
boolean
lastTry
(){
...
...
@@ -39,6 +40,7 @@ public class Hangman {
printHang
(
this
.
failedAttempts
());
}
public
void
printGallowIfError
(){
System
.
out
.
println
(
"Error(s): "
+
this
.
failedAttempts
());
if
(!
this
.
lastTry
()){
printHang
(
this
.
failedAttempts
());
}
...
...
@@ -82,6 +84,18 @@ public class Hangman {
return
true
;
}
private
static
char
askLetter
(){
System
.
out
.
println
(
"Enter a letter :"
);
Scanner
myObj
=
new
Scanner
(
System
.
in
);
String
str
=
myObj
.
nextLine
();
if
(
str
.
length
()
!=
1
){
System
.
out
.
println
(
" Just one letter please : "
);
str
=
myObj
.
nextLine
();
}
return
str
.
charAt
(
0
);
}
private
static
void
printHang
(
int
i
){
String
i0
=
""
;
String
i1
=
"----------\n|/\n|\n|\n|\n|\n|\n|"
;
...
...
@@ -96,11 +110,26 @@ public class Hangman {
String
[]
drawHangMan
=
{
i0
,
i1
,
i2
,
i3
,
i4
,
i5
,
i6
,
i7
,
i8
,
i9
};
System
.
out
.
println
(
drawHangMan
[
i
]);
}
public
static
void
main
(
String
[]
args
){
Hangman
h
=
Hangman
.
withSecretWord
(
"mystère"
);
String
currentWord
=
h
.
currentWord
();
public
static
void
runGame
(
String
secretWord
){
Hangman
h
=
Hangman
.
withSecretWord
(
secretWord
);
while
(!
h
.
isFinished
()){
System
.
out
.
println
(
"-----------------"
);
char
askedChar
=
Hangman
.
askLetter
();
h
=
h
.
tryWith
(
askedChar
);
h
.
printCurrentWord
();
h
.
printGallowIfError
();
}
if
(
h
.
hasWon
()){
System
.
out
.
println
(
"Goal Achieved !"
);
}
else
{
System
.
out
.
println
(
"That's an horrible fail, you had to find: "
+
h
.
secretWord
()
);
}
}
public
static
void
main
(
String
[]
args
){
Hangman
.
runGame
(
"helloworld"
);
}
...
...
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