Suby

board.cpp

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