Results 1 to 10 of 17

Thread: Online torpedo game

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #10
    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

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
  •