Utworzenie klasy gry
This commit is contained in:
@@ -90,3 +90,24 @@ void Board::draw(sf::RenderWindow& window)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Pawn* Board::selectPawn(Vector position)
|
||||
{
|
||||
// Jeżeli pionek na tym polu istnieje
|
||||
if(board[position.x][position.y])
|
||||
{
|
||||
// Odznaczamy wszystkie pionki
|
||||
for(int x = 0; x<TILES_COUNT; ++x)
|
||||
for(int y = 0; y<TILES_COUNT; ++y)
|
||||
if(board[x][y]) board[x][y]->deselect();
|
||||
|
||||
// Zaznaczamy właściwy
|
||||
board[position.x][position.y]->select();
|
||||
|
||||
// Zwracamy zaznaczony
|
||||
return board[position.x][position.y];
|
||||
}
|
||||
|
||||
// Zwracamy NULL, bo pionek nie istnieje
|
||||
return NULL;
|
||||
}
|
||||
|
||||
32
src/game.cpp
Normal file
32
src/game.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "../inc/game.hh"
|
||||
|
||||
Game::Game()
|
||||
:
|
||||
window(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, 32), "Warcaby", sf::Style::Close),
|
||||
selected(NULL),
|
||||
player_color(CL_WHITE)
|
||||
{
|
||||
// Kod inicjalizujący
|
||||
// Pętla główna
|
||||
loop();
|
||||
}
|
||||
|
||||
void Game::killPawn(Vector position)
|
||||
{
|
||||
}
|
||||
|
||||
Player Game::getPlayer(Vector position)
|
||||
{
|
||||
//
|
||||
return PL_HUMAN;
|
||||
}
|
||||
|
||||
bool Game::movePawn(Vector position, Vector target)
|
||||
{
|
||||
//
|
||||
return true;
|
||||
}
|
||||
|
||||
void Game::loop()
|
||||
{
|
||||
}
|
||||
17
src/main.cpp
17
src/main.cpp
@@ -6,23 +6,34 @@
|
||||
#include "../inc/object.hh"
|
||||
#include "../inc/pawn.hh"
|
||||
#include "../inc/board.hh"
|
||||
#include "../inc/game.hh"
|
||||
|
||||
int main()
|
||||
{
|
||||
sf::ContextSettings settings;
|
||||
/* sf::ContextSettings settings;
|
||||
settings.antialiasingLevel = 8;
|
||||
sf::RenderWindow window(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, 32), "Warcaby", sf::Style::Close, settings);
|
||||
Board board;
|
||||
Pawn* selected;
|
||||
while(window.isOpen())
|
||||
{
|
||||
sf::Event event;
|
||||
while(window.pollEvent(event))
|
||||
{
|
||||
if(event.type == sf::Event::Closed) window.close();
|
||||
if(event.type == sf::Event::Closed) window.close();
|
||||
if(event.type == sf::Event::MouseButtonPressed)
|
||||
{
|
||||
if(event.mouseButton.button == sf::Mouse::Left)
|
||||
{
|
||||
Pawn* tmp = board.selectPawn(Vector(sf::Vector2f(event.mouseButton.x, event.mouseButton.y)));
|
||||
if(tmp) selected = tmp;
|
||||
else board.movePawn(selected->getPosition(), Vector(sf::Vector2f(event.mouseButton.x, event.mouseButton.y)));
|
||||
}
|
||||
}
|
||||
}
|
||||
window.clear(sf::Color(255, 255, 255));
|
||||
board.draw(window);
|
||||
window.display();
|
||||
}
|
||||
}*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user