⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 player.java

📁 扑克牌的发牌:按一定的规则四人玩牌;谁赢了先给谁发牌 (默认先给主人公控制的人发牌)2.扑克牌的出牌:谁拿了红桃4,谁先出;出牌规则
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                for(int i = 0; i < 3; i++)                    if(hand.getFaceUp(i) != null)                     if(hand.getFaceUp(i).getNumber() == card.getNumber()){                        hand.removeFaceUp(i);                        break;                    }        }else{//if only cards down            card = hand.getFaceDown(cardno);            command = "turn:facedown:";            if(isValidCard(card, command))                hand.removeFaceDown(cardno);            else{//player must pick up the pile if not valide                hand.addCard(hand.getFaceDown(cardno));                sendCommand("turn:facedown:pickup:" + hand.getFaceDown(cardno).getNumber() + ":");                sh.addMsg("The card you played was a " + hand.getFaceDown(cardno).getStringValue() + " you had to pick up the pile");                for(int n = 0; n < 52; n++){                    if(pile[n] == null)                        break;                    hand.addCard(pile[n]);                    pile[n] = null;                }                hand.removeFaceDown(cardno);                sh.setmyTurn(false);                nextTurn();            }        }    }else{// if player still has cards in hand        card = hand.getCard(cardno);        command = "turn:";        if(isValidCard(card, command))            for(int n = 0; n < hand.length() -1; n++)                if(card.getNumber() == hand.getCard(n).getNumber()){                    hand.removeCard(n);                    break;                }    }    if(deck <= 0 || hand.length() > 3)        displayTable();    }    private boolean isValidCard(Card card, String command)    {    int top = 0;    boolean multi = false;    if(hand.getCard(0) != null)       multi = checkformulti(card);    else if(hand.isFaceUp())       multi = checkformultiFaceUp(card);    if(multi)        return true;    if(card.getValue() == 2){//2 can be played at anytime        cardAccepted(card, command);        return true;    }else if(card.getValue() == 10 || fourOfAKind(card) == true){//pile is burn and its players turn again        burnt = true;        for(int n = 0; n < 51; n++)            pile[n] = null;        sendCommand(command + card.getNumber() + ":");        sh.addMsg("You have burnt the pile, its your turn again");        return true;    }else if(pile[0] == null){        cardAccepted(card, command);        return true;    }else if(nine == true && card.getValue() == 9){        cardAccepted(card, command);        return true;    }    if(nine == true && pile[0].getValue() == 9){        for(int i = 0; i < 52; i++){            if(pile[i] == null){                cardAccepted(card, command);                return true;            }            if(pile[i].getValue() == 9)                top++;            else                break;        }    }    if(seven == true && pile[top].getValue() == 7){        if(card.getValue() >= 7){            sh.addMsg("You Must Play Less Than a Seven");            return false;        }else{            cardAccepted(card, command);            return true;        }    }    if(pile[top].getValue() <= card.getValue()){        cardAccepted(card, command);        return true;    }    if(hand.isFaceUp() == true || hand.length() > 1)        sh.addMsg("You can't play a " + card.getStringValue() + " please select another card");    return false;    }    private boolean checkformulti(Card card)    {    //checking if card selection is valid    if(pile[0] != null){        if(nine == true && pile[0].getValue() == 9){            int count = 0;//determining the number of nines on top of pile            for(int i = 0; i < 52; i++){                if(pile[i] == null)                    break;                if(pile[i].getValue() == 9)                    count++;                else                    break;            }            if(pile[count] != null){                if(card.getValue() == 9){                //do nothing as valid card                }else if(seven == true && pile[count].getValue() == 7){                    if(card.getValue() >= 7)                        return false;                }else if(!(card.getValue() == 2 || card.getValue() == 10 || card.getValue() >= pile[count].getValue()))                    return false;            }        }else if(card.getValue() == 9 && nine == true){        //do nothing as valid card            }else if(seven == true && pile[0].getValue() == 7){            if(card.getValue() >= 7)                return false;                }else if(!(card.getValue() == 2 || card.getValue() == 10 || card.getValue() >= pile[0].getValue()))            return false;    }    //checking how many card of the same value as card played are in players hand    int amountinhand = 0;    for(int n = 0; n < hand.length(); n++){        if(hand.getCard(n) == null)            break;        if(hand.getCard(n).getValue() == card.getValue())            amountinhand++;    }    if(amountinhand <= 1)        return false;    MultiCardD dialog = new MultiCardD(sh, amountinhand);    int numbertoplay = dialog.getChoice();    if(numbertoplay <= 1)        return false;    String command = "turn:multi:" + numbertoplay + ":" + card.getNumber() + ":";    addcardtopile(card);    numbertoplay--;    int toberemovedcount = 0;    int toberemoved[] = new int[3];    for(int n = 0; n < 3; n++)        toberemoved[n] = -1;    for(int n = 0; n < hand.length() - 1; n++){        if(hand.getCard(n) == null)            break;        if(numbertoplay <= 0)            break;        if(card.getValue() == hand.getCard(n).getValue() && card.getNumber() != hand.getCard(n).getNumber()){            command = command.concat(hand.getCard(n).getNumber() +":");            addcardtopile(hand.getCard(n));            //storing which card are to be removed            toberemoved[toberemovedcount] = hand.getCard(n).getNumber();            toberemovedcount++;            numbertoplay--;        }    }    //removing card from hand    for(int n = 0; n < 3; n++){        if(toberemoved[n] == -1)            break;        for(int i = 0; i < hand.length() -1; i++)            if(hand.getCard(i).getNumber() == toberemoved[n]){                hand.removeCard(i);                break;            }    }    //sending command    sendCommand(command);            //checking for 4 of a kind    if(fourOfAKind(pile[3]) || pile[0].getValue() == 10){        burnt = true;        for(int n = 0; n < 51; n++)            pile[n] = null;        sh.addMsg("You burn the pile is your turn again");     }else{        sh.setmyTurn(false);        nextTurn();     }    return true;    }    private boolean checkformultiFaceUp(Card card)    {    //checking if card selection is valid    if(pile[0] != null){        if(card.getValue() == 9 && nine == true){            //do nothing as valid card            }else if(card.getValue() == 10 || card.getValue() == 2){            //do nothing as valid card        }else if(nine == true && pile[0].getValue() == 9){            int count = 0;//determining the number of nines on top of pile            for(int i = 0; i < 52; i++){                if(pile[i] == null)                    break;                if(pile[i].getValue() == 9)                    count++;                else                    break;            }            if(pile[count] != null){                if(seven == true && pile[count].getValue() == 7){                    if(card.getValue() >= 7)                        return false;                }else if(!(card.getValue() == 2 || card.getValue() == 10 || card.getValue() >= pile[count].getValue()))                    return false;            }        }else if(seven == true && pile[0].getValue() == 7){            if(card.getValue() >= 7)                return false;                }else if(!(card.getValue() == 2 || card.getValue() == 10 || card.getValue() >= pile[0].getValue()))            return false;    }    //checking how many card of the same value as card played are in players hand    int amountinhand = 0;    for(int n = 0; n < 3; n++){        if(hand.getFaceUp(n) != null)            if(hand.getFaceUp(n).getValue() == card.getValue())                amountinhand++;    }    if(amountinhand <= 1)        return false;    MultiCardD dialog = new MultiCardD(sh, amountinhand);    int numbertoplay = dialog.getChoice();    if(numbertoplay <= 1)        return false;    String command = "turn:faceup:multi:" + numbertoplay + ":" + card.getNumber() + ":";    addcardtopile(card);    numbertoplay--;    int toberemovedcount = 0;    int toberemoved[] = new int[3];    for(int n = 0; n < 3; n++)        toberemoved[n] = -1;    for(int n = 0; n < 3; n++)        if(hand.getFaceUp(n) != null){            if(numbertoplay <= 0)                break;            if(card.getValue() == hand.getFaceUp(n).getValue() && card.getNumber() != hand.getFaceUp(n).getNumber()){                command = command.concat(hand.getFaceUp(n).getNumber() +":");                addcardtopile(hand.getFaceUp(n));                //storing which card are to be removed                toberemoved[toberemovedcount] = hand.getFaceUp(n).getNumber();                toberemovedcount++;                numbertoplay--;            }        }    //removing card from hand    for(int n = 0; n < 3; n++){        if(toberemoved[n] == -1)            break;        for(int i = 0; i < 3; i++)            if(hand.getFaceUp(i) != null)            if(hand.getFaceUp(i).getNumber() == toberemoved[n]){                hand.removeFaceUp(i);                break;            }    }    //sending command    sendCommand(command);            //checking for 4 of a kind    if(fourOfAKind(pile[3]) || pile[0].getValue() == 10){        burnt = true;        for(int n = 0; n < 51; n++)            pile[n] = null;        sh.addMsg("You burn the pile is your turn again");     }else{        sh.setmyTurn(false);        nextTurn();     }    return true;    }    private void addcardtopile(Card card)    {    //adding card to pile    for(int i = 51; i > 0; i--)        pile[i] = pile[i - 1];    pile[0] = card;    }    private void cardAccepted(Card card, String command)    {        sendCommand(command + card.getNumber() + ":");        //adding card to pile        for(int n = 51; n > 0; n--)            pile[n] = pile[n - 1];        pile[0] = card;        sh.setmyTurn(false);        nextTurn();    }    private int pilelength()    {    int cardCount = 0;    for(int n = 0; n < 52; n++){        if(pile[n] == null)            break;        cardCount++;    }    return cardCount;    }class WaitforMsg implements Runnable{        Thread wt; //Wait Thread    WaitforMsg()    {        wt = new Thread(this, "Wait");        wt.start(); // Starting thread    }    public void run()    {    do{    String otherplayermsg = "Message Error";    try{        otherplayermsg = in.readLine();    }catch(IOException e) {        sh.addMsg("Read Error: " + e);        sh.addMsg("Server Disconnection");        listen = false;    }        if(otherplayermsg == null)            endConnection();        else    if(otherplayermsg.equals("end:"))    endConnection();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -