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 {
public
Card
(
String
color
){
this
.
cardColor
=
color
;
}
public
int
turnSkip
(){
return
1
;
}
...
...
Colored.java
View file @
e5f353eb
package
com
.
company
;
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
)
{
super
(
color
);
if
(
colorType
==
1
||
colorType
==
0
)
...
...
@@ -9,7 +9,7 @@ public class Colored extends Card {
}
public
boolean
checkEquality
(
Colored
coloredToCompare
){
if
(
cardColor
.
equals
(
coloredToCompare
.
cardColor
)
||
colorType
==
coloredToCompare
.
colorType
)
if
(
cardColor
.
equals
(
coloredToCompare
.
cardColor
))
return
true
;
return
false
;
}
...
...
Draw.java
View file @
e5f353eb
...
...
@@ -7,6 +7,13 @@ public class Draw extends Movemention {
super
(
color
,
colorType
,
moveType
);
}
@Override
public
boolean
checkEquality
(
Colored
coloredToCompare
)
{
if
(!
super
.
checkEquality
(
coloredToCompare
)
&&
coloredToCompare
instanceof
Draw
)
return
true
;
return
false
;
}
@Override
public
String
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;
public
class
Main
{
public
static
void
main
(
String
[]
args
)
{
ArrayList
<
Card
>
cards
=
new
ArrayList
<>();
String
Color
;
String
Color1
;
for
(
int
i
=
1
;
i
<
5
;
i
++){
switch
(
i
){
ArrayList
<
Card
>
cards
=
new
ArrayList
<>();
String
Color
;
String
Color1
;
for
(
int
i
=
1
;
i
<
5
;
i
++)
{
switch
(
i
)
{
case
1
:
Color
=
"Red"
;
break
;
...
...
@@ -39,8 +40,8 @@ public class Main {
Black
black
=
new
Black
(
"Black"
,
0
);
cards
.
add
(
black
);
}
for
(
int
i
=
1
;
i
<
5
;
i
++){
switch
(
i
)
{
for
(
int
i
=
1
;
i
<
5
;
i
++)
{
switch
(
i
)
{
case
1
:
Color1
=
"Red"
;
break
;
...
...
@@ -73,63 +74,73 @@ public class Main {
/*for (int i = 0; i < 108; i++){
System.out.println(cards.get(i).toString());
}*/
Random
r
=
new
Random
();
int
next
;
Random
r
=
new
Random
();
int
nextCardNumber
;
ArrayList
<
Player
>
players
=
new
ArrayList
<>();
for
(
int
i
=
1
;
i
<
5
;
i
++)
{
Player
p
=
new
Player
();
players
.
add
(
p
);
for
(
int
j
=
1
;
j
<
8
;
j
++){
next
=
r
.
nextInt
(
cards
.
size
());
p
.
getPlayerCards
().
add
(
cards
.
get
(
next
));
cards
.
remove
(
next
);
for
(
int
j
=
1
;
j
<
8
;
j
++)
{
nextCardNumber
=
r
.
nextInt
(
cards
.
size
());
p
.
getPlayerCards
().
add
(
cards
.
get
(
nextCardNumber
));
cards
.
remove
(
nextCardNumber
);
//System.out.println("cardNumber = " + next);
}
//p.printAllCards(i);
}
/*
for (int i = 0; i < 4; i++) {
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
players
.
get
(
i
).
printAllCards
(
i
+
1
);
System
.
out
.
println
(
players
.
get
(
i
).
getPlayerPoint
());
}
*/
System
.
out
.
println
();
}
// first random card from the storage of cards (most be a colored card)
next
=
r
.
nextInt
(
cards
.
size
());
if
(
cards
.
get
(
next
)
instanceof
Black
)
{
while
(
cards
.
get
(
next
)
instanceof
Black
)
{
next
=
r
.
nextInt
(
cards
.
size
());
next
CardNumber
=
r
.
nextInt
(
cards
.
size
());
if
(
cards
.
get
(
next
CardNumber
)
instanceof
Black
)
{
while
(
cards
.
get
(
next
CardNumber
)
instanceof
Black
)
{
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
while
(
true
)
{
Iterator
<
Player
>
playerIterator
=
players
.
iterator
();
while
(
playerIterator
.
hasNext
()){
while
(
playerIterator
.
hasNext
())
{
p
=
playerIterator
.
next
();
if
(
p
.
getPlayerCards
().
size
()
==
0
)
break
;
}
if
(
p
.
getPlayerCards
().
size
()
==
0
)
break
;
break
;
if
(
move
==
1
)
System
.
out
.
println
(
"Clockwise"
);
else
System
.
out
.
println
(
"CounterClockwise"
);
if
(
turns
!=
2
){
}
}
// 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()){
p = players1.next();
if
(
p
.
getPlayerPoint
()
>
min
)
if (p.getPlayerPoint()
<
min)
min = p.getPlayerPoint();
}
}
*/
// 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()){
c++;
players2
.
next
().
toString
(
c
);
}
System.out.println(players2.next().toString(c));
}*/
// unicode of black color: "\033[0;30m"
// unicode of red color: "\033[0;31m"
// unicode of green color: "\033[0;32m"
...
...
Numeric.java
View file @
e5f353eb
...
...
@@ -13,6 +13,14 @@ public class Numeric extends Colored {
", number="
+
number
+
'}'
;
}
@Override
public
boolean
checkEquality
(
Colored
coloredToCompare
)
{
if
(!
super
.
checkEquality
(
coloredToCompare
)
&&
coloredToCompare
instanceof
Numeric
&&
((
Numeric
)
coloredToCompare
).
number
==
number
)
return
true
;
return
false
;
}
@Override
public
int
getCardPoint
()
{
return
number
;
...
...
Player.java
View file @
e5f353eb
...
...
@@ -4,13 +4,25 @@ import java.util.ArrayList;
import
java.util.Iterator
;
public
class
Player
{
// List of player's cards
private
ArrayList
<
Card
>
playerCards
=
new
ArrayList
<>();
// point of the player
private
int
playerPoint
;
ArrayList
<
Card
>
possibleCards
;
/**
* returns the list of player's cards
* @return the list of player's cards
*/
public
ArrayList
<
Card
>
getPlayerCards
()
{
return
playerCards
;
}
/**
*
* @param playerNumber
*/
public
void
printAllCards
(
int
playerNumber
){
System
.
out
.
println
(
"Player"
+
playerNumber
+
":"
);
Iterator
<
Card
>
cardIterator
=
playerCards
.
iterator
();
...
...
@@ -18,7 +30,6 @@ public class Player {
Card
c
=
cardIterator
.
next
();
System
.
out
.
println
(
c
.
toString
());
}
System
.
out
.
println
();
}
public
int
getPlayerPoint
()
{
...
...
@@ -29,6 +40,54 @@ public class Player {
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
)
{
return
"Player"
+
playerNumber
+
" {playerPoint="
+
playerPoint
+
...
...
Reverse.java
View file @
e5f353eb
...
...
@@ -12,6 +12,13 @@ public class Reverse extends Movemention {
return
-
1
;
}
@Override
public
boolean
checkEquality
(
Colored
coloredToCompare
)
{
if
(!
super
.
checkEquality
(
coloredToCompare
)
&&
coloredToCompare
instanceof
Reverse
)
return
true
;
return
false
;
}
@Override
public
String
toString
()
{
return
"Reverse{ "
+
super
.
toString
();
...
...
Skip.java
View file @
e5f353eb
...
...
@@ -6,6 +6,18 @@ public class Skip extends Movemention {
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
public
String
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