Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Score Board
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
octopi




PostPosted: Thu Feb 12, 2004 12:09 am   Post subject: Score Board

code:
procedure addscore (name: string, score: int)
  var url:string:="http://turingscore.etw.ca/add.php?name=" +name + "&score=" + intstr(score);
  var conn : int
  var line : string
 
  for loopvar : 1..3
    conn := Net.OpenURLConnection (url)
    if (conn > 0) then
      get : conn, line
        exit when (line = "okay");
    end if
    Net.CloseConnection (conn)
  end for
end addscore

function getscore (place: int) : string
  var url:string:="http://turingscore.etw.ca/get.php?place=" + intstr(place) ;
  var conn : int
  var line : string := " "
  for loopvar : 1..3
    conn := Net.OpenURLConnection (url)
    if (conn > 0) then
      get : conn, line
      if(line = "okay") then
        get : conn, line : *
        exit
      else
        line := " "
      end if
    end if
    Net.CloseConnection (conn)
  end for
  result line
end getscore


%in the above, you'll notice it has a for loop that goes 1..3
%this just attempts to connect mulitple times, until the network
%connection works....if it works the first time, it exits the loop.


%addscore("etw.ca", 2000)
for score : 1..2
  put getscore(score);
end for



I'll post the php code sometime, in the PHP section, its pretty simple.

For those wondering/needing certain functions not availible in turing, it would be possible to make a function that would send the data to the server, be processed by the server, and then returned back to the user.

You could, for example, impliment a md5 function in turing, to allow you to have secure storage of passwords... by making a function that connects to a server and then has the server in php/perl/c/c++ etc.. preform a md5 of the data passed to it, and then it would return the result of the md5, back to the turing program.... this would take only one network connection.

What I mentioned above, is basically what is refered to by RPC, Remote Procedure Call, for anyone whos interested.
Sponsor
Sponsor
Sponsor
sponsor
netninja




PostPosted: Thu Feb 12, 2004 7:47 am   Post subject: (No subject)

awesome
GUI.GetScrollBarWidth : i




PostPosted: Fri Feb 13, 2004 5:30 pm   Post subject: (No subject)

your program looks realy good but my computer is being anoying and really slow and doesn't want to work right so i can't run it. Sad
jonos




PostPosted: Fri Feb 13, 2004 10:22 pm   Post subject: (No subject)

that is nice, but im not sure what score it gets. is it something on the compsci website?
octopi




PostPosted: Sat Feb 14, 2004 12:15 am   Post subject: (No subject)

Its a score board...its an example of a high score thing for a game...



you use the addscore command to add a new score to the scoreboard
and you use the getscore command to get a score from the scoreboard

code:
getscore(1)    gets the person in 1st place
getscore(3)    gets the person in 3rd

addscore("octopi", 500)     adds the score 500 to the score board, with the name octopi.
apomb




PostPosted: Mon Feb 16, 2004 8:32 pm   Post subject: (No subject)

So just a question ... adding this to a pong program for example could keep the score ... if you posted it on the internet?
octopi




PostPosted: Mon Feb 16, 2004 10:09 pm   Post subject: (No subject)

Posted it on the internet?

If you added this code to your pong game, so that the addscore function was called when the game was over, it would record the name, and score of the person on the internet,


you can then retrieve that saved score from the internet using the getscore function.


If you made a compiled version of your game, and then gave it to a few people, everyone with an internet connection would be able to save there scores, and see the top scores of the others.
apomb




PostPosted: Tue Feb 17, 2004 10:27 am   Post subject: (No subject)

Awsome... ill try it ... is that ok:?:
Sponsor
Sponsor
Sponsor
sponsor
octopi




PostPosted: Tue Feb 17, 2004 11:38 am   Post subject: (No subject)

Yah, go ahead....thats the reason I posted the code.

If you want I can set up your own score board, for you...so that you can use it in your code and not have other people interfering with it.
octopi




PostPosted: Tue Feb 17, 2004 12:00 pm   Post subject: (No subject)

code:
procedure addscore (name: string, score: int)
  var id:string:="yourid"
  var url:string:="http://turingscore.etw.ca/add.php?id=" + id +"&name=" + name + "&score=" + intstr(score);
  var conn : int
  var line : string:=""
  for loopvar : 1..3
    conn := Net.OpenURLConnection (url)
    if (conn > 0) then
      get : conn, line
      Net.CloseConnection (conn)
      exit when (line = "okay");
    end if
  end for
  if(line not= "okay") then
    put "No network connection."
  end if
end addscore

function getscore (place: int) : string
  var id:string:="yourid"
  var url:string:="http://turingscore.etw.ca/get.php?id=" + id +"&place=" + intstr(place) ;
  var conn : int
  var line : string := " "
  for loopvar : 1..3
    conn := Net.OpenURLConnection (url)
    if (conn > 0) then
      get : conn, line
      if(line = "okay") then
        get : conn, line : *
        exit
      else
        line := " "
      end if
      Net.CloseConnection (conn)
    end if
 
  end for
  %if(line = " ") then
  %  put "No network connection."
  %end if
  result line
end getscore


%in the above, you'll notice it has a for loop that goes 1..3
%this just attempts to connect mulitple times, until the network
%connection works....if it works the first time, it exits the loop.


%addscore("etw.ca", 2000)
for score : 1..2
  var res:string:= getscore(score);
  if (res not= " ") then
    put res
  else
    put "No network connection."
    exit
  end if
end for


This version adds some error checking. If it can't connect to the server it will show an error message saying No network connection.

It also adds support for an ID tag, just pick some random word...maybe the name of your program, and replace yourid with the word....make sure you put it in both places, spelt the same.

I will add support to the php code later tonight, so that the id's will all be seperate. (other program's scores won't overlap.)
Mazer




PostPosted: Tue Feb 17, 2004 2:00 pm   Post subject: (No subject)

Is it possible to have the PHP script or whatever take the information being sent by this program and update a webpage with the top 10 scores or something?
octopi




PostPosted: Tue Feb 17, 2004 4:44 pm   Post subject: (No subject)

Sure.

http://192.etw.ca/view.php?amount=10&place=0

When I get time, I'll post this in php forum too.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 12 Posts ]
Jump to:   


Style:  
Search: