Esempio n. 1
0
int localGame() {
    system("cls");
    char winner = 0;
    TILE board[121];
    memset(&board, 0, sizeof board);
    initBoard(board);
    char currentPlayer = 1;
    TILE t = {0,0,0,0}, g;
    do {
        jumpTo(0,0);
        printf("%s, make a move!\n", currentPlayer==1?"Attacker":"Defender");
        printBoard(board);
        int r;
        t = selectPiece(board, currentPlayer, t);
        if (tileEmpty(t)) return 0;
        printIntense(t);
        g = selectNewPosition(board, t, &r);
        if (tileEmpty(g)) return 0;
        if (r) continue;
        makeMove(t, g, board);
        winner = hasWinner(board, board[getIndex(g)]);
        currentPlayer = currentPlayer % 2 + 1;
        t = g;
    } while (!winner);
    
    // reblit board to capture last move
    jumpTo(0,1);
    printBoard(board);
    return winner;
}
Esempio n. 2
0
		bool BoardModel::moveTile(const vector2du32 &source, const vector2du32 &dest)
		{
			if (!tileEmpty(source))
			{
				LOG_DEBUG("Moving tile from " << source.x << "," << source.y << " to " << dest.x << "," << dest.y);

				SITilePointer sourceTile{ getTile(source) };
				WITilePointer destTile{ getTile(dest) };

				LOG_DEBUG("Source Value: " << sourceTile->getData());

				if (sourceTile)
				{
					//			__ASSERT(!tileEmpty(xSource, ySource), "Tile " << xSource << "," << ySource << " is empty");
					__ASSERT(!destTile.lock(), "Trying to move to a not empty tile: " << dest.x << "," << dest.y << " contains " << destTile.lock()->getData());

					_setTile(dest, sourceTile);
					_setTile(source, WITilePointer());

					if (p_tController) p_tController->tileMoved(source, dest, sourceTile);
					return true;
				}
			}
			else
			{
				LOG_DEBUG("Trying to move empty tile: " << source.x << "," << source.y << " ignoring it");
			}
			return false;
		}
Esempio n. 3
0
		void BoardModel::deleteTile(const vector2du32 &position)
		{
			__ASSERT(!tileEmpty(position), "You can only delete not empty tiles");
			WITilePointer current = getTile(position);
			_tiles[position.x][position.y].reset();
			if (p_tController) p_tController->tileDeleted(position,current);
		}
Esempio n. 4
0
		void BoardModel::setTile(const lib::vector2du32 &tPosition, WITilePointer newTile)
		{
			__ASSERT(tileEmpty(tPosition), "You can only set data in empty tiles");

			_setTile(tPosition, newTile);
			if (p_tController) p_tController->tileAdded(tPosition, newTile);
		}
Esempio n. 5
0
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;
}
Esempio n. 6
0
		void BoardModel::changeTileData(const vector2du32 &source, const BoardTileData &nv)
		{
			__ASSERT(!tileEmpty(source), "You can only change data in not empty tiles");

			auto tile = getTile(source).lock();
			BoardTileData ov = tile->getData();
			tile->setData(nv);
			if (p_tController) p_tController->tileChanged(source, tile, ov,nv);
		}
Esempio n. 7
0
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;
}