Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
Project3_Uno
Project
Project
Details
Activity
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
9831113
Project3_Uno
Commits
ed2b30de
Commit
ed2b30de
authored
Apr 18, 2020
by
amir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Another error :((
parent
640d7eb1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
97 additions
and
16 deletions
+97
-16
Comp.java
Comp.java
+23
-2
Human.java
Human.java
+48
-6
Main.java
Main.java
+10
-4
Player.java
Player.java
+16
-4
No files found.
Comp.java
View file @
ed2b30de
...
@@ -9,8 +9,8 @@ public class Comp extends Player {
...
@@ -9,8 +9,8 @@ public class Comp extends Player {
@Override
@Override
public
Card
chooseCardToThrow
(
ArrayList
<
Card
>
cards
,
Card
card
)
{
public
Card
chooseCardToThrow
(
ArrayList
<
Card
>
cards
,
Card
card
)
{
Card
c
=
null
;
Card
c
=
null
;
if
(
possibleCards
.
size
()
>
0
)
{
if
(
(
getCounter
()
==
0
&&
possibleCards
.
size
()
>
0
)
||
(
getCounter
()
>
0
&&
possibleCards
.
size
()
>
1
)
)
{
int
number
=
r
.
nextInt
(
getPossibleCards
().
size
());
int
number
=
r
.
nextInt
(
getPossibleCards
().
size
());
c
=
possibleCards
.
get
(
number
);
c
=
possibleCards
.
get
(
number
);
possibleCards
=
null
;
possibleCards
=
null
;
getPlayerCards
().
remove
(
c
);
getPlayerCards
().
remove
(
c
);
...
@@ -51,4 +51,25 @@ public class Comp extends Player {
...
@@ -51,4 +51,25 @@ public class Comp extends Player {
}
}
return
s
;
return
s
;
}
}
@Override
public
Card
chooseColorToThrow
(
ArrayList
<
Card
>
cards
,
String
Color
)
{
Card
c
=
null
;
if
((
getCounter
()
==
0
&&
possibleCards
.
size
()
>
0
)
||
(
getCounter
()
>
0
&&
possibleCards
.
size
()
>
1
))
{
int
number
=
r
.
nextInt
(
getPossibleCards
().
size
());
c
=
possibleCards
.
get
(
number
);
possibleCards
=
null
;
getPlayerCards
().
remove
(
c
);
}
else
{
c
=
randomPunishmentCard
(
cards
);
getPlayerCards
().
add
(
c
);
if
(
c
instanceof
Colored
)
{
if
(!
c
.
cardColor
.
equals
(
Color
))
{
c
=
null
;
}
}
}
return
c
;
}
}
}
Human.java
View file @
ed2b30de
...
@@ -5,30 +5,34 @@ import java.util.Scanner;
...
@@ -5,30 +5,34 @@ import java.util.Scanner;
public
class
Human
extends
Player
{
public
class
Human
extends
Player
{
Scanner
scanner
=
new
Scanner
(
System
.
in
);
Scanner
scanner
=
new
Scanner
(
System
.
in
);
int
counter
=
0
;
@Override
@Override
public
Card
chooseCardToThrow
(
ArrayList
<
Card
>
cards
,
Card
c
)
{
public
Card
chooseCardToThrow
(
ArrayList
<
Card
>
cards
,
Card
c
)
{
Card
card
=
null
;
Card
card
=
null
;
if
(
possibleCards
.
size
()
>
0
)
{
if
(
((
getCounter
()
==
0
&&
possibleCards
.
size
()
>
0
)
||
(
getCounter
()
>
0
&&
possibleCards
.
size
()
>
1
))
)
{
System
.
out
.
println
(
"Enter number of the card you wanna throw it!"
);
System
.
out
.
println
(
"Enter number of the card you wanna throw it!"
);
int
number
=
scanner
.
nextInt
();
int
number
=
scanner
.
nextInt
();
if
(
number
>
0
&&
number
<=
getPlayerCards
().
size
()
&&
if
(
number
>
0
&&
number
<=
getPlayerCards
().
size
()
&&
possibleCards
.
contains
(
getPlayerCards
().
get
(
number
-
1
)))
{
possibleCards
.
contains
(
getPlayerCards
().
get
(
number
-
1
)))
{
//possibleCards = null;
//possibleCards = null;
System
.
out
.
println
(
"kire khar!"
);
System
.
out
.
println
(
"kire khar!"
);
card
=
getPlayerCards
().
get
(
number
-
1
);
getPlayerCards
().
remove
(
number
-
1
);
return
card
;
}
else
{
}
else
{
while
(
number
<=
0
||
number
>
getPlayerCards
().
size
()
||
while
(
number
<=
0
||
number
>
getPlayerCards
().
size
()
||
!
possibleCards
.
contains
(
getPlayerCards
().
get
(
number
-
1
)))
{
!
possibleCards
.
contains
(
getPlayerCards
().
get
(
number
-
1
)))
{
System
.
out
.
println
(
"Invalid input"
);
System
.
out
.
println
(
"Invalid input"
);
chooseCardToThrow
(
cards
,
c
);
System
.
out
.
println
(
"Enter number of the card you wanna throw it!"
);
number
=
scanner
.
nextInt
();
}
}
System
.
out
.
println
(
"gaav!"
);
}
}
card
=
getPlayerCards
().
get
(
number
-
1
);
getPlayerCards
().
remove
(
number
-
1
);
return
card
;
}
else
{
}
else
{
card
=
randomPunishmentCard
(
cards
);
card
=
randomPunishmentCard
(
cards
);
System
.
out
.
println
(
card
.
toString
());
getPlayerCards
().
add
(
card
);
getPlayerCards
().
add
(
card
);
cards
.
remove
(
card
);
if
(
card
instanceof
Colored
)
{
if
(
card
instanceof
Colored
)
{
if
(
c
instanceof
Colored
)
{
if
(
c
instanceof
Colored
)
{
if
(!((
Colored
)
c
).
checkEquality
((
Colored
)
card
))
if
(!((
Colored
)
c
).
checkEquality
((
Colored
)
card
))
...
@@ -48,4 +52,42 @@ public class Human extends Player {
...
@@ -48,4 +52,42 @@ public class Human extends Player {
}
}
return
s
;
return
s
;
}
}
@Override
public
Card
chooseColorToThrow
(
ArrayList
<
Card
>
cards
,
String
Color
)
{
Card
card
=
null
;
if
((
getCounter
()
==
0
&&
possibleCards
.
size
()
>
0
)
||
(
getCounter
()
>
0
&&
possibleCards
.
size
()
>
1
))
{
System
.
out
.
println
(
"Enter number of the card you wanna throw it!"
);
int
number
=
scanner
.
nextInt
();
if
(
number
>
0
&&
number
<=
getPlayerCards
().
size
()
&&
possibleCards
.
contains
(
getPlayerCards
().
get
(
number
-
1
)))
{
//possibleCards = null;
System
.
out
.
println
(
"kire khar!"
);
card
=
getPlayerCards
().
get
(
number
-
1
);
getPlayerCards
().
remove
(
number
-
1
);
return
card
;
}
else
{
while
(
number
<=
0
||
number
>
getPlayerCards
().
size
()
||
!
possibleCards
.
contains
(
getPlayerCards
().
get
(
number
-
1
)))
{
System
.
out
.
println
(
"Invalid input"
);
System
.
out
.
println
(
"Enter number of the card you wanna throw it!"
);
number
=
scanner
.
nextInt
();
}
System
.
out
.
println
(
"gaav!"
);
card
=
getPlayerCards
().
get
(
number
-
1
);
cards
.
remove
(
card
);
getPlayerCards
().
remove
(
number
-
1
);
return
card
;
}
}
else
{
card
=
randomPunishmentCard
(
cards
);
getPlayerCards
().
add
(
card
);
if
(
card
instanceof
Colored
)
{
if
(!
card
.
cardColor
.
equals
(
Color
))
{
card
=
null
;
}
}
}
return
card
;
}
}
}
Main.java
View file @
ed2b30de
...
@@ -111,7 +111,7 @@ public class Main {
...
@@ -111,7 +111,7 @@ public class Main {
System
.
out
.
println
(
"Player"
+
(
nextPlayerNumber
+
1
)
+
" starts the game"
);
System
.
out
.
println
(
"Player"
+
(
nextPlayerNumber
+
1
)
+
" starts the game"
);
int
move
=
1
;
int
move
=
1
;
Player
p
=
null
;
Player
p
=
null
;
int
turns
=
nextPlayerNumber
;
int
c
=
0
;
String
nextColor
=
null
;
int
turns
=
nextPlayerNumber
;
int
c
=
0
;
String
nextColor
=
null
;
Card
card
=
null
;
// starts a round
// starts a round
while
(
c
<
9
)
{
while
(
c
<
9
)
{
turns
%=
4
;
turns
%=
4
;
...
@@ -136,17 +136,23 @@ public class Main {
...
@@ -136,17 +136,23 @@ public class Main {
System
.
out
.
println
();
System
.
out
.
println
();
players
.
get
(
turns
).
printAllCards
(
turns
+
1
);
players
.
get
(
turns
).
printAllCards
(
turns
+
1
);
System
.
out
.
println
();
System
.
out
.
println
();
Card
card
=
players
.
get
(
turns
).
chooseCardToThrow
(
cards
,
nextCard
);
if
(
nextCard
!=
null
)
card
=
players
.
get
(
turns
).
chooseCardToThrow
(
cards
,
nextCard
);
else
card
=
players
.
get
(
turns
).
chooseColorToThrow
(
cards
,
nextColor
);
if
(
card
!=
null
)
{
if
(
card
!=
null
)
{
System
.
out
.
println
(
card
.
toString
());
System
.
out
.
println
(
card
.
toString
());
nextColor
=
players
.
get
(
turns
).
chooseColorIfBlack
(
card
);
nextColor
=
players
.
get
(
turns
).
chooseColorIfBlack
(
card
);
if
(
nextColor
==
null
)
if
(
nextColor
==
null
)
nextCard
=
card
;
nextCard
=
card
;
}
}
System
.
out
.
println
(
nextCard
.
toString
());
if
(
nextCard
!=
null
)
System
.
out
.
println
(
nextCard
.
toString
());
else
System
.
out
.
println
(
nextColor
);
turns
+=
move
;
turns
+=
move
;
}
}
// sort players by each player's point (A
cs
ending sort)
// sort players by each player's point (A
sc
ending sort)
/*Iterator<Player> players1 = players.iterator(); int min = 350;
/*Iterator<Player> players1 = players.iterator(); int min = 350;
while (players1.hasNext()){
while (players1.hasNext()){
p = players1.next();
p = players1.next();
...
...
Player.java
View file @
ed2b30de
...
@@ -37,6 +37,10 @@ public class Player {
...
@@ -37,6 +37,10 @@ public class Player {
}
}
}
}
public
int
getCounter
()
{
return
counter
;
}
public
ArrayList
<
Card
>
getPossibleCards
()
{
public
ArrayList
<
Card
>
getPossibleCards
()
{
return
possibleCards
;
return
possibleCards
;
}
}
...
@@ -51,7 +55,9 @@ public class Player {
...
@@ -51,7 +55,9 @@ public class Player {
public
void
checkAllCards
(
Card
card
){
public
void
checkAllCards
(
Card
card
){
boolean
isColored
=
false
;
boolean
isColored
=
false
;
if
(
possibleCards
!=
null
){
if
(
possibleCards
==
null
)
possibleCards
=
new
ArrayList
<>();
if
(
possibleCards
.
size
()
>
1
){
for
(
int
i
=
1
;
i
<
possibleCards
.
size
();
i
++){
for
(
int
i
=
1
;
i
<
possibleCards
.
size
();
i
++){
possibleCards
.
remove
(
i
);
possibleCards
.
remove
(
i
);
i
--;
i
--;
...
@@ -86,10 +92,10 @@ public class Player {
...
@@ -86,10 +92,10 @@ public class Player {
public
void
printAllPossibleCards
(
int
playerNumber
){
public
void
printAllPossibleCards
(
int
playerNumber
){
System
.
out
.
println
(
"Player"
+
playerNumber
+
": (Possible cards)"
);
System
.
out
.
println
(
"Player"
+
playerNumber
+
": (Possible cards)"
);
Iterator
<
Card
>
cardIterator
=
possibleCards
.
iterator
();
Iterator
<
Card
>
cardIterator
=
possibleCards
.
iterator
();
if
(
counter
!=
0
){
if
(
counter
!=
0
)
{
cardIterator
.
next
();
cardIterator
.
next
();
}
}
while
(
cardIterator
.
hasNext
()){
while
(
cardIterator
.
hasNext
())
{
Card
c
=
cardIterator
.
next
();
Card
c
=
cardIterator
.
next
();
System
.
out
.
println
(
c
.
toString
());
System
.
out
.
println
(
c
.
toString
());
}
}
...
@@ -131,7 +137,9 @@ public class Player {
...
@@ -131,7 +137,9 @@ public class Player {
" }"
;
" }"
;
}
}
public
void
checkColors
(
String
color
){
public
void
checkColors
(
String
color
){
if
(
possibleCards
!=
null
){
if
(
possibleCards
==
null
)
possibleCards
=
new
ArrayList
<>();
if
(
possibleCards
.
size
()
>
1
){
for
(
int
i
=
1
;
i
<
possibleCards
.
size
();
i
++){
for
(
int
i
=
1
;
i
<
possibleCards
.
size
();
i
++){
possibleCards
.
remove
(
i
);
possibleCards
.
remove
(
i
);
i
--;
i
--;
...
@@ -146,4 +154,8 @@ public class Player {
...
@@ -146,4 +154,8 @@ public class Player {
}
}
}
}
public
Card
chooseColorToThrow
(
ArrayList
<
Card
>
cards
,
String
Color
){
return
null
;
}
}
}
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