Commit 55d28438 authored by 9731301's avatar 9731301

Add some methods like pass user to implement the body of the main

parent 0c1e73cc
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Uno/ColoredCard.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Uno/ColoredCard.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/Uno/ColoredCard.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Uno/ColoredCard.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Uno/Draw2Card.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Uno/Draw2Card.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/Uno/Draw2Card.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Uno/Draw2Card.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Uno/NumericalCard.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Uno/NumericalCard.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Uno/ReverseCard.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Uno/ReverseCard.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/Uno/ReverseCard.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Uno/ReverseCard.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Uno/SkipCard.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Uno/SkipCard.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/Uno/SkipCard.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Uno/SkipCard.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Uno/Uno.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Uno/Uno.class" afterDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/Uno/Uno.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Uno/Uno.class" afterDir="false" />
...@@ -68,7 +67,7 @@ ...@@ -68,7 +67,7 @@
<workItem from="1586696062533" duration="20074000" /> <workItem from="1586696062533" duration="20074000" />
<workItem from="1586769548038" duration="8743000" /> <workItem from="1586769548038" duration="8743000" />
<workItem from="1586800273922" duration="8352000" /> <workItem from="1586800273922" duration="8352000" />
<workItem from="1586853542539" duration="9514000" /> <workItem from="1586853542539" duration="15929000" />
</task> </task>
<servers /> <servers />
</component> </component>
...@@ -76,42 +75,42 @@ ...@@ -76,42 +75,42 @@
<option name="version" value="1" /> <option name="version" value="1" />
</component> </component>
<component name="WindowStateProjectService"> <component name="WindowStateProjectService">
<state x="574" y="97" key="#com.intellij.ide.util.MemberChooser" timestamp="1586863668622"> <state x="574" y="97" key="#com.intellij.ide.util.MemberChooser" timestamp="1586873194317">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="574" y="97" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1586863668622" /> <state x="574" y="97" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1586873194317" />
<state width="1493" height="166" key="GridCell.Tab.0.bottom" timestamp="1586809445260"> <state width="1493" height="261" key="GridCell.Tab.0.bottom" timestamp="1586875227765">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="166" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1586809445260" /> <state width="1493" height="261" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1586875227765" />
<state width="1493" height="166" key="GridCell.Tab.0.center" timestamp="1586809445260"> <state width="1493" height="261" key="GridCell.Tab.0.center" timestamp="1586875227763">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="166" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1586809445260" /> <state width="1493" height="261" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1586875227763" />
<state width="1493" height="166" key="GridCell.Tab.0.left" timestamp="1586809445260"> <state width="1493" height="261" key="GridCell.Tab.0.left" timestamp="1586875227763">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="166" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1586809445260" /> <state width="1493" height="261" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1586875227763" />
<state width="1493" height="166" key="GridCell.Tab.0.right" timestamp="1586809445260"> <state width="1493" height="261" key="GridCell.Tab.0.right" timestamp="1586875227765">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="166" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1586809445260" /> <state width="1493" height="261" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1586875227765" />
<state width="1493" height="261" key="GridCell.Tab.1.bottom" timestamp="1586783306694"> <state width="1493" height="261" key="GridCell.Tab.1.bottom" timestamp="1586875227765">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="261" key="GridCell.Tab.1.bottom/0.0.1536.824@0.0.1536.824" timestamp="1586783306694" /> <state width="1493" height="261" key="GridCell.Tab.1.bottom/0.0.1536.824@0.0.1536.824" timestamp="1586875227765" />
<state width="1493" height="261" key="GridCell.Tab.1.center" timestamp="1586783306694"> <state width="1493" height="261" key="GridCell.Tab.1.center" timestamp="1586875227765">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="261" key="GridCell.Tab.1.center/0.0.1536.824@0.0.1536.824" timestamp="1586783306694" /> <state width="1493" height="261" key="GridCell.Tab.1.center/0.0.1536.824@0.0.1536.824" timestamp="1586875227765" />
<state width="1493" height="261" key="GridCell.Tab.1.left" timestamp="1586783306694"> <state width="1493" height="261" key="GridCell.Tab.1.left" timestamp="1586875227765">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="261" key="GridCell.Tab.1.left/0.0.1536.824@0.0.1536.824" timestamp="1586783306694" /> <state width="1493" height="261" key="GridCell.Tab.1.left/0.0.1536.824@0.0.1536.824" timestamp="1586875227765" />
<state width="1493" height="261" key="GridCell.Tab.1.right" timestamp="1586783306694"> <state width="1493" height="261" key="GridCell.Tab.1.right" timestamp="1586875227765">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="261" key="GridCell.Tab.1.right/0.0.1536.824@0.0.1536.824" timestamp="1586783306694" /> <state width="1493" height="261" key="GridCell.Tab.1.right/0.0.1536.824@0.0.1536.824" timestamp="1586875227765" />
<state x="107" y="217" key="com.intellij.ide.util.TipDialog" timestamp="1586853731045"> <state x="107" y="217" key="com.intellij.ide.util.TipDialog" timestamp="1586853731045">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
...@@ -120,9 +119,9 @@ ...@@ -120,9 +119,9 @@
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="425" y="187" key="run.anything.popup/0.0.1536.824@0.0.1536.824" timestamp="1586862725471" /> <state x="425" y="187" key="run.anything.popup/0.0.1536.824@0.0.1536.824" timestamp="1586862725471" />
<state x="431" y="145" width="672" height="678" key="search.everywhere.popup" timestamp="1586717206978"> <state x="431" y="145" width="672" height="678" key="search.everywhere.popup" timestamp="1586872893622">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="431" y="145" width="672" height="678" key="search.everywhere.popup/0.0.1536.824@0.0.1536.824" timestamp="1586717206978" /> <state x="431" y="145" width="672" height="678" key="search.everywhere.popup/0.0.1536.824@0.0.1536.824" timestamp="1586872893622" />
</component> </component>
</project> </project>
\ No newline at end of file
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
File added
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
...@@ -16,7 +16,7 @@ public class GivingCard { ...@@ -16,7 +16,7 @@ public class GivingCard {
} }
} }
public Card chooseUpperCardRandomly (ArrayList<Card> remainingCards){ public Card chooseUpperCardRandomly (ArrayList<Card> remainingCards ){
int randomNum = r.nextInt(remainingCards.size()); int randomNum = r.nextInt(remainingCards.size());
return remainingCards.get(randomNum); return remainingCards.get(randomNum);
} }
......
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner; import java.util.Scanner;
public class Uno { public class Uno {
public static void main(String [] args){ public static void main(String [] args){
int numOfPlayers; int userChosenCardNum ;
int numOfPlayers = 0;
ArrayList<User> users = new ArrayList<>(); ArrayList<User> users = new ArrayList<>();
ArrayList<Card> remainingCards = new ArrayList<>(); ArrayList<Card> remainingCards = new ArrayList<>();//cards remains in sours and users can not see it
GivingCard givingCard = new GivingCard(); GivingCard givingCard = new GivingCard();
Scanner scanner = new Scanner(System.in); Scanner scanner = new Scanner(System.in);
Card upperCard = givingCard.chooseUpperCardRandomly(remainingCards); Card upperCard ;
User chosenUser = new User(); User chosenUser = new User();
for (int i = 0 ; i < 2 ; i++) { for (int i = 0 ; i < 2 ; i++) {
for (int numNumericalCard = 1; numNumericalCard < 10; numNumericalCard++) { for (int numNumericalCard = 1; numNumericalCard < 10; numNumericalCard++) {
...@@ -65,27 +67,38 @@ public class Uno { ...@@ -65,27 +67,38 @@ public class Uno {
remainingCards.add(wild4Card); remainingCards.add(wild4Card);
remainingCards.add(wildColor); remainingCards.add(wildColor);
} }
upperCard = givingCard.chooseUpperCardRandomly(remainingCards);
while (numOfPlayers == 0) {//set num of players and their names at first
while (true) {//set num of players and their names at first
System.out.println("plz enter number of users"); System.out.println("plz enter number of users");
numOfPlayers = scanner.nextInt(); numOfPlayers = scanner.nextInt();
if (numOfPlayers >=3 && numOfPlayers <= 5) if (!(numOfPlayers >=3 && numOfPlayers <= 5)) {
break; numOfPlayers = 0;
continue;
}
else { else {
for (int i =0 ; i < numOfPlayers ; i++){ for (int i =0 ; i < numOfPlayers ; i++){
System.out.println("plz enter your name"); System.out.println("plz enter your name");
String name = scanner.nextLine(); String name = scanner.next();
User user = new User(name); User user = new User(name);
givingCard.give_n_Cards(user , remainingCards , 7); givingCard.give_n_Cards(user , remainingCards , 7);
users.add(user); users.add(user);
} }
chosenUser = users.get(0);
} }
} }
while (true){ while (true){
System.out.println(); System.out.println("UPPER CARD IS");
upperCard.print();
System.out.println("TURN IS FOR "+chosenUser.getName() +"YOUR CARDS ARE");
chosenUser.printCards();
userChosenCardNum = scanner.nextInt() -1;
upperCard = chosenUser.getUserCards().get(userChosenCardNum);
chosenUser.removeCard(upperCard);
remainingCards.add(upperCard);
chosenUser = chosenUser.pass(users,chosenUser);
} }
} }
} }
...@@ -53,8 +53,23 @@ public class User { ...@@ -53,8 +53,23 @@ public class User {
return score; return score;
} }
public void pass(ArrayList<User> users , User chosenUser){ public User pass(ArrayList<User> users , User chosenUser){
chosenUser = users.get(users.indexOf(chosenUser)); return users.get(users.indexOf(chosenUser) + 1);
}
public ArrayList<Card> getUserCards() {
return userCards;
}
public void printCards(){
System.out.println("enter the number of your card for example : 3");
int counter = 1;
for (Card card : userCards){
System.out.println(counter);
card.print();
counter++;
}
System.out.println(counter+"\n+drawCard");
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment