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
640d7eb1
Commit
640d7eb1
authored
Apr 18, 2020
by
amir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
shit!
parent
875d98dd
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
131 additions
and
21 deletions
+131
-21
Colored.java
Colored.java
+1
-0
Comp.java
Comp.java
+36
-1
Draw.java
Draw.java
+1
-1
Human.java
Human.java
+27
-4
Main.java
Main.java
+20
-4
Player.java
Player.java
+44
-9
Reverse.java
Reverse.java
+1
-1
Skip.java
Skip.java
+1
-1
No files found.
Colored.java
View file @
640d7eb1
...
@@ -14,6 +14,7 @@ public class Colored extends Card {
...
@@ -14,6 +14,7 @@ public class Colored extends Card {
return
false
;
return
false
;
}
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
"Colored{"
+
return
"Colored{"
+
...
...
Comp.java
View file @
640d7eb1
package
com
.
company
;
package
com
.
company
;
import
java.util.ArrayList
;
import
java.util.Random
;
import
java.util.Random
;
public
class
Comp
extends
Player
{
public
class
Comp
extends
Player
{
Random
r
=
new
Random
();
Random
r
=
new
Random
();
@Override
@Override
public
Card
chooseCardToThrow
()
{
public
Card
chooseCardToThrow
(
ArrayList
<
Card
>
cards
,
Card
card
)
{
Card
c
=
null
;
Card
c
=
null
;
if
(
possibleCards
.
size
()
>
0
)
{
if
(
possibleCards
.
size
()
>
0
)
{
int
number
=
r
.
nextInt
(
getPossibleCards
().
size
());
int
number
=
r
.
nextInt
(
getPossibleCards
().
size
());
...
@@ -14,6 +15,40 @@ public class Comp extends Player {
...
@@ -14,6 +15,40 @@ public class Comp extends Player {
possibleCards
=
null
;
possibleCards
=
null
;
getPlayerCards
().
remove
(
c
);
getPlayerCards
().
remove
(
c
);
}
}
else
{
c
=
randomPunishmentCard
(
cards
);
getPlayerCards
().
add
(
c
);
if
(
c
instanceof
Colored
)
{
if
(
card
instanceof
Colored
)
{
if
(!((
Colored
)
c
).
checkEquality
((
Colored
)
card
))
c
=
null
;
}
else
c
=
null
;
}
}
return
c
;
return
c
;
}
}
public
String
chooseColorIfBlack
(
Card
card
){
String
s
=
null
;
if
(
card
instanceof
Black
){
int
color
=
r
.
nextInt
(
4
)
+
1
;
switch
(
color
){
case
1
:
s
=
"red"
;
break
;
case
2
:
s
=
"green"
;
break
;
case
3
:
s
=
"yellow"
;
break
;
case
4
:
s
=
"blue"
;
break
;
}
}
return
s
;
}
}
}
Draw.java
View file @
640d7eb1
...
@@ -11,7 +11,7 @@ public class Draw extends Movemention {
...
@@ -11,7 +11,7 @@ public class Draw extends Movemention {
public
boolean
checkEquality
(
Colored
coloredToCompare
)
{
public
boolean
checkEquality
(
Colored
coloredToCompare
)
{
if
(
super
.
checkEquality
(
coloredToCompare
))
if
(
super
.
checkEquality
(
coloredToCompare
))
return
true
;
return
true
;
if
(
!
super
.
checkEquality
(
coloredToCompare
)
&&
coloredToCompare
instanceof
Draw
)
if
(
coloredToCompare
instanceof
Draw
)
return
true
;
return
true
;
return
false
;
return
false
;
}
}
...
...
Human.java
View file @
640d7eb1
package
com
.
company
;
package
com
.
company
;
import
java.util.ArrayList
;
import
java.util.Scanner
;
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
);
@Override
@Override
public
Card
chooseCardToThrow
()
{
public
Card
chooseCardToThrow
(
ArrayList
<
Card
>
cards
,
Card
c
)
{
Card
card
=
null
;
Card
card
=
null
;
if
(
possibleCards
.
size
()
>
0
)
{
if
(
possibleCards
.
size
()
>
0
)
{
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!"
);
card
=
getPlayerCards
().
get
(
number
-
1
);
card
=
getPlayerCards
().
get
(
number
-
1
);
getPlayerCards
().
remove
(
number
-
1
);
getPlayerCards
().
remove
(
number
-
1
);
return
card
;
}
else
{
}
else
{
while
(
true
){
while
(
number
<=
0
||
number
>
getPlayerCards
().
size
()
||
!
possibleCards
.
contains
(
getPlayerCards
().
get
(
number
-
1
)))
{
System
.
out
.
println
(
"Invalid input"
);
System
.
out
.
println
(
"Invalid input"
);
chooseCardToThrow
();
chooseCardToThrow
(
cards
,
c
);
}
}
}
}
else
{
card
=
randomPunishmentCard
(
cards
);
getPlayerCards
().
add
(
card
);
if
(
card
instanceof
Colored
)
{
if
(
c
instanceof
Colored
)
{
if
(!((
Colored
)
c
).
checkEquality
((
Colored
)
card
))
card
=
null
;
}
else
card
=
null
;
}
}
}
}
return
card
;
return
card
;
}
}
public
String
chooseColorIfBlack
(
Card
card
){
String
s
=
null
;
if
(
card
instanceof
Black
){
System
.
out
.
println
(
"Choose a color: red, green, yellow, blue"
);
s
=
scanner
.
next
();
}
return
s
;
}
}
}
Main.java
View file @
640d7eb1
...
@@ -103,15 +103,17 @@ public class Main {
...
@@ -103,15 +103,17 @@ public class Main {
nextCardNumber
=
r
.
nextInt
(
cards
.
size
());
nextCardNumber
=
r
.
nextInt
(
cards
.
size
());
}
}
}
}
System
.
out
.
println
(
cards
.
get
(
nextCardNumber
).
toString
());
Card
nextCard
=
cards
.
get
(
nextCardNumber
);
System
.
out
.
println
(
nextCard
.
toString
());
System
.
out
.
println
();
System
.
out
.
println
();
cards
.
remove
(
nextCardNumber
);
int
nextPlayerNumber
=
r
.
nextInt
(
4
);
int
nextPlayerNumber
=
r
.
nextInt
(
4
);
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
;
int
turns
=
nextPlayerNumber
;
int
c
=
0
;
String
nextColor
=
null
;
// starts a round
// starts a round
while
(
c
<
5
)
{
while
(
c
<
9
)
{
turns
%=
4
;
turns
%=
4
;
c
++;
c
++;
Iterator
<
Player
>
playerIterator
=
players
.
iterator
();
Iterator
<
Player
>
playerIterator
=
players
.
iterator
();
...
@@ -126,8 +128,22 @@ public class Main {
...
@@ -126,8 +128,22 @@ public class Main {
System
.
out
.
println
(
"Clockwise"
);
System
.
out
.
println
(
"Clockwise"
);
else
else
System
.
out
.
println
(
"CounterClockwise"
);
System
.
out
.
println
(
"CounterClockwise"
);
players
.
get
(
turns
).
checkAllCards
(
cards
.
get
(
nextCardNumber
));
if
(
nextColor
==
null
)
players
.
get
(
turns
).
checkAllCards
(
nextCard
);
else
players
.
get
(
turns
).
checkColors
(
nextColor
);
players
.
get
(
turns
).
printAllPossibleCards
(
turns
+
1
);
players
.
get
(
turns
).
printAllPossibleCards
(
turns
+
1
);
System
.
out
.
println
();
players
.
get
(
turns
).
printAllCards
(
turns
+
1
);
System
.
out
.
println
();
Card
card
=
players
.
get
(
turns
).
chooseCardToThrow
(
cards
,
nextCard
);
if
(
card
!=
null
)
{
System
.
out
.
println
(
card
.
toString
());
nextColor
=
players
.
get
(
turns
).
chooseColorIfBlack
(
card
);
if
(
nextColor
==
null
)
nextCard
=
card
;
}
System
.
out
.
println
(
nextCard
.
toString
());
turns
+=
move
;
turns
+=
move
;
}
}
// sort players by each player's point (Acsending sort)
// sort players by each player's point (Acsending sort)
...
...
Player.java
View file @
640d7eb1
...
@@ -5,6 +5,7 @@ import com.sun.javafx.scene.control.skin.VirtualFlow;
...
@@ -5,6 +5,7 @@ import com.sun.javafx.scene.control.skin.VirtualFlow;
import
java.lang.reflect.Array
;
import
java.lang.reflect.Array
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.Random
;
public
class
Player
{
public
class
Player
{
// List of player's cards
// List of player's cards
...
@@ -12,7 +13,8 @@ public class Player {
...
@@ -12,7 +13,8 @@ public class Player {
// point of the player
// point of the player
private
int
playerPoint
;
private
int
playerPoint
;
protected
ArrayList
<
Card
>
possibleCards
;
protected
ArrayList
<
Card
>
possibleCards
=
new
ArrayList
<>();
private
int
counter
=
0
;
/**
/**
* returns the list of player's cards
* returns the list of player's cards
...
@@ -48,12 +50,15 @@ public class Player {
...
@@ -48,12 +50,15 @@ public class Player {
}
}
public
void
checkAllCards
(
Card
card
){
public
void
checkAllCards
(
Card
card
){
possibleCards
=
new
ArrayList
<>();
boolean
isColored
=
false
;
boolean
isColored
;
if
(
possibleCards
!=
null
){
for
(
int
i
=
1
;
i
<
possibleCards
.
size
();
i
++){
possibleCards
.
remove
(
i
);
i
--;
}
}
if
(
card
instanceof
Colored
)
if
(
card
instanceof
Colored
)
isColored
=
true
;
isColored
=
true
;
else
isColored
=
false
;
Iterator
<
Card
>
cardIterator
=
playerCards
.
iterator
();
Iterator
<
Card
>
cardIterator
=
playerCards
.
iterator
();
while
(
cardIterator
.
hasNext
())
{
while
(
cardIterator
.
hasNext
())
{
Card
c
=
cardIterator
.
next
();
Card
c
=
cardIterator
.
next
();
...
@@ -72,17 +77,26 @@ public class Player {
...
@@ -72,17 +77,26 @@ public class Player {
}
}
public
Card
randomPunishmentCard
(
ArrayList
<
Card
>
cards
){
Random
r
=
new
Random
();
int
next
=
r
.
nextInt
(
cards
.
size
());
return
cards
.
get
(
next
);
}
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
){
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
());
}
}
counter
++;
}
}
p
ublic
int
searchWildDraws
(){
p
rivate
int
searchWildDraws
(){
int
counterWildDraw
=
0
;
int
counterWildDraw
=
0
;
Iterator
<
Card
>
cardIterator
=
possibleCards
.
iterator
();
Iterator
<
Card
>
cardIterator
=
possibleCards
.
iterator
();
while
(
cardIterator
.
hasNext
()){
while
(
cardIterator
.
hasNext
()){
...
@@ -93,7 +107,7 @@ public class Player {
...
@@ -93,7 +107,7 @@ public class Player {
return
counterWildDraw
;
return
counterWildDraw
;
}
}
p
ublic
void
deleteWildDraws
(){
p
rivate
void
deleteWildDraws
(){
for
(
int
i
=
0
;
i
<
possibleCards
.
size
();
i
++){
for
(
int
i
=
0
;
i
<
possibleCards
.
size
();
i
++){
if
(
possibleCards
.
get
(
i
)
instanceof
WildDraw
){
if
(
possibleCards
.
get
(
i
)
instanceof
WildDraw
){
possibleCards
.
remove
(
i
);
possibleCards
.
remove
(
i
);
...
@@ -102,13 +116,34 @@ public class Player {
...
@@ -102,13 +116,34 @@ public class Player {
}
}
}
}
public
Card
chooseCardToThrow
(){
public
Card
chooseCardToThrow
(
ArrayList
<
Card
>
cards
,
Card
c
){
return
null
;
return
null
;
}
}
public
String
chooseColorIfBlack
(
Card
card
){
String
s
=
null
;
return
s
;
}
public
String
toString
(
int
playerNumber
)
{
public
String
toString
(
int
playerNumber
)
{
return
"Player"
+
playerNumber
+
return
"Player"
+
playerNumber
+
" {playerPoint="
+
playerPoint
+
" {playerPoint="
+
playerPoint
+
" }"
;
" }"
;
}
}
public
void
checkColors
(
String
color
){
if
(
possibleCards
!=
null
){
for
(
int
i
=
1
;
i
<
possibleCards
.
size
();
i
++){
possibleCards
.
remove
(
i
);
i
--;
}
}
Iterator
<
Card
>
cardIterator
=
playerCards
.
iterator
();
while
(
cardIterator
.
hasNext
())
{
Card
c
=
cardIterator
.
next
();
if
(
c
instanceof
Colored
)
if
(
c
.
cardColor
.
equals
(
color
))
possibleCards
.
add
(
c
);
}
}
}
}
Reverse.java
View file @
640d7eb1
...
@@ -16,7 +16,7 @@ public class Reverse extends Movemention {
...
@@ -16,7 +16,7 @@ public class Reverse extends Movemention {
public
boolean
checkEquality
(
Colored
coloredToCompare
)
{
public
boolean
checkEquality
(
Colored
coloredToCompare
)
{
if
(
super
.
checkEquality
(
coloredToCompare
))
if
(
super
.
checkEquality
(
coloredToCompare
))
return
true
;
return
true
;
if
(
!
super
.
checkEquality
(
coloredToCompare
)
&&
coloredToCompare
instanceof
Reverse
)
if
(
coloredToCompare
instanceof
Reverse
)
return
true
;
return
true
;
return
false
;
return
false
;
}
}
...
...
Skip.java
View file @
640d7eb1
...
@@ -10,7 +10,7 @@ public class Skip extends Movemention {
...
@@ -10,7 +10,7 @@ public class Skip extends Movemention {
public
boolean
checkEquality
(
Colored
coloredToCompare
)
{
public
boolean
checkEquality
(
Colored
coloredToCompare
)
{
if
(
super
.
checkEquality
(
coloredToCompare
))
if
(
super
.
checkEquality
(
coloredToCompare
))
return
true
;
return
true
;
if
(
!
super
.
checkEquality
(
coloredToCompare
)
&&
coloredToCompare
instanceof
Skip
)
if
(
coloredToCompare
instanceof
Skip
)
return
true
;
return
true
;
return
false
;
return
false
;
}
}
...
...
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