Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "board.h"
- #include "SDL_gfxPrimitives.h"
- #include "sdl_graphics.h"
- #include "SDL.h"
- #include "SDL_image.h"
- Board::Board()
- {
- int counter = 0;
- int i = 0;
- Cell[counter].x = 0;
- Cell[counter].y = 0;
- Cell[counter].h = SQUARE_WIDTH;
- Cell[counter].w = SQUARE_HEIGHT;
- counter++;
- while (counter < NUMBER_OF_CELLS_ON_GRID)
- {
- Cell[counter].x = Cell[counter -1].x + SQUARE_WIDTH;
- Cell[counter].y = Cell[counter -1].y;
- if (Cell[counter].x == SCREEN_WIDTH)
- {
- Cell[counter].x = 0;
- Cell[counter].y = Cell[counter].y + SQUARE_HEIGHT;
- }
- Cell[counter].h = SQUARE_WIDTH;
- Cell[counter].w = SQUARE_HEIGHT;
- counter++;
- }
- counter = 0;
- while (i < 2)
- {
- IsCellOccupied[i][counter] = 0;
- Color[i][counter] = NO_COLOR;
- counter++;
- if (counter == (NUMBER_OF_CELLS_ON_GRID - 1))
- {
- i++;
- counter = 0;
- }
- }
- Switcher = 0;
- }
- void Board::DrawBoard(SDL_Graphics *aGraphicsObject)
- {
- int yValue = 0;
- int xValue = SQUARE_WIDTH;
- while (xValue <= SCREEN_WIDTH)
- {
- lineRGBA(aGraphicsObject->getShapeSurfaceScreen(),
- xValue, yValue,
- xValue, SCREEN_HEIGHT,
- 190, 190, 190, 255);
- xValue = xValue + SQUARE_WIDTH;
- }
- xValue = 0;
- yValue = SQUARE_HEIGHT;
- while (yValue <= SCREEN_HEIGHT)
- {
- lineRGBA(aGraphicsObject->getShapeSurfaceScreen(),
- xValue, yValue,
- SCREEN_WIDTH, yValue,
- 190, 190, 190, 255);
- yValue = yValue + SQUARE_HEIGHT;
- }
- //render the boxes
- int counter = 0;
- SDL_Rect clip;
- clip.x = 0;
- clip.y = 0;
- clip.w = SQUARE_WIDTH;
- clip.h = SQUARE_HEIGHT;
- while (counter < NUMBER_OF_CELLS_ON_GRID)
- {
- if (IsCellOccupied[Switcher][counter] == true && Color[Switcher][counter] == GREEN)
- aGraphicsObject->drawSprite(Cell[counter].x + 1, Cell[counter].y + 1, aGraphicsObject->getShapeSurfaceGreenSquare(), aGraphicsObject->getShapeSurfaceScreen(), &clip);
- if (IsCellOccupied[Switcher][counter] == true && Color[Switcher][counter] == RED)
- aGraphicsObject->drawSprite(Cell[counter].x + 1, Cell[counter].y + 1, aGraphicsObject->getShapeSurfaceRedSquare(), aGraphicsObject->getShapeSurfaceScreen(), &clip);
- counter++;
- }
- }
- SDL_Rect Board::getCell(int WhichOne)
- {
- return Cell[WhichOne];
- }
- void Board::setIsCellOccupied(int WhichOne, bool Value)
- {
- IsCellOccupied[Switcher][WhichOne] = Value;
- }
- bool Board::getIsCellOccupied(int WhichOne)
- {
- return IsCellOccupied[Switcher][WhichOne];
- }
- bool Board::getSwitcher()
- {
- return Switcher;
- }
- void Board::setSwitcher()
- {
- if (Switcher == 0)
- Switcher = 1;
- else if (Switcher == 1)
- Switcher = 0;
- }
- void Board::resetIsCellOccupied()
- {
- int counter = 0;
- while (counter < NUMBER_OF_CELLS_ON_GRID)
- {
- IsCellOccupied[Switcher][counter] = 0;
- counter++;
- }
- }
- void Board::setColor(int WhichOne, int value)
- {
- Color[Switcher][WhichOne] = value;
- }
- int Board::getColor(int WhichOne)
- {
- return Color[Switcher][WhichOne];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement