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