program5.java:18: non-static method newGame(game) cannot be referenced from a static context.
The particular line giving me this error is "goFish = newGame(goFish);" goFish is a game struct. There's more to this program that I don't think is causing the problem, but I guess I wouldn't be posting here if I really knew so please let me know if I should post the whole thing.
*edit: I found out that if I put static after public in the newGame and deckInit functions it works, but I having a feeling that's not the right way to do it.
Main:
public static void main (String args[]) {
game goFish = new game(); //struct so methods can pass deck & hands
goFish.gDeck = new bag(52);
goFish.hand1 = new bag(5);
goFish.hand2 = new bag(5);
goFish.hand3 = new bag(5);
goFish.hand4 = new bag(5);
goFish = newGame(goFish);
System.out.println(goFish.hand1.delete().toString());
System.out.println(goFish.hand2.delete().toString());
System.out.println(goFish.gDeck.delete().toString());
} //main
A struct containing the deck and four hands:
class game {
public bag gDeck;
public bag hand1;
public bag hand2;
public bag hand3;
public bag hand4;
} //game struct
The newGame function:
public game newGame(game fish) {
int i = 0;
//put all 52 cards in deck
fish.gDeck = deckInit();
//Deal four hands
for(i = 0; i < 5; i++){
fish.hand1.add(fish.gDeck.delete());
}
for(i = 0; i < 5; i++){
fish.hand2.add(fish.gDeck.delete());
}
for(i = 0; i < 5; i++){
fish.hand3.add(fish.gDeck.delete());
}
for(i = 0; i < 5; i++){
fish.hand4.add(fish.gDeck.delete());
}
return fish;
} //newGame
This post has been edited by drpppr242: 02 November 2008 - 10:21 PM

New Topic/Question
Reply




MultiQuote






|