#include "nimform.h" #include "optionsform.h" #include "stapeldisplay.h" #include "const.h" #include #include #include #include #include #include #include #include #include #include #include NimForm::NimForm( ) //constructor : QMainWindow( 0, 0, WDestructiveClose) { QAction *fileNewAction; QAction *fileQuitAction; fileNewAction = new QAction( "New Game", "&New", CTRL+Key_N,this, "new"); connect( fileNewAction, SIGNAL( activated() ), this, SLOT( fileNew() ) ); fileQuitAction = new QAction( "Quit", "&Quit", CTRL+Key_Q, this, "quit" ); connect( fileQuitAction, SIGNAL( activated() ), this, SLOT( fileQuit() ) ); fileMenu = new QPopupMenu( this ); menuBar()->insertItem( "&File", fileMenu ); fileNewAction->addTo( fileMenu ); fileQuitAction->addTo ( fileMenu ); QAction *helpHelpAction; QAction *helpAboutAction; helpHelpAction = new QAction( "H&elp", "H&elp", CTRL+Key_H,this, "help"); connect( helpHelpAction, SIGNAL( activated() ), this, SLOT( helpHelp() ) ); helpAboutAction = new QAction( "&About", "&About", CTRL+Key_A,this, "about"); connect( helpAboutAction, SIGNAL( activated() ), this, SLOT( helpAbout() ) ); helpMenu = new QPopupMenu( this ); menuBar()->insertItem( "&Help", helpMenu ); helpHelpAction->addTo ( helpMenu ); helpAboutAction->addTo ( helpMenu ); statusBar()->message( "Welcome to Nim"); resize( QSize(600, 480).expandedTo(minimumSizeHint()) ); clearWState( WState_Polished ); //global var standard value for(int i = 0; i < MAX_STAPELS; i++) { stapelBox[i] = NULL; } stapelAantal = -1; stokjesMin = 0; stokjesMax = 0; niveauComputer = 0; } NimForm::~NimForm() { } void NimForm::clearBord( int stapelAantalLocal, int stokjesMinLocal, int stokjesMaxLocal ) { stapelAantal = stapelAantalLocal; stokjesMin = stokjesMinLocal; stokjesMax = stokjesMaxLocal; for(int i = 0; i < stapelAantalLocal; i++) { if (not( stapelBox[i] == NULL )) {delete stapelBox[i];} } } void NimForm::createBord( int stapelAantalLocal, int stokjesMinLocal, int stokjesMaxLocal ) { int Y = -30; //xcoord int X = 10; //ycoord int tmpAantal = 0; //aantal onthouden ivm met rijen stapelAantal = stapelAantalLocal; stokjesMin = stokjesMinLocal; stokjesMax = stokjesMaxLocal; for(int i = 0; i < stapelAantalLocal; i++) { if (tmpAantal == 10) { X = X + 360; Y = 40; tmpAantal = 1; } else { tmpAantal++; Y = Y + 70; } stapelBox[i] = new StapelGroupBox( this, "stapelGroupBox" ); stapelBox[i]->setXY( X, Y ); stapelBox[i]->setRange( stokjesMinLocal, stokjesMaxLocal ); stapelBox[i]->setCaption(i); connect( stapelBox[i], SIGNAL( buttonPressed(int,int) ), this, SLOT( stapelMin(int,int) ) ); stapelBox[i]->show(); } resize( QSize(600, 480).expandedTo(minimumSizeHint()) ); clearWState( WState_Polished ); } //void NimForm::closeEvent( QCloseEvent * ) //{ // //} void NimForm::fileNew() { OptionsForm * optionsForm = new OptionsForm( this ); if ( optionsForm->exec() ) { clearBord( stapelAantal, 0 , 0 ); int stapelAantalOptions = optionsForm->stapelsSlider->value(); int stokjesMinOptions = 0; int stokjesMaxOptions = optionsForm->stokjesSlider->value(); if ( optionsForm->niveau1RadioButton->isChecked() ) { niveauComputer = 1; } else if (optionsForm->niveau2RadioButton->isChecked() ) { niveauComputer = 2; } createBord( stapelAantalOptions, stokjesMinOptions, stokjesMaxOptions ); } delete optionsForm; } void NimForm::fileQuit() { qApp->exit ( 0 ); } void NimForm::helpHelp() { } void NimForm::helpAbout() { } // END SCREEN BUILDING // // BEGIN SPELLETJES int NimForm::getStapelAantal( int stapelNumber ) { return(stapelBox[stapelNumber]->stapelLCDNumber->value()); } void NimForm::stapelMin( int stapelNumber , int aantal ) { //eerst gegevens speler verwerken int tmpOudAantal = getStapelAantal( stapelNumber ); int tmpNieuwAantal = 0; if ( (tmpOudAantal == 1) or (tmpOudAantal == 2) and (aantal == 2) ) { tmpNieuwAantal = 0; stapelBox[stapelNumber]->stapelMin1PushButton->setEnabled ( FALSE ); stapelBox[stapelNumber]->stapelMin2PushButton->setEnabled ( FALSE ); } else { tmpNieuwAantal = tmpOudAantal - aantal; } stapelBox[stapelNumber]->stapelLCDNumber->display( tmpNieuwAantal ); stapelBox[stapelNumber]->stapelProgressBar->setProgress( tmpNieuwAantal ); if ( checkGewonnen ) //speler gewonnen { statusBar()->message("Voila, u heeft gewonnen!"); } //dan computer een zet laten doen void }