Advertisement
Suby

board.cpp

Jun 1st, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.92 KB | None | 0 0
  1. #include "board.h"
  2. #include "SDL_gfxPrimitives.h"
  3. #include "sdl_graphics.h"
  4. #include "SDL.h"
  5. #include "SDL_image.h"
  6.  
  7. Board::Board()
  8. {
  9.     int counter = 0;
  10.     int i = 0;
  11.  
  12.     Cell[counter].x = 0;
  13.     Cell[counter].y = 0;
  14.     Cell[counter].h = SQUARE_WIDTH;
  15.     Cell[counter].w = SQUARE_HEIGHT;
  16.     counter++;
  17.  
  18.     while (counter < NUMBER_OF_CELLS_ON_GRID)
  19.     {
  20.         Cell[counter].x = Cell[counter -1].x + SQUARE_WIDTH;
  21.         Cell[counter].y = Cell[counter -1].y;
  22.  
  23.         if (Cell[counter].x == SCREEN_WIDTH)
  24.         {
  25.             Cell[counter].x = 0;
  26.             Cell[counter].y = Cell[counter].y + SQUARE_HEIGHT;
  27.         }
  28.  
  29.         Cell[counter].h = SQUARE_WIDTH;
  30.         Cell[counter].w = SQUARE_HEIGHT;
  31.  
  32.         counter++;
  33.     }
  34.     counter = 0;
  35.  
  36.     while (i < 2)
  37.     {
  38.         IsCellOccupied[i][counter] = 0;
  39.         Color[i][counter] = NO_COLOR;
  40.         counter++;
  41.  
  42.         if (counter == (NUMBER_OF_CELLS_ON_GRID - 1))
  43.         {
  44.             i++;
  45.             counter = 0;
  46.         }
  47.  
  48.     }
  49.  
  50.     Switcher = 0;
  51. }
  52.  
  53. void Board::DrawBoard(SDL_Graphics *aGraphicsObject)
  54. {
  55.     int yValue = 0;
  56.     int xValue = SQUARE_WIDTH;
  57.     while (xValue <= SCREEN_WIDTH)
  58.     {
  59.         lineRGBA(aGraphicsObject->getShapeSurfaceScreen(),
  60.                   xValue, yValue,
  61.                   xValue, SCREEN_HEIGHT,
  62.                   190, 190, 190, 255);
  63.         xValue = xValue + SQUARE_WIDTH;
  64.     }
  65.     xValue = 0;
  66.     yValue = SQUARE_HEIGHT;
  67.     while (yValue <= SCREEN_HEIGHT)
  68.     {
  69.         lineRGBA(aGraphicsObject->getShapeSurfaceScreen(),
  70.                   xValue, yValue,
  71.                   SCREEN_WIDTH, yValue,
  72.                   190, 190, 190, 255);
  73.         yValue = yValue + SQUARE_HEIGHT;
  74.     }
  75.  
  76.  
  77.     //render the boxes
  78.     int counter = 0;
  79.     SDL_Rect clip;
  80.     clip.x = 0;
  81.     clip.y = 0;
  82.     clip.w = SQUARE_WIDTH;
  83.     clip.h = SQUARE_HEIGHT;
  84.  
  85.     while (counter < NUMBER_OF_CELLS_ON_GRID)
  86.     {
  87.         if (IsCellOccupied[Switcher][counter] == true && Color[Switcher][counter] == GREEN)
  88.             aGraphicsObject->drawSprite(Cell[counter].x + 1, Cell[counter].y + 1, aGraphicsObject->getShapeSurfaceGreenSquare(), aGraphicsObject->getShapeSurfaceScreen(), &clip);
  89.         if (IsCellOccupied[Switcher][counter] == true && Color[Switcher][counter] == RED)
  90.             aGraphicsObject->drawSprite(Cell[counter].x + 1, Cell[counter].y + 1, aGraphicsObject->getShapeSurfaceRedSquare(), aGraphicsObject->getShapeSurfaceScreen(), &clip);
  91.         counter++;
  92.     }
  93. }
  94.  
  95. SDL_Rect Board::getCell(int WhichOne)
  96. {
  97.     return Cell[WhichOne];
  98. }
  99.  
  100. void Board::setIsCellOccupied(int WhichOne, bool Value)
  101. {
  102.     IsCellOccupied[Switcher][WhichOne] = Value;
  103. }
  104.  
  105. bool Board::getIsCellOccupied(int WhichOne)
  106. {
  107.     return IsCellOccupied[Switcher][WhichOne];
  108. }
  109.  
  110. bool Board::getSwitcher()
  111. {
  112.     return Switcher;
  113. }
  114.  
  115. void Board::setSwitcher()
  116. {
  117.     if (Switcher == 0)
  118.         Switcher = 1;
  119.     else if (Switcher == 1)
  120.         Switcher = 0;
  121. }
  122.  
  123. void Board::resetIsCellOccupied()
  124. {
  125.     int counter = 0;
  126.     while (counter < NUMBER_OF_CELLS_ON_GRID)
  127.     {
  128.         IsCellOccupied[Switcher][counter] = 0;
  129.         counter++;
  130.     }
  131. }
  132.  
  133. void Board::setColor(int WhichOne, int value)
  134. {
  135.     Color[Switcher][WhichOne] = value;
  136. }
  137.  
  138. int Board::getColor(int WhichOne)
  139. {
  140.     return Color[Switcher][WhichOne];
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement