Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. package application;
  2.  
  3. import java.io.IOException;
  4. import java.util.Vector;
  5.  
  6. import javafx.event.ActionEvent;
  7. import javafx.fxml.FXML;
  8. import javafx.fxml.FXMLLoader;
  9. import javafx.scene.control.Button;
  10. import javafx.scene.control.Label;
  11. import javafx.scene.control.ScrollPane;
  12.  
  13. import javafx.scene.layout.FlowPane;
  14. import javafx.scene.layout.GridPane;
  15. import javafx.scene.layout.Pane;
  16.  
  17. public class GameController {
  18.  
  19. @FXML
  20. private Button StartButton;
  21. @FXML
  22. private Button ExitButton;
  23. @FXML
  24. private Button MakeamoveButton;
  25. @FXML
  26. private Button NextTurnButton;
  27. @FXML
  28. private Button BeatButton;
  29. @FXML
  30. private Label trumpField;
  31. @FXML
  32. private ScrollPane firstPlayerScroll;
  33. @FXML
  34. private ScrollPane secondPlayerScroll;
  35. @FXML
  36. private FlowPane firstPlayerPane;
  37. @FXML
  38. private FlowPane secondPlayerPane;
  39. @FXML
  40. private GridPane deskAttackCardPane;
  41. @FXML
  42. private GridPane deskAnswerCardPane;
  43. @FXML
  44. private Pane Allbuttons;
  45.  
  46. public static Player[] players = new Player[2];
  47. public static Deck deck = new Deck();
  48. public static Vector<Card> table = new Vector<Card>(); // One-dimensional, because of an agreement with Player team
  49. public static String trump;
  50. public static int currentAttackerID;
  51.  
  52. public static int nextPlayer() {
  53. if (currentAttackerID < players.length - 1) {
  54. return currentAttackerID + 1;
  55. } else {
  56. return 0;
  57. }
  58. }
  59.  
  60. public static void nextTurn() {
  61. table.clear();
  62. currentAttackerID = nextPlayer();
  63. }
  64.  
  65. public void botmove() {
  66. table.clear();
  67. table.add(players[0].move());
  68. MakeamoveButton.setDisable(true);
  69.  
  70. }
  71.  
  72. public static boolean isSomePlayerHandEmpty() {
  73. for (int i = 0; i < players.length; i++)
  74. if (players[i].numberOfCardsInHand() == 0)
  75. return true;
  76. return false;
  77. }
  78.  
  79. public static boolean isGameEnded() {
  80. if ((deck.amountCard() == 0) && (isSomePlayerHandEmpty() == true))
  81. return true;
  82. return false;
  83. }
  84.  
  85. public static String durak() {
  86. for (int i = 0; i < players.length; i++)
  87. if (players[i].numberOfCardsInHand() > 0)
  88. return players[i].ourname;
  89. return "Somehow its no one";
  90. }
  91.  
  92. @FXML
  93. // старт игры, ходит бот
  94. public void StartButtonAction() {
  95. System.out.println(1);
  96. deck.shuffleDeck(); // перемешка карт в колоде
  97. players[0] = new Player("Бот");
  98. players[1] = new Player("player");
  99.  
  100. trump = deck.getAndMoveTrump(); // какой козырь
  101. trumpField.setText("Козырь " + trump); // вывод козыря
  102. table.add(players[0].move()); // ходит бот
  103. StartButton.setDisable(true);
  104.  
  105. }
  106.  
  107. // кнопка принудительного выхода из игры
  108. @FXML
  109. public void ExitButtonAction() {
  110. System.exit(0);
  111. }
  112.  
  113. // кнопка дать первую карту в коне, после этого ход завершается без возможности
  114. // отбить
  115. @FXML
  116. void MakeamoveButtonAction() {
  117. table.add(players[1].move()); // ходит игрок
  118. if (players[0].canCover(table.lastElement()) == false) { // если не может покрыть
  119. players[0].take_from_desk(table); // берет
  120. } else {
  121. table.add(players[0].cover(table.lastElement())); // кроет
  122. }
  123. table.clear(); // очищается стол
  124. players[0].takeFromDeck(); // добирает из колоды
  125. players[1].takeFromDeck(); // добирает из колоды
  126. if (isGameEnded()) {
  127. // возможно заменить это какой-то красивой табличкой
  128. System.out.println("Вы победили!!!");
  129. System.exit(0);
  130. }
  131. }
  132.  
  133. // кнопка взять карту (переименовать в взять?)
  134. @FXML
  135. void NextTurnButtonAction() {
  136. players[0].take_from_desk(table); // берет все карты на столе
  137. table.clear();
  138. if (isGameEnded()) {
  139. // возможно заменить это какой-то красивой табличкой
  140. System.out.println("Вы проиграли(((");
  141. System.exit(0);
  142. }
  143. }
  144.  
  145. // кнопка отбиться
  146. @FXML
  147. void BeatButtonAction() {
  148. System.out.println(2);
  149. if (players[1].canCover(table.lastElement()) == false) {
  150. players[1].take_from_desk(table);
  151.  
  152. } else {
  153. table.add(players[1].cover(table.lastElement()));
  154. }
  155. botmove(); // ходит бот
  156. BeatButton.setDisable(true); // кнопка пропадает, потому что отбиться ток один раз
  157. if (isGameEnded()) {
  158. // возможно заменить это какой-то красивой табличкой
  159. System.out.println("Вы победили!!!");
  160. System.exit(0);
  161. }
  162.  
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement