EDIT: This is a tetris clone, just realized that I din't mention that.
Anyways, I have been having trouble making any class members private, and I am told that this is bad style. So, here are the header files of my only completed project in which I had zero private members. I would greatly appreciate if someone could explain to me which members should be private and the reasoning.
c_app.h
//#pragma once#include "c_events.h"#include "c_surface.h"#include "c_control.h"class c_app : public c_events, public c_surface{ bool app_running;//exit when falsepublic: class c_control *p_control; bool ini_app();//initialization int run_app();//program loop void update_app();//all program actions void draw_screen();//drawing actions void ini_cleanup();//clear memory and such on exit void ev_exit();//actions after clicking the x void ev_keydown(SDLKey sym, SDLMod mod, Uint16 unicode);//actions afetr key press};
c_surface.h
//#pragma once#include <SDL.h>class c_surface {public: SDL_Surface* s_screen; SDL_Surface* load_surface(char* File);//load an image from file bool draw_surface(SDL_Surface* s_dest,SDL_Surface* s_src, int x, int y);//draw image bool draw_surface(SDL_Surface* s_dest, SDL_Surface* s_src, int x, int y, int x2, int y2, int W, int H);//overlaod bool set_transparency(SDL_Surface* s_dest, int R, int G, int B);//set transparent color};
c_events.h
//#pragma once#include <SDL.h>class c_events{public: virtual void do_event(SDL_Event* Event); //Events virtual void ev_input_focus(); virtual void ev_input_blur(); virtual void ev_keydown(SDLKey sym, SDLMod mod, Uint16 unicode); virtual void ev_keyup(SDLKey sym, SDLMod mod, Uint16 unicode); virtual void ev_mouse_focus(); virtual void ev_mouse_blur(); virtual void ev_mouse_move(int mx, int my, int relx, int rely, bool left,bool right,bool middle); virtual void ev_mouse_wheel(bool up, bool down); virtual void ev_mouse_ldown(int mx, int my); virtual void ev_mouse_lup(int mx, int my); virtual void ev_mouse_rdown(int mx, int my); virtual void ev_mouse_rup(int mx, int my); virtual void ev_mouse_mdown(int mx, int my); virtual void ev_mouse_mup(int mx, int my); virtual void ev_joy_axis(Uint8 which,Uint8 axis,Sint16 value); virtual void ev_joy_bdown(Uint8 which,Uint8 butt); virtual void ev_joy_bup(Uint8 which,Uint8 butt); virtual void ev_joy_hat(Uint8 which,Uint8 hat,Uint8 value); virtual void ev_joy_ball(Uint8 which,Uint8 ball,Sint16 xrel,Sint16 yrel); virtual void ev_minimize(); virtual void ev_restore(); virtual void ev_resize(int w,int h); virtual void ev_expose(); virtual void ev_exit(); virtual void ev_user(Uint8 type, int code, void* data1, void* data2);};
c_control.h
//#pragma once#include "c_app.h"#include "c_piece.h"#include <sdl_gfxprimitives.h>//customization#define BOARD_WIDTH 10#define BOARD_HEIGHT 20#define LINE_WIDTH 5#define PIECE_BLOCKS 5#define BLOCK_SIZE 20#define DROP_RATE 500//colors#define C_BOARD 0x00FFFFff//light blue#define C_LINE 0xFF0000ff//red#define C_BLOCK_NORMAL 0x0000FFff//blue#define C_BLOCK_PIVOT 0xEEEE00ff//yellow#define C_BLOCK_STORED 0x00FF1Aff//green#define C_BLOCK_STORED2 0xFF6600ff//orange#define C_BLOCK_GAMEOVER 0xFFFFFFff//whiteclass c_control{public: c_control(class c_app *curr_app); c_app *p_app; c_piece *p_piece; //values int px, py, ptype, prot;//piece location, type, and rotation int next_px, next_py, next_ptype, next_prot; int board_x, board_y;//board position in window int storage[BOARD_WIDTH][BOARD_HEIGHT];//locked pieces 0=empty 1=full//list of stored pieces int line_combo;//multiple lines cleared at once long score;//game score long lines_done;//total liens bool game_over;//as it says int paused;//-1=paused bool show_bonus;//if true show splash int show_lines, show_change;//splash info unsigned long time1, time2;//fps timers //functions void ini_board();//start game void clear_board();//as it says void new_piece();//create new piece void store_piece();//lock in a piece void draw_board();//as it says void draw_piece(int px,int py,int ptype,int prot);//as it says void check_lines();//check for filled lines void clear_line(int ly);//clear filled line bool can_move(int px,int py,int ptype,int prot);//check if move is legal void fast_drop_piece();//immediately drop piece void drop_piece();//gradually drop piece void show_score(int lines, int change);//define splash void draw_score();//render splash};
c_piece.h
//#pragma onceclass c_piece{public: int get_block_type(int ptype, int prot, int px, int py);//return type of block at a location in piece int get_xoff(int ptype, int prot);//return starting coords int get_yoff(int ptype, int prot);//return starting coords};//those get functions access arrays that I added in the .cpp file but outside //of any...thing, so does that make them have global scope? I tried declaring them in the header first, but that didn't work out.
Ok so there was *one* private memebr, but that was probably accidental in all honesty. Any pointers or suggestions on which variables/functions should be private/public would be greatly appreciated.
Also, completely unrelated, can vectors be multi-dimensional?
[Edited by - wioneo on July 21, 2010 4:47:21 PM]