コード例 #1
0
ファイル: logic.c プロジェクト: winterweird/hnefatafl-console
TILE selectPiece(TILE board[], char currentPlayer, TILE last) {
    do {
        last = selectTile(board, last);
        if (tileEmpty(last)) break;
        printErrorString(ownsPiece(currentPlayer, last) ? 0 : 6);
    } while (!ownsPiece(currentPlayer, last));
    return last;
}
コード例 #2
0
ファイル: logic.c プロジェクト: winterweird/hnefatafl-console
TILE selectNewPosition(TILE board[], TILE last, int* r) {
    TILE g;
    do {
        g = selectTile(board, last);
        if (tileEmpty(g)) break;
        *r = moveValidity(last, g, board);
        if (*r==1) break;
        printErrorString(*r);
    } while (*r != 0);
    return g;
}
コード例 #3
0
EditorWindow::EditorWindow() : QMainWindow(), newmap(this), editgroup(this)
{
	ui.setupUi(this);

	// Set up input
	QObject::connect(ui.ActionNew, SIGNAL(activated()), &newmap, SLOT(exec()));
	QObject::connect(ui.ActionOpen, SIGNAL(activated()), this, SLOT(openDialog()));
	QObject::connect(ui.ActionSave, SIGNAL(activated()), this, SLOT(save()));
	QObject::connect(ui.ActionSaveAs, SIGNAL(activated()), this, SLOT(saveAs()));
	QObject::connect(ui.ActionCompile, SIGNAL(activated()), this, SLOT(compile()));
	QObject::connect(ui.ActionAbout, SIGNAL(activated()), this, SLOT(about()));
	QObject::connect(&newmap, SIGNAL(accepted()), this, SLOT(newMap()));
	QObject::connect(&openmap, SIGNAL(accepted()), this, SLOT(open()));
	QObject::connect(ui.ActionGrid, SIGNAL(toggled(bool)), ui.levelview, SLOT(showGrid(bool)));
	ui.ActionGrid->setChecked(true);
	QObject::connect(ui.ActionMiniMap, SIGNAL(toggled(bool)), ui.levelview, SLOT(showMiniMap(bool)));
	ui.ActionMiniMap->setChecked(true);
	QObject::connect(ui.resize, SIGNAL(clicked()), this, SLOT(resize()));
	QObject::connect(ui.tilelist, SIGNAL(clicked(QModelIndex)), this, SLOT(selectTile(QModelIndex)));
	QObject::connect(ui.entitylist, SIGNAL(clicked(QModelIndex)), this, SLOT(selectEntity(QModelIndex)));
	QObject::connect(ui.toolbox, SIGNAL(currentChanged(int)), this, SLOT(selectPanel(int)));
	// Create edit input group
	editgroup.addAction(ui.ActionDraw);
	editgroup.addAction(ui.ActionErase);
	editgroup.addAction(ui.ActionSelect);
	editgroup.setExclusive(true);
	ui.ActionSelect->setChecked(true);
	QObject::connect(&editgroup, SIGNAL(triggered(QAction*)), this, SLOT(setAction(QAction*)));
	// Fill tile list
	std::vector<std::string> tilenames = TileSet::getTiles();
	for (unsigned int i = 0; i < tilenames.size(); i++)
	{
		tilelist.appendRow(new QStandardItem(tilenames[i].c_str()));
	}
	ui.tilelist->setModel(&tilelist);
	// Fill entity list
	std::vector<std::string> entitynames = Game::get().getEntities();
	for (unsigned int i = 0; i < entitynames.size(); i++)
	{
		entitylist.appendRow(new QStandardItem(entitynames[i].c_str()));
	}
	ui.entitylist->setModel(&entitylist);
}
コード例 #4
0
ファイル: GameUi.cpp プロジェクト: TED-996/MinesweeperMp
	bool GameUi::handleEvent(Event event) {
		if (event.type != Event::KeyPressed) {
			return false;
		}
		auto keyEvent = event.key;

		if (keyEvent.code == Keyboard::Return) {
			onButtonFlag(selectedPoint.line, selectedPoint.column);
			return true;
		}
		if (keyEvent.code == Keyboard::Space) {
			onButtonReveal(selectedPoint.line, selectedPoint.column);
			return true;
		}

		Direction direction;
		if (keyEvent.code == Keyboard::Up) {
			direction = Direction::Up;
		}
		else if (keyEvent.code == Keyboard::Right) {
			direction = Direction::Right;
		}
		else if (keyEvent.code == Keyboard::Down) {
			direction = Direction::Down;
		}
		else if (keyEvent.code == Keyboard::Left) {
			direction = Direction::Left;
		}
		else {
			return false;
		}
		auto oldSelection = selectedPoint;
		selectedPoint = selectedPoint.getNeighbor(direction).clampMax(gameSettings.boardSize);
		if (oldSelection != selectedPoint) {
			unselectTile(oldSelection);
			selectTile(selectedPoint);
		}

		return true;
	}
コード例 #5
0
ファイル: Tile.cpp プロジェクト: JustPowell/Project_C
void Tile::load(sf::Texture& texturefile, int tiletype)
{
    selectTile(texturefile, tiletype);
}
コード例 #6
0
ファイル: GameUi.cpp プロジェクト: TED-996/MinesweeperMp
	void GameUi::initWindow() {
		window->SetStyle(Style::Fullscreen);
		window->SetRequisition(Vector2f((float)ct::WindowWidth, (float)ct::WindowHeight));

		auto mainBox = Box::Create(Box::Orientation::VERTICAL);

		auto topBox = Box::Create(Box::Orientation::HORIZONTAL);

		auto backButton = Button::Create("Back");
		backButton->GetSignal(Widget::OnLeftClick).Connect(closeAction);
		topBox->Pack(backButton, false, false);

		clockLabel = Label::Create("00:00");
		clockLabel->SetAlignment(Vector2f(1.0f, 0.5f));
		topBox->Pack(createAlignment(clockLabel, Vector2f(1.0f, 0.5f)), true, true);

		auto middleBox = Box::Create(Box::Orientation::HORIZONTAL);

		auto gameBox = Box::Create(Box::Orientation::HORIZONTAL, 5);
		auto table = Table::Create();
		int buttonSize = (int) (ct::WindowHeight * 0.7 / gameSettings.boardSize);
		for (int l = 0; l < gameSettings.boardSize; l++) {
			for (int c = 0; c < gameSettings.boardSize; c++) {
				auto tileButton = getNewButton(l, c, buttonSize);

				tileButtons[l][c] = tileButton;
				table->Attach(tileButton, Rect<Uint32>(c, l, 1, 1));
			}
		}
		gameBox->Pack(table, false, false);

		if (gameSettings.isMp) {
			auto rightPane = Box::Create(Box::Orientation::VERTICAL);
			rightPane->Pack(scoreboard.getWidget());

			auto turnFrame = Frame::Create("Turn");
			auto turnBox = Box::Create(Box::Orientation::VERTICAL, 5);

			revealCountBar = ProgressBar::Create(ProgressBar::Orientation::HORIZONTAL);
			revealCountBar->SetFraction(0);
			revealCountBar->SetRequisition(Vector2f(10, 10));
			turnBox->Pack(revealCountBar);

			auto turnEndButton = Button::Create("End turn");
			turnEndButton->GetSignal(Widget::OnLeftClick).Connect(bind(&GameUi::onTurnEnd, this));
			turnBox->Pack(turnEndButton);
			
			turnFrame->Add(turnBox);
			rightPane->Pack(turnFrame);

			gameBox->Pack(rightPane);
		}
		middleBox->Pack(createAlignment(gameBox, Vector2f(0.5f, 0.5f)));

		auto bottomBox = Box::Create(Box::Orientation::HORIZONTAL);

		messageLabel = Label::Create("Good luck!");
		messageTimeout = sf::seconds(3);
		bottomBox->Pack(messageLabel, false, true);
		bottomBox->Pack(Separator::Create(Separator::Orientation::VERTICAL), true, true);

		flagCountLabel = Label::Create(getFlagCountStr());
		auto mineCountLabel = Label::Create(string("/") + to_string(gameSettings.mineCount));
		auto mineStatBox = Box::Create(Box::Orientation::HORIZONTAL, 2);
		mineStatBox->Pack(flagCountLabel, false, false);
		mineStatBox->Pack(mineCountLabel, false, false);
		bottomBox->Pack(createAlignment(mineStatBox, Vector2f(1.0f, 0.5f), Vector2f(0.0f, 0.0f)), true, true);

		mainBox->Pack(topBox, true, true);
		mainBox->Pack(gameBox, true, true);
		mainBox->Pack(bottomBox, true, true);

		window->Add(createAlignment(mainBox, Vector2f(0.5f, 0.5f), Vector2f(0.0f, 0.0f)));

		selectTile(selectedPoint);
	}