.:: Bots United ::.

.:: Bots United ::. (http://forums.bots-united.com/index.php)
-   Offtopic (http://forums.bots-united.com/forumdisplay.php?f=23)
-   -   Show off your finest piece of code! (http://forums.bots-united.com/showthread.php?t=3292)

stefanhendriks 30-12-2004 17:19

Re: Show off your finest piece of code!
 
Quote:

Originally Posted by Rifleman
I would love to :)

You should grab Allegro, you can get a windows binary , lib package or 'compilable version' (source) from http://www.allegro.cc , i suggest you grab the compilable version and make it compile, (read the documents very well). Its a bit of fiddling around with the paths (well, COULD be), but once THAT compiles, the game will compile.

Its 10MB (zipped), but it contains all you need: Source, gfx, grabber utility, etc.

CS2d\CS2d contains the source
CS2d\<dir> contains what it should contain (look at the name)

ow, and if you look at the source, you will laugh your ass off, seriously.

http://realbot.bots-united.com/files/CS2D.ZIP

(its up)

Rifleman 30-12-2004 17:44

Re: Show off your finest piece of code!
 
hey , dude that link's broken ...

AH and yes , would you mind if I use the code ? OF course credit will be given

stefanhendriks 30-12-2004 18:00

Re: Show off your finest piece of code!
 
fixed the link.

sure, no problem (else i would'nt have put it here anyways).

dub 30-12-2004 19:50

Re: Show off your finest piece of code!
 
here`s my 2cents a nice little cpp doubly linked list class

Code:

CLinkedList *pLL = NULL;
 
 static bool        bStart = TRUE;
 
 CLinkedList::~CLinkedList( )
 {
        delete (pLL);
        pLL = NULL;
        bStart = TRUE;
 }
 
 void CLinkedList::SetToStartNode ( )
 {
        while (pLL->prev != NULL)
                pLL = pLL->prev;
 }
 
 void CLinkedList::SetToEndNode ( )
 {
        while (pLL->next != NULL)
                pLL = pLL->next;
 }
 
 long CLinkedList::GetNumberOfNodes ( )
 {
        long lNumberOfNodes;
 
        pLL->SetToStartNode ();
 
        lNumberOfNodes = 0;
 
        while (pLL->next != NULL)
        {
                pLL = pLL->next;
                lNumberOfNodes++;
        }
 
        return (lNumberOfNodes);
 }
 
 void CLinkedList::DeleteAllNodes ( )
 {
        pLL->SetToEndNode ();
 
        while (pLL->prev != NULL)
        {
                pLL = pLL->prev;
                delete (pLL->next);
                pLL->next = NULL;
        }
 
        bStart = TRUE;
        return;
 }
 
 void CLinkedList::AddNode (int iData)
 {
        CLinkedList *pNewNode;
 
        if (bStart)
        {
                bStart = FALSE;
                pLL->iData = iData;
                pLL->prev = NULL;
                pLL->next = NULL;
        }
        else
        {
                pLL->SetToEndNode ();
                pNewNode = new (CLinkedList);
                pLL->next = pNewNode;
                pNewNode->prev = pLL;
                pNewNode->iData = pLL->iData;
                pNewNode->next = NULL;
                pLL = pNewNode;
        }
 }
 
 void CLinkedList::DeleteNode ( )
 {
        CLinkedList *pNode = NULL;
 
        if (pLL->next != NULL)
                pNode = pLL->next;
        else if (pLL->prev != NULL)
                pNode = pLL->prev;
        else // dont delete the start node
                return;
 
        pLL->prev->next = pLL->next;
        pLL->next->prev = pLL->prev;
 
        pLL = pNode;
        return;
 }
 
 void CLinkedList::GoToNextNode ( )
 {
        if (pLL->next != NULL)
                pLL = pLL->next;
 }
 
 void CLinkedList::GoToPreviousNode ( )
 {
        if (pLL->prev != NULL)
                pLL = pLL->prev;
 }
 
 bool CLinkedList::IsNextNodeNull ( )
 {
        if (pLL->next != NULL)
                return FALSE;
        return TRUE;
 }
 
 bool CLinkedList::IsPrevNodeNull ( )
 {
        if (pLL->prev != NULL)
                return FALSE;
        return TRUE;
 }
 
 int CLinkedList::GetVar ( )
 {
        return (pLL->iData);
 }
 
 
 class CLinkedList
 {
        int                        iData;
        CLinkedList *prev;
        CLinkedList *next;
 
 public:
        // Class Construction
        CLinkedList ( ) :  prev(NULL), next(NULL) , iData(0)
        {
        }
        // Class Destruction
        virtual                ~CLinkedList ( );
        // Class Function Prototypes...
        void                AddNode (int fData);
        void                DeleteNode ( );
        void                DeleteAllNodes ( );
        void                SetToStartNode ( );
        void                SetToEndNode ( );
        long                GetNumberOfNodes ( );
        void                GoToNextNode ( );
        void                GoToPreviousNode ( );
        bool                IsNextNodeNull ( );
        bool                IsPrevNodeNull ( );
        int                        GetVar ( );
 };
 extern CLinkedList *pLL;

enjoy Dubb.

@$3.1415rin 30-12-2004 20:12

Re: Show off your finest piece of code!
 
hm, somehow you missed something in your c++ course ;)

remove that pLL variable ... in the methods of that class ( that are the fucntions of a class ) you can access its variables directly. your solution works fine for one instance of that class, but you'll get into trouble once you wanna have more of them

PS: deleting isnt permitted in this forums :) just edit it if you like to

dub 30-12-2004 20:40

Re: Show off your finest piece of code!
 
thanks for that aspirin;), i will upload a fixed version at about 10pm GMT
going out now.
p.s what names do you guys play cs under mines -=[AK]=- Dubb because i might have been playing with you yesterday.
p.p.s could one of the moderators delete the previous code thread.

sfx1999 31-12-2004 01:31

Re: Show off your finest piece of code!
 
I would say my vector class is good, but I am not sure whether it works properly with pointers, so I'll only post part of it.

Code:

class vector3
 {
        public:
                vector3(void);
                vector3(float tempx, float tempy, float tempz);
                vector3(const vector3 &vector);
 
                float getLength(void);
 
                void normalize(void);
                vector3 normalized(void);
 
                vector3 operator+(vector3 vector);
                vector3 operator-(vector3 vector);
                vector3 operator*(vector3 vector);
                bool operator==(vector3 vector);
                bool operator!=(vector3 vector);
                void operator=(vector3 vector);
 
                float dotProduct(vector3 vector);
 
                float x, y, z;
 };

I mean, it works properly, but I think that some overloaded operators will shit themselves if you try to use a pointer. I have it under the X Consortium License.

Rifleman 31-12-2004 04:01

Re: Show off your finest piece of code!
 
ah and yes stefan , do I need to do extra stuff with Allegro or just install it ?

Whistler 31-12-2004 04:09

Re: Show off your finest piece of code!
 
Allegro is a library, you can just compile it and copy it into your MSVC folder

Rifleman 31-12-2004 04:25

Re: Show off your finest piece of code!
 
I get the Windows Binary version and I do the manual installation then I think its alright since I have copied many lib files into the "LIB" directory :)


All times are GMT +2. The time now is 04:33.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.