Alec 3 years ago
commit
09aba9f73d

+ 3 - 0
.idea/.gitignore

@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml

+ 1 - 0
.idea/description.html

@@ -0,0 +1 @@
+<html>Simple <b>Java</b> application that includes a class with <code>main()</code> method</html>

+ 6 - 0
.idea/encodings.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Encoding">
+    <file url="PROJECT" charset="UTF-8" />
+  </component>
+</project>

+ 9 - 0
.idea/misc.xml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectKey">
+    <option name="state" value="project://e2804f05-5315-4fc6-a121-c522a6c26470" />
+  </component>
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_14" default="true" project-jdk-name="openjdk-14" project-jdk-type="JavaSDK">
+    <output url="file://$PROJECT_DIR$/out" />
+  </component>
+</project>

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/Pocker.iml" filepath="$PROJECT_DIR$/Pocker.iml" />
+    </modules>
+  </component>
+</project>

+ 3 - 0
.idea/project-template.xml

@@ -0,0 +1,3 @@
+<template>
+  <input-field default="com.company">IJ_BASE_PACKAGE</input-field>
+</template>

+ 12 - 0
Pocker.iml

@@ -0,0 +1,12 @@
+<?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>
+

BIN
out/production/Pocker/com/company/Card.class


BIN
out/production/Pocker/com/company/Dealler.class


BIN
out/production/Pocker/com/company/Deck.class


BIN
out/production/Pocker/com/company/LEAR.class


BIN
out/production/Pocker/com/company/Main.class


BIN
out/production/Pocker/com/company/Player.class


+ 51 - 0
src/com/company/Card.java

@@ -0,0 +1,51 @@
+package com.company;
+
+
+// 363
+
+public class Card {
+    // Масть
+    private LEAR lear;
+    // Номинал (2-14)
+    private int Denomination;
+    private boolean OnHand = false;
+
+    public boolean isOnHand() {
+        return OnHand;
+    }
+
+    public void setOnHand(boolean onHand) {
+        OnHand = onHand;
+    }
+
+    /**
+     * Метод возвращает занчение номинала карты
+     * @return int
+     */
+    public int getDenomination() {
+        return Denomination;
+    }
+
+    /**
+     * Метод устанавливает номинал карты
+     * @param denomination устанавливаемый номинал
+     * @return true если значение успешно установлено
+     */
+    public boolean setDenomination(int denomination) {
+        // Если переданный в метод номинал не соответствует
+        // допустимому значению, то вернуть FALSE
+        if (denomination < 2 || denomination > 14) {
+            return false;
+        }
+        Denomination = denomination;
+        return true;
+    }
+
+    public LEAR getLear() {
+        return lear;
+    }
+
+    public void setLear(LEAR lear) {
+        this.lear = lear;
+    }
+}

+ 62 - 0
src/com/company/Dealler.java

@@ -0,0 +1,62 @@
+package com.company;
+
+import java.util.Random;
+
+public class Dealler {
+    private Deck deck =  new Deck();
+    private Player []players;
+    private Card []table = new Card[5];
+    private GAME_STAGE stage = GAME_STAGE.PREFLOP;
+    private Random random = new Random(System.currentTimeMillis());
+
+    public Dealler(String []playerNames) throws Exception {
+        if (playerNames.length < 2 || playerNames.length > 10) {
+            throw new Exception("Некорректное количество игроков");
+        }
+        players = new Player[playerNames.length];
+
+        for (int i = 0; i < playerNames.length; i++) {
+            players[i] = new Player(playerNames[i]);
+        }
+    }
+
+    public void HandOut() {
+        switch (stage) {
+            case PREFLOP: {
+                boolean isLeftCardOnHand = false;
+                for (int i = 0; i < players.length; i++) {
+                    Card currentCard = deck.Cards[random.nextInt(deck.CARD_COUNT)];
+                    if (!isLeftCardOnHand) {
+                        if (currentCard.isOnHand()) {
+                            i--;
+                            continue;
+                        }
+                        isLeftCardOnHand = true;
+                        players[i].setLeft(currentCard);
+                        currentCard.setOnHand(true);
+                    }
+                    currentCard = deck.Cards[random.nextInt(deck.CARD_COUNT)];
+                    if (currentCard.isOnHand()) {
+                        i--;
+                        continue;
+                    }
+                    players[i].setRight(currentCard);
+                    currentCard.setOnHand(true);
+                }
+            } break;
+            case FLOP: {
+
+            } break;
+            case TURN: {
+
+            } break;
+            case RIVER: {
+
+            } break;
+            case OPENING: {
+
+            } break;
+        }
+    }
+
+}

+ 41 - 0
src/com/company/Deck.java

@@ -0,0 +1,41 @@
+package com.company;
+
+import java.sql.CallableStatement;
+
+/**
+ * Колода
+ */
+public class Deck {
+    // Количество карт в колоде
+    final byte CARD_COUNT = 52;
+    // Колода из 52 карт
+    public Card Cards[] = new Card[CARD_COUNT];
+
+    /**
+     * Конструктор создающий колоду
+     */
+    public Deck() {
+        // Проход по массву и создание
+        // нового экземпляра класса Card
+        for (int i = 0; i < CARD_COUNT; i++) {
+            Cards[i] = new Card();
+        }
+
+        // Счётчик всех карт в массиве Cards
+        int cardCounter = 0;
+        // Цикл foreach (проход по всем мастям)
+        for (LEAR lear: LEAR.values()) {
+            // Цикл по всем номиналам
+            for (int i = 2; i < 15; i++) {
+                // Установить масть из переменной lear
+                // в карту с индексом cardCounter
+                Cards[cardCounter].setLear(lear);
+                // Установить номинал из переменной i
+                // в карту с индексом cardCounter
+                // и увеличить счетчик карт
+                Cards[cardCounter++].setDenomination(i);
+            }
+        }
+    }
+
+}

+ 12 - 0
src/com/company/GAME_STAGE.java

@@ -0,0 +1,12 @@
+package com.company;
+
+/**
+ * Этапы игры
+ */
+public enum GAME_STAGE {
+    PREFLOP,
+    FLOP,
+    TURN,
+    RIVER,
+    OPENING,
+}

+ 11 - 0
src/com/company/LEAR.java

@@ -0,0 +1,11 @@
+package com.company;
+
+/**
+ * Перечислений мастей
+ */
+public enum LEAR {
+    DIAMONDS,   // буби
+    HEARTS,     // черви
+    SPADES,     // пики
+    CLUBS,      // крести
+}

+ 13 - 0
src/com/company/Main.java

@@ -0,0 +1,13 @@
+package com.company;
+
+public class Main {
+
+    public static void main(String[] args) {
+
+        try {
+            Dealler d = new Dealler(1);
+        } catch (Exception e) {
+            System.out.print(e.getMessage());
+        }
+    }
+}

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

@@ -0,0 +1,33 @@
+package com.company;
+
+import javax.swing.*;
+
+public class Player {
+    private Card left = new Card();
+    private Card right = new Card();
+    private String name = new String();
+
+    public Player(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public Card getLeft() {
+        return left;
+    }
+
+    public void setLeft(Card left) {
+        this.left = left;
+    }
+
+    public Card getRight() {
+        return right;
+    }
+
+    public void setRight(Card right) {
+        this.right = right;
+    }
+}