parent
004e5cf177
commit
471dab296b
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* \file Board.h
|
||||
* \brief Board management
|
||||
* \author Théotime Maillarbaux
|
||||
* \date 29/11/221
|
||||
*/
|
||||
|
||||
#ifndef BOARD_H
|
||||
#define BOARD_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "model/Piece.h"
|
||||
#include <SDL2/SDL_pixels.h> // SDL_Color
|
||||
|
||||
/**
|
||||
* \struct Board
|
||||
* \brief Represents a board for a Game.
|
||||
*
|
||||
* The bridges are represented by 2D-arrays of SDL_Bools.
|
||||
* For a given set of coordinates, the value is TRUE if the bridge is there,
|
||||
* else false.
|
||||
*/
|
||||
typedef struct {
|
||||
// y x
|
||||
bool vBridges[4][5]; ///< 2D-array of vertical bridges.
|
||||
bool hBridges[5][4]; ///< 2D-array of horizontal bridges.
|
||||
Piece arrPieces[9]; ///< Array of pieces on the Board.
|
||||
} Board;
|
||||
|
||||
Board newBoard(int nbPlayers);
|
||||
|
||||
#endif // BOARD_H
|
@ -0,0 +1,26 @@
|
||||
#include "model/Board.h"
|
||||
|
||||
Board newBoard(int nbPlayers) {
|
||||
Board board;
|
||||
int nbPiecesPerPlayer = (nbPlayer == 4) ? 2 : 3;
|
||||
int pieceIndex = 0;
|
||||
|
||||
// Init pieces
|
||||
for (int player_i = 0; i < nbPlayers; player_i++) {
|
||||
for (int piece_i = 0; i < nbPiecesPerPlayer; piece_i++) {
|
||||
board.arrPieces[pieceIndex] = newPiece(player_i);
|
||||
pieceIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
// Init bridges
|
||||
// max of vy (vertical y) is equal to max of hx (horizontal x),
|
||||
// so vy will be used as hx as well.
|
||||
for (int vy = 0; vy < 4; vy++) {
|
||||
for (int vx = 0; vx < 5; vx++) {
|
||||
board.vBridges[vy][vx] = true;
|
||||
board.hBridges[vx][vy] = false;
|
||||
}
|
||||
}
|
||||
return board;
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
#include "model/Piece.h"
|
||||
|
||||
Piece newPiece(int idJ) {
|
||||
Piece piece;
|
||||
piece.idJ = idJ;
|
||||
piece.stuck = false;
|
||||
return piece;
|
||||
}
|
||||
|
Loading…
Reference in new issue