source: liacs/pm/qt-nim2/nimform.cpp@ 100

Last change on this file since 100 was 2, checked in by Rick van der Zwet, 15 years ago

Initial import of data of old repository ('data') worth keeping (e.g. tracking
means of URL access statistics)

  • Property svn:executable set to *
File size: 4.6 KB
Line 
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
18NimForm::NimForm( )
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
75NimForm::~NimForm()
76{
77
78}
79
80void 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
92void 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
132void 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
150void NimForm::fileQuit()
151{
152 qApp->exit ( 0 );
153}
154
155
156void NimForm::helpHelp()
157{
158
159}
160
161
162void NimForm::helpAbout()
163{
164
165}
166
167void NimForm::stapelMin( int stapelNumber , int aantal )
168{
169 int tmpOudAantal = getStapelAantal( stapelNumber );
170 int tmpNieuwAantal = 0;
171 if ( (tmpOudAantal == 1) or
172 (tmpOudAantal == 2) and (aantal == 2) )
173 {
174 tmpNieuwAantal = 0;
175 stapelBox[stapelNumber]->stapelMin1PushButton->setEnabled ( FALSE );
176 stapelBox[stapelNumber]->stapelMin2PushButton->setEnabled ( FALSE );
177 }
178 else {
179 tmpNieuwAantal = tmpOudAantal - aantal;
180 }
181 stapelBox[stapelNumber]->stapelLCDNumber->display( tmpNieuwAantal );
182 stapelBox[stapelNumber]->stapelProgressBar->setProgress( tmpNieuwAantal );
183}
184
185int NimForm::getStapelAantal( int stapelNumber )
186{
187 return(stapelBox[stapelNumber]->stapelLCDNumber->value());
188}
Note: See TracBrowser for help on using the repository browser.