내 플레이어 개체를 찾을 수 없지만이를 선언했습니다 ... 카드를 손에 넣으려고하면 어떤 오류가 수정됩니까?'심볼을 찾을 수 없습니다.'하지만 틀린 것이 없습니다.
여기에 메인 클래스의 관련 부분입니다 :
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
좋아, 우리 모두는 그 문제를 알고있다. 하지만 정확히 여기에서 성취하려고 노력하고 있습니다. 간단히 말하자면 전 세계적으로 트릭을하지 않을 수 있습니다. 따라서 프로그램을 통해 완전히 달성하려는 노력을 알기 전까지는 제안하지 않겠습니다. –