J
JoeC
I am a self taught programmer and I have figured out most syntax but
desigining my programs is a challenge. I realize that there are many
ways to design a program but what are some good rules to follow for
creating a program?
I am writing a map game program. I created several objects: board
object that is an array of integers each number 0-5 is a kind of
terrain, a terrain object that is an array of terrain types and each
number of the map coresponds to a kind terrain on the map. Finally I
have a unit object:
#include "graphic.h"
#include "libs.h"
#include "board.h"
#ifndef UNIT_H
#define UNIT_H
class unit : public graphic{
std::map<char, coord> keys; //movement engine
coord n; //directions
coord s;
coord e;
coord w;
int xloc; //x location
int yloc; //ylocation
int r, g, b; //color
int attack; //attack factor
int defence; //defence facor
int move; //movemnt factor
int moved; //the number of factors used
void make();
public:
unit();
void SetGr(int, int, int, BYTE c[]); //sets graphic info
void SetData(int, int, int);//sets ofensive defensive and move facors
void Place(int, int); //puts on the map
void moveUD(int, int); //handled up down movment
//direction, cost to enter next space.
void moveLR(int, int);
void newMove(char, board *,terrain trn[]);
void show(HWND); //displays the unit
void reset(); //restes movemnt
int red(){return r;} //returns colors for display
int grn(){return g;}
int blu(){return b;}
int getXloc()const {return xloc;} //returns location
int getYloc()const {return yloc;}
bool canMove(); //still has movement factors left.
};
void unit::newMove(char ch, board * b, terrain trn[]){
int n, mv;
int tempX = xloc + keys[ch].x;
int tempY = yloc + keys[ch].y;
mv = trn[b->GetSpace(tempY, tempX)].move();
if(moved > 0 && mv != 0){
moved -= mv;
xloc = tempX;
yloc = tempY;
}
}
case VK_UP:
if(red){rteam[t1m].newMove('n',b,trn);}
else{ yteam[t2m].newMove('n',b,trn);}
This all works and my units move around the map but is it good design
to send up the board and terrain objects to the function? I am
planning to have a fight function and that may involve even ore
objects, that is units from both sides the map and the kind of terrain.
Are there some rules or guides I can go by to write better programs?
For example I was instructed to tell on ask objects to do things.
desigining my programs is a challenge. I realize that there are many
ways to design a program but what are some good rules to follow for
creating a program?
I am writing a map game program. I created several objects: board
object that is an array of integers each number 0-5 is a kind of
terrain, a terrain object that is an array of terrain types and each
number of the map coresponds to a kind terrain on the map. Finally I
have a unit object:
#include "graphic.h"
#include "libs.h"
#include "board.h"
#ifndef UNIT_H
#define UNIT_H
class unit : public graphic{
std::map<char, coord> keys; //movement engine
coord n; //directions
coord s;
coord e;
coord w;
int xloc; //x location
int yloc; //ylocation
int r, g, b; //color
int attack; //attack factor
int defence; //defence facor
int move; //movemnt factor
int moved; //the number of factors used
void make();
public:
unit();
void SetGr(int, int, int, BYTE c[]); //sets graphic info
void SetData(int, int, int);//sets ofensive defensive and move facors
void Place(int, int); //puts on the map
void moveUD(int, int); //handled up down movment
//direction, cost to enter next space.
void moveLR(int, int);
void newMove(char, board *,terrain trn[]);
void show(HWND); //displays the unit
void reset(); //restes movemnt
int red(){return r;} //returns colors for display
int grn(){return g;}
int blu(){return b;}
int getXloc()const {return xloc;} //returns location
int getYloc()const {return yloc;}
bool canMove(); //still has movement factors left.
};
void unit::newMove(char ch, board * b, terrain trn[]){
int n, mv;
int tempX = xloc + keys[ch].x;
int tempY = yloc + keys[ch].y;
mv = trn[b->GetSpace(tempY, tempX)].move();
if(moved > 0 && mv != 0){
moved -= mv;
xloc = tempX;
yloc = tempY;
}
}
case VK_UP:
if(red){rteam[t1m].newMove('n',b,trn);}
else{ yteam[t2m].newMove('n',b,trn);}
This all works and my units move around the map but is it good design
to send up the board and terrain objects to the function? I am
planning to have a fight function and that may involve even ore
objects, that is units from both sides the map and the kind of terrain.
Are there some rules or guides I can go by to write better programs?
For example I was instructed to tell on ask objects to do things.