Commit 0c1e73cc authored by 9731301's avatar 9731301

Add users and implement some methods

parent b0439da9
...@@ -2,8 +2,16 @@ ...@@ -2,8 +2,16 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="608d52d9-3dd7-4e55-84b9-421c09e25ee0" name="Default Changelist" comment=""> <list default="true" id="608d52d9-3dd7-4e55-84b9-421c09e25ee0" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/vcs.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<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/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" />
<change beforePath="$PROJECT_DIR$/out/production/Uno/Wild4.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Uno/Wild4.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Uno/WildCard.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Uno/WildCard.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Uno/WildColor.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Uno/WildColor.class" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
...@@ -59,6 +67,8 @@ ...@@ -59,6 +67,8 @@
<workItem from="1586639798096" duration="7822000" /> <workItem from="1586639798096" duration="7822000" />
<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="1586853542539" duration="9514000" />
</task> </task>
<servers /> <servers />
</component> </component>
...@@ -66,26 +76,26 @@ ...@@ -66,26 +76,26 @@
<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="1586782366631"> <state x="574" y="97" key="#com.intellij.ide.util.MemberChooser" timestamp="1586863668622">
<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="1586782366631" /> <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="261" key="GridCell.Tab.0.bottom" timestamp="1586783306694"> <state width="1493" height="166" key="GridCell.Tab.0.bottom" timestamp="1586809445260">
<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.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1586783306694" /> <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.center" timestamp="1586783306694"> <state width="1493" height="166" key="GridCell.Tab.0.center" timestamp="1586809445260">
<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.0.center/0.0.1536.824@0.0.1536.824" timestamp="1586783306694" /> <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.left" timestamp="1586783306693"> <state width="1493" height="166" key="GridCell.Tab.0.left" timestamp="1586809445260">
<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.0.left/0.0.1536.824@0.0.1536.824" timestamp="1586783306693" /> <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.right" timestamp="1586783306694"> <state width="1493" height="166" key="GridCell.Tab.0.right" timestamp="1586809445260">
<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.0.right/0.0.1536.824@0.0.1536.824" timestamp="1586783306694" /> <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.1.bottom" timestamp="1586783306694">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
...@@ -102,14 +112,14 @@ ...@@ -102,14 +112,14 @@
<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="1586783306694" />
<state x="107" y="217" key="com.intellij.ide.util.TipDialog" timestamp="1586769552313"> <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>
<state x="107" y="217" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1586769552313" /> <state x="107" y="217" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1586853731045" />
<state x="425" y="187" key="run.anything.popup" timestamp="1586782658252"> <state x="425" y="187" key="run.anything.popup" timestamp="1586862725471">
<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="1586782658252" /> <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="1586717206978">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
......
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
No preview for this file type
public abstract class Card { public abstract class Card {
protected String name; protected String name;
private int score; private int score;
public static final String set = "\u001B[0m";
public static final String green = "\u001B[32m";
public static final String red = "\u001B[31m";
public static final String yellow = "\u001B[33m";
public static final String blue = "\u001B[34m";
public Card() {
}
public Card(int score) { public Card(int score) {
this.score = score; this.score = score;
......
...@@ -3,11 +3,6 @@ ...@@ -3,11 +3,6 @@
*/ */
public class ColoredCard extends Card { public class ColoredCard extends Card {
private String color; private String color;
public static final String set = "\u001B[0m";
public static final String green = "\u001B[32m";
public static final String red = "\u001B[31m";
public static final String yellow = "\u001B[33m";
public static final String blue = "\u001B[34m";
/** /**
* create a Colored card that according to subClasses create a special kind of colored cards * create a Colored card that according to subClasses create a special kind of colored cards
...@@ -39,7 +34,7 @@ public class ColoredCard extends Card { ...@@ -39,7 +34,7 @@ public class ColoredCard extends Card {
public String toString() { public String toString() {
String s ="|$$$$$$$$$$$$$$$|\n"; String s ="|$$$$$$$$$$$$$$$|\n";
s +="| |\n"; s +="| |\n";
s +="| "+name+" |\n"; s += name+"\n";
s +="| |\n"; s +="| |\n";
s +="|$$$$$$$$$$$$$$$|\n"; s +="|$$$$$$$$$$$$$$$|\n";
return s; return s;
......
import java.util.ArrayList;
public class Draw2Card extends MotiveCard { public class Draw2Card extends MotiveCard {
/** /**
...@@ -8,11 +10,11 @@ public class Draw2Card extends MotiveCard { ...@@ -8,11 +10,11 @@ public class Draw2Card extends MotiveCard {
*/ */
public Draw2Card(String color, int score) { public Draw2Card(String color, int score) {
super(color, score); super(color, score);
name = "+2"; name = "| +2 |";
} }
@Override @Override
public void move() { public void move(User chosenUser, ArrayList<User> users) {
} }
......
...@@ -15,4 +15,9 @@ public class GivingCard { ...@@ -15,4 +15,9 @@ public class GivingCard {
cardNam++; cardNam++;
} }
} }
public Card chooseUpperCardRandomly (ArrayList<Card> remainingCards){
int randomNum = r.nextInt(remainingCards.size());
return remainingCards.get(randomNum);
}
} }
import java.util.ArrayList;
public abstract class MotiveCard extends ColoredCard{ public abstract class MotiveCard extends ColoredCard{
/** /**
* create a Colored card that according to subClasses create a special kind of colored cards * create a Colored card that according to subClasses create a special kind of colored cards
...@@ -9,6 +11,5 @@ public abstract class MotiveCard extends ColoredCard{ ...@@ -9,6 +11,5 @@ public abstract class MotiveCard extends ColoredCard{
super(color, score); super(color, score);
} }
public abstract void move(); public abstract void move(User chosenUser, ArrayList<User> users);
} }
\ No newline at end of file
...@@ -5,6 +5,7 @@ public class NumericalCard extends ColoredCard { ...@@ -5,6 +5,7 @@ public class NumericalCard extends ColoredCard {
public NumericalCard(String color, int score, int number) { public NumericalCard(String color, int score, int number) {
super(color, score); super(color, score);
this.number = number; this.number = number;
name= Integer.toString(number); name="| "+ Integer.toString(number) +" |";
} }
} }
import java.util.ArrayList;
public class ReverseCard extends MotiveCard { public class ReverseCard extends MotiveCard {
/** /**
...@@ -8,12 +10,17 @@ public class ReverseCard extends MotiveCard { ...@@ -8,12 +10,17 @@ public class ReverseCard extends MotiveCard {
*/ */
public ReverseCard(String color, int score) { public ReverseCard(String color, int score) {
super(color, score); super(color, score);
name = "reverse"; name = "| reverse |";
} }
@Override @Override
public void move() { public void move(User chosenUser, ArrayList<User> users) {
chosenUser = users.get(users.indexOf(chosenUser) - 1);
ArrayList<User> reverseUsers = new ArrayList<>();
for (int i = users.size() ; i > -1 ; i++){
reverseUsers.add(users.get(i));
}
users = reverseUsers;
} }
......
import java.util.ArrayList;
public class SkipCard extends MotiveCard { public class SkipCard extends MotiveCard {
...@@ -9,11 +11,12 @@ public class SkipCard extends MotiveCard { ...@@ -9,11 +11,12 @@ public class SkipCard extends MotiveCard {
*/ */
public SkipCard(String color, int score) { public SkipCard(String color, int score) {
super(color, score); super(color, score);
name = "skip" ; name = "| skip |";
} }
@Override
public void move() {
@Override
public void move(User chosenUser , ArrayList<User> users) {
chosenUser = users.get(users.indexOf(chosenUser) + 2);
} }
} }
...@@ -8,12 +8,14 @@ public class Uno { ...@@ -8,12 +8,14 @@ public class Uno {
ArrayList<Card> remainingCards = new ArrayList<>(); ArrayList<Card> remainingCards = new ArrayList<>();
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);
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++) {
Card newRedCard = new NumericalCard("red", numNumericalCard, numNumericalCard); Card newRedCard = new NumericalCard("red", numNumericalCard, numNumericalCard);
Card newYellowCard = new NumericalCard("Yellow", numNumericalCard, numNumericalCard); Card newYellowCard = new NumericalCard("yellow", numNumericalCard, numNumericalCard);
Card newBlueCard = new NumericalCard("Blue", numNumericalCard, numNumericalCard); Card newBlueCard = new NumericalCard("blue", numNumericalCard, numNumericalCard);
Card newGreenCard = new NumericalCard("Green", numNumericalCard, numNumericalCard); Card newGreenCard = new NumericalCard("green", numNumericalCard, numNumericalCard);
remainingCards.add(newRedCard); remainingCards.add(newRedCard);
remainingCards.add(newYellowCard); remainingCards.add(newYellowCard);
remainingCards.add(newBlueCard); remainingCards.add(newBlueCard);
...@@ -49,9 +51,9 @@ public class Uno { ...@@ -49,9 +51,9 @@ public class Uno {
remainingCards.add(newReverseG); remainingCards.add(newReverseG);
} }
Card newRedCard = new NumericalCard("red", 0, 0); Card newRedCard = new NumericalCard("red", 0, 0);
Card newYellowCard = new NumericalCard("Yellow", 0, 0); Card newYellowCard = new NumericalCard("yellow", 0, 0);
Card newBlueCard = new NumericalCard("Blue", 0, 0); Card newBlueCard = new NumericalCard("blue", 0, 0);
Card newGreenCard = new NumericalCard("Green", 0, 0); Card newGreenCard = new NumericalCard("green", 0, 0);
remainingCards.add(newRedCard); remainingCards.add(newRedCard);
remainingCards.add(newYellowCard); remainingCards.add(newYellowCard);
remainingCards.add(newBlueCard); remainingCards.add(newBlueCard);
...@@ -65,18 +67,25 @@ public class Uno { ...@@ -65,18 +67,25 @@ public class Uno {
} }
for (Card c : remainingCards){ while (true) {//set num of players and their names at first
c.print();
}
while (true) {//set num of players 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; break;
else {
for (int i =0 ; i < numOfPlayers ; i++){
System.out.println("plz enter your name");
String name = scanner.nextLine();
User user = new User(name);
givingCard.give_n_Cards(user , remainingCards , 7);
users.add(user);
}
}
} }
while (true){
System.out.println();
}
} }
} }
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Objects;
public class User { public class User {
private String name; private String name;
...@@ -14,6 +15,10 @@ public class User { ...@@ -14,6 +15,10 @@ public class User {
this.name = name; this.name = name;
} }
public User() {
}
/** /**
* remove a card from user cards * remove a card from user cards
* @param card * @param card
...@@ -48,4 +53,21 @@ public class User { ...@@ -48,4 +53,21 @@ public class User {
return score; return score;
} }
public void pass(ArrayList<User> users , User chosenUser){
chosenUser = users.get(users.indexOf(chosenUser));
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof User)) return false;
User user = (User) o;
return getScore() == user.getScore() &&
getName().equals(user.getName()) &&
userCards.equals(user.userCards);
}
@Override
public int hashCode() {
return Objects.hash(getName(), getScore(), userCards);
}
} }
public class Wild4 extends WildCard { import java.util.ArrayList;
public class Wild4 extends WildCard {
GivingCard givingCard = new GivingCard();
public Wild4(int score) { public Wild4(int score) {
super(score); super(score);
name = "+4"; name = "| +4 |\n";
} }
@Override
public void giveCard() { public void giveCard(User chosenUser, ArrayList<Card> cards , Card chosenCard , ArrayList<User> users) {
System.out.println("is it a bluff؟");
//if (.equals("yes"))
//User nextUser = new User()
givingCard.give_n_Cards(chosenUser , cards , 4);
givingCard.give_n_Cards(chosenUser , cards , 6);
givingCard.give_n_Cards(chosenUser , cards , 4);
} }
} }
import java.util.Scanner;
public abstract class WildCard extends Card { public abstract class WildCard extends Card {
Scanner scanner = new Scanner(System.in);
public WildCard(int score){ public WildCard(int score){
super(score); super(score);
} }
public abstract void giveCard(); public void chooseColor() {
System.out.println("plz choose a color (just choose the number)\n1:blue 2:red 3:yellow 4:green");
switch (scanner.nextInt()) {
case 1: {
System.out.println("next:" + blue + "blue" + set);
break;
}
case 2: {
System.out.println("next:" + red + "red" + set);
break;
}
case 3: {
System.out.println("next:" + yellow + "yellow" + set);
break;
}
case 4: {
System.out.println("next:" + green + "green" + set);
break;
}
}
}
@Override @Override
public String toString(){ public String toString(){
String s = "|$$$$$$$$$$$$$$$|\n"; String s = "|$$$$$$$$$$$$$$$|\n";
s += "| |\n"; s += "| |\n";
s += "| "+name+" |\n"; s += name;
s += "| |\n"; s += "| |\n";
s += "|$$$$$$$$$$$$$$$|\n"; s += "|$$$$$$$$$$$$$$$|\n";
return s; return s;
......
public class WildColor extends WildCard { public class WildColor extends WildCard {
public WildColor(int score) { public WildColor(int score) {
super(score); super(score);
name = "setColor"; name = "| setColor |\n";
} }
@Override
public void giveCard() {
}
} }
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