3 класса. Карта, игра и колода. Я не знаю, почему это дает мне ошибку. Если кто-то может мне помочь, я хотел бы знать, в чем проблема.
Что говорит заголовок, я должен догадаться, будет ли следующая карта, которую я получу, выше или ниже.
package CardGame;
import java.util.Scanner;
import java.util.*;
public class Game {
private static int score;
// currentCard : Card
private static Card currentCard;
// Next Card
private Card nextCard;
// Scanner
private static Deck deck;
private static Scanner sc = new Scanner(System.in);
// Main
public static void main(String[] args) {
deck = new Deck();
currentCard = deck.getNextCard();
Game.gameTurn();
}
// get turn method
public static void gameTurn() {
// System.out.println(Deck.getCards().size());
System.out.print("is your next card higher or lower than the next card?");
System.out.print(sc);
String answer = sc.nextLine();
Card nextCard = deck.getNextCard();
if (answer.equals("higher") && nextCard.isHigherOrEqual(currentCard)) {
correct();
} else if (answer.equals("lower") && !nextCard.isHigherOrEqual(currentCard)) {
correct();
// answer.equals("lower")&& !nextCard.isHigherOrEqual(currentCard)
} else {
gameOver();
}
}
// correct method
public static void correct() {
Game.gameTurn();
score = 0;
score++;
}
// Game over Method
public static void gameOver() {
System.out.println("total score is " + score + "!");
}
}
package CardGame;
import java.util.ArrayList;
import java.util.Collections;
public class Deck {
// cards = Card = new ArrayList<>()
private static ArrayList<Card> cards = new ArrayList<>();
// Deck Method
public void Deck() {
for (int i = 1; i < 4; i++) {
String suits;
switch (i) {
case 1:
suits = "Hearts";
break;
case 2:
suits = "Diamonds";
break;
case 3:
suits = "Spades";
break;
case 4:
suits = "Clubs";
break;
default:
suits = "";
break;
}
for (int j = 1; j <= 10; j++) {
int value = j;
String name = j + " of " + suits;
Card c = new Card(suits, name, value);
cards.add(c);
}
// add 1.3 tot 1.11
Card jack = new Card(suits, "jack of " + suits, 11);
cards.add(jack); // JACK
Card queen = new Card(suits, "queen of " + suits, 12);
cards.add(queen); // QUEEN
Card king = new Card(suits, "king of " + suits, 13);
cards.add(king); // KING
Card ace = new Card(suits, "ace of " + suits, 14);
}
// 1.11 shuffle cards
Collections.shuffle(cards);
}
// getNextCard() : Card
public Card getNextCard() {
Card nextCard = cards.remove(0);
return nextCard;
}
// getCards() : ArrayList <card>
public static ArrayList<Card> getCards() {
return cards;
}
}
package CardGame;
public class Card {
// Suit String
private String suit;
// Name String
private String name;
// Value int
private int value;
// Card constructor
public Card(String suit, String name, int value) {
this.value = value;
this.name = name;
this.suit = suit;
}
public int getValue() {
return value;
}
// toString Method
public String toString() {
if (value == 15);
return "";
}
// isHigherorEqual Method
public boolean isHigherOrEqual(Card c) {
if (this.value >= c.getValue()) {
return true;
} else {
return false;
}
}
}