Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
lab1
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Einar.Stamland
lab1
Commits
0766472e
Commit
0766472e
authored
2 years ago
by
Einar Stamland
Browse files
Options
Downloads
Patches
Plain Diff
rpsFinished
parent
81de9a53
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/rockPaperScissors/RockPaperScissors.java
+49
-1
49 additions, 1 deletion
src/main/java/rockPaperScissors/RockPaperScissors.java
with
49 additions
and
1 deletion
src/main/java/rockPaperScissors/RockPaperScissors.java
+
49
−
1
View file @
0766472e
...
...
@@ -2,8 +2,10 @@ package rockPaperScissors;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Random
;
import
java.util.Scanner
;
public
class
RockPaperScissors
{
public
static
void
main
(
String
[]
args
)
{
...
...
@@ -25,7 +27,53 @@ public class RockPaperScissors {
public
void
run
()
{
// TODO: Implement Rock Paper Scissors
}
while
(
true
){
// Imput Choise
System
.
out
.
println
(
"Let's play round "
+
roundCounter
);
roundCounter
++;
System
.
out
.
println
(
"Your choice (Rock/Paper/Scissors)?"
);
String
MyChoice
=
sc
.
nextLine
();
if
(!
rpsChoices
.
contains
(
MyChoice
)){
System
.
out
.
println
(
"I do not understand"
+
MyChoice
+
". Could you try again?"
);
}
//Computer Choise
String
ComputerChoise
=
rpsChoices
.
get
(
new
Random
().
nextInt
(
rpsChoices
.
size
()));
//Compare Choise and Add score
if
(
MyChoice
.
equals
(
ComputerChoise
))
{
System
.
out
.
println
(
"Human chose "
+
MyChoice
+
", computer chose "
+
ComputerChoise
+
". It's a tie!"
);
}
else
if
((
MyChoice
.
equals
(
"Rock"
)
&&
ComputerChoise
.
equals
(
"Scissors"
))
||
(
MyChoice
.
equals
(
"Paper"
)
&&
ComputerChoise
.
equals
(
"Rock"
))
||
(
MyChoice
.
equals
(
"Scissors"
)
&&
ComputerChoise
.
equals
(
"Paper"
))){
System
.
out
.
println
(
"Human chose "
+
MyChoice
+
", computer chose "
+
ComputerChoise
+
". Human wins!"
);
humanScore
++;
}
else
{
System
.
out
.
println
(
"Human chose "
+
MyChoice
+
", computer chose "
+
ComputerChoise
+
". Computer wins!"
);
computerScore
++;
}
System
.
out
.
println
(
"Score: human "
+
humanScore
+
", computer "
+
computerScore
);
System
.
out
.
println
(
"Do you wish to continue playing? (y/n)?"
);
String
play
=
sc
.
nextLine
();
if
(
play
.
equals
(
"n"
)){
break
;
}
}
//Continiuse play
System
.
out
.
println
(
"Bye bye :)"
);
}
/**
* Reads input from console with given prompt
...
...
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