Original Post
I need help comprehending a function!!!! Im still a newb at this game programming stuff, but I do understand C++.
//////GRID.H/////////////////////////////////////////////////////
#pragma once
#ifndef CGRID_H
#define CGRID_H
#include "stdafx.h" //includes every header file needed
const int maxCellX = 11; //these two values define the maximum x,y size for a grid
const int maxCellY = 16; // set low, easier to debug
const int cellX = 40; //these two values define the x,y size of a cell
const int cellY = 40; //a grid comprises many cells
class CGrid
{
public:
CGrid(int x, int y); //if x or y exceed maxCellX or maxCellY, they are used as defaults
~CGrid();
int getGdXSize(); //returns the number of horizontal cells
int getGdYSize(); //returns the number of vertical cells
int getCellX();
int getCellY();
int getCellVal(int x, int y); //returns the int value of cell(x,y)
RECT* getCellRect(int x, int y); //returns a RECTANGLE encompasing the cell(x,y)
int setCellVal(int x, int y, int b);//set a cells int value, returns true if successful
int copyCellVal(int xDest, int yDest, int xScr, int yScr, int Mode); //Modes: SCRCOPY, SCRERASE
void shiftDown(int shifts);
private:
int gdXSize;
int gdYSize;
int grid[maxCellX][maxCellY]; //the actual virtual grid
};
#endif
THE STUFF I DON"T UNDERSTAND!!!!!
GRID.CPP
This is the function I''m having problem comprehending...
int CGrid::getCellVal(int x, int y)
{
if(x >= this->getGdXSize() || y >= this->getGdYSize()) //make sure valid x,y are given
return 0; // <----- why is this a 0?
else
return this->grid[x][y]; //<--- it returns the grid with which part of the grid is occupied. I think..
}
I UNDERSTAND THE SETCELLVAL..
int CGrid::setCellVal(int x, int y, int b)
{
//parameters
// x = the cordinate used for cell..
// y = the cordinate used for cell..
// b = the block ID used for each block.
if(x >= this->getGdXSize() || y >= this->getGdYSize()) //make sure valid x,y are given
return 0;
else
{
this->grid[x][y] = b;
return (this->grid[x][y] == b);
}
}
}
I''m goin crazy just lookin at the code... Please help me!