⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 board.cpp

📁 通用网络游戏开发框架
💻 CPP
字号:
// ============================================================================
// Board core functions
//
// (c) 2003 Ken Reed
//
// This is free software. You can redistribute it and/or modify it under the
// terms of the GNU General Public License version 2 as published by the Free
// Software Foundation.
// ============================================================================

#include "stdafx.h"
#include "cell.h"
#include "board.h"
#include "universal.h"


// ============================================================================
// Construction
// ============================================================================

Board::Board()
{
   // Calculate the window size. Note that, because of the tiling, y is half a
   // cell bigger than the y array size. Similarly, the x size increments from
   // 1 in chunks of 0.75 of a cell.

   size.x = cell_size + ((board_x_size - 1) * (cell_size - (cell_size / 4)));
   size.y = (board_y_size * cell_size) + (cell_size / 2);
   attrition = false;

   int y_position = 0;
   int x_position = 0;

   // Run through every cell in the board and initialise it with its position
   // and board array indices (they come in handy later).

   for (int j = 0; j < board_y_size; j++) {
      for (int i = 0; i < board_x_size; i++) {
         Cell cell;

         cell.position.x = x_position;
         cell.position.y = y_position;
         cell.i = i;
         cell.j = j;

         if (i & 1) {
            cell.position.y += cell_size / 2;
         }

         x_position += cell_size - (cell_size / 4);
         cells[j][i] = cell;
      }

      y_position += cell_size;
      x_position = 0;
   }
}


// ============================================================================
// Draw board into a window
// ============================================================================

void Board::draw()
{
   for (int j = 0; j < board_y_size; j++) {
      for (int i = 0; i < board_x_size; i++) {
         cells[j][i].draw(window, hidden, player);
      }
   }
}


// ============================================================================
// Return the board size
// ============================================================================

Point Board::get_size()
{
   return size;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -