Он не может найти объекты моего Игрока, но я их объявил ... Что исправит мою ошибку, когда я попытаюсь добавить карты в руки?«Не могу найти символ», но я ничего не вижу
Вот соответствующая часть основного класса:
while (something2.equals("yes") || playercount < 2) //Add players to game
{
System.out.println("Would a(nother) player like to join?");
something2 = scan.nextLine();
System.out.println();
if (something2.equals("yes"))
{
if (playercount <= 4)
{
if (playercount == 0)
{
System.out.println("What is your name: ");
Player one = new Player(scan.nextLine());
playercount++;
System.out.println();
}
else if (playercount == 1)
{
System.out.println("What is your name: ");
Player two = new Player(scan.nextLine());
playercount++;
System.out.println();
}
else if (playercount == 2)
{
System.out.println("What is your name: ");
Player three = new Player(scan.nextLine());
playercount++;
System.out.println();
}
else if (playercount == 3)
{
System.out.println("What is your name: ");
Player four = new Player(scan.nextLine());
playercount++;
System.out.println();
}
else {System.out.println("Only four players are allowed.");
something2 = "no";}
}
}
else if (playercount < 2)
{
System.out.println("You need at least two players...");
System.out.println();
}
else something2 = "no";
}
//Deal cards
if (playercount == 2)
{
for (int i = 1; i < 8; i++)
{
one.addCard(Card.draw(deck));
deck = Card.getDeck();
two.addCard(Card.draw(deck));
deck = Card.getDeck();
}
}
else if (playercount == 3)
{
for (int i = 1; i < 8; i++)
{
one.addCard(Card.draw(deck));
deck = Card.getDeck();
two.addCard(Card.draw(deck));
deck = Card.getDeck();
three.addCard(Card.draw(deck));
deck = Card.getDeck();
}
}
else
{
for (int i = 1; i < 8; i++)
{
one.addCard(Card.draw(deck));
deck = Card.getDeck();
two.addCard(Card.draw(deck));
deck = Card.getDeck();
three.addCard(Card.draw(deck));
deck = Card.getDeck();
four.addCard(Card.draw(deck));
deck = Card.getDeck();
}
}
}
И мой игрок Класс:
import java.util.*;
public class Player
{
private static String name;
private static Card[] hand = new Card[52];
private static int handsize = 0;
//Constructor
public Player(String n)
{
name = n;
}
//Mutators
public static void addCard(Card c)
{
hand[handsize] = c;
handsize++;
}
//Accessors
public static String getName()
{
return name;
}
public static Card[] getHand()
{
return hand;
}
}
Я признателен за любую помощь, и я могу предоставить больше кода из моих классов, если вам это нужно.
Сфера применения, человек, прицел! –
Что значит? – William
Хорошо, мы все знаем проблему. Но что именно вы пытаетесь выполнить здесь. Простые объявить их по всему миру не могут сделать трюк, поэтому я не буду предлагать это, пока не узнаю, что вы пытаетесь полностью выполнить с вашей программой. –