• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Help with my game.

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello. I'm creating a game where people can set up an account. Their registration information includes but is not limited to a login and a password. The login and the password are used to sign in. I store the sign in information in a player object, and each player object is stored in an Array List called players. How do I prevent the player objects from being deleted when I compile the program. Am I doing this the right way? Should I be storing the players sign in information in a file? If so, I'm not sure how to do this. Please help. Thank you. My code:

[edit]Newlines because lines too long. CR[/edit]
 
Ranch Hand
Posts: 95
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dude, please, use the code tags. Edit your message.
Do this: click the Code button. Paste your code. Click do Code button again.

This way people can read your code in a better way and the chances that someone help you is bigger
Sorry my english.
 
John Michaels
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you dude. Sorry I didn't do that before. That was my first post.
 
Ranch Hand
Posts: 686
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you only want to have a few "pretend" users to work with while you develop the game, then consider having calls to the player constructor in your main method, where the player info such as name, etc. is hard coded into the constructor call. This will allow you to continue with developing the game without having to enter the user info each time.

This is a temporary solution that is useful if you don't want to deal with files yet. If you ever reach the point where real people will be using the game without your intervention, then you can deal with creating files at that time.

keep in mind as you develop the game that you may wish to store additional info with each user, such as the player's high score. You may also wish to have a way to store the highest score among all the users.
 
Marshal
Posts: 80754
486
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As well as code tags, please make sure your lines are a reasonable length. I ahve been back and "broken" the lines so your whole code fits onto the width of the screen.

Never say if (x == true) . . . nor if (x == false) . . . That is poor style and also liable to serious errors if you mistakenly write = for ==. You write if (x) . . . or if (!x) . . .
 
Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
John, the simple answer to your question is yes, you do want to store that data in some type of file or DB. If you are saving that information inside an object that is only in memory than every time your server resets or you have to start the application over again you will lose all of your data. Personally I would recommend using a lightweight DB program like MySQL to store the info. This makes it easy to check for existing players, and other data gathering without having to reinvent the wheel.

GL and hope to see you on the JavaRanch Game Forums as well.
 
John Michaels
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you guys. BTW, what is my sql exactly? Is it what I need if I want to keep track of multiple users simultaneously?
 
Fred Hamilton
Ranch Hand
Posts: 686
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Michaels wrote:Thank you guys. BTW, what is my sql exactly? Is it what I need if I want to keep track of multiple users simultaneously?



mySQL is a very popular server based database application. A lot of web hosting providers have it on their servers. It is used by many big websites to store user registration info.

If you intend design your game so that users run it from a website, then mySQL is a logical choice for storing user info. You would probably need to learn some html and some php in order to make use of it to validate users of your java application. So you do have your work cut out for you.

http://www.mysql.com/


p.s. it is appropriate for multiple simultaneous users. In your case it would be used for storing registration information about users. and maybe also game history information, if a game extends past one session. If you design things right, mySQL will not care how many users you have at any one time.
 
John Michaels
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Fred. But what if I plan on making a very small website, one that might only have a few people logged on at any given time. Also, I don't plan to have that many registered users. It's just something basic, something my friends and I can use. You register, you place a bet, people can accept, and one party wins. The program does this and also keeps track of who owes who money. Is my sql necessary? Or would it make more sense to do something else, something a bit simpler? Should I just learn it regardless, as it would be beneficial to know for future projects? And do you have to pay?
 
Fred Hamilton
Ranch Hand
Posts: 686
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Michaels wrote:Thank you Fred. But what if I plan on making a very small website, one that might only have a few people logged on at any given time. Also, I don't plan to have that many registered users. It's just something basic, something my friends and I can use. You register, you place a bet, people can accept, and one party wins. The program does this and also keeps track of who owes who money. Is my sql necessary? Or would it make more sense to do something else, something a bit simpler? Should I just learn it regardless, as it would be beneficial to know for future projects? And do you have to pay?



I use x10hosting.com, they have a free service that includes mySQL, php, etc.

You kind of answered your own question. If you want to learn mySQL, then go ahead and use it. But it is not a necessity. If the program is only gonna be used by you and a few of your friends, then you don't have to use files at all if you don't want, you're calling the shots.

Did my other post about have constructor calls with hard coded values make sense to you? That will work and eliminate the need for files. You would just need to update your source code when you added a new user.

edit: ok, I just noticed your comment about keeping track of bets and who owes who. AS I think about it more. this sort of thing might be rather tricky to do without files.
 
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Michaels wrote:Thank you Fred. But what if I plan on making a very small website, one that might only have a few people logged on at any given time.



If you thinking of a web site where people can log in and place bets - you'll need something more than Java -- Servlets, JSp maybe Applets - but a plain Java class won't work!

The current program reads input data of the console - so it will only work on one PC at a time - You could get different people to play it from all over - If you get an online database - Reading and writing into local Files won't do the trick here.
 
Fred Hamilton
Ranch Hand
Posts: 686
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sam Mercs wrote:

John Michaels wrote:Thank you Fred. But what if I plan on making a very small website, one that might only have a few people logged on at any given time.



If you thinking of a web site where people can log in and place bets - you'll need something more than Java -- Servlets, JSp maybe Applets - but a plain Java class won't work!

The current program reads input data of the console - so it will only work on one PC at a time - You could get different people to play it from all over - If you get an online database - Reading and writing into local Files won't do the trick here.



agreed with regard to console input and one pc at a time. All in good time. Also, keep in mind that it's not a real betting site, I rather doubt credit cards will be involved.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic