📄 dealer.java
字号:
if(pile[1].getValue() == 9){ top = 2; if(pile[2] != null) if(pile[2].getValue() == 9) top = 3; } } int samecount = 1; for(int n = top + 1; n < top + 4; n++){ if(pile[n] == null) break; if(pile[n].getValue() == pile[top].getValue()) samecount++; else break; } if(samecount == 1){//one of a kind if(pile[top] != null) pile[top].drawCard(centre1); }else if(samecount == 2){//2 of a kind pile[top + 1].drawCard2((int)centre1.getX(), (int)centre1.getY() - 10); pile[top].drawCard2((int)centre1.getX(), (int)centre1.getY() + 10); }else if(samecount >= 3){//3 of a kind pile[top + 2].drawCard2((int)centre1.getX(), (int)centre1.getY() - 20); pile[top + 1].drawCard2((int)centre1.getX(), (int)centre1.getY()); pile[top].drawCard2((int)centre1.getX(), (int)centre1.getY() + 20); } if(nine == true && pile[0].getValue() == 9) if(top == 1)//one nine pile[0].drawSideWays2((int)centre1.getX() - 15, (int)centre1.getY() + 40); if(top == 2){//2 nines pile[1].drawSideWays2((int)centre1.getX() - 15, (int)centre1.getY() + 40); pile[0].drawSideWays2((int)centre1.getX() - 15, (int)centre1.getY() + 50); } if(top == 3){//3 nines pile[2].drawSideWays2((int)centre1.getX() - 15, (int)centre1.getY() + 40); pile[1].drawSideWays2((int)centre1.getX() - 15, (int)centre1.getY() + 50); pile[0].drawSideWays2((int)centre1.getX() - 15, (int)centre1.getY() + 60); } }else if(burnt){ g.drawImage(burntPic, 130, 190, sh); burnt = false; } g.drawImage(pointer[whosturn], (int)pointerpoints[whosturn].getX(), (int)pointerpoints[whosturn].getY(), sh); if(sh.smallscreen()) sh.scalepic(); sh.repaint(); } public void redeal() { if (socketCount >= 3){ for(int n = 0; n < 4; n++){ //setting scoreboard if game finishes early if( n < 3){ if(outofgame[n] == false) score.addScore(otherNames[n], position); }else{ if(outofgame[n] == false) score.addScore(playersName, position); } outofgame[n] = false; if(n < 3) waitformsg[n] = false; hands[n].removeAll(); } whosturn = 2; position = 1; swapcount = 0; for(int n = 0; n < 52; n++) pile[n] = null; for(int n = 0; n < 3; n++) sendCommand("reset:", n); deal(); } } private int pilelength() { int cardCount = 0; for(int n = 0; n < 52; n++){ if(pile[n] == null) break; cardCount++; } return cardCount; } private int decklength() { int cardCount = 0; for(int n = 0; n < 52; n++){ if(deck[n] == null) break; cardCount++; } return cardCount; } private void outofgame(int playerout) { String name = ""; //telling whos out of the game there are out if(playerout == 3){//dealer out of game if(position == 1) sh.addMsg("Well done you have won the game your the first out !!"); else if(position == 2) sh.addMsg("You've done alright you the second out of the game"); else if(position == 3) sh.addMsg("Just made it, congrats your not a ShitHead !"); name = playersName; }else{ sendCommand("out:" + position + ":", playerout); name = otherNames[playerout]; sh.addMsg( name + " is out of the game"); } //updating scoreboard score.addScore(name, position); //sending message to everyone else for(int n = 0; n < 3; n++) if(n != playerout) sendCommand("otherout:" + name + ":", n); outofgame[playerout] = true; position++; //ending game if over if(position == 4){ gameID++; int wholost = 0; //finding out which player is still in the game for(int n = 0; n < 4; n++) if(!outofgame[n]){ wholost = n; outofgame[n] = true; break; } if(wholost == 3){ sh.addMsg("You Lost ShitHead !!!"); sh.addMsg("Game Over"); name = playersName; displayTable(); }else{ sendCommand("out:" + position + ":", wholost); name = otherNames[wholost]; sh.addMsg( name + " is the Shithead"); sh.addMsg("Game Over"); whosturn = 3; displayTable(); } //updating scoreboard score.addScore(name, 4); new ScoreThread(); //sending message to everyone else for(int n = 0; n < 3; n++) if(otherNames[n] != name) sendCommand("lost:" + name + ":", n); outofgame[wholost] = true; } } public void cardSelection(int cardno) { Card card; String command; if(hands[3].getCard(0) == null){//if player only has cards on table if(hands[3].getFaceUp(0) != null || hands[3].getFaceUp(1) != null || hands[3].getFaceUp(2) != null){ // if cards still faceup on table card = hands[3].getFaceUp(cardno); command = "othersturn:" + playersName + ":faceup:"; if(isValidCard(card, command)) hands[3].removeFaceUp(cardno); }else{//if only cards down card = hands[3].getFaceDown(cardno); command = "othersturn:" + playersName + ":facedown:"; if(isValidCard(card, command)){ hands[3].removeFaceDown(cardno); //checking if player is out of the game if(hands[3].getFaceDown(0) == null && hands[3].getFaceDown(1) == null && hands[3].getFaceDown(2) == null) outofgame(3); }else{//player must pick up the deck if not valid sh.addMsg("The card you played was a " + hands[3].getFaceDown(cardno).getStringValue() + " you had to pick up the pile"); hands[3].addCard(hands[3].getFaceDown(cardno)); for(int n = 0; n < 3; n++) sendCommand("othersturn:" + playersName +":facedown:pickup:" + hands[3].getFaceDown(cardno).getNumber() + ":", n); for(int n = 0; n < 52; n++){ if(pile[n] == null) break; hands[3].addCard(pile[n]); pile[n] = null; } hands[3].removeFaceDown(cardno); nextTurn(); } } }else{// if player still has cards in hand card = hands[3].getCard(cardno); command = "othersturn:" + playersName + ":"; if(isValidCard(card, command)) for(int n = 0; n < hands[3].length() -1; n++) if(card.getNumber() == hands[3].getCard(n).getNumber()){ hands[3].removeCard(n); break; } //checking if player is out of the game if(hands[3].getFaceDown(0) == null && hands[3].getFaceDown(1) == null && hands[3].getFaceDown(2) == null && hands[3].getCard(0) == null){ outofgame(3); if(whosturn == 3) nextTurn(); } } //if players hand is less than 3 card and card still in deck give another card to player while(deck[0] != null && hands[3].length() <= 3){ hands[3].addCard(deck[0]); //removing card from deck deck[51] = null; for(int w = 0; w < 51; w++) deck[w] = deck[w + 1]; } displayTable(); } 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(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(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(hands[3].getFaceUp(n) != null) if(hands[3].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 = "othersturn:" + playersName +":faceup:multi:" + numbertoplay + ":" + card.getNumber() + ":"; addcardtopile(card); numbertoplay--; for(int n = 0; n < 3; n++) if(hands[3].getFaceUp(n) != null){ if(numbertoplay <= 0) break; if(card.getValue() == hands[3].getFaceUp(n).getValue() && card.getNumber() != hands[3].getFaceUp(n).getNumber()){ command = command.concat(hands[3].getFaceUp(n).getNumber() +":"); addcardtopile(hands[3].getFaceUp(n)); //storing which card are to be removed hands[3].removeFaceUp(n); numbertoplay--; } } //sending command for(int n = 0; n < 3; n++) sendCommand(command, n); //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 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 < hands[3].length(); n++){ if(hands[3].getCard(n) == null) break; if(hands[3].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 = "othersturn:" + playersName + ":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 < hands[3].length() - 1; n++){ if(hands[3].getCard(n) == null) break; if(numbertoplay <= 0) break; if(card.getValue() == hands[3].getCard(n).getValue() && card.getNumber() != hands[3].getCard(n).getNumber()){ command = command.concat(hands[3].getCard(n).getNumber() +":"); addcardtopile(hands[3].getCard(n)); //storing which card are to be removed toberemoved[toberemovedcount] = hands[3].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 < hands[3].length() -1; i++) if(hands[3].getCard(i).getNumber() == toberemoved[n]){ hands[3].removeCard(i); break; } } //sending command for(int n = 0; n < 3; n++) sendCommand(command, n); //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; //checking if player is out of game if(hands[3].getFaceDown(0) == null && hands[3].getFaceDown(1) == null && hands[3].getFaceDown(2) == null && hands[3].getCard(0) == null) nextTurn(); else//else there go again sh.addMsg("You burn the pile is your turn again"); }else{ sh.setmyTurn(false); nextTurn(); } return true; } private void nextTurn() { whosturn++; if(whosturn >= 4) whosturn = 0; int loop = 0;//stop program becoming trapped in loop while(outofgame[whosturn] && loop < 5){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -