View unanswered posts | View active topics
It is currently Wed May 07, 2025 2:45 pm
Author |
Message |
big_D
What's a life?
Joined: Thu Apr 23, 2009 8:25 pm Posts: 10691 Location: Bramsche
|
For a start, the first class should be Dart, with a method Throw!
The class is the object, throw dart is an action, therefore it has to be a method!
I would set it up with something like
public class Game() { Dart dart = new Dart; Board board = new Board; int dartsThrown = 0;
for(i = 1; i <= 3; i++) { if(quit) { break; } else { board.hit(dart.throw()); } }
Something along those lines, the dart would then have a throw method, which would interact with the board, either you generate a random number in the dart.throw method and pass it to the board.hit method or pass the board into the dart - the former makes more logical sense
The throw method would return either the x,y co-ordinates or a number representative of its board location - easier to implement than having board co-ordinates, but maybe less accurate.
_________________ "Do you know what this is? Hmm? No, I can see you do not. You have that vacant look in your eyes, which says hold my head to your ear, you will hear the sea!" - Londo Molari
Executive Producer No Agenda Show 246
|
Wed Dec 02, 2009 6:02 pm |
|
 |
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|

Yep, Dave pretty much said it all. As an outline you should be looking at something like this... CLASS 1public class Board() { public Board() { } public int hit(int aimNum) { /* **Generate the hit number depending on what number was aimed at **i.e. if aimed at 20 then choose 1, 5 or 20 randomly. */ } //end hit method public int getModifier() { /* **randomly generate a number 1, 2 or 3 (maybe you could weight the **probability in favour of 1) this is the modifier. */ } //end getModifier method public int aim(String targetArea) { /*Generate a random number corresponding to the area targeted.*/ return aimNum. } //end aim method } //end Board class CLASS 2public class Game() { private int hitNum; private int modifier; private int turnTotal; private String targetArea; private Board board; public Game() { board = new Board(); /* **Put your game loop into here. ** i.e. to get the results from one turn of three throws you would do this... */ turnTotal = 0; for (int i = 1 ; i <= 3 ; i++) { targetArea = //Input area to be aimed at (i.e. top, left, right, bottom, centre)// hitNum = board.hit(board.aim(targetArea); modifier = board.getModifier(); //print congratulations you scored hitNum * modifier with that throw// turnTotal = turnTotal + (hitNum * modifier); } // print You scored turnTotal for those three darts!// } //end Game constructor method public static void main(String [] args) { //main method will run when you start the program. new Game(); } } //end Game class I would suggest getting a beginner book along the lines of ... http://www.amazon.co.uk/Head-First-Java ... 257&sr=8-1 ... this will help you get your head around objects, classes, methods, variables, private variables, loops, etc... It will be a big help for you! ::EDIT forget about the Dart class. You don't need it.
All you need is a board.
(In the real world) The throw of a dart doesn't actually do anything. First you AIM at a part of the BOARD. Then once you have thrown the dart you HIT a NUMBER on the BOARD and could possibly land a MODIFIER (i.e double, treble).
The dart itself doesn't do anything.
N.B. this is one way out of myriad ways of doing the same thing. Although, thinking about it is prob the way I'd start.
|
Wed Dec 02, 2009 6:41 pm |
|
 |
big_D
What's a life?
Joined: Thu Apr 23, 2009 8:25 pm Posts: 10691 Location: Bramsche
|
I think you are right.
As I was writing my previous response, I thought that the Dart was a bit redundant, but couldn't get around the fact that it is an object in the real game...
I guess throwDart could be a method of board, for example, which would essentially be a combination of your hit and modifier?
Edit: You also need to take into account aiming at the inner and outer bullseye! Those are special cases, which would alter the way hit and modifier work! Instead of having 20 = 5, 20, 1, it would need to include the chance of hitting all other numbers.
Don't forget to include a modifier for going outside the target!
_________________ "Do you know what this is? Hmm? No, I can see you do not. You have that vacant look in your eyes, which says hold my head to your ear, you will hear the sea!" - Londo Molari
Executive Producer No Agenda Show 246
|
Wed Dec 02, 2009 8:04 pm |
|
 |
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
I was thinking that also  Although I think getting a working program with no bullseye and no misses would be a good start and then things can be added later 
|
Wed Dec 02, 2009 8:18 pm |
|
 |
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
I suppose you could include a dart class and the throw would return a boolean of hit or miss.
If you hit then you can go on to find what you hit.
i.e.
board.aim dart.throw if miss break board.hit if bullseye break board.getmodifier
or something
Maybe it's over complicating it though?
|
Wed Dec 02, 2009 8:28 pm |
|
 |
kalisclark
Occasionally has a life
Joined: Mon May 04, 2009 10:16 am Posts: 130 Location: In between a rock and a hard place
|
Thanks guys, I will be doing Java tomorrow and give this a crack, wow this is complicated, its like trying to solve a puzzle.
If you have any other suggestions please feel free to add them.
I would like to thank you guys for taking the time out to read over my posts, I know you probably have to look at java all day at work and its kinda the last thing you wanna see when you go home, so thank you very much.
Kal
_________________ [color=#BF0000][b]Arctic Cooling Freezer 7 Pro 620W Corsair HX Series Modular SLi PSU Intel Core 2 Quad-Core Q6600 G0 SLACR, 95W, S775, 2.40 GHz asus maximus formula, iX38, S 775 ASUS GEFORCE EN8800 GT 512MB GDDR3
|
Wed Dec 02, 2009 11:05 pm |
|
 |
big_D
What's a life?
Joined: Thu Apr 23, 2009 8:25 pm Posts: 10691 Location: Bramsche
|
This is why you generally started with the analysis, get a signed off design from the client, mock it up in UML, ensure the classes all work together, dry run the UML, then write your test plans, before finally starting to write any code, then you start running it against the test plans.  The actual coding is probably less than about 10% of the whole process of creating an application.
_________________ "Do you know what this is? Hmm? No, I can see you do not. You have that vacant look in your eyes, which says hold my head to your ear, you will hear the sea!" - Londo Molari
Executive Producer No Agenda Show 246
|
Thu Dec 03, 2009 5:16 am |
|
 |
EddArmitage
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 9:40 pm Posts: 5288 Location: ln -s /London ~
|
It's all C++ and Ada here. (8-p)
|
Thu Dec 03, 2009 8:29 am |
|
 |
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
My work is all Progress (OpenEdge) so it's ctually quite nice to be able to do some Java every now and then. I prefer Java and OO programming in general.
|
Thu Dec 03, 2009 8:42 am |
|
 |
finlay666
Spends far too much time on here
Joined: Thu Apr 23, 2009 9:40 pm Posts: 4876 Location: Newcastle
|
C++,C#,C and other stuff here, but not Java
_________________TwitterCharlie Brooker: Macs are glorified Fisher-Price activity centres for adults; computers for scaredy cats too nervous to learn how proper computers work; computers for people who earnestly believe in feng shui.
|
Thu Dec 03, 2009 10:22 am |
|
 |
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
Any updates yet?
|
Mon Dec 07, 2009 1:35 pm |
|
 |
kalisclark
Occasionally has a life
Joined: Mon May 04, 2009 10:16 am Posts: 130 Location: In between a rock and a hard place
|

Thanks guys,
We have been told its not what they are looking for lol, so we need to tear it apart and put it in different classes lol.
Im sure we will get there but this is what we were told haha.
A number of you seem to have misinterpreted the words "data structure" in the coursework handout. For part 1 it is not sufficient to have declared some int variables in the main() method of your application to store the number that is hit, whether there is a multiplier (double or treble) for that number, and what the score for the throw is. You need to create a "record" type for these results - that is, a Java class with instance variables that hold these results. You can then have three instances of that class (as an array, or as three instance reference variables) in a Turn class to store the results of a "turn" (three dart throws).
Later in the assignment you are asked to provide a facility to re-create a game of darts by reconstructing the sequence of throws - this is most easily done by using an array whose elements are instances of the class that stores the results for a turn.
Solutions that use only local primitive type variable declarations in the main() method to store the results will not be sufficient to pass the coursework.
I swear this Java is gonna be the death of me lol.
Speaking of death, anyone here ever used Scratch lol im having trouble setting health for my platform game haha. one thing at a time though I guess. I have 8 days to finish this Java project, do think its possible?
Thanks for all your help guys, its much appreciated.
_________________ [color=#BF0000][b]Arctic Cooling Freezer 7 Pro 620W Corsair HX Series Modular SLi PSU Intel Core 2 Quad-Core Q6600 G0 SLACR, 95W, S775, 2.40 GHz asus maximus formula, iX38, S 775 ASUS GEFORCE EN8800 GT 512MB GDDR3
|
Wed Dec 09, 2009 1:11 pm |
|
 |
EddArmitage
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 9:40 pm Posts: 5288 Location: ln -s /London ~
|
Easy (8-p) 8hrs is when you need to start worrying about how much coffee you have left in stock (8-p)
|
Wed Dec 09, 2009 1:14 pm |
|
 |
finlay666
Spends far too much time on here
Joined: Thu Apr 23, 2009 9:40 pm Posts: 4876 Location: Newcastle
|
8 days is easy, I have started my networked Pong game and could finish it easily in 8 days, that is from scratch implementing my own UDP method and having a cross language interface between C and Java.
_________________TwitterCharlie Brooker: Macs are glorified Fisher-Price activity centres for adults; computers for scaredy cats too nervous to learn how proper computers work; computers for people who earnestly believe in feng shui.
|
Wed Dec 09, 2009 1:45 pm |
|
 |
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|

I think you really should change the way in which you are going about this project.
What I normally do (at least in my head) is create a UML diagram of the thing I am going to produce.
That is, a quick overview of what classes I will have and what methods/variables they will have in them.
In order to create it think first what you need to do. Firstly you just need to be able to recreate a single "turn" in which there are three "throws". You then need to to somehow save the score from each throw in the turn. Secondly you need to create a "game" which involves multiple turns. Once you have the first bit set up the second is easy.
Notation like this...
ClassName ------- variable 1 variable 2 ------- method 1 method 2
To start with you will have something like:
Throw ------- Integer numberHit Integer multiplier ------- getTotalScore return int Throw (constructor)
Turn ------- ArrayList throws ------- getTotalScore return int Turn (constructor)
Main ------- Turn turn ------- public static void main goes
So, your Main method will say something like....
Turn turn = new Turn(); System.out.println("You scored a total of " + turn.getTotalScore() + " with that turn");
That is all it needs.
Your Turn constructor will create the throws ArrayList and have a for loop that runs 3 times...
i.e. throws = new ArrayList();
for {int i = 0 ; i < 3 ;i++}
in which you will ask for an input number that the player wishes to hit.
Then it will add a new Throw object to the throws ArrayList...
i.e. throws.add(new Throw(targetNum));
That is all it needs.
Your throw constructor will take the targetNum and work out which actual number was hit and whether or not a multiplier was hit.
That is all it needs.
Now you have created three throws and calculated the scores and stored them and all you need to run is "new Turn();"!
Now when you run turn.getTotalScore() it will go through the ArrayList and get the totalScore from each throw adding them up as it goes and then return the total.
|
Wed Dec 09, 2009 6:54 pm |
|
|
Who is online |
Users browsing this forum: No registered users and 5 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum
|
|