Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.util.Vector;
- import javafx.event.ActionEvent;
- import javafx.fxml.FXML;
- import javafx.fxml.FXMLLoader;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.control.ScrollPane;
- import javafx.scene.layout.FlowPane;
- import javafx.scene.layout.Pane;
- public class GameController {
- @FXML
- private Button StartButton;
- @FXML
- private Button ExitButton;
- @FXML
- private Button MakeamoveButton;
- @FXML
- private Button NextTurnButton;
- @FXML
- private Button BeatButton;
- @FXML
- private Label trumpField;
- @FXML
- private ScrollPane firstPlayerScroll;
- @FXML
- private ScrollPane secondPlayerScroll;
- @FXML
- private FlowPane firstPlayerPane;
- @FXML
- private FlowPane secondPlayerPane;
- public static Player[] players = new Player[2];
- public static Deck deck = new Deck();
- public static Vector<Card> table = new Vector<Card>(); // One-dimensional, because of an agreement with Player team
- public static String trump;
- public static int currentAttackerID;
- public static int nextPlayer() {
- if (currentAttackerID < players.length - 1) {
- return currentAttackerID + 1;
- } else {
- return 0;
- }
- }
- public static void nextTurn() {
- table.clear();
- currentAttackerID = nextPlayer();
- }
- public void botmove() {
- table.clear();
- table.add(players[0].move());
- MakeamoveButtonAction.setDisable(true);
- }
- public static boolean isSomePlayerHandEmpty() {
- for (int i = 0; i < players.length; i++)
- if (players[i].numberOfCardsInHand() == 0)
- return true;
- return false;
- }
- public static boolean isGameEnded() {
- if ((deck.amountCard() == 0) && (isSomePlayerHandEmpty() == true))
- return true;
- return false;
- }
- public static String durak() {
- for (int i = 0; i < players.length; i++)
- if (players[i].numberOfCardsInHand() > 0)
- return players[i].ourname;
- return "Somehow its no one";
- }
- @FXML
- //старт игры, ходит бот
- public void StartButtonAction() {
- System.out.println(1);
- deck.shuffleDeck(); //перемешка карт в колоде
- players[0] = new Player("Бот");
- players[1] = new Player("player");
- trump = deck.getAndMoveTrump(); //какой козырь
- trumpField.setText("Козырь "+trump); //вывод козыря
- table.add(players[0].move()); // ходит бот
- StartButton.setDisable(true);
- }
- //кнопка принудительного выхода из игры
- @FXML
- public void ExitButtonAction() {
- System.exit(0);
- }
- //кнопка дать первую карту в коне, после этого ход завершается без возможности отбить
- @FXML
- void MakeamoveButtonAction() {
- table.add(players[1].move()); //ходит игрок
- if (players[0].canCover(table.lastElement()) == false) { //если не может покрыть
- players[0].take_from_desk(table); //берет
- } else{
- table.add(players[0].cover(table.lastElement())); //кроет
- }
- table.clear(); //очищается стол
- players[0].takeFromDeck(); //добирает из колоды
- players[1].takeFromDeck(); //добирает из колоды
- if(isGameEnded()){
- //возможно заменить это какой-то красивой табличкой
- System.out.println("Вы победили!!!");
- System.exit(0);
- }
- }
- //кнопка взять карту (переименовать в взять?)
- @FXML
- void NextTurnButtonAction() {
- players[0].take_from_desk(table); //берет все карты на столе
- table.clear;
- if(isGameEnded()){
- //возможно заменить это какой-то красивой табличкой
- System.out.println("Вы проиграли(((");
- System.exit(0);
- }
- }
- //кнопка отбиться
- @FXML
- void BeatButtonAction() {
- System.out.println(2);
- if (players[1].canCover(table.lastElement()) == false) {
- players[1].take_from_desk(table);
- } else {
- table.add(players[1].cover(table.lastElement())); }
- botmove(); //ходит бот
- BeatButtonAction.setDisable(true); //кнопка пропадает, потому что отбиться ток один раз
- if(isGameEnded()){
- //возможно заменить это какой-то красивой табличкой
- System.out.println("Вы победили!!!");
- System.exit(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement