Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
prog_beadando_3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Barna Réka Emese
prog_beadando_3
Commits
89f8f055
Commit
89f8f055
authored
1 month ago
by
Barna Réka Emese
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
f6de800c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sajatalkalmazas.cpp
+150
-0
150 additions, 0 deletions
sajatalkalmazas.cpp
with
150 additions
and
0 deletions
sajatalkalmazas.cpp
0 → 100644
+
150
−
0
View file @
89f8f055
#include
"sajatalkalmazas.hpp"
#include
<iostream>
using
namespace
genv
;
SajatAlkalmazas
::
SajatAlkalmazas
(
int
szelesseg
,
int
magassag
)
:
Alkalmazas
(
szelesseg
,
magassag
),
allapotUzenet_
(
""
)
{
// Betűtípus betöltése
if
(
!
gout
.
load_font
(
"LiberationSans-Regular.ttf"
,
20
))
{
std
::
cerr
<<
"Nem sikerult betolteni a fontot!
\n
"
;
}
// 15x15-ös játék inicializálása
jatekVezerlo_
=
new
JatekVezerlo
(
15
);
jatekTer_
=
new
JatekTer
(
this
,
50
,
50
,
600
,
jatekVezerlo_
);
// Nagyobb játéktér
ujJatekGomb_
=
new
Gomb
(
this
,
670
,
50
,
100
,
40
,
"Uj jatek"
,
[
this
](){
ujJatekInditas
();
});
// Widgetek regisztrálása
widgetRegisztral
(
jatekTer_
);
widgetRegisztral
(
ujJatekGomb_
);
// Kezdeti állapot frissítése
frissitKovetkezoJatekos
();
}
void
SajatAlkalmazas
::
akcio
(
std
::
string
azonosito
)
{
if
(
azonosito
==
"escape"
)
{
exit
(
0
);
}
else
if
(
azonosito
==
"space"
||
azonosito
==
"n"
)
{
ujJatekInditas
();
}
else
if
(
jatekTer_
->
vanFokuszkent
())
{
if
(
azonosito
==
"up"
)
{
jatekTer_
->
mozgatFokuszt
(
0
,
-
1
);
}
else
if
(
azonosito
==
"down"
)
{
jatekTer_
->
mozgatFokuszt
(
0
,
1
);
}
else
if
(
azonosito
==
"left"
)
{
jatekTer_
->
mozgatFokuszt
(
-
1
,
0
);
}
else
if
(
azonosito
==
"right"
)
{
jatekTer_
->
mozgatFokuszt
(
1
,
0
);
}
else
if
(
azonosito
==
"enter"
)
{
jatekTer_
->
lepesFokuszuPoziciora
();
frissitKovetkezoJatekos
();
frissitAllapotUzenet
();
}
}
gout
<<
refresh
;
}
void
SajatAlkalmazas
::
ujJatekInditas
()
{
jatekVezerlo_
->
ujJatek
();
jatekTer_
->
resetFokuszt
();
allapotUzenet_
=
""
;
frissitKovetkezoJatekos
();
gout
<<
refresh
;
}
void
SajatAlkalmazas
::
rajzolFeliratokat
()
{
// Következő játékos felirat
buffer
<<
color
(
50
,
50
,
50
)
<<
move_to
(
670
,
120
)
<<
box
(
200
,
30
);
buffer
.
load_font
(
"LiberationSans-Regular.ttf"
,
20
);
//buffer.load_font("arial.ttf", 20);
std
::
string
jatekos
=
(
jatekVezerlo_
->
aktualisJatekos
()
==
JatekVezerlo
::
X_JATEKOS
)
?
"X"
:
"O"
;
buffer
<<
color
(
255
,
255
,
255
)
<<
move_to
(
670
,
140
)
<<
text
(
"Kovetkezo: "
+
jatekos
);
// Állapotüzenet
if
(
!
allapotUzenet_
.
empty
())
{
buffer
<<
color
(
50
,
50
,
50
)
<<
move_to
(
670
,
170
)
<<
box
(
200
,
30
);
buffer
<<
color
(
255
,
255
,
0
)
<<
move_to
(
670
,
190
)
<<
text
(
allapotUzenet_
);
}
}
void
SajatAlkalmazas
::
frissitAllapotUzenet
()
{
if
(
!
jatekVezerlo_
)
{
std
::
cerr
<<
"HIBA: Nincs jatekVezerlo_!"
<<
std
::
endl
;
return
;
}
JatekVezerlo
::
Jatekos
nyertes
=
jatekVezerlo_
->
nyertesEllenorzes
();
bool
voltValtozas
=
false
;
if
(
nyertes
!=
JatekVezerlo
::
URES
)
{
std
::
string
ujUzenet
=
(
nyertes
==
JatekVezerlo
::
X_JATEKOS
)
?
"X jatekos nyert!"
:
"O jatekos nyert!"
;
if
(
allapotUzenet_
!=
ujUzenet
)
{
allapotUzenet_
=
ujUzenet
;
voltValtozas
=
true
;
std
::
cerr
<<
"Nyertes detektalva: "
<<
allapotUzenet_
<<
std
::
endl
;
}
}
else
if
(
jatekVezerlo_
->
teleVanATabla
())
{
if
(
allapotUzenet_
!=
"Dontetlen!"
)
{
allapotUzenet_
=
"Dontetlen!"
;
voltValtozas
=
true
;
std
::
cerr
<<
"Dontetlen detektalva"
<<
std
::
endl
;
}
}
else
{
if
(
!
allapotUzenet_
.
empty
())
{
allapotUzenet_
.
clear
();
voltValtozas
=
true
;
std
::
cerr
<<
"Allapot uzenet torolve"
<<
std
::
endl
;
}
}
if
(
voltValtozas
)
{
rajzolFeliratokat
();
gout
<<
refresh
;
}
}
void
SajatAlkalmazas
::
frissitKovetkezoJatekos
()
{
// Csak az állapot frissítése, nem rajzolás
frissitAllapotUzenet
();
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment