Solved

save high score

Posted on 1997-03-20
1
527 Views
Last Modified: 2006-11-17
HOw can I save high score in my applet game ?
0
Comment
Question by:mindtwisted
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

696 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