Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

PartyOmNi

Tetris Code...

This topic is 5540 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement
Q. why is this a 0?
A. ok the purpose of the function is to make sure the cell that "this" is in is still in the grid. if it is not still in the grid, the function returns 0 telling u that it is not in the grid

Q. (not really a question) it returns the grid with which part of the grid is occupied. I think..
A. Im assuming this is returning the current position of the grid which the piece is in.

So basically if the piece is outside the grid, return 0 and tell there is something wrong...else (the piece is still in the grid) return its current position...

this is just my take and my experience from tetris...without seeing the rest of the code that is

Share this post


Link to post
Share on other sites
Thank you very much, I wasn''t sure if the 0 was for the shape, meaning, 0 = Block.ID, so I was kinda trippin''. Thank you

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!