Solved

Indy - Making a game Protoptic

Posted on 2004-03-29
11
347 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
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.

 
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
 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Title # Comments Views Activity
Working with hours 3 65
How to debug For loops? 3 56
Delphi: Connect to running MS Outlook 4 119
scroll down TListBox component in Delphi 1 19
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 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