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 @@
<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/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/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" />
......@@ -68,7 +67,7 @@
<workItem from="1586696062533" duration="20074000" />
<workItem from="1586769548038" duration="8743000" />
<workItem from="1586800273922" duration="8352000" />
<workItem from="1586853542539" duration="9514000" />
<workItem from="1586853542539" duration="15929000" />
</task>
<servers />
</component>
......@@ -76,42 +75,42 @@
<option name="version" value="1" />
</component>
<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" />
</state>
<state x="574" y="97" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1586863668622" />
<state width="1493" height="166" key="GridCell.Tab.0.bottom" timestamp="1586809445260">
<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="261" key="GridCell.Tab.0.bottom" timestamp="1586875227765">
<screen x="0" y="0" width="1536" height="824" />
</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="166" key="GridCell.Tab.0.center" 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="261" key="GridCell.Tab.0.center" timestamp="1586875227763">
<screen x="0" y="0" width="1536" height="824" />
</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="166" key="GridCell.Tab.0.left" 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="261" key="GridCell.Tab.0.left" timestamp="1586875227763">
<screen x="0" y="0" width="1536" height="824" />
</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="166" key="GridCell.Tab.0.right" 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="261" key="GridCell.Tab.0.right" timestamp="1586875227765">
<screen x="0" y="0" width="1536" height="824" />
</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.1.bottom" timestamp="1586783306694">
<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="1586875227765">
<screen x="0" y="0" width="1536" height="824" />
</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.center" 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="1586875227765">
<screen x="0" y="0" width="1536" height="824" />
</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.left" 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="1586875227765">
<screen x="0" y="0" width="1536" height="824" />
</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.right" 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="1586875227765">
<screen x="0" y="0" width="1536" height="824" />
</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">
<screen x="0" y="0" width="1536" height="824" />
</state>
......@@ -120,9 +119,9 @@
<screen x="0" y="0" width="1536" height="824" />
</state>
<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" />
</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>
</project>
\ No newline at end of file
......@@ -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());
return remainingCards.get(randomNum);
}
......
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
public class Uno {
public static void main(String [] args){
int numOfPlayers;
int userChosenCardNum ;
int numOfPlayers = 0;
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();
Scanner scanner = new Scanner(System.in);
Card upperCard = givingCard.chooseUpperCardRandomly(remainingCards);
Card upperCard ;
User chosenUser = new User();
for (int i = 0 ; i < 2 ; i++) {
for (int numNumericalCard = 1; numNumericalCard < 10; numNumericalCard++) {
......@@ -65,27 +67,38 @@ public class Uno {
remainingCards.add(wild4Card);
remainingCards.add(wildColor);
}
upperCard = givingCard.chooseUpperCardRandomly(remainingCards);
while (true) {//set num of players and their names at first
while (numOfPlayers == 0) {//set num of players and their names at first
System.out.println("plz enter number of users");
numOfPlayers = scanner.nextInt();
if (numOfPlayers >=3 && numOfPlayers <= 5)
break;
if (!(numOfPlayers >=3 && numOfPlayers <= 5)) {
numOfPlayers = 0;
continue;
}
else {
for (int i =0 ; i < numOfPlayers ; i++){
System.out.println("plz enter your name");
String name = scanner.nextLine();
String name = scanner.next();
User user = new User(name);
givingCard.give_n_Cards(user , remainingCards , 7);
users.add(user);
}
chosenUser = users.get(0);
}
}
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 {
return score;
}
public void pass(ArrayList<User> users , User chosenUser){
chosenUser = users.get(users.indexOf(chosenUser));
public User pass(ArrayList<User> users , User 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
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