#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2011
    Posts
    3
    Rep Power
    0

    Game Improvement


    So. I am new to this site, and don't really know the most efficient ways of finding the information I'm looking for, so I'll just post and work with what I hear. Here goes:

    I have designed a college basketball simulation game (and am currently working on an NBA version.) This game is not the program in question. Instead, I have written a program to help me with the game, specifically by handling the game simulating (which is a pain to do by hand.) Recruiting, stat compiling and standings adjustments are all done in excel.

    The game-simulation program works fine, though is fairly rudimentary. It's written in Java because I needed a language that ran easily on macs. All the team and player variables are defined in the program itself - the interface is simply "give me the numbers of the two teams" (which of course correlate to the appropriate subscripts) "and I'll sim the game."

    Here is what I want. I want some way to have a file/database that the game continuously updates. To have every team's players/stats/scores/wins/whatever in this file, have it updated as the season progresses, and then to write the results back to this file. If I can accomplish this (which shouldn't be that hard, in theory) my life would get much better.

    My first instinct was to create a text file as the basic data file, and then read it and write it back later, which is what I would have done in Pascal. But I ran into serious issues trying to code that - getting both integers and strings out of the file alone created issues.

    I am a fairly novice programmer with Java, and don't really know where to go with this. I don't know if I'm simply missing some simple file R/W commands, or if I should be looking for some kind of database functionality.

    I would appreciate any feedback you guys can offer.
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,730
    Rep Power
    1959
    If you have problem to read the file, it would be nice if you can explain how you created the file.
    What kind of structure did you use for the file or want to use? comma-separated value (csv)? xml? something else?

    if you have any relevant code, please post it. Remember to use code tags.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2011
    Posts
    3
    Rep Power
    0
    Originally Posted by MrFujin
    If you have problem to read the file, it would be nice if you can explain how you created the file.
    What kind of structure did you use for the file or want to use? comma-separated value (csv)? xml? something else?

    if you have any relevant code, please post it. Remember to use code tags.
    Here's what appears to be the relevant code:


    Scanner data = new Scanner("cbbdata.txt");

    try {

    BufferedReader brdata = new BufferedReader(new
    FileReader("cbbdata.txt"));

    for (x=0;x<8;x++){
    CName[x]=brdata.readLine();
    }

    TName = brdata.readLine();
    mascot = brdata.readLine();
    conf = brdata.getlnInt();
    wins = brdata.readInt();
    losses = brdata.readInt();
    pf = brdata.readInt();
    pa = brdata.readInt();

    I'm not actually getting errors in the running, it's giving me the 'cannot find symbol' error on compilation.

    The file is just a text file with enters marking entries, ie:

    Alabama
    Crimson Tide
    6
    Eric Dyment
    5

    And so on.

    Again, a serious novice here; please assume that I'm fairly ignorant and dense, it may save time.
  6. #4
  7. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,730
    Rep Power
    1959
    Please post the complete error message.



    btw, you forgot the code tags (is explained in the stickies)
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2011
    Posts
    3
    Rep Power
    0
    Sorry about that. Try #2:

    Code:
    Scanner data = new Scanner("cbbdata.txt");
    		
    		try {
    		
    		BufferedReader brdata = new BufferedReader(new
    				FileReader("cbbdata.txt"));
    		
    		
    				
    			for (x=0;x<8;x++){
    				CName[x]=brdata.readLine();
    			}
    				
    			TName = brdata.readLine();
    			mascot = brdata.readLine();
    			conf = brdata.getlnInt();
    			wins = brdata.readInt();
    			losses = brdata.readInt();
    			pf = brdata.readInt();
    			pa = brdata.readInt();
    Below is one sample compilation error.

    texttest.java:40: cannot find symbol
    symbol : method readInt()
    location: class java.io.BufferedReader
    pf = brdata.readInt();
  10. #6
  11. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,730
    Rep Power
    1959
    If you look at the BufferedReader API , you can see there is no functions called readInt().

    You will have to use readLine first and then convert it to an integer.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2011
    Posts
    2
    Rep Power
    0
    text files is a tough way to go with this game. Is it meant to remain a stand alone that people download and play on their pc/mac and never interact with other players, or do you hope at some point to have leagues and PvP?

    you might want to consider adding some sort of database as opposed to text files, especially if the game will eventually incorporate PvP, standings, leagues, hall of fame, records etc. This would allow you to store the data on a web server and help keep things honest (though people could possibly hack/reverse engineer the client and still pass back results that had been fudged)

IMN logo majestic logo threadwatch logo seochat tools logo