?
Solved

save high score

Posted on 1997-03-20
1
Medium Priority
?
533 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 400 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

Industry Leaders: 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 This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

770 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