Thread: My Brain Exploded -,-

  1. #1
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379

    My Brain Exploded -,-

    Ok, I'm working on a class for a little console game, I have two conundrums that have anihilated my brain (Which building the game has already destroyed a good bit of -,-)...

    First, you need to see the class:
    Code:
    #include <windows.h> //Theyse are includes for the whole game.
    #include <iostream>
    #include <string.h>
    #include <conio.h>
    #include <fstream.h>
    using namespace std;
    
    class Enemy {
     private:
     HANDLE hOt = GetStdHandle(STD_OUTPUT_HANDLE);
     HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
     char type;
     int x_pos;
     int y_pos;
     int tag;
     SHORT alive;
     public:
    
     Enemy();
     Enemy(char t, int ex, int ey, int etag, SHORT dead) {t=type;ex=x_pos;ey=y_pos;etag=tag; dead=alive}
     
    
     int EnemyTracker[50][1];
    
     int GetTagXY(int x, y);
     Enemy GetEnemyStatsXY(int x, y);
     COORD GetEnemyStatusXY(Enemy e);
    }
    
    COORD Enemy::GetEnemyXY(Enemy e) {
      int x_pos, y_pos;
     DWORD reader;
     char Ace[1];
     COORD Pos;
     
     Pos.X = x;
     Pos.Y = y;
     ReadConsoleOutputCharacter(hOt, &Ace[0], 1, Pos, &reader);
     if(Ace[0] == Enemy1 || Ace[0] == Enemy2 || Ace[0] == Enemy3 || Ace[0] == Enemy4) {
      Pos.X = x;
      Pos.Y = y;
      return Pos;
    }
    
    int Enemy::GetTagXY(int x, y) {
     int x_pos, y_pos;
     DWORD reader;
     char Ace[1];
     COORD Pos;
     
     Pos.X = x;
     Pos.Y = y;
     ReadConsoleOutputCharacter(hOt, &Ace[0], 1, Pos, &reader);
     if(Ace[0] == Enemy1 || Ace[0] == Enemy2 || Ace[0] == Enemy3 || Ace[0] == Enemy4)
      return tag;
    }
    
    Enemy Enemy::GetEnemyStatusXY(int x, y) {
     int x_pos, y_pos;
     DWORD reader;
     char Ace[1];
     COORD Pos;
     
     Pos.X = x;
     Pos.Y = y;
     ReadConsoleOutputCharacter(hOt, &Ace[0], 1, Pos, &reader);
     if(Ace[0] == Enemy1 || Ace[0] == Enemy2 || Ace[0] == Enemy3 || Ace[0] == Enemy4)
      return Enemy;
    }
    Mmmm, some of you might see my problem. I have no bloody idea how to pull a part of information out of the class that I put in it! :/. I ended up stairing blankly thinking about how a co-ordinant relate to a tag... That didint go anywhere.

    So, what I'm trying to do is, be able to declare an enemy, lets say:

    Code:
    int main() {
     Enemy Hi('&', 15, 27, 1);
     COORD Pos;
    
     Pos=GetEnemyXY(Hi);
     cout << GetTagXY(Pos.x, Pos.y);
    }
    But... How do I do this -,-. My brain is in like... Meltdown mode ... I'm hoping theres a simple answer, but for now, I'll just stair blankly at my program and hope an answer magicaly pops into my head (it wont :/).

    Any help is greatly apreciated. Also, I'm taking donations to recover my brain particles and rebuild them >.<.
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Does any of this compile?

  3. #3
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    Nope, good thing to because this code wont work anyways.

    Mmm... I have no idea what in hell I was thinking...

    I revised my code a bit, but I'm not sure what the rest of theyse errors mean. (Very incomplete)

    Code:
    class Enemy {
     private:
     char type;
     int x_pos;
     int y_pos;
     int tag;
     SHORT alive;
     public:
    
     Enemy();
     Enemy(char t, int ex, int ey, int etag, SHORT dead) {t=type;ex=x_pos;ey=y_pos;etag=tag; dead=alive;}
     
    
     int EnemyTracker[50][1];
     HANDLE ehOt = GetStdHandle(STD_OUTPUT_HANDLE);
     HANDLE ehIn = GetStdHandle(STD_INPUT_HANDLE);
    
     int GetTagXY(int x, y);
     Enemy GetEnemyXY(int x, y);
     COORD GetEnemyStatusXY(Enemy e);
    }
    
    COORD Enemy::GetEnemyXY(Enemy e) {
      int x_pos, y_pos;
     DWORD reader;
     char Ace[1];
     COORD Pos;
     
     Pos.X = x;
     Pos.Y = y;
     ReadConsoleOutputCharacter(ehOt, &Ace[0], 1, Pos, &reader);
     if(Ace[0] == Enemy1 || Ace[0] == Enemy2 || Ace[0] == Enemy3 || Ace[0] == Enemy4) {
      Pos.X = x;
      Pos.Y = y;
      return Pos;
    }
    
    int Enemy::GetTagXY(int x, y) {
     int x_pos, y_pos;
     DWORD reader;
     char Ace[1];
     COORD Pos;
     
     Pos.X = x;
     Pos.Y = y;
     ReadConsoleOutputCharacter(ehOt, &Ace[0], 1, Pos, &reader);
     if(Ace[0] == Enemy1 || Ace[0] == Enemy2 || Ace[0] == Enemy3 || Ace[0] == Enemy4)
      return tag;
    }
    
    Enemy Enemy::GetEnemyStatusXY(int x, y) {
     int x_pos, y_pos;
     DWORD reader;
     char Ace[1];
     COORD Pos;
     
     Pos.X = x;
     Pos.Y = y;
     ReadConsoleOutputCharacter(ehOt, &Ace[0], 1, Pos, &reader);
     if(Ace[0] == Enemy1 || Ace[0] == Enemy2 || Ace[0] == Enemy3 || Ace[0] == Enemy4)
      return Enemy;
    }
    Errors:
    Code:
    Error E2233 C:\EnemyClass.h 15: Cannot initialize a class member here
    Error E2233 C:\EnemyClass.h 16: Cannot initialize a class member here
    Error E2303 C:\EnemyClass.h 18: Type name expected
    Error E2303 C:\EnemyClass.h 19: Type name expected
    Error E2238 C:\EnemyClass.h 23: Multiple declaration for 'COORD'
    Error E2344 c:\Borland\Bcc55\include\wincon.h 33: Earlier declaration of 'COORD'
    
    Error E2356 C:\EnemyClass.h 23: Type mismatch in redeclaration of 'COORD'
    Error E2344 c:\Borland\Bcc55\include\wincon.h 33: Earlier declaration of 'COORD'
    
    Error E2141 C:\EnemyClass.h 23: Declaration syntax error
    From what I gather... It thinks I'm trying to make another class named COORD? I'm no stones throw at classes, I probably should have started off a bit smaller -,-. Well I'm glaring at this code to see whats wrong. If someone could tell me why I'm getting thoes errors it would be good.
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  4. #4
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    No semi-colon at the end of the class.

    You have to initialize class variables in the constructor:

    Code:
    int EnemyTracker[50][1];
    HANDLE ehOt;
    HANDLE ehIn;
    
    Enemy(char t, int ex, int ey, int etag, SHORT dead)
    {
      t=type;ex=x_pos;ey=y_pos;etag=tag; dead=alive;
      ehOt = GetStdHandle(STD_OUTPUT_HANDLE);
      ehIn = GetStdHandle(STD_INPUT_HANDLE);
    }
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  5. #5
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    Thoes functions I had in their were pure crap. And they dont seem to be improving either. I fixed my code so it now compiles (thanks Dae)

    Code:
    #include <windows.h>
    #include <iostream>
    #include <string.h>
    #include <conio.h>
    #include <fstream.h>
    using namespace std;
    
    #define Enemy1 '@'
    #define Enemy2 '&' 
    #define Enemy3 '$'
    #define Enemy4 '%'
    
    HANDLE hOt = GetStdHandle(STD_OUTPUT_HANDLE);
    HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE);
    
    class Enemy {
     private:
     char type;
     int ex_pos;
     int ey_pos;
     int tag;
     SHORT alive;
    
     public:
    
     Enemy();
    
     int EnemyTracker[50][1];
    
     Enemy(char t, int ex, int ey, int etag, SHORT dead) {
      t=type;ex=ex_pos;ey=ey_pos;etag=tag; dead=alive;
     }
    };
    So, I'm wondering, how do I extract just a small peice of data from my class.

    IE:

    Code:
    Enemy Hi('%', 10, 10, 1, 0);
    
    Hi.ex_pos();
    Hi.ey_pos();
    Hi.tag();
    Hi.alive();
    Hi.Type();
    I know I can call that by using struct, but how do I do this using a class?
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > I know I can call that by using struct, but how do I do this using a class?
    You already are. Since you've listed everything inside public: and private: sections, you can change
    class Enemy
    to
    struct Enemy
    and it would be exactly the same as it is now.

    > t=type;ex=ex_pos;ey=ey_pos;etag=tag; dead=alive;
    Pick better variable names and member names.
    Half your assignments copy from the class member vars to the parameter, and the others copy from the parameters to the class member vars.

    > So, I'm wondering, how do I extract just a small peice of data from my class.
    Well you write a member function
    Code:
    int Enemy::getPosX ( void ) {
      return ex_pos;
    }
    Which you would call with
    Code:
    int theirXpos = Hi.getPosX();

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Left Brain v Right Brain
    By stevesmithx in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-30-2008, 09:13 AM
  2. Human brain and programing
    By avgprogamerjoe in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 08-27-2007, 04:48 PM
  3. Mouse to have human brain
    By nickname_changed in forum A Brief History of Cprogramming.com
    Replies: 22
    Last Post: 03-10-2005, 05:39 PM
  4. brain vs. computer (brain wins hands down)
    By hk_mp5kpdw in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 09-17-2003, 08:41 PM
  5. Re: Girlfriend Post
    By PsychoBrat in forum A Brief History of Cprogramming.com
    Replies: 57
    Last Post: 05-13-2002, 06:11 AM