[2] | 1 | #include "nimform.h"
|
---|
| 2 | #include "optionsform.h"
|
---|
| 3 | #include "stapeldisplay.h"
|
---|
| 4 | #include "const.h"
|
---|
| 5 |
|
---|
| 6 | #include <qaction.h>
|
---|
| 7 | #include <qapplication.h>
|
---|
| 8 | #include <qlcdnumber.h>
|
---|
| 9 | #include <qmenubar.h>
|
---|
| 10 | #include <qmessagebox.h>
|
---|
| 11 | #include <qpopupmenu.h>
|
---|
| 12 | #include <qpushbutton.h>
|
---|
| 13 | #include <qprogressbar.h>
|
---|
| 14 | #include <qradiobutton.h>
|
---|
| 15 | #include <qslider.h>
|
---|
| 16 | #include <qstatusbar.h>
|
---|
| 17 |
|
---|
| 18 | NimForm::NimForm( ) //constructor
|
---|
| 19 | : QMainWindow( 0, 0, WDestructiveClose)
|
---|
| 20 | {
|
---|
| 21 | QAction *fileNewAction;
|
---|
| 22 | QAction *fileQuitAction;
|
---|
| 23 |
|
---|
| 24 | fileNewAction = new QAction(
|
---|
| 25 | "New Game",
|
---|
| 26 | "&New", CTRL+Key_N,this, "new");
|
---|
| 27 | connect( fileNewAction, SIGNAL( activated() ),
|
---|
| 28 | this, SLOT( fileNew() ) );
|
---|
| 29 |
|
---|
| 30 | fileQuitAction = new QAction(
|
---|
| 31 | "Quit",
|
---|
| 32 | "&Quit", CTRL+Key_Q, this, "quit" );
|
---|
| 33 | connect( fileQuitAction, SIGNAL( activated() ),
|
---|
| 34 | this, SLOT( fileQuit() ) );
|
---|
| 35 |
|
---|
| 36 | fileMenu = new QPopupMenu( this );
|
---|
| 37 | menuBar()->insertItem( "&File", fileMenu );
|
---|
| 38 | fileNewAction->addTo( fileMenu );
|
---|
| 39 | fileQuitAction->addTo ( fileMenu );
|
---|
| 40 |
|
---|
| 41 | QAction *helpHelpAction;
|
---|
| 42 | QAction *helpAboutAction;
|
---|
| 43 |
|
---|
| 44 | helpHelpAction = new QAction(
|
---|
| 45 | "H&elp",
|
---|
| 46 | "H&elp", CTRL+Key_H,this, "help");
|
---|
| 47 | connect( helpHelpAction, SIGNAL( activated() ),
|
---|
| 48 | this, SLOT( helpHelp() ) );
|
---|
| 49 |
|
---|
| 50 | helpAboutAction = new QAction(
|
---|
| 51 | "&About",
|
---|
| 52 | "&About", CTRL+Key_A,this, "about");
|
---|
| 53 | connect( helpAboutAction, SIGNAL( activated() ),
|
---|
| 54 | this, SLOT( helpAbout() ) );
|
---|
| 55 |
|
---|
| 56 | helpMenu = new QPopupMenu( this );
|
---|
| 57 | menuBar()->insertItem( "&Help", helpMenu );
|
---|
| 58 | helpHelpAction->addTo ( helpMenu );
|
---|
| 59 | helpAboutAction->addTo ( helpMenu );
|
---|
| 60 |
|
---|
| 61 |
|
---|
| 62 | statusBar()->message( "Welcome to Nim");
|
---|
| 63 | resize( QSize(600, 480).expandedTo(minimumSizeHint()) );
|
---|
| 64 | clearWState( WState_Polished );
|
---|
| 65 |
|
---|
| 66 | //global var standard value
|
---|
| 67 | for(int i = 0; i < MAX_STAPELS; i++) { stapelBox[i] = NULL; }
|
---|
| 68 | stapelAantal = -1;
|
---|
| 69 | stokjesMin = 0;
|
---|
| 70 | stokjesMax = 0;
|
---|
| 71 | niveauComputer = 0;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 |
|
---|
| 75 | NimForm::~NimForm()
|
---|
| 76 | {
|
---|
| 77 |
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | void NimForm::clearBord( int stapelAantalLocal, int stokjesMinLocal,
|
---|
| 81 | int stokjesMaxLocal )
|
---|
| 82 | {
|
---|
| 83 | stapelAantal = stapelAantalLocal;
|
---|
| 84 | stokjesMin = stokjesMinLocal;
|
---|
| 85 | stokjesMax = stokjesMaxLocal;
|
---|
| 86 |
|
---|
| 87 | for(int i = 0; i < stapelAantalLocal; i++) {
|
---|
| 88 | if (not( stapelBox[i] == NULL )) {delete stapelBox[i];}
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | void NimForm::createBord( int stapelAantalLocal, int stokjesMinLocal,
|
---|
| 93 | int stokjesMaxLocal )
|
---|
| 94 | {
|
---|
| 95 | int Y = -30; //xcoord
|
---|
| 96 | int X = 10; //ycoord
|
---|
| 97 | int tmpAantal = 0; //aantal onthouden ivm met rijen
|
---|
| 98 |
|
---|
| 99 | stapelAantal = stapelAantalLocal;
|
---|
| 100 | stokjesMin = stokjesMinLocal;
|
---|
| 101 | stokjesMax = stokjesMaxLocal;
|
---|
| 102 |
|
---|
| 103 | for(int i = 0; i < stapelAantalLocal; i++) {
|
---|
| 104 | if (tmpAantal == 10) {
|
---|
| 105 | X = X + 360;
|
---|
| 106 | Y = 40;
|
---|
| 107 | tmpAantal = 1;
|
---|
| 108 | }
|
---|
| 109 | else {
|
---|
| 110 | tmpAantal++;
|
---|
| 111 | Y = Y + 70;
|
---|
| 112 | }
|
---|
| 113 | stapelBox[i] = new StapelGroupBox( this, "stapelGroupBox" );
|
---|
| 114 | stapelBox[i]->setXY( X, Y );
|
---|
| 115 | stapelBox[i]->setRange( stokjesMinLocal, stokjesMaxLocal );
|
---|
| 116 | stapelBox[i]->setCaption(i);
|
---|
| 117 | connect( stapelBox[i], SIGNAL( buttonPressed(int,int) ),
|
---|
| 118 | this, SLOT( stapelMin(int,int) ) );
|
---|
| 119 | stapelBox[i]->show();
|
---|
| 120 | }
|
---|
| 121 | resize( QSize(600, 480).expandedTo(minimumSizeHint()) );
|
---|
| 122 | clearWState( WState_Polished );
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 |
|
---|
| 126 | //void NimForm::closeEvent( QCloseEvent * )
|
---|
| 127 | //{
|
---|
| 128 | //
|
---|
| 129 | //}
|
---|
| 130 |
|
---|
| 131 |
|
---|
| 132 | void NimForm::fileNew()
|
---|
| 133 | {
|
---|
| 134 | OptionsForm * optionsForm = new OptionsForm( this );
|
---|
| 135 | if ( optionsForm->exec() ) {
|
---|
| 136 | clearBord( stapelAantal, 0 , 0 );
|
---|
| 137 | int stapelAantalOptions = optionsForm->stapelsSlider->value();
|
---|
| 138 | int stokjesMinOptions = 0;
|
---|
| 139 | int stokjesMaxOptions = optionsForm->stokjesSlider->value();
|
---|
| 140 | if ( optionsForm->niveau1RadioButton->isChecked() )
|
---|
| 141 | { niveauComputer = 1; }
|
---|
| 142 | else if (optionsForm->niveau2RadioButton->isChecked() )
|
---|
| 143 | { niveauComputer = 2; }
|
---|
| 144 | createBord( stapelAantalOptions, stokjesMinOptions, stokjesMaxOptions );
|
---|
| 145 | }
|
---|
| 146 | delete optionsForm;
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 |
|
---|
| 150 | void NimForm::fileQuit()
|
---|
| 151 | {
|
---|
| 152 | qApp->exit ( 0 );
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 |
|
---|
| 156 | void NimForm::helpHelp()
|
---|
| 157 | {
|
---|
| 158 |
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 |
|
---|
| 162 | void NimForm::helpAbout()
|
---|
| 163 | {
|
---|
| 164 |
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | // END SCREEN BUILDING
|
---|
| 168 | //
|
---|
| 169 | // BEGIN SPELLETJES
|
---|
| 170 | int NimForm::getStapelAantal( int stapelNumber )
|
---|
| 171 | {
|
---|
| 172 | return(stapelBox[stapelNumber]->stapelLCDNumber->value());
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 | void NimForm::stapelMin( int stapelNumber , int aantal )
|
---|
| 176 | {
|
---|
| 177 | //eerst gegevens speler verwerken
|
---|
| 178 | int tmpOudAantal = getStapelAantal( stapelNumber );
|
---|
| 179 | int tmpNieuwAantal = 0;
|
---|
| 180 | if ( (tmpOudAantal == 1) or
|
---|
| 181 | (tmpOudAantal == 2) and (aantal == 2) )
|
---|
| 182 | {
|
---|
| 183 | tmpNieuwAantal = 0;
|
---|
| 184 | stapelBox[stapelNumber]->stapelMin1PushButton->setEnabled ( FALSE );
|
---|
| 185 | stapelBox[stapelNumber]->stapelMin2PushButton->setEnabled ( FALSE );
|
---|
| 186 | }
|
---|
| 187 | else {
|
---|
| 188 | tmpNieuwAantal = tmpOudAantal - aantal;
|
---|
| 189 | }
|
---|
| 190 | stapelBox[stapelNumber]->stapelLCDNumber->display( tmpNieuwAantal );
|
---|
| 191 | stapelBox[stapelNumber]->stapelProgressBar->setProgress( tmpNieuwAantal );
|
---|
| 192 |
|
---|
| 193 |
|
---|
| 194 | if ( checkGewonnen ) //speler gewonnen
|
---|
| 195 | {
|
---|
| 196 | statusBar()->message("Voila, u heeft gewonnen!");
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | //dan computer een zet laten doen
|
---|
| 200 |
|
---|
| 201 | void
|
---|
| 202 |
|
---|
| 203 |
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 |
|
---|