Я использовал объект карты для работы с которым я создал список ссылок игральной карты.
Из списка ссылок карт я пытаюсь удалить все карты действий. Но удаление узла или карты действий ничего не делает. Он всегда печатает все карты, не вынимая его.
import java.util.Scanner;
import java.util.Collections;
public class CreateDeck {
class Node{
Card uno_card;
Node next;
public Node (Card uno_card) {
this.uno_card = uno_card;
this.next = null;
}
}
public static CreateDeck playing_deck = new CreateDeck();
public Node head = null;
public Node tail = null;
public static Card[] primary_deck = new Card[108];
public void addCard(Card uno_card) {
Node newNode = new Node(uno_card);
if (head == null) {
head = newNode;
tail = newNode;
}
else {
tail.next = newNode;
tail = newNode;
}
}
public static void printDeck(Card[] cards){
for (int i = 0; i < cards.length; i++){
System.out.println(cards[i].get_unoCard());
}
}
public void display() {
Node current = head ;
if (current == null) {
System.out.println("List is empty.\n");
return;
}
System.out.println("Uno Deck ::\n");
while (current != null) {
System.out.println(current.uno_card.get_unoCard());
current = current.next;
}
}
public static void init_deck(){
int index = 0;
for (int color = 1; color <= 4; color++){
for (int rank = 0; rank <= 26; rank++){
if (rank <= 24)
primary_deck[index] = new Card(rank, color);
else
primary_deck[index] = new Card(rank, 0);
index++;
}
}
}
public void remove_actionCard(){
Card temp_card;
for (int color = 1; color <= 4; color++){
for (int rank = 19; rank <= 26; rank++){
if (rank <= 24)
temp_card = new Card(rank, color);
else
temp_card = new Card(rank, 0);
Node current = head, temp = null;
if(current != null && current.uno_card == temp_card){
head = current.next;
return;
}
while ( current != null && current.uno_card != temp_card){
temp = current;
current = current.next;
}
if (current == null) {
return;
}
temp.next = current.next;
}
}
}
public static void main(String[] args) {
Scanner scanf = new Scanner(System.in);
int deck_count;
int choice;
int ans;
System.out.println("How many decks do you want to use?\n");
deck_count = scanf.nextInt();
System.out.println("How do you want to shuffle the decks?\n 1. Together\n 2. Indivisually");
choice = scanf.nextInt();
init_deck();
if (choice == 2){
for (int j = 0; j < deck_count; j++){
Card[] temp_deck = primary_deck;
shuffle.shuffle(temp_deck, 108);
for (int k = 0; k < 108; k++){
playing_deck.addCard(temp_deck[k]);
}
}
}
if (choice == 1){
Card[] temp_deck = new Card[108*deck_count];
int to_card = 0;
for (int j = 0; j < deck_count; j++){
for (int k = 0; k < 108; k++){
temp_deck[to_card] = primary_deck[k];
to_card++;
}
}
shuffle.shuffle(temp_deck, 108*deck_count );
for (int x = 0; x < 108*deck_count; x++){
playing_deck.addCard(temp_deck[x]);
}
}
System.out.println("Do you want to remove action cards from the game?\n 1. NO\n 2. YES");
ans = scanf.nextInt();
if (ans == 2){
playing_deck.remove_actionCard();
}
playing_deck.display();
}
}