Solved

save high score

Posted on 1997-03-20
1
519 Views
Last Modified: 2006-11-17
HOw can I save high score in my applet game ?
0
Comment
Question by:mindtwisted
1 Comment
 
LVL 2

Accepted Solution

by:
majkl earned 200 total points
ID: 1219175
Well. Applet cannot write or read from files, so you have to write another so called middle-ware program, that serves datas.
He sends to applet last high score and if player scores new high score, then send this data back to program, which stores it in the file.
This program is standalone application, which watch specific port for connections. Applet can connect to this program, because applets can connect to computer, from which they were loaded from. So program must run on web machine.
I will give you an example how to make a client, how to make a server is much easier.
 import java.io.*;
import java.net.*;

public  class SocketClient
{
  Socket socket;
  DataInputStream in;
  PrintStream out;
  boolean connected = false ;
 
  public SocketClient( String host, int port) throws IOException
  {
    socket = new Socket(host, port);
    in = new DataInputStream(socket.getInputStream());
    out = new PrintStream (socket.getOutputStream());
    connected = true ;
}

  public void write(String data)
  {
    out.println(data);
 }

  public String read() throws IOException
  {
    return in.readLine();
  }
 
  public void disconnect ()
     {
        if ( connected )
          {
             try
               {
                  in.close();
                  out.close();
               } catch (IOException e) { }
             if ( socket != null )
               {
                  try {socket.close();
                  }
                  catch (Exception e) { }
               }
          }
       in = null;
        out = null;
        socket = null;
        connected = false;
     }
 
 public boolean isConnected () { return connected;}



}
*********************************************
Use it in you code like this:
 try
   {    
    client = new SocketClient("name.of.the.machine",41234);
   }
            catch (IOException e )
if (client != null )
   {
     if ( client.isConnected())
       {
        //lets write something to server
      client.write("HELLO");
       //lets read lines until server closes connection
        while ( ( line = client.get_line()) != null)
                      {
                        System.out.println("GOT : "+line);
                      }
        //lets disconnect
        client.disconnect();

Hope this is the answer ?

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question