Campbell Ritchie wrote:Welcome to the Ranch
Nothing needs a “big” answer. Maybe lots of small answers. And that is how you should proceed. Lots of small steps. Start by working out how you can tell who has won the most games/points/whatever to be top of the leader board. To do that there are a few preliminaries: get pencil paper and eraser. And turn your computer off.
This doesn't seem to be a GUI topic, so I shall move this discussion.
Pawel Pawlowicz wrote:One idea is to create PlayerScore class that implements Comparable<PlayerScore >.
In compareTo method you could write logic that determines which score is "bigger" that other.
Grace Loughran wrote:And yes perhaps you are right about this not being a GUI topic...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Grace Loughran wrote:And yes perhaps you are right about this not being a GUI topic...
Unless you actually want to know how to paint things, or show panels and buttons and have them interact with each other, it almost never is.
GUI is all about presentation. You, on the other hand, have a problem to solve, namely: How to get the "leaders" out of a collection of items.
There are myriad ways of doing this, but using a TreeSet might be the simplest.
Winston
Campbell Ritchie wrote:Will a TreeSet cope with several players with the same scores?
Grace Loughran wrote:Can you perhaps, only if it's okay, give another suggestion on how I can approach this in an easier way?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Grace Loughran wrote:Can you perhaps, only if it's okay, give another suggestion on how I can approach this in an easier way?
Grace Loughran wrote: - Am I correct with my algorithm: Load the info first from the .txt file, add them up together with the current players' info, sort them all, overwrite the .txt file with the new info, then display them (only the top 5 though)?
Wow I'm a mess, my head is about to explode
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Programming is about breaking down problems. Right now you're all over the place because you're trying to do too much at once.
I should add that the above is only one way of doing it, but even if you decide to code it differently, concentrate on one thing at a time, and don't move onto the next until you know it works.
Grace Loughran wrote:Thank you so much for this Winston!
Now I have another problem:...
I need to output the top 5 from the list to a JTextArea and I've made some attempts.
I copied the sorted list (List) to another ArrayList because whenever I passed it to the GUI class using List I get an error saying there's a conflict between util and awt.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
So you've changed your code? That's a terrible reason to redesign.
GUI (which includes 'awt') is solely concerned with DISPLAYING (and maybe gathering) data, so if something in it causes your information design to be changed - choose another GUI.
GUI is glitz. It's shiny buttons and bouncing balls and scrollable text; it is NOT the heart of your project, it's the "chrome-plating".
I can (and have) designed entire information systems without it, so if you run into problems when using one, it's almost certainly because you don't understand what the GUI requires, which should be completely separate from how your information is structured. It's a glorified parrot.
And the first thing I see with your Leaderboard class is that it includes references to a 'textarea' (which I suspect is a GUI component).
DON'T.
The business of a Leaderboard is to return the "top" (or "bottom") n items of whatever list of "things" you hand it (ie, probably another List). It has nothing to do with display, or text areas, or buttons, or anything else to do with your screen.
Again: One thing at a time. Create a Leaderboard class that does exactly what I described. Worry about how you're going to display what it returns later.
HIH
Winston
Grace Loughran wrote:Really sorry, I hope you'll bear with me. Thank you for all the tips, really. About the GUI part, I'm quite confused though, are you simply implying that I stop using GUI...
And you suggested for me to choose another GUI...
(By the way the Leaderboard class is the GUI class to show the leaderboard and the Player is the class which has the logic for the leaderboard.
Suggestions/tips?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Grace Loughran wrote:Suggestions/tips?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
1. Separate your GUI from your game completely.
Winston Gutkowski wrote:
2. Keep your Player class for stuff to do with a single Player. Add another one to deal with all of them.
Winston Gutkowski wrote:
3. Your Game class appears to be an ActionListener, which is normally a GUI-type object. My advice: DON'T.
Grace Loughran wrote:By 'completely' what do you really mean? Because so far the code to perform the logical stuff and the code to deal with the GUI stuff are in separate classes.
Unfortunately that's actually my problem. It's a two-player game, and I'm not sure how to take info from both of the players.
I'm not sure what you mean, but though may I add that it's not the whole Game class (it contains more complicated-except-not-really stuff because it is the 'main' code of the game), I just included the part which I thought was relevant.
The Leaderboard class which handles all the GUI stuff by the way extends JFrame and contains a JLabel (for the image background) and a JTextArea, that's all. It doesn't implement any interface as well.
What I really need help about now is how to deal with taking information from both of the players.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
I think you need to get back to basics and think clearly about WHAT you need to do; not HOW you're going to do it.
And for that, your best friend is pencil and paper, NOT a Java IDE or editor.
(And don't worry; it's a common occurrence, even among us old warhorses. Design is NOT easy).
Winston
Grace Loughran wrote:Can't believe I hadn't thought of it before though.
But thanks for all the help, I'm keeping them all in mind!
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here