Browse Source

JKSAhdfjk

Your Name 3 years ago
parent
commit
986439b85c
3 changed files with 70 additions and 15 deletions
  1. 61 14
      src/com/company/Dealer.java
  2. 1 1
      src/com/company/Main.java
  3. 8 0
      src/com/company/Player.java

+ 61 - 14
src/com/company/Dealer.java

@@ -116,6 +116,8 @@ public class Dealer {
                 e.printStackTrace();
             }
 
+            player.Calc();
+
             PrintCard(player.cards);
 
             if (!isRoyalFlush(player.cards, player)) {
@@ -127,7 +129,8 @@ public class Dealer {
                                     if (!isThreeOfAKind(player.cards, player)) {
                                         if (!isTwoPairs(player.cards, player)) {
                                             if (!isOnePair(player.cards, player)) {
-
+                                                player.combination.Value = player.cards[0].getDenomination();
+                                                player.combination.CurrentCombination = Combination.LIST.HIGH_CARD;
                                             }
                                         }
                                     }
@@ -141,23 +144,43 @@ public class Dealer {
             System.out.println(player.getName() + " " + player.combination.Value);
         }
 
-        for (int k = 0; k < players.length; k++) {
-            for (int l = 1; l < players.length; l++) {
-                if (players[k] == players[l]) {
-                    continue;
-                }
+        Sorting(players);
 
-                if (players[k].combination.Value == players[l].combination.Value) {
-                    for (int x = 0; x < 7; x++) {
-                        if (players[k].cards[x].getDenomination() > players[l].cards[x].getDenomination()) {
+        Player pWin;
 
-                        }
+        int count = 0;
+        if (players[0].combination.Value == players[1].combination.Value) {
+            int value = players[0].combination.Value;
+            count++;
+            for (int q = 2; q < players.length - 1; q++) {
+                if (players[q].combination.Value == players[q + 1].combination.Value) {
+                    if (value == players[q].combination.Value) {
+                        count++;
+                    } else {
+                        break;
                     }
                 }
             }
         }
+
+        if (count > 0) {
+
+            Player[] winPlayers = new Player[count + 1];
+            for (int wp = 0; wp <= count; wp++) {
+                winPlayers[wp] = players[wp];
+            }
+
+            SortingBySum(winPlayers);
+
+            pWin = winPlayers[0];
+        } else {
+            pWin = players[0];
+        }
+
+        System.out.println("Игрок " + pWin.getName() + " выйграл");
     }
 
+
     public void PrintCard(Card[] cards) {
         for (Card card : cards) {
             System.out.print(
@@ -188,6 +211,30 @@ public class Dealer {
         }
     }
 
+    public void Sorting(Player[] players) {
+        for (int i = 0; i < players.length; i++) {
+            for (int j = 0; j < players.length - 1; j++) {
+                if (players[j].combination.Value < players[j + 1].combination.Value) {
+                    Player temp = players[j];
+                    players[j] = players[j + 1];
+                    players[j + 1] = temp;
+                }
+            }
+        }
+    }
+
+    public void SortingBySum(Player[] players) {
+        for (int i = 0; i < players.length; i++) {
+            for (int j = 0; j < players.length - 1; j++) {
+                if (players[j].SumDenomination < players[j + 1].SumDenomination) {
+                    Player temp = players[j];
+                    players[j] = players[j + 1];
+                    players[j + 1] = temp;
+                }
+            }
+        }
+    }
+
     /**
      * Проверяет есть ли в переданном массиве комбинация Стрит
      *
@@ -224,7 +271,8 @@ public class Dealer {
 
     /**
      * Стрит-флеш
-     * @param cards массив карт игрока и на столе отсортированных по номиналу
+     *
+     * @param cards  массив карт игрока и на столе отсортированных по номиналу
      * @param player экземпляр игрока
      */
     public boolean isStraightFlush(Card[] cards, Player player) {
@@ -261,7 +309,8 @@ public class Dealer {
 
     /**
      * Каре (четыре одного вида)
-     * @param cards массив карт игрока и на столе отсортированных по номиналу
+     *
+     * @param cards  массив карт игрока и на столе отсортированных по номиналу
      * @param player экземпляр игрока
      */
     public boolean isFourOfAKind(Card[] cards, Player player) {
@@ -347,9 +396,7 @@ public class Dealer {
     }
 
     /**
-     *
      * !!! ДОРАБОТАТЬ !!!
-     *
      */
     public boolean isFlush(Card[] cards, Player player) {
         int CountHearts = 0;

+ 1 - 1
src/com/company/Main.java

@@ -4,7 +4,7 @@ public class Main {
 
     public static void main(String[] args) throws Exception {
 
-        Dealer dealer = new Dealer(4);
+        Dealer dealer = new Dealer(6);
         dealer.HandOut();
         dealer.HandOut();
         dealer.HandOut();

+ 8 - 0
src/com/company/Player.java

@@ -8,6 +8,7 @@ package com.company;
 public class Player {
     public final Card[] cards = new Card[7];
     private String name;
+    public int SumDenomination = 0;
     public Combination combination;
 
     public Player(String name) {
@@ -15,6 +16,13 @@ public class Player {
         this.combination = new Combination();
     }
 
+    public void Calc() {
+        SumDenomination = 0;
+        for (int i = 0; i < cards.length; i++) {
+            SumDenomination += cards[i].getDenomination();
+        }
+    }
+
     public String getName() {
         return name;
     }