📄 player.java
字号:
try{ numPlayed = Integer.parseInt(numPlayedString); }catch(NumberFormatException b){ sh.addMsg("processTurn - multi - variable to Int error: " + b); } for(int n = 0; n < numPlayed; n++){ varlength2 = varlength3; //determining how many card where played varlength3 = 0; for(int i = varlength2 + 1; i < otherplayermsg.length(); i++){ char extract = otherplayermsg.charAt(i); if(extract == (':')){ varlength3 = i; break; } } String cardnoString = otherplayermsg.substring(varlength2 + 1, varlength3); //converting string to int for processing try{ Card card = new Card(Integer.parseInt(cardnoString), cardspic, sh, g); addcardtopile(card); }catch(NumberFormatException b){ sh.addMsg("processTurn - multi - variable to Int error: " + b); } if(deck == 0 || cardcount[playernumber] > 3){ if(cardcount[playernumber] > 0) cardcount[playernumber]--; }else deck--; } //burning pile if a 10 is played or 4 of a kind if(pile[0].getValue() == 10 || fourOfAKind(pile[3]) == true) { burnt = true; burn = true; //removing cards from pile sh.addMsg(name + " burnt the pile."); for(int i = 0; i < 51; i++) pile[i] = null; } }else{ //adding card to pile try{ Card card = new Card(Integer.parseInt(cardno), cardspic, sh, g); for(int n = 51; n > 0; n--) pile[n] = pile[n - 1]; pile[0] = card; //burning pile if a 10 is played if(pile[0].getValue() == 10 || fourOfAKind(pile[3]) == true) { burn = true; burnt = true; //removing cards from pile sh.addMsg(name + " burnt the pile."); for(int n = 0; n < 51; n++) pile[n] = null; } }catch(NumberFormatException b){ sh.addMsg("Otherplayer else - variable to Int error: " + b); } if(deck == 0 || cardcount[playernumber] > 3){ if(cardcount[playernumber] > 0) cardcount[playernumber]--; }else deck--; } if(!burn) nextTurn(); displayTable(); } private boolean faceupmulti(String otherplayermsg, int varlength2, int playernumber) { boolean burn = false; //determining how many card where played int varlength3 = 0; for(int n = varlength2 + 1; n < otherplayermsg.length(); n++){ char extract = otherplayermsg.charAt(n); if(extract == (':')){ varlength3 = n; break; } } String numPlayedString = otherplayermsg.substring(varlength2 + 1, varlength3); //converting string to int for processing int numPlayed = 0; try{ numPlayed = Integer.parseInt(numPlayedString); }catch(NumberFormatException b){ sh.addMsg("processTurn - multi face up - variable to Int error: " + b); } for(int n = 0; n < numPlayed; n++){ varlength2 = varlength3; //determining how many card where played varlength3 = 0; for(int i = varlength2 + 1; i < otherplayermsg.length(); i++){ char extract = otherplayermsg.charAt(i); if(extract == (':')){ varlength3 = i; break; } } String cardnoString = otherplayermsg.substring(varlength2 + 1, varlength3); //converting string to int for processing try{ Card card = new Card(Integer.parseInt(cardnoString), cardspic, sh, g); addcardtopile(card); for(int i = 0; i < 3; i++) if(faceup[playernumber][i] != null) if(faceup[playernumber][i].getNumber() == card.getNumber()){ faceup[playernumber][i] = null; break; } }catch(NumberFormatException b){ sh.addMsg("processTurn - multi - variable to Int error: " + b); } } //burning pile if a 10 is played or 4 of a kind if(pile[0].getValue() == 10 || fourOfAKind(pile[3]) == true) { burnt = true; burn = true; //removing cards from pile sh.addMsg(othernames[playernumber] + " burnt the pile."); for(int i = 0; i < 51; i++) pile[i] = null; } return burn; } private void yourturn() { //making sure turn arrow is pointed correctly if(whosturn != 3){ whosturn = 3; displayTable(); } int top = 0; //testing is player has a card they can play if(pile[0] != null) { boolean canplay = false; if(hand.getCard(0) == null){//if player only has card on the table if(hand.isFaceUp())//if player has faceup card on the table { for(int n = 0; n < 3; n++){ if(hand.getFaceUp(n) != null){ if(nine == true && pile[0].getValue() == 9){ top = 0; for(int i = 0; i < 52; i++){ if(pile[i] == null){ canplay = true; break; } if(pile[i].getValue() == 9) top++; else break; } } if(canplay) break; if (seven == true && pile[top].getValue() == 7 && hand.getFaceUp(n).getValue() < 7){ canplay = true; break; }else if(hand.getFaceUp(n).getValue() == 2 || hand.getFaceUp(n).getValue() == 10){ canplay = true; break; }else if(nine == true && hand.getFaceUp(n).getValue() == 9){ canplay = true; break; }else if(seven != true || pile[top].getValue() != 7){ if(pile[top].getValue() <= hand.getFaceUp(n).getValue()){ canplay = true; break; } } } } }else//if player only has facedown cards canplay = true; }else{ for(int n = 0; n < hand.length() - 1; n++){ if(hand.getCard(n) == null) break; if(nine == true && pile[0].getValue() == 9){ top = 0; for(int i = 0; i < 52; i++){ if(pile[i] == null){ canplay = true; break; } if(pile[i].getValue() == 9) top++; else break; } } if(canplay) break; if(hand.getCard(n).getValue() == 2 || hand.getCard(n).getValue() == 10){ canplay = true; break; } if(nine == true && hand.getCard(n).getValue() == 9){ canplay = true; break; } if (seven == true && pile[top].getValue() == 7 && hand.getCard(n).getValue() < 7){ canplay = true; break; }else if(seven != true || pile[top].getValue() != 7){ if(pile[top].getValue() <= hand.getCard(n).getValue()){ canplay = true; break; } } } } if(canplay){ //sh.addMsg("Its Your Turn"); sh.setmyTurn(true); }else{//cant play then must pick up the pile sh.addMsg("The card played was a " + pile[top].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; } sendCommand("turn:pickup:"); nextTurn(); displayTable(); } }else{ //sh.addMsg("Its Your Turn"); sh.setmyTurn(true); } } private void getcard(String otherplayermsg, int commandlength) { //decode variable that came with message int varlength = 0; for(int n = commandlength + 1; n < otherplayermsg.length(); n++){ char extract = otherplayermsg.charAt(n); if(extract == (':')){ varlength = n; break; } } String variable = otherplayermsg.substring(commandlength + 1, varlength); //Adding card to hand try{ Card card = new Card(Integer.parseInt(variable), cardspic, sh, g); hand.addCard(card); }catch(NumberFormatException b){ sh.addMsg("Deal - variable to Int error: " + b); } deck--; displayTable(); } private void deal(String otherplayermsg, int commandlength) { //decode variable that came with message int varlength = 0; for(int n = commandlength + 1; n < otherplayermsg.length(); n++){ char extract = otherplayermsg.charAt(n); if(extract == (':')){ varlength = n; break; } } String variable = otherplayermsg.substring(commandlength + 1, varlength); //Adding card to deck try{ Card card = new Card(Integer.parseInt(variable), cardspic, sh, g); hand.deal(card); }catch(NumberFormatException b){ sh.addMsg("Deal - variable to Int error: " + b); } } //getting the details of other players private void otherdetails(String otherplayermsg, int commandlength) { //decode variable that came with message String variables[] = new String[12]; for(int i = 0; i < 12; i++){ int varlength = 0; for(int n = commandlength + 1; n < otherplayermsg.length(); n++){ char extract = otherplayermsg.charAt(n); if(extract == (':')){ varlength = n; break; } } variables[i] = otherplayermsg.substring(commandlength + 1, varlength); commandlength = varlength; } //adding other players details to storage arrays for(int n = 0; n < 3; n++) { othernames[n] = variables[4*n]; score.addName(variables[4*n]); //sh.addMsg("Test - othername " + othernames[n] + " severname " + servername);//--------------------TEST if(othernames[n].equals(servername)) whosturn = n; cardcount[n] = 3; carddowncount[n] = 3; try{ for(int i = 0; i < 3; i++){ Card card = new Card(Integer.parseInt(variables[4*n + 1 + i]), cardspic, sh, g); faceup[n][i] = card; } }catch(NumberFormatException b){ sh.addMsg("otherdetails - variable to Int error: " + b); } } deck = 16; if(fastgame) deck = 0; displayTable(); if(swap == true && swapdone == false){//if performing card swap Card inhand[] = new Card[3]; Card ontable[] = new Card[3]; for(int n = 0; n < 3; n++){ inhand[n] = hand.getCard(n); ontable[n] = hand.getFaceUp(n); } SwapD swapD = new SwapD(sh, inhand, ontable); if(swapD.display()){ inhand = swapD.getInHand(); ontable = swapD.getOnTable(); hand.swap(inhand, ontable); displayTable(); } sendCommand("swap:" + inhand[0].getNumber() + ":" + inhand[1].getNumber() + ":" + inhand[2].getNumber() + ":" + ontable[0].getNumber() + ":" + ontable[1].getNumber() + ":" + ontable[2].getNumber() + ":"); swapdone = true; } }}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -