Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Games
KReversi
Commits
dcb78cc2
Commit
dcb78cc2
authored
Sep 04, 2006
by
Dmitry Suzdalev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented kaction & co for setting computer skill
svn path=/branches/work/kreversi_rewrite/; revision=580783
parent
bd81e747
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
53 additions
and
8 deletions
+53
-8
kreversichip.h
kreversichip.h
+1
-1
kreversigame.cpp
kreversigame.cpp
+6
-0
kreversigame.h
kreversigame.h
+4
-0
kreversiui.rc
kreversiui.rc
+2
-0
mainwindow.cpp
mainwindow.cpp
+35
-7
mainwindow.h
mainwindow.h
+5
-0
No files found.
kreversichip.h
View file @
dcb78cc2
...
...
@@ -61,7 +61,7 @@ public:
* Supposes that allFrames represents an animation sequence
* going from black to white.
* @param allFrames a pixmap containing whole animation sequence
* @param
chip
Size size of each frame's pixmap. Frames are squares.
* @param
frame
Size size of each frame's pixmap. Frames are squares.
*/
KReversiChipFrameSet
(
const
QPixmap
&
allFrames
,
int
frameSize
);
/**
...
...
kreversigame.cpp
View file @
dcb78cc2
...
...
@@ -435,6 +435,12 @@ bool KReversiGame::isAnyComputerMovePossible() const
return
false
;
}
void
KReversiGame
::
setComputerSkill
(
int
skill
)
{
kDebug
()
<<
"setting skill to "
<<
skill
<<
endl
;
m_engine
->
setStrength
(
skill
);
}
KReversiMove
KReversiGame
::
getHint
()
const
{
// FIXME dimsuz: don't use true, use m_competitive
...
...
kreversigame.h
View file @
dcb78cc2
...
...
@@ -55,6 +55,10 @@ public:
* Sets the strength of game engine (1 to 7)
*/
void
setEngineStrength
(
uint
strength
);
/**
* Sets the computer skill level. From 1 to 7
*/
void
setComputerSkill
(
int
skill
);
/**
* @return strength of the game engine
*/
...
...
kreversiui.rc
View file @
dcb78cc2
...
...
@@ -13,6 +13,8 @@
</Menu>
<Menu
name=
"settings"
><text>
&
Settings
</text>
<Action
name=
"choose_bkgnd"
/>
<Action
name=
"anim_speed"
/>
<Action
name=
"skill"
/>
</Menu>
</MenuBar>
...
...
mainwindow.cpp
View file @
dcb78cc2
...
...
@@ -27,6 +27,8 @@ KReversiMainWindow::KReversiMainWindow(QWidget* parent)
m_view
->
show
();
setupActions
();
loadSettings
();
setCentralWidget
(
m_view
);
statusBar
()
->
insertItem
(
i18n
(
"Your turn."
),
0
);
...
...
@@ -47,8 +49,8 @@ void KReversiMainWindow::setupActions()
m_demoAct
->
setShortcut
(
Qt
::
Key_D
);
connect
(
m_demoAct
,
SIGNAL
(
triggered
(
bool
)),
SLOT
(
slotDemoMode
(
bool
))
);
KSelectAction
*
bkgndAct
=
new
KSelectAction
(
i18n
(
"Choose background"
),
actionCollection
(),
"choose_bkgnd"
);
connect
(
bkgndAct
,
SIGNAL
(
triggered
(
const
QString
&
)),
SLOT
(
slotBackgroundChanged
(
const
QString
&
)));
m_
bkgndAct
=
new
KSelectAction
(
i18n
(
"Choose background"
),
actionCollection
(),
"choose_bkgnd"
);
connect
(
m_
bkgndAct
,
SIGNAL
(
triggered
(
const
QString
&
)),
SLOT
(
slotBackgroundChanged
(
const
QString
&
)));
QStringList
pixList
=
kapp
->
dirs
()
->
findAllResources
(
"appdata"
,
"pics/background/*.png"
,
false
,
true
);
// let's find a name of files w/o extensions
...
...
@@ -58,19 +60,27 @@ void KReversiMainWindow::setupActions()
{
int
idx1
=
str
.
lastIndexOf
(
'/'
);
int
idx2
=
str
.
lastIndexOf
(
'.'
);
bkgndAct
->
addAction
(
str
.
mid
(
idx1
+
1
,
idx2
-
idx1
-
1
));
m_
bkgndAct
->
addAction
(
str
.
mid
(
idx1
+
1
,
idx2
-
idx1
-
1
));
}
bkgndAct
->
setCurrentAction
(
Preferences
::
backgroundImageName
()
);
slotBackgroundChanged
(
Preferences
::
backgroundImageName
()
);
KToggleAction
*
showLast
=
new
KToggleAction
(
KIcon
(
"lastmoves"
),
i18n
(
"Show last move"
),
actionCollection
(),
"show_last_move"
);
connect
(
showLast
,
SIGNAL
(
triggered
(
bool
)),
m_scene
,
SLOT
(
setShowLastMove
(
bool
))
);
KToggleAction
*
showLegal
=
new
KToggleAction
(
KIcon
(
"legalmoves"
),
i18n
(
"Show legal moves"
),
actionCollection
(),
"show_legal_moves"
);
connect
(
showLegal
,
SIGNAL
(
triggered
(
bool
)),
m_scene
,
SLOT
(
setShowLegalMoves
(
bool
))
);
KSelectAction
*
animSpeed
=
new
KSelectAction
(
i18n
(
"Animation speed"
),
actionCollection
(),
"anim_speed"
);
QStringList
acts
;
acts
<<
"Slow"
<<
"Normal"
<<
"Fast"
;
animSpeed
->
setItems
(
acts
);
m_skillAct
=
new
KSelectAction
(
i18n
(
"Computer skill"
),
actionCollection
(),
"skill"
);
acts
.
clear
();
// FIXME dimsuz: this utilises 5 skills. although 7 is possible
acts
<<
"Very easy"
<<
"Easy"
<<
"Normal"
<<
"Hard"
<<
"Unbeatable"
;
m_skillAct
->
setItems
(
acts
);
connect
(
m_skillAct
,
SIGNAL
(
triggered
(
int
)),
SLOT
(
slotSkillChanged
(
int
))
);
addAction
(
newGameAct
);
addAction
(
quitAct
);
addAction
(
m_undoAct
);
...
...
@@ -78,6 +88,16 @@ void KReversiMainWindow::setupActions()
addAction
(
m_demoAct
);
}
void
KReversiMainWindow
::
loadSettings
()
{
m_bkgndAct
->
setCurrentAction
(
Preferences
::
backgroundImageName
()
);
slotBackgroundChanged
(
Preferences
::
backgroundImageName
()
);
int
skill
=
Preferences
::
skill
();
m_skillAct
->
setCurrentItem
(
skill
-
1
);
slotSkillChanged
(
skill
-
1
);
}
void
KReversiMainWindow
::
slotBackgroundChanged
(
const
QString
&
text
)
{
// FIXME dimsuz: I'm removing "&" from text here, because
...
...
@@ -96,6 +116,14 @@ void KReversiMainWindow::slotBackgroundChanged( const QString& text )
Preferences
::
writeConfig
();
}
void
KReversiMainWindow
::
slotSkillChanged
(
int
skill
)
{
// m_game takes it from 1 to 7
m_game
->
setComputerSkill
(
skill
+
1
);
Preferences
::
setSkill
(
skill
+
1
);
Preferences
::
writeConfig
();
}
void
KReversiMainWindow
::
slotDemoMode
(
bool
toggled
)
{
kDebug
()
<<
k_funcinfo
<<
endl
;
...
...
mainwindow.h
View file @
dcb78cc2
...
...
@@ -7,6 +7,7 @@ class KReversiScene;
class
KReversiGame
;
class
KReversiView
;
class
KAction
;
class
KSelectAction
;
class
KReversiMainWindow
:
public
KMainWindow
{
...
...
@@ -16,12 +17,14 @@ public:
public
slots
:
void
slotNewGame
();
void
slotBackgroundChanged
(
const
QString
&
text
);
void
slotSkillChanged
(
int
);
void
slotUndo
();
void
slotMoveFinished
();
void
slotGameOver
();
void
slotDemoMode
(
bool
);
private:
void
setupActions
();
void
loadSettings
();
KReversiScene
*
m_scene
;
KReversiView
*
m_view
;
...
...
@@ -30,5 +33,7 @@ private:
KAction
*
m_undoAct
;
KAction
*
m_hintAct
;
KAction
*
m_demoAct
;
KSelectAction
*
m_bkgndAct
;
KSelectAction
*
m_skillAct
;
};
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment