Solved

Indy - Making a game Protoptic

Posted on 2004-03-29
11
352 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
[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
  • 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
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!

 
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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

734 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