Results 1 to 10 of 17

Thread: Online torpedo game

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Thanks I've already looked at your artillery tutorial but since that was over my level too I didn't get it too much
    The artillery tutorial is not really complicated IMHO. What is your programming experience so far?

    As you said, it is best to start things as simple as possible. Even after a lot of years of programming, I still underestimate many projects. Just take your time to learn SDL. Have a look at some examples/open-source-games and you'll learn alot.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  2. #2
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25
    Would you say that you understand Object Oriented Programming and the Object Pascal language as well as just Pascal? If you have a hard time with OOP then I can see how you might have a difficult time with my tutorial. It is written with the assumption that you understand basic object class structures. I don't go much further into it than that, but if you are having trouble with the OOP portion of the code, I can understand where I lost you in it.

    I suppose I could start writing a couple of smaller beginner tutorials about the basics of objects and classes and their usage in a simple to learn way. At least that's how I learned it so at least from me I'd be able to explain it to you and others in a "plain" form of language. I'd offer the basics of SDL, but to be honest I think that our friends at 'Freepascal meets SDL' have that covered.

    Your torpedo game sounds like a good game to start with. I assume that the game mechanics will be much like Battleship, am I right? If so, this is good! Start with something like that. My first games where Pong, Arkanoid and Tron.(or Snakes or whatever other names it's given)
    Jason McMillen
    Pascal Game Development
    Co-Founder





  3. #3
    Yes I have serious troubles with OOP both with syntaxes and methods. My torpedo game would be like this:
    Each player has a 10x10 board (A..J and 1..10). On that you set up your ships by giving the coordinates. Then the players take turns and shoots at coordinates like A9. If there is a ship of the opponent player they can shoot again. If there isn't then it's the opponent's turn. When all parts of a ship has been hit it sinks. The player who first sinks all of the other player's ships wins the game. It is really not that hard. I'm working on that I finally got SDL working now. It would be possible to leave OOP out of this but I need to practise so I made an object for the AI. And anyways I think it's more practical to handle the AI variables and procedures as part of an AI object than totally global. However I get some stupid error I don't get... The parts of the code which could be related to the error look like these:

    Code:
    type
    sq=record
    x:integer;
    y:integer;
    end;
    PAI=^TAI;
    TAI=object
    currenttarget,nexttarget:sq;
    procedure ClearRegion(r:integer); {this is a basic AI procedure I'm not finished with it yet it is for making it not totally random}
    procedure Shoot(c1,c2:integer);
    end;
    
    var
    AI: PAI;
    Procedure AI.ClearRegion(r:integer);
    begin
    {This is not finished yet}
    end;
    Procedure AI.Shoot(c1,c2:integer);
    begin
    {This is pretty long and yet not complete}
    end;
    begin
    New(AI);
    {program parts which are not too important}
    Repeat
    AI.Shoot(AI.currenttarget.x,AI.currenttarget.y);
    Until RegionCleared(Region(AI.currenttarget.x,AI.currenttarget.y));
    {RegionCleared(r:integer):boolean and Region(c1,c2:integer):integer are functions defined correctly they work well I've made test programs for those.
    (the AI.ClearRegion procedure is called inside the AI.Shoot procedure it's not yet working correctly I know that but the errors I get seem to have nothing to do with that...)
    
    Now I've got two errors. First is like "Until expected AI.Shoot found". wtf??
    Second is at the definition of procedure AI.Shoot(c1,c2) it says "class" type expected. I've tried setting up PAI as class type and AI as PAI type but then it said: unkown identifier: class. how could class be an unkown identifier for God's sake????:D}
    
    end.
    Any ideas? I remember the times when I had errors like runtime error 103 or 201 with simple pascal and I didn't know what to do with them. Now they are like routines: "Oh error 103 must have called close(f); in a loop somewhere and forgot to Reset(f);". I know times will come when this will be the same with OOP but I'm not there yet.. And sorry for this superlong post if you didn't have the patience reading this through I understand if you did well thanks
    Last edited by WILL; 26-10-2010 at 04:57 PM. Reason: Added code blocks

  4. #4
    okay I finally solved this now the program actually runs without an error message. which is a good thing Now I just have to finish those functions and procedures and check if everything works fine(since running w/o error message doesn't mean it works well too) And correct a major bug with the SDL because now it freezes for some reason, it should not be a big problem. I think my beta version will be ready latest by the end of the week. I finally start to get the syntax and basic concepts of OOP too. And during I'm learning OOP I'm also learning the usage of pointers. Since my older programs were not big and the most complicated method was searching/modifying something in a binary file I didn't have memory issues and didn't need pointers at all, but now I want my game to run fluently.

  5. #5
    No offence, but I'd suggest learning the syntax first before you start writing a game so you won't bite off more than you can chew. If I may suggest, I'd start by reading thoroughly the Delphi Basics website.

  6. #6
    I have never learned like that. I can not just learn the syntaxes I am physically unable to do that. I learn the syntaxes by writing programs.
    Now I got the most interesting error ever. So the main program looks like this:
    Code:
    BEGIN
    Assign(ships,'C:\ships.dat');
        GenerateShips;
        ReadShips;
        DrawBoard;
        New(AI);
        ReadShot;
            Readln;
        {parts not written yet}
        SDL_FREESURFACE(screen);
        SDL_FREESURFACE(boardpict);
        SDL_FREESURFACE(hitpict);
        SDL_FREESURFACE(misspict);
        SDL_QUIT;
        Readln;
    END.
    Now the error is a simple runtime error #201 it should be a range check error. But if I place a Breakpoint ANYWHERE in the program and by this I mean the subprocedures, a function, or the main program, even just before the last END, the program does not return this error. I'm wondering why is it doing that since in the main program there isn't any loop that should overload a variable or anything like that and the procedures should be okay as the program runs just until the last Readln; line if I put the breakpoint there. However if I do that, the program seems to skip some procedures(especially the ReadShot procedure) and just freezes. It might be a wrong code(with the ReadShot procedure) but since I couldn't solve inputing strings with SDL I had to read the coordinates with mouse and it creates a whole bunch of complications. Besides. I've been having an error with SDL ever since I got it: The SDL screen simply freezes irreversibly if I change to another window. This is a big problem as I can not use F7 to find the exact source of errors and I have to restart the whole IDE after every breakpoint check and inputing things becomes very complicated too.

  7. #7

    Its first version is almost finished =)

    Okay I have got rid of all of the major bugs. The game is now theoritically playable. What is left to be done:
    1) The ships are yet just random squares they don't form a ship this should really not be a problem I just write an organising procedure and there it is.
    2) Graphics. Now I always use simple sprites for testing(red square, gray square etc...) but a game should really not have graphs like that
    3) Sounds. Should not be a problem either.
    4) A menu system with some kind of in-game menu with nice functions. Any good games have these why won't I put them in mine? I think it won't be hard altough it could be a bit tricky. Especially the in-game part.
    5) This is the most interesting part: make it work online. I think I will save this for later... I'm just not skilled enough for that yet.

    Now as you can see most of the remaining parts of the game takes more time than skill to get them done. And that's what I hate in designing games(I have like a dozens of game maker games all done with complicated calculations, AI and stuff like that but I was way too lazy to do the health-life counts, animations, spirtes, musics, backgrounds, level-designs and all the easy stuff...). Someone said I could lose interest if I made the game too hard to design for my skills. Well actually I usually lose interest at these parts of the game. When the hard parts are done and just time-work is what's left. Anyways I will finish this I've decided it. I just messed up too many hours and nerves on it not to do so However this is my very first game written in Pascal and still I got many help from you guys here(for which I am very grateful) I think I could be proud of myself. I really also solved things by myself I wouldn't have imagined I could a few weeks ago. Also this one simple game at least doubled my programming skills. It gave me some insight into OOP and SDL too. It's been a useful week.

  8. #8
    I do not know what you are using a compiler, but you can say you are using Delphi, you can create a class from TPersistent descendants. You want to transfer the data can be stored in this class of property released ... then you can use in the Delphi streaming mechanism, and said, Indy components and simply flow through the socket connection class.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •