473,490 Members | 2,495 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Really hard to explain...

3 New Member
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:
Expand|Select|Wrap|Line Numbers
  1. private spelPlan planen=new spelPlan();
  2. private Spelare[] spelare=new Spelare[2]; 
  3.  
and if i for instance want to change the position of the player:

Expand|Select|Wrap|Line Numbers
  1. player[0].sättNuvarandePosition(20);
  2.  
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:
Expand|Select|Wrap|Line Numbers
  1. if (pos==4 || pos==8)
  2. {
  3.         new händelser();    
  4.  
  5. }
  6.  
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.

Expand|Select|Wrap|Line Numbers
  1.  
  2. import java.util.*;
  3. public class Spelare {
  4.     private String namn;
  5.     private int pengar, position, id;
  6.     spelPlan planen=new spelPlan();
  7.  
  8.     Spelare(){}
  9.  
  10.     Spelare(String namn){
  11.         this.namn=namn;
  12.  
  13.     }
  14.     Spelare(int id,String namn){
  15.         this.id=id;
  16.         this.namn=namn;
  17.         pengar=20000;
  18.     }
  19.  
  20.     //this methods move the player on a 40 square board (like monopoly)
  21.  
  22.     public int flyttaSpelare(int steg){
  23.         if((position + steg) > 40){
  24.             position = (position + steg - 40);
  25.         }
  26.         else
  27.             position =position+steg;
  28.         return geNuvarandePosition();
  29.     }
  30. //this return the current position of the player
  31.     public int geNuvarandePosition(){
  32.         return position;
  33.     }
  34. //this changes the position of the player
  35.     public int sättNuvarandePosition(int position){
  36.         this.position=position;
  37.         return position;
  38.     }
  39.  
  40.  
  41.  
  42. }
  43.  
  44.  
  45. import java.util.Random;
  46.  
  47. public class händelser {
  48.     private Random chans = new Random();
  49.     private spelPlan rutor= new spelPlan();
  50.  
  51.     int slump;
  52.  
  53.     händelser()
  54.     {
  55.         slumpChans();
  56.     }
  57.     //this method creates a random message from the String array
  58.     public String slumpChans()
  59.     {    
  60.         String[] moveMessage = {"Move 3 steps forward","Collect 300$",
  61. "and so on...."};
  62.         slump=chans.nextInt(moveMessage.length);
  63.         System.out.println("du har kommit till chans");
  64.         System.out.println(moveMessage[slump]);
  65.         return moveMessage[slump];
  66.  
  67.  
  68.     }    
  69.  
  70. }
  71.  
  72.  
Sep 22 '08 #1
10 1623
MarkoKlacar
296 Recognized Expert Contributor
Hi,

Visst går det att göra! Sure it can be done!

I would strongly recommend you to not use 'å', 'ä', 'ö' in you classnames, variables och method names.....

You need a String in the Spelare class that keeps track of the status, and you could create the methods getStatus() and setStatus(String newStatus) or similar...

The setStatus method could also contain the random generator.

Lycka till! Good luck!

/MK
Sep 23 '08 #2
doubleac
3 New Member
Hi and thanks for the reply (tack!)

Okey, ill have it in mind, thanks for the tip.

But i dont think i understood your answer. Well maybe i didnt explain good enough.

I already have a similar methods in the class Spelare for the status (the one you suggested), like "sättNuvarandePosition", "flyttaSpelare" and so on.
What i need is the Händelser class to CHANGE (calling (anropa) any of the methods in the class Spelare) for instanse the position of the Player class the one i created in Start!

Im going to write it in swedish, i hope its ok.

I klassen Start har jag skapat ett objekt (säger man så?) av Spelare.
Expand|Select|Wrap|Line Numbers
  1. Spelare new sp();
  2.  
Därifrån kan jag genom att anropa t.ex.

Expand|Select|Wrap|Line Numbers
  1. sp.flyttaSpelare(5); //det här kommer att förflytta spelaren 5 steg.
  2.  
..flytta spelare 5 steg. Nu hamnar spelare på en ruta som ska generera ett medelande, t.ex "Gå fram 3 steg". Det här går smärtfritt, eftersom objektet av Spelare som jag har skapat ligger i klassen Start.

Men jag vill inte ha dessa medelande i classen Start, för det skulle bli för mycket kod på samma ställe. Plus att projektet kräver att man har många klasser.Därför vill jag, varje gång någon spelare hamnar på en likadan ruta, skapa ett objekt av klassen Händelser som skall sköta om sånt.
Alltså:Hur skall jag kunna styra objektet "sp" (t.ex. ändra position), som är skapad i klassen Start, från klassen Händelser?

Du kanske redan har svarat på frågan, men isf förstod jag inte riktigt.

Tack!

Thx :)
Sep 23 '08 #3
chaarmann
785 Recognized Expert Contributor
Hi,
I would strongly recommend you to not use 'å', 'ä', 'ö' in you classnames, variables och method names.....
/MK
Why is Suns's Java API written all in English, and there are no local languages available? I mean the same API functions with German function names, Chinese or Arabic ones? Wouldn't it be easier for a Chinese or Arabic person to write source code in his own language with his own character set and keyboard?

I would strongly recomment not to use any language except English.
All of us understand english, but only a few speak your language.
Most times you can understand quickly the meaning of a function or variable by its english name. Just ask yourself: How likely is it that you would help somebody where you can understand what his code is doing within one minute, and on the other side how likely is it that you would help somebody where you need hours to understand because it's all in chinese, kisuaheli or other strange language you don't know?

With this in mind, you would use string constants instead of putting the strings directly.
Referring to your source code, you would change:
Expand|Select|Wrap|Line Numbers
  1. System.out.println("du har kommit till chans"); 
to:
Expand|Select|Wrap|Line Numbers
  1. private static final String YOU_HAVE_TO_COMMIT_UNTIL_CHANGED ="du har kommit till chans" // or whatever that means in english 
  2. System.out.println(YOU_HAVE_TO_COMMIT_UNTIL_CHANGED); 
And if you want to become very professional, read these strings from localized text files using java class java.util.Properties.
Sep 23 '08 #4
doubleac
3 New Member
Hi

Yeah i just started with swedish namnes (for class namnes and methods), didnt think about back then. From now on i wont.
Okey, ill have it in mind, thanks for the tip.
I refered to that in my last reply.

And i know that ill get a lot more help if i wrote in english, and i did, but couldnt explain good enough so i wrote another more detailed version in swedish because MarkoKlacar knows swedish. But of course you are right.

thx
Sep 23 '08 #5
myusernotyours
188 New Member
Thought I saw somewhere that as a policy on this site, Posts should only be in english... here

Kwani nini mbaya bwana?
Sep 23 '08 #6
JosAH
11,448 Recognized Expert MVP
Thought I saw somewhere that as a policy on this site, Posts should only be in english... here

Kwani nini mbaya bwana?
You're right; I wanted to send the OP a personal message about it but you beat me
so I'll write it here: please use the English language only here; it is the lingua Franca
overhere (and in a lot of other forums for that matter). If you're having problems
you can always PM a moderator or administrator and s/he will help you out.

kind regards,

Jos (moderator)

ps. and Swahili is not done either ;-)
Sep 23 '08 #7
Kevinyy
77 New Member
Why is Suns's Java API written all in English, and there are no local languages available? I mean the same API functions with German function names, Chinese or Arabic ones? Wouldn't it be easier for a Chinese or Arabic person to write source code in his own language with his own character set and keyboard?

I would strongly recomment not to use any language except English.
All of us understand english, but only a few speak your language.
Most times you can understand quickly the meaning of a function or variable by its english name. Just ask yourself: How likely is it that you would help somebody where you can understand what his code is doing within one minute, and on the other side how likely is it that you would help somebody where you need hours to understand because it's all in chinese, kisuaheli or other strange language you don't know?

With this in mind, you would use string constants instead of putting the strings directly.
Referring to your source code, you would change:
Expand|Select|Wrap|Line Numbers
  1. System.out.println("du har kommit till chans"); 
to:
Expand|Select|Wrap|Line Numbers
  1. private static final String YOU_HAVE_TO_COMMIT_UNTIL_CHANGED ="du har kommit till chans" // or whatever that means in english 
  2. System.out.println(YOU_HAVE_TO_COMMIT_UNTIL_CHANGED); 
And if you want to become very professional, read these strings from localized text files using java class java.util.Properties.
English is the universal language. Chinese are required to learn english in schools. so it would not be any more difficult to program in chinese than english
Sep 23 '08 #8
myusernotyours
188 New Member

ps. and Swahili is not done either ;-)
Would you by any chance know what that meant? Am willing to translate it for you. Effectively turning this in to a language forum. Isn't it anyway...
Sep 24 '08 #9
JosAH
11,448 Recognized Expert MVP
Would you by any chance know what that meant? Am willing to translate it for you. Effectively turning this in to a language forum. Isn't it anyway...
I don't really know what it means; I just recognized it as being Swahili. It has
a "sir" or "mister" in it and something "bad" but that's as far as I understood it ;-)

kind regards,

Jos
Sep 24 '08 #10
myusernotyours
188 New Member
I don't really know what it means; I just recognized it as being Swahili. It has
a "sir" or "mister" in it and something "bad" but that's as far as I understood it ;-)

kind regards,

Jos
Yah Almost there. Thought you only knew computers and trout fishing ;-)
Loose translation "Why, what's wrong man?"

Regards

Alex.
Sep 24 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

72
5300
by: Mel | last post by:
Are we going backwards ? (please excuse my spelling...) In my opinion an absolute YES ! Take a look at what we are doing ! we create TAGS, things like <H1> etc. and although there are tools...
5
1685
by: Simon Harvey | last post by:
Hi everyone, I'm hoping for a little bit of advice on the following. I am in the process of making a small application that can send, receive and store email messages. The current area that I am...
4
1509
by: Nip | last post by:
I am trying to make a database for my test participants. I have 10 participants and have a table with them called participants which includes an auto number ID and then the participant number and...
0
1076
by: TheConcernedOne | last post by:
We've got a lot to deal with these days. Terrorism, Recession, Weather and more. It's all got me concerned. I thought I'd tell you all about this group I found where everyday people get together...
5
1289
by: Miles Keaton | last post by:
I'm switching to PostgreSQL from MySQL. Using the SAMs book called PostgreSQL which has been great to skim the surface of the differerences. I had never even heard of things like triggers,...
1
3596
by: Troels Arvin | last post by:
Hello, In a DB2 LUW v. 8.1.1.96, I have a hard time giving users access to the db2expln utility. Let's say that user FOOBAR needs to be able to run the db2expln utility. I do: - provide...
18
2002
by: Earl Anderson | last post by:
First, I feel somewhat embarrassed and apologetic that this post is lengthy, but in an effort to furnish sufficient information (as opposed to too little information) to you, I wanted to supply all...
0
2176
by: raylopez99 | last post by:
I ran afoul of this Compiler error CS1612 recently, when trying to modify a Point, which I had made have a property. It's pointless to do this (initially it will compile, but you'll run into...
3
2852
jkmyoung
by: jkmyoung | last post by:
Hey, are there any sudoku experts out there? Can anyone tell me the next step in solving this sudoku and explain it properly? I've used all the rules I can think of but am now stuck. 51--263--...
0
7112
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6974
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7183
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6852
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4878
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3074
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
628
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.