Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
FloraGnomeWars
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
Hans-Georg Sommer
FloraGnomeWars
Merge requests
!5
Add command line input class
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Add command line input class
input
into
master
Overview
0
Commits
1
Pipelines
1
Changes
1
Merged
Hans-Georg Sommer
requested to merge
input
into
master
6 years ago
Overview
0
Commits
1
Pipelines
1
Changes
1
Expand
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
51bf0e44
1 commit,
6 years ago
1 file
+
48
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
src/flowerwarspp/MoveRequesterCli.java
0 → 100644
+
48
−
0
Options
package
flowerwarspp
;
import
flowerwarspp.preset.Move
;
import
flowerwarspp.preset.MoveFormatException
;
import
flowerwarspp.preset.PlayerColor
;
import
flowerwarspp.preset.Requestable
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
/**
* Simple input class which reads moves from the command line.
*/
public
class
MoveRequesterCli
implements
Requestable
{
/**
* Name used in input prompt.
*/
private
String
playerName
;
/**
* Reader used to read input from stdin.
*/
private
BufferedReader
input
=
new
BufferedReader
(
new
InputStreamReader
(
System
.
in
));
/**
* Create a new MoveRequesterCli for the given player color.
* @param color PlayerColor used in input prompt
*/
public
MoveRequesterCli
(
PlayerColor
color
)
{
playerName
=
color
.
name
();
}
/*
* @see flowerwars.preset.Requestable#request(flowerwars.preset.Requestable)
*/
@Override
public
Move
request
()
{
Move
move
=
null
;
while
(
move
==
null
)
{
try
{
System
.
out
.
printf
(
"Enter move for player %s: "
,
playerName
);
move
=
Move
.
parseMove
(
input
.
readLine
());
}
catch
(
IOException
|
MoveFormatException
e
)
{
System
.
out
.
println
(
"Error: "
+
e
);
}
}
return
move
;
}
}
Loading