Hi
This is the first time for me asking for help in forums on the net. I hope ill make myself understood. And sorry for my bad english.
I have 4 classes: Spelare, Händelser, SpelPlan and Start.
In the class "Händelser" a random message apperas, if the players land on a couple of specific squares. A message is supposed to change the players status, such as position (move to GO), money (paying or reciving).
The class "Spelare" have all the necessary methods for moving, adding money, and stuff like that.
The SpelPlan is just the GameBoard, with methods for changing the owner and so on.
In the class Start (where the method "main" is) i create a new player and a new SpelPlan like this:
and if i for instance want to change the position of the player:
I can change the players position, adding money and all that from the Start class. If the player land on a free space, i take information from the SpelPlan class about that free space, and the player can choose to buy it.
When the player arrives on specific spaces for messages, i create a new Händelser:
And a random message apperas. BUT i want that random message, what ever that is, to be able TO CHANGE the status of the player i created in the Start class. For instanse: "Move 3 steps forward" would be able to call the method "movePlayer " in the Player class and change his position.
Can it be done, and if yes: how?
I really hope you guys understood what i ask, 'cos im confused myself.
Im glad for any help i get.
I dont know if the code is neccesary but here is a simplified versions:
The SpelPlan i just one array and one matrix, and i have already wrote the important codes in Start.
This is the first time for me asking for help in forums on the net. I hope ill make myself understood. And sorry for my bad english.
I have 4 classes: Spelare, Händelser, SpelPlan and Start.
In the class "Händelser" a random message apperas, if the players land on a couple of specific squares. A message is supposed to change the players status, such as position (move to GO), money (paying or reciving).
The class "Spelare" have all the necessary methods for moving, adding money, and stuff like that.
The SpelPlan is just the GameBoard, with methods for changing the owner and so on.
In the class Start (where the method "main" is) i create a new player and a new SpelPlan like this:
Code:
private spelPlan planen=new spelPlan(); private Spelare[] spelare=new Spelare[2];
Code:
player[0].sättNuvarandePosition(20);
When the player arrives on specific spaces for messages, i create a new Händelser:
Code:
if (pos==4 || pos==8)
{
new händelser();
}
Can it be done, and if yes: how?
I really hope you guys understood what i ask, 'cos im confused myself.
Im glad for any help i get.
I dont know if the code is neccesary but here is a simplified versions:
The SpelPlan i just one array and one matrix, and i have already wrote the important codes in Start.
Code:
import java.util.*;
public class Spelare {
private String namn;
private int pengar, position, id;
spelPlan planen=new spelPlan();
Spelare(){}
Spelare(String namn){
this.namn=namn;
}
Spelare(int id,String namn){
this.id=id;
this.namn=namn;
pengar=20000;
}
//this methods move the player on a 40 square board (like monopoly)
public int flyttaSpelare(int steg){
if((position + steg) > 40){
position = (position + steg - 40);
}
else
position =position+steg;
return geNuvarandePosition();
}
//this return the current position of the player
public int geNuvarandePosition(){
return position;
}
//this changes the position of the player
public int sättNuvarandePosition(int position){
this.position=position;
return position;
}
}
import java.util.Random;
public class händelser {
private Random chans = new Random();
private spelPlan rutor= new spelPlan();
int slump;
händelser()
{
slumpChans();
}
//this method creates a random message from the String array
public String slumpChans()
{
String[] moveMessage = {"Move 3 steps forward","Collect 300$",
"and so on...."};
slump=chans.nextInt(moveMessage.length);
System.out.println("du har kommit till chans");
System.out.println(moveMessage[slump]);
return moveMessage[slump];
}
}
Comment