Skip to main content
gamedev.net
🔒 Locked

[java] trouble x 10

Started by sushi-one Jan 16, 2004 at 4:56 PM 7 replies 550+ views
Original Post
sushi-one
sushi-one
Just write my question again in a new thread How can I (if possible) controll a variable in "SpaceInvader" class from my "player" class?? (I need to be able to control some of the game stated from the "Player" class?? I thought it only was to write "extends Player" in my "SpaceInvader" class, and use the variable as it was made in "SpaceInvader"..?? Hans-Petter
Hans-Petter Harveg
garazdawi
garazdawi
Could u write down some psudocode for what you want to do? I''m not usre I get hwat you want to say....
garazdawi - 'I put the laughter back in slaughter'
sushi-one
sushi-one

ok, this is preaty much like I have done it:

------------------------

class player {
final int intro=1;
final int playgame=2;
int state=intro;

void handleinput() {
if( keyDown ) {
// I want to change the state here
state = playgame;
}
}
}


class space extends player {

(and in the rungame method):
handleinput();

switch() {
case intro:
break;

case playgame:
break;
}

}

------------------------

The strange thing is, this is working if I change the state in the "player" constructor only, but if I change it in any other method, it do not work.. :/



Hans-Petter
Hans-Petter Harveg
garazdawi
garazdawi
try placing a super before referencing the variables in the space class. super.state=super.playgame or something lik ethat.... not sure if it will help at all, but maybe it''s wortha try....
garazdawi - 'I put the laughter back in slaughter'
sushi-one
sushi-one
no, i still can''t make it work.. hehe, the reason is probably just becaouse I''m very stupid, but is''t this like the heaven of OOP??

Hans-Petter
Hans-Petter Harveg
garazdawi
garazdawi
quote:
Original post by sushi-one
no, i still can''t make it work.. hehe, the reason is probably just becaouse I''m very stupid, but is''t this like the heaven of OOP??

Hans-Petter

The thing is that the way you describe it it should work.

public class test {
public static final int STATE_1=0;
public static final int STATE_2=1;
protected int state;
public test(){
state=STATE_1;
}

public static void main(String[] arg){
test2 ts=new test2();
}
}

class test2 extends test {
public test2(){
super();
System.out.println("Initial state is="+state);
System.out.println("Changing state...");
state=STATE_2;
System.out.println("Final state is="+state);
}
}


This code snippet works fine. Is this something like what you wanted or...?
garazdawi - 'I put the laughter back in slaughter'
sushi-one
sushi-one
jupp, thanx! It works fine now, really cool

Hans-Petter
Hans-Petter Harveg

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.