Solved

Indy - Making a game Protoptic

Posted on 2004-03-29
11
343 Views
Last Modified: 2010-05-18
Okie, I have a lil Web Game. It is a Flash - ASP - SQL game and now i want to migrate it to a Client - server - SQL game. All doing "fine" till now but... i have some questions and i will be glad if u guys help me a bit.

Delphi 7 Indy 9

since its a game protoptic with losts of variables:

1) Is WriteLn / ReadLn the best way to make my communications ? If not please give me a hint in what I should use :)
2) how I should handle like 30 variables received in my Client main command  ? ReadLn gives me a String and .... omg this cant be the right way :)
3) IF ReadLn is the right way, how to verify if the server sent me anything without the Client needs to send a command ? ( like a message to all users Online or to a particular ID ). I cant try except it cuz the game freeze till timeout.
4) some commands are real text like on my chat but the server handle them as params and AHHHH ! :(

Well... I hope u guys can undertand me ( im Brazilian and my english is very poor ).

thx in advance.
0
Comment
Question by:furmiga
  • 7
  • 4
11 Comments
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10710393
What I do is create command types as enumerated types

 TMyCommand = (ctStop, ctSTart, ctPause, ctSmile, etc. etc. etc.)


var
 MyCommand: TMyCommand;

 
  Then I use the

 methods from TypInfo unit

GetEnumName
GetEnumValue

 to convert back and fourth between enumerated types and strings.


when you receive a string command , convert it to its enumertaed type using GetEnumValue
then pass it to a case statement to perform some kind of action


  case MyCommand of
  ctStop: begin
               //do something
               end;
 ctStart:begin
             end;
 ctPause:begin
             end;
 ctSmile:begin
             end;
  end;


when you send a command, convert it to string using GetEnumName


The test it on the other end..... with case


Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10710401

Enumerated to String

 MyCommandStr := GetEnumName(TypeInfo(TMyCommand), Ord(MyCommand))

String to Enumerated

MyCommand:= TMyCommand(GetEnumValue(TypeInfo(TMyCommand), MyCommandStr));

Hope this helps!

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10710411
If its Chat text your sending

Send a Command such as

  CtStartChat

 this will tell you take all next string's as literal chat text

then send command

   CtStopChat

so you know to stop excepting text as chat text ans start excepting it as commands

SHane
0
 
LVL 7

Author Comment

by:furmiga
ID: 10713040
Okie Shane, u gave me an idea but sometimes, the server send commands to determinated clients without the client request it. what should i do to keep the client "listening" the incomming messages without make the client freeze till timeout or something ?
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10713074
What are u using for your component set? TServerSocket & TClientSocket?

Shane
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 7

Author Comment

by:furmiga
ID: 10713318
I am using Indy TCP client / server IdTCPClient / IdTCPServer
0
 
LVL 11

Accepted Solution

by:
shaneholmes earned 300 total points
ID: 10713380
If your application is based off from the premise I described above. i.e. sending text commands which are them converted to enumerated types for comparison - then performing sometype of action,

Then then client should always be listening. If you are experiencing a freeze in your client, then you need to wrap your functionality up into a thread.

Scenario :

Your client is listening all the time, a command comes across, you act on that command by spawning another process (thread) which performs the action. This will allow for the client to not be interfered and keeps on listening....

Hope this helps!

Shane
0
 
LVL 7

Author Comment

by:furmiga
ID: 10713421
And i have a silly question :)

Supose im receiving 5 variables as string like '10 1227 33 21 44'. I know that the first one is life, the second one is how much gold i have and so on. but how I can retrieve those values into the real variables in game ?
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10713492
First, word of advice - you can't keep nesting questions - <smile>

Second,

Of the top of my head something like:

Value1: Real;
Value2: Real;

 Value1:= StrToFloat(Copy(MyString,1,2));
 Value2:= StrToFloat(Copy(MyString,3,4));

 etc.

 You will have to play with the numbers to get the postions correct. Look at the String Handling function Copy in your help to see how it works.

Then its just a matter of converting it to a float.

Shane
0
 
LVL 7

Author Comment

by:furmiga
ID: 10713601
Okie Shane srry about all those questions. i ll give u the points :) I was just wondering a esay way to handle those variables :)  I think i ll use like 10#1222#1845#2# and then search for the # to split it. well ty for your time and srry again :)
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10713631
No need to aplogize, im aware your intensions were good... <smile>

No problem here.... if you need anymore help down the road, give a hollar!

Shane
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Mydac connection data base issue 3 107
Delphi application Soap connection 5 79
Delphi Form ownership 4 53
select query - oracle 16 81
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now