コード例 #1
0
ファイル: life.cpp プロジェクト: bsubrama/projects
int main(int argc, char *argv[])
{
    if (argc < 4) {
        std::cout << "Usage: basiclife <rows> <cols> <numstart> <generations> <prefix>" << std::endl;
        return 0;
    }
	
	int rows = atoi(argv[1]);
	int cols = atoi(argv[2]);
	int numStart = atoi(argv[3]);
	int numGenerations = atoi(argv[4]);
	std::string prefix(argv[5]);
	
    std::vector< std::vector<bool> > arena;
	
	initializeArena(arena, rows, cols, numStart);
	
	int generationCount = 0;
	
	while (generationCount < numGenerations) {
		writeGenerationToFile(arena, prefix, generationCount);
		computeNextGeneration(arena);
		generationCount++;
	}
}
コード例 #2
0
void playGame (char currentBoard [] [WIDTH], char nextGenBoard [][WIDTH], int nrows, int ncols )
{
	int i, turns;
	do{
	cout << "How Many Turns?: ";
	cin >> turns;
		if (turns <= 0) {
			cout << "Error: Invalid Entry. Number must be positive" << endl << endl;
		}
	}while (turns <= 0);
	
	displayCurrentBoard(currentBoard, nrows, ncols);
	
	for (i = 0; i < turns; ++i) {
		
		computeNextGeneration(currentBoard, nextGenBoard, nrows, ncols);
		displayCurrentBoard( nextGenBoard, nrows, ncols);
		arrayCopy(currentBoard, nextGenBoard);
		
	}
}
コード例 #3
0
ファイル: winGOL.cpp プロジェクト: pol51/LifeGame
winGOL::winGOL(QWidget *parent):QWidget(parent)
{
	this->ui.setupUi(this);
	
	//chargement du style
	this->changeStyle("Plastique");
	
	//evenements
	QObject::connect(
		this->ui.btnQuit, SIGNAL(clicked()),
		this, SLOT(close()));
	QObject::connect(
		this->ui.btnNext, SIGNAL(clicked()),
		this->ui.wgtGOL, SLOT(computeNextGeneration()));
	QObject::connect(
		this->ui.btnClear, SIGNAL(clicked()),
		this->ui.wgtGOL, SLOT(clearGameTable()));
	QObject::connect(
		this->ui.wgtGOL, SIGNAL(nbLifeChanged(int)),
		this, SLOT(updateText(int)));
}
コード例 #4
0
ファイル: lifeWidget.cpp プロジェクト: pol51/LifeGame
LifeWidget::LifeWidget(QWidget *parent, int nbCases)
    : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
{
	assert(nbCases);
	
	showGrid = true;
	
	refreshTimer.setSingleShot(false);
    connect(&refreshTimer, SIGNAL(timeout()), this, SLOT(update()));
    refreshTimer.start(15);

    setAttribute(Qt::WA_NoSystemBackground);
    setMinimumSize(320, 320);
    setWindowTitle("LifeGame");
	
	mouseX = 0.0;
	mouseY = 0.0;
	
	posX = 0;
	posY = 0;
	
	setMouseTracking(true);
	
	this->nbCases = nbCases;
	lifeGame = new LifeGame(this->nbCases);
	
	toggleFullScreenAction = new QAction(this);
	toggleFullScreenAction->setShortcutContext(Qt::ApplicationShortcut);
	toggleFullScreenAction->setCheckable(true);
	toggleFullScreenAction->setShortcut(Qt::Key_Return | Qt::AltModifier);
	connect(toggleFullScreenAction, SIGNAL(triggered(bool)),
			this, SLOT(toggleFullScreen(bool)));
	
	toggleGridAction = new QAction(this);
	toggleGridAction->setShortcutContext(Qt::ApplicationShortcut);
	toggleGridAction->setCheckable(true);
	toggleGridAction->setShortcut(Qt::Key_G | Qt::AltModifier);
	connect(toggleGridAction, SIGNAL(triggered(bool)),
			this, SLOT(toggleGrid(bool)));
	
	nextGenerationAction = new QAction(this);
	nextGenerationAction->setShortcutContext(Qt::ApplicationShortcut);
	nextGenerationAction->setShortcut(Qt::Key_Plus);
	connect(nextGenerationAction, SIGNAL(triggered()),
			this, SLOT(computeNextGeneration()));
	
	clearGameAction = new QAction(this);
	clearGameAction->setShortcutContext(Qt::ApplicationShortcut);
	clearGameAction->setShortcut(Qt::Key_Asterisk);
	connect(clearGameAction, SIGNAL(triggered()),
			this, SLOT(clearGameTable()));
	
	addAction(toggleFullScreenAction);
	addAction(toggleGridAction);
	addAction(nextGenerationAction);
	addAction(clearGameAction);
	
	gameHud = new QtHud(this);
	QFont font;
	font.setFamily("Lucida Console");
	font.setPixelSize(14);
	font.setBold(true);
	gameHud->setFont(font);
	gameHud->setForeColor(QColor::fromRgb(0, 255, 127));
}