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
e5f353eb
Commit
e5f353eb
authored
Apr 17, 2020
by
amir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Checking cards and some new methods
parent
4aeeddde
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
141 additions
and
31 deletions
+141
-31
Card.java
Card.java
+1
-0
Colored.java
Colored.java
+2
-2
Draw.java
Draw.java
+7
-0
Human.java
Human.java
+5
-0
Main.java
Main.java
+39
-28
Numeric.java
Numeric.java
+8
-0
Player.java
Player.java
+60
-1
Reverse.java
Reverse.java
+7
-0
Skip.java
Skip.java
+12
-0
No files found.
Card.java
View file @
e5f353eb
...
@@ -7,6 +7,7 @@ public class Card {
...
@@ -7,6 +7,7 @@ public class Card {
public
Card
(
String
color
){
public
Card
(
String
color
){
this
.
cardColor
=
color
;
this
.
cardColor
=
color
;
}
}
public
int
turnSkip
(){
public
int
turnSkip
(){
return
1
;
return
1
;
}
}
...
...
Colored.java
View file @
e5f353eb
package
com
.
company
;
package
com
.
company
;
public
class
Colored
extends
Card
{
public
class
Colored
extends
Card
{
private
int
colorType
;
// 0 for numeric, 1 == movement
private
int
colorType
;
// 0 for numeric, 1 == movement
public
Colored
(
String
color
,
int
colorType
)
{
public
Colored
(
String
color
,
int
colorType
)
{
super
(
color
);
super
(
color
);
if
(
colorType
==
1
||
colorType
==
0
)
if
(
colorType
==
1
||
colorType
==
0
)
...
@@ -9,7 +9,7 @@ public class Colored extends Card {
...
@@ -9,7 +9,7 @@ public class Colored extends Card {
}
}
public
boolean
checkEquality
(
Colored
coloredToCompare
){
public
boolean
checkEquality
(
Colored
coloredToCompare
){
if
(
cardColor
.
equals
(
coloredToCompare
.
cardColor
)
||
colorType
==
coloredToCompare
.
colorType
)
if
(
cardColor
.
equals
(
coloredToCompare
.
cardColor
))
return
true
;
return
true
;
return
false
;
return
false
;
}
}
...
...
Draw.java
View file @
e5f353eb
...
@@ -7,6 +7,13 @@ public class Draw extends Movemention {
...
@@ -7,6 +7,13 @@ public class Draw extends Movemention {
super
(
color
,
colorType
,
moveType
);
super
(
color
,
colorType
,
moveType
);
}
}
@Override
public
boolean
checkEquality
(
Colored
coloredToCompare
)
{
if
(!
super
.
checkEquality
(
coloredToCompare
)
&&
coloredToCompare
instanceof
Draw
)
return
true
;
return
false
;
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
"Draw{ "
+
super
.
toString
();
return
"Draw{ "
+
super
.
toString
();
...
...
Human.java
0 → 100644
View file @
e5f353eb
package
com
.
company
;
public
class
Human
extends
Player
{
}
Main.java
View file @
e5f353eb
...
@@ -7,10 +7,11 @@ import java.util.Random;
...
@@ -7,10 +7,11 @@ import java.util.Random;
public
class
Main
{
public
class
Main
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
ArrayList
<
Card
>
cards
=
new
ArrayList
<>();
ArrayList
<
Card
>
cards
=
new
ArrayList
<>();
String
Color
;
String
Color1
;
String
Color
;
for
(
int
i
=
1
;
i
<
5
;
i
++){
String
Color1
;
switch
(
i
){
for
(
int
i
=
1
;
i
<
5
;
i
++)
{
switch
(
i
)
{
case
1
:
case
1
:
Color
=
"Red"
;
Color
=
"Red"
;
break
;
break
;
...
@@ -39,8 +40,8 @@ public class Main {
...
@@ -39,8 +40,8 @@ public class Main {
Black
black
=
new
Black
(
"Black"
,
0
);
Black
black
=
new
Black
(
"Black"
,
0
);
cards
.
add
(
black
);
cards
.
add
(
black
);
}
}
for
(
int
i
=
1
;
i
<
5
;
i
++){
for
(
int
i
=
1
;
i
<
5
;
i
++)
{
switch
(
i
)
{
switch
(
i
)
{
case
1
:
case
1
:
Color1
=
"Red"
;
Color1
=
"Red"
;
break
;
break
;
...
@@ -73,63 +74,73 @@ public class Main {
...
@@ -73,63 +74,73 @@ public class Main {
/*for (int i = 0; i < 108; i++){
/*for (int i = 0; i < 108; i++){
System.out.println(cards.get(i).toString());
System.out.println(cards.get(i).toString());
}*/
}*/
Random
r
=
new
Random
();
int
next
;
Random
r
=
new
Random
();
int
nextCardNumber
;
ArrayList
<
Player
>
players
=
new
ArrayList
<>();
ArrayList
<
Player
>
players
=
new
ArrayList
<>();
for
(
int
i
=
1
;
i
<
5
;
i
++)
{
for
(
int
i
=
1
;
i
<
5
;
i
++)
{
Player
p
=
new
Player
();
Player
p
=
new
Player
();
players
.
add
(
p
);
players
.
add
(
p
);
for
(
int
j
=
1
;
j
<
8
;
j
++){
for
(
int
j
=
1
;
j
<
8
;
j
++)
{
next
=
r
.
nextInt
(
cards
.
size
());
nextCardNumber
=
r
.
nextInt
(
cards
.
size
());
p
.
getPlayerCards
().
add
(
cards
.
get
(
next
));
p
.
getPlayerCards
().
add
(
cards
.
get
(
nextCardNumber
));
cards
.
remove
(
next
);
cards
.
remove
(
nextCardNumber
);
//System.out.println("cardNumber = " + next);
//System.out.println("cardNumber = " + next);
}
}
//p.printAllCards(i);
//p.printAllCards(i);
}
}
/*
for (int i = 0; i < 4; i++) {
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
players
.
get
(
i
).
printAllCards
(
i
+
1
);
players
.
get
(
i
).
printAllCards
(
i
+
1
);
System
.
out
.
println
(
players
.
get
(
i
).
getPlayerPoint
());
System
.
out
.
println
(
players
.
get
(
i
).
getPlayerPoint
());
System
.
out
.
println
();
}
*/
}
// first random card from the storage of cards (most be a colored card)
// first random card from the storage of cards (most be a colored card)
next
=
r
.
nextInt
(
cards
.
size
());
next
CardNumber
=
r
.
nextInt
(
cards
.
size
());
if
(
cards
.
get
(
next
)
instanceof
Black
)
{
if
(
cards
.
get
(
next
CardNumber
)
instanceof
Black
)
{
while
(
cards
.
get
(
next
)
instanceof
Black
)
{
while
(
cards
.
get
(
next
CardNumber
)
instanceof
Black
)
{
next
=
r
.
nextInt
(
cards
.
size
());
next
CardNumber
=
r
.
nextInt
(
cards
.
size
());
}
}
}
}
System
.
out
.
println
(
"Player"
+
r
.
nextInt
(
5
)
+
" starts the game"
);
int
move
=
1
;
Player
p
=
null
;
int
nextPlayerNumber
=
r
.
nextInt
(
4
);
System
.
out
.
println
(
"Player"
+
(
nextPlayerNumber
+
1
)
+
" starts the game"
);
int
move
=
1
;
Player
p
=
null
;
int
turns
=
nextPlayerNumber
;
// starts a round
// starts a round
while
(
true
)
{
while
(
true
)
{
Iterator
<
Player
>
playerIterator
=
players
.
iterator
();
Iterator
<
Player
>
playerIterator
=
players
.
iterator
();
while
(
playerIterator
.
hasNext
()){
while
(
playerIterator
.
hasNext
())
{
p
=
playerIterator
.
next
();
p
=
playerIterator
.
next
();
if
(
p
.
getPlayerCards
().
size
()
==
0
)
if
(
p
.
getPlayerCards
().
size
()
==
0
)
break
;
break
;
}
}
if
(
p
.
getPlayerCards
().
size
()
==
0
)
if
(
p
.
getPlayerCards
().
size
()
==
0
)
break
;
break
;
if
(
move
==
1
)
if
(
move
==
1
)
System
.
out
.
println
(
"Clockwise"
);
System
.
out
.
println
(
"Clockwise"
);
else
else
System
.
out
.
println
(
"CounterClockwise"
);
System
.
out
.
println
(
"CounterClockwise"
);
if
(
turns
!=
2
){
}
}
}
// sort players by each player's point (Acsending sort)
// sort players by each player's point (Acsending sort)
Iterator
<
Player
>
players1
=
players
.
iterator
();
int
min
=
-
1
;
/*Iterator<Player> players1 = players.iterator(); int min = 350
;
while (players1.hasNext()){
while (players1.hasNext()){
p = players1.next();
p = players1.next();
if
(
p
.
getPlayerPoint
()
>
min
)
if (p.getPlayerPoint()
<
min)
min = p.getPlayerPoint();
min = p.getPlayerPoint();
}
}
*/
// end the round by showing each player's point
// end the round by showing each player's point
Iterator
<
Player
>
players2
=
players
.
iterator
();
int
c
=
0
;
/*
Iterator<Player> players2 = players.iterator(); int c = 0;
while (players2.hasNext()){
while (players2.hasNext()){
c++;
c++;
players2
.
next
().
toString
(
c
);
System.out.println(players2.next().toString(c));
}
}*/
// unicode of black color: "\033[0;30m"
// unicode of black color: "\033[0;30m"
// unicode of red color: "\033[0;31m"
// unicode of red color: "\033[0;31m"
// unicode of green color: "\033[0;32m"
// unicode of green color: "\033[0;32m"
...
...
Numeric.java
View file @
e5f353eb
...
@@ -13,6 +13,14 @@ public class Numeric extends Colored {
...
@@ -13,6 +13,14 @@ public class Numeric extends Colored {
", number="
+
number
+
'}'
;
", number="
+
number
+
'}'
;
}
}
@Override
public
boolean
checkEquality
(
Colored
coloredToCompare
)
{
if
(!
super
.
checkEquality
(
coloredToCompare
)
&&
coloredToCompare
instanceof
Numeric
&&
((
Numeric
)
coloredToCompare
).
number
==
number
)
return
true
;
return
false
;
}
@Override
@Override
public
int
getCardPoint
()
{
public
int
getCardPoint
()
{
return
number
;
return
number
;
...
...
Player.java
View file @
e5f353eb
...
@@ -4,13 +4,25 @@ import java.util.ArrayList;
...
@@ -4,13 +4,25 @@ import java.util.ArrayList;
import
java.util.Iterator
;
import
java.util.Iterator
;
public
class
Player
{
public
class
Player
{
// List of player's cards
private
ArrayList
<
Card
>
playerCards
=
new
ArrayList
<>();
private
ArrayList
<
Card
>
playerCards
=
new
ArrayList
<>();
// point of the player
private
int
playerPoint
;
private
int
playerPoint
;
ArrayList
<
Card
>
possibleCards
;
/**
* returns the list of player's cards
* @return the list of player's cards
*/
public
ArrayList
<
Card
>
getPlayerCards
()
{
public
ArrayList
<
Card
>
getPlayerCards
()
{
return
playerCards
;
return
playerCards
;
}
}
/**
*
* @param playerNumber
*/
public
void
printAllCards
(
int
playerNumber
){
public
void
printAllCards
(
int
playerNumber
){
System
.
out
.
println
(
"Player"
+
playerNumber
+
":"
);
System
.
out
.
println
(
"Player"
+
playerNumber
+
":"
);
Iterator
<
Card
>
cardIterator
=
playerCards
.
iterator
();
Iterator
<
Card
>
cardIterator
=
playerCards
.
iterator
();
...
@@ -18,7 +30,6 @@ public class Player {
...
@@ -18,7 +30,6 @@ public class Player {
Card
c
=
cardIterator
.
next
();
Card
c
=
cardIterator
.
next
();
System
.
out
.
println
(
c
.
toString
());
System
.
out
.
println
(
c
.
toString
());
}
}
System
.
out
.
println
();
}
}
public
int
getPlayerPoint
()
{
public
int
getPlayerPoint
()
{
...
@@ -29,6 +40,54 @@ public class Player {
...
@@ -29,6 +40,54 @@ public class Player {
return
playerPoint
;
return
playerPoint
;
}
}
public
void
checkAllCards
(
Card
card
){
possibleCards
=
new
ArrayList
<>();
boolean
isColored
;
if
(
card
instanceof
Colored
)
isColored
=
true
;
else
isColored
=
false
;
Iterator
<
Card
>
cardIterator
=
playerCards
.
iterator
();
while
(
cardIterator
.
hasNext
()){
Card
c
=
cardIterator
.
next
();
if
(
c
instanceof
Colored
)
{
if
(
isColored
)
if
(((
Colored
)
c
).
checkEquality
((
Colored
)
card
))
possibleCards
.
add
(
c
);
}
else
possibleCards
.
add
(
c
);
}
if
(
possibleCards
.
size
()
>
0
)
{
if
(
possibleCards
.
size
()
!=
searchWildDraws
())
deleteWildDraws
();
}
}
public
int
searchWildDraws
(){
int
counterWildDraw
=
0
;
Iterator
<
Card
>
cardIterator
=
possibleCards
.
iterator
();
while
(
cardIterator
.
hasNext
()){
Card
c
=
cardIterator
.
next
();
if
(
c
instanceof
WildDraw
)
counterWildDraw
++;
}
return
counterWildDraw
;
}
public
void
deleteWildDraws
(){
Iterator
<
Card
>
cardIterator
=
possibleCards
.
iterator
();
while
(
cardIterator
.
hasNext
())
{
Card
c
=
cardIterator
.
next
();
if
(
c
instanceof
WildDraw
)
possibleCards
.
remove
(
c
);
}
}
public
void
whichCard
(
Card
card
){
}
public
String
toString
(
int
playerNumber
)
{
public
String
toString
(
int
playerNumber
)
{
return
"Player"
+
playerNumber
+
return
"Player"
+
playerNumber
+
" {playerPoint="
+
playerPoint
+
" {playerPoint="
+
playerPoint
+
...
...
Reverse.java
View file @
e5f353eb
...
@@ -12,6 +12,13 @@ public class Reverse extends Movemention {
...
@@ -12,6 +12,13 @@ public class Reverse extends Movemention {
return
-
1
;
return
-
1
;
}
}
@Override
public
boolean
checkEquality
(
Colored
coloredToCompare
)
{
if
(!
super
.
checkEquality
(
coloredToCompare
)
&&
coloredToCompare
instanceof
Reverse
)
return
true
;
return
false
;
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
"Reverse{ "
+
super
.
toString
();
return
"Reverse{ "
+
super
.
toString
();
...
...
Skip.java
View file @
e5f353eb
...
@@ -6,6 +6,18 @@ public class Skip extends Movemention {
...
@@ -6,6 +6,18 @@ public class Skip extends Movemention {
super
(
color
,
colorType
,
moveType
);
super
(
color
,
colorType
,
moveType
);
}
}
@Override
public
boolean
checkEquality
(
Colored
coloredToCompare
)
{
if
(!
super
.
checkEquality
(
coloredToCompare
)
&&
coloredToCompare
instanceof
Skip
)
return
true
;
return
false
;
}
@Override
public
int
turnSkip
()
{
return
super
.
turnSkip
();
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
"Skip{ "
+
super
.
toString
();
return
"Skip{ "
+
super
.
toString
();
...
...
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