1
找不到我的播放器對象,但我宣佈了它們...當我嘗試添加卡片時,什麼會解決我的錯誤?'找不到符號',但我沒有看到任何錯誤
這裏是主類的相關部分:
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
好的,我們都知道這個問題。但是你究竟想在這裏完成什麼?一個簡單的全局聲明可能不會訣竅,所以我不會建議,直到我知道你想完全用你的程序完成什麼。 –