Commit c674abee authored by 9731301's avatar 9731301

Add Uno Class and create acards in it and Create CardClassGiving

parent 55a28d92
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_10" default="true" project-jdk-name="10" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Uno.iml" filepath="$PROJECT_DIR$/Uno.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/src" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="608d52d9-3dd7-4e55-84b9-421c09e25ee0" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/src/Card.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Card.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/ColoredCard.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ColoredCard.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Draw2Card.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Draw2Card.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/MotiveCard.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/MotiveCard.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/ReverseCard.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ReverseCard.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/SkipCard.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/SkipCard.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/User.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/User.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Wild4.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Wild4.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/WildCard.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/WildCard.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/WildColor.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/WildColor.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/src" />
</component>
<component name="ProjectId" id="1aPagVKczd51qAfmeiqRTIQtfoK" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showExcludedFiles" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="aspect.path.notification.shown" value="true" />
</component>
<component name="RunManager">
<configuration name="Uno" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="Uno" />
<module name="Uno" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<recent_temporary>
<list>
<item itemvalue="Application.Uno" />
</list>
</recent_temporary>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="608d52d9-3dd7-4e55-84b9-421c09e25ee0" name="Default Changelist" comment="" />
<created>1586639793866</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1586639793866</updated>
<workItem from="1586639798096" duration="7822000" />
<workItem from="1586696062533" duration="20074000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="WindowStateProjectService">
<state x="574" y="97" key="#com.intellij.ide.util.MemberChooser" timestamp="1586718271606">
<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="1586718271606" />
<state width="1493" height="194" key="GridCell.Tab.0.bottom" timestamp="1586718479498">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="194" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1586718479498" />
<state width="1493" height="194" key="GridCell.Tab.0.center" timestamp="1586718479498">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="194" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1586718479498" />
<state width="1493" height="194" key="GridCell.Tab.0.left" timestamp="1586718479498">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="194" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1586718479498" />
<state width="1493" height="194" key="GridCell.Tab.0.right" timestamp="1586718479498">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="194" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1586718479498" />
<state x="107" y="217" key="com.intellij.ide.util.TipDialog" timestamp="1586696159864">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="107" y="217" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1586696159864" />
<state x="431" y="145" width="672" height="678" key="search.everywhere.popup" timestamp="1586717206978">
<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" />
</component>
</project>
\ No newline at end of file
public class Draw2Card extends MotiveCard {
@Override
public void move() {
}
}
public abstract class MotiveCard extends ColoredCard{
public abstract void move();
}
\ No newline at end of file
public class ReverseCard extends MotiveCard {
@Override
public void move() {
}
}
public class SkipCard extends MotiveCard {
@Override
public void move() {
}
}
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
public abstract class Card {
private int score;
public Card(int score) {
this.score = score;
}
public int getScore() {
return score;
}
......
/**
*
*/
public class ColoredCard extends Card {
private String color;
/**
* create a Colored card that according to subClasses create a special kind of colored cards
* @param color
* @param score
*/
public ColoredCard(String color , int score) {
this.color = color;
super(score);
setScore(score);
}
private String color;
/**
* get the color of card
* @return
*/
public String getColor() {
return color;
}
......
public class Draw2Card extends MotiveCard {
/**
* create a Colored card that according to subClasses create a special kind of colored cards
*
* @param color
* @param score
*/
public Draw2Card(String color, int score) {
super(color, score);
}
@Override
public void move() {
}
}
import java.util.ArrayList;
import java.util.Random;
public class GivingCard {
Random r;
public GivingCard(){
r = new Random();
}
public void give_n_Cards(User chosenUser , ArrayList<Card> remainingCards , int n){
for (int cardNam = 0; cardNam < n ; ){
int randomNum = r.nextInt(remainingCards.size());
chosenUser.addCard( remainingCards.get(randomNum));
remainingCards.remove(randomNum);
cardNam++;
}
}
}
public abstract class MotiveCard extends ColoredCard{
/**
* create a Colored card that according to subClasses create a special kind of colored cards
*
* @param color
* @param score
*/
public MotiveCard(String color, int score) {
super(color, score);
}
public abstract void move();
}
\ No newline at end of file
public class ReverseCard extends MotiveCard {
/**
* create a Colored card that according to subClasses create a special kind of colored cards
*
* @param color
* @param score
*/
public ReverseCard(String color, int score) {
super(color, score);
}
@Override
public void move() {
}
}
public class SkipCard extends MotiveCard {
/**
* create a Colored card that according to subClasses create a special kind of colored cards
*
* @param color
* @param score
*/
public SkipCard(String color, int score) {
super(color, score);
}
@Override
public void move() {
}
}
import java.util.ArrayList;
import java.util.Scanner;
public class Uno {
public static void main(String [] args){
int numOfPlayers;
ArrayList<User> users = new ArrayList<>();
ArrayList<Card> remainingCards = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
for (int i = 0 ; i < 2 ; i++) {
for (int numNumericalCard = 1; numNumericalCard < 10; numNumericalCard++) {
Card newRedCard = new NumericalCard("red", numNumericalCard, numNumericalCard);
Card newYellowCard = new NumericalCard("Yellow", numNumericalCard, numNumericalCard);
Card newBlueCard = new NumericalCard("Blue", numNumericalCard, numNumericalCard);
Card newGreenCard = new NumericalCard("Green", numNumericalCard, numNumericalCard);
remainingCards.add(newRedCard);
remainingCards.add(newYellowCard);
remainingCards.add(newBlueCard);
remainingCards.add(newGreenCard);
}
Card newDraw2r = new Draw2Card("red",20);
remainingCards.add(newDraw2r);
Card newDraw2y = new Draw2Card("yellow",20);
remainingCards.add(newDraw2y);
Card newDraw2b = new Draw2Card("blue",20);
remainingCards.add(newDraw2b);
Card newDraw2g = new Draw2Card("green",20);
remainingCards.add(newDraw2g);
Card newSkipCadR = new SkipCard("red",20);
remainingCards.add(newSkipCadR);
Card newSkipCadY = new SkipCard("yellow",20);
remainingCards.add(newSkipCadY);
Card newSkipCadB= new SkipCard("blue",20);
remainingCards.add(newSkipCadB);
Card newSkipCadG = new SkipCard("green",20);
remainingCards.add(newSkipCadG);
Card newReverseR = new ReverseCard("red",20);
remainingCards.add(newReverseR);
Card newReverseB = new ReverseCard("blue",20);
remainingCards.add(newReverseB);
Card newReverseY = new ReverseCard("yellow",20);
remainingCards.add(newReverseY);
Card newReverseG = new ReverseCard("green",20);
remainingCards.add(newReverseG);
}
Card newRedCard = new NumericalCard("red", 0, 0);
Card newYellowCard = new NumericalCard("Yellow", 0, 0);
Card newBlueCard = new NumericalCard("Blue", 0, 0);
Card newGreenCard = new NumericalCard("Green", 0, 0);
remainingCards.add(newRedCard);
remainingCards.add(newYellowCard);
remainingCards.add(newBlueCard);
remainingCards.add(newGreenCard);
for (int i = 0 ; i < 4 ; i++){
Card wild4Card = new Wild4(50);
Card wildColor = new WildColor(50);
remainingCards.add(wild4Card);
remainingCards.add(wildColor);
}
while (true) {//set num of players at first
System.out.println("plz enter number of users");
numOfPlayers = scanner.nextInt();
if (numOfPlayers >=3 && numOfPlayers <= 5)
break;
}
}
}
......@@ -2,17 +2,50 @@ import java.util.ArrayList;
public class User {
private String name;
private int sore;
private int score;
private ArrayList<Card> userCards;
public User(){
/**
* create a user
*/
public User( String name){
userCards = new ArrayList<>();
score = 0;
this.name = name;
}
/**
* remove a card from user cards
* @param card
*/
public void addCard(Card card){
userCards.add(card);
}
/**
* remove a card from user cards
* @param card
*/
public void removeCard(Card card){
userCards.remove(card);
}
/**
* @return user name
*/
public String getName() {
return name;
}
/**
* at the end of the game returns the score of user
* @return score field
*/
public int getScore() {
for (Card card : userCards ){
score += card.getScore();
}
return score;
}
}
public class Wild4 extends WildCard {
public Wild4(int score) {
super(score);
}
@Override
public void giveCard() {
......
public abstract class WildCard extends Card {
public WildCard(int score){
super(score);
}
public abstract void giveCard();
}
public class WildColor extends WildCard {
public WildColor(int score) {
super(score);
}
@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