Thread: Errors in my program

  1. #1
    C++ beginner
    Join Date
    Sep 2005
    Posts
    4

    Errors in my program

    I am writing a game program kind of like pac man.

    As of now I am just trying to get my maze to display, but run into errors.

    Could someone take a look at my code and see what i am doing wrong.
    Thanks,

    GJ
    Code:
    #include <ctime>
    #include <conio.h>
    #include <windows.h>
    #include "Maze.h"
    
    int main()
    {
        Status s = CONTINUE;
        short kb;
        char c;
        bool b =  false;
        
        system("cls");
        srand(time(0));
        Maze mObj("Maze.dat");
        mObj.displayMaze();
        
        while(s == CONTINUE)
        {
           if(kbhit())
           {
              kb = getche();
              kb = getche();
              cout << "\b \b";
              mObj.movePlayer(kb);
           }
           mObj.moveGhosts();
           s = mObj.determineStatus();
           mObj.displayMaze();
           Sleep(250);
        }
        if(s == WIN)
           cout << "Player found the treasure - you win!    ";
        else
           cout << "Player was killed by ghost - you lose    ";
        system("pause");
        return 0;
    }
    header file
    my class and constructor

    Code:
    #include <iostream>
    #include <iomanip>
    #include <fstream>
    using namespace std;
    
    enum Status
       {CONTINUE, WIN, LOSE};
    const int mazeSize = 24;
    const int numberOfGhosts = 10;
    
    class Maze
    {
       private:
          // data members
          char maze[mazeSize][mazeSize];
          char fileName[21];
          struct location
          {
             int row;
             int column;
          };
          location player;
          location treasure;
          location ghosts[numberOfGhosts];
       
       public:
          // constructor
    Maze(char fn[])
    {
          strcpy(fileName,fn);
          ifstream mazeFile;
          mazeFile.open("Maze.dat");       
          for(int r = 0; r < mazeSize; ++r)
          {
             for(int c = 0; c < mazeSize; ++c)
             {
                mazeFile >> Maze[r][c];
                if(Maze[r][c] == "#")
                   Maze[r][c] = '\xba';
                else
                   Maze[r][c] = ' ';
             }
          }
          mazeFile.close();
    }
          
          //member functions
    void displayMaze()
    {
         
    }
    void movePlayer()
    {
    }
    void setPlayer()
    {
    }
    void setTreasure()
    {
    }
    void moveGhosts()
    {
    }
    void setGhosts()
    {
    }
    void setMazeSize()
    {
    }
    Status determineStatus()
    {
       return CONTINUE;
    }
    };

  2. #2
    Registered User
    Join Date
    Oct 2005
    Posts
    38
    Please post your compiler errors

  3. #3
    C++ beginner
    Join Date
    Sep 2005
    Posts
    4
    My compiler errors.

    GJ
    Code:
    In file included from C:\Documents and Settings\Workstation\My Documents\Program6\Program6.cpp:7:
    C:\Documents and Settings\Workstation\My Documents\Program6\/Maze.h: In constructor `Maze::Maze(char*)':
    C:\Documents and Settings\Workstation\My Documents\Program6\/Maze.h:40: error: expected primary-expression before '[' token
    C:\Documents and Settings\Workstation\My Documents\Program6\/Maze.h:41: error: expected primary-expression before '[' token
    C:\Documents and Settings\Workstation\My Documents\Program6\/Maze.h:42: error: expected primary-expression before '[' token
    C:\Documents and Settings\Workstation\My Documents\Program6\/Maze.h:44: error: expected primary-expression before '[' token
    
    C:\Documents and Settings\Workstation\My Documents\Program6\Program6.cpp: In function `int main()':
    C:\Documents and Settings\Workstation\My Documents\Program6\Program6.cpp:28: error: no matching function for call to `Maze::movePlayer(short int&)'
    C:\Documents and Settings\Workstation\My Documents\Program6\/Maze.h:56: note: candidates are: void Maze::movePlayer()
    
    Execution terminated

  4. #4
    Registered User
    Join Date
    Oct 2005
    Posts
    38
    preprocessor directives?
    Code:
    #ifndef MAZE_H
    #define MAZE_H
    
    class Maze{
    
    };
    
    #endif
    lets try and go through errors one at a time:
    C:\Documents and Settings\Workstation\My Documents\Program6\Program6.cpp:28: error: no matching function for call to `Maze::movePlayer(short int&)'

    your definition for movePlayer takes no arguments

    also, do yourself a favor and separate your class implementation from your definition. You don't have to, but it is much easier to go through when the implementations are in a separate .cpp (IMO)
    Last edited by ExxNuker; 11-17-2005 at 02:49 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. mega compile errors for small program
    By s_UNI_ in forum C++ Programming
    Replies: 4
    Last Post: 04-28-2005, 12:00 PM
  3. Errors with program
    By nizbit in forum C Programming
    Replies: 37
    Last Post: 12-19-2004, 09:56 PM
  4. Average Rainfall Program Errors
    By JamesAnthony23 in forum C Programming
    Replies: 1
    Last Post: 09-11-2002, 10:44 PM
  5. I'm a newbie and I can't understand the errors in my program
    By iluvmyafboys in forum C++ Programming
    Replies: 19
    Last Post: 02-20-2002, 10:40 AM