This repository was archived by the owner on Aug 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.cpp
More file actions
152 lines (132 loc) · 4.14 KB
/
Copy pathapplication.cpp
File metadata and controls
152 lines (132 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "application.hpp"
#include "graphics.hpp"
#include "importimage.hpp"
#include <sstream>
using namespace genv;
using namespace std;
Application::Application( int _SX, int _SY, std::string _name , Referee* _Boss) : SX(_SX), SY(_SY), name(_name), Boss(_Boss)
{
isExiting = false;
focused = -1;
}
void Application::addWidget( Widget *w )
{
widgets.push_back( w );
}
void Application::run()
{
gout.open( SX, SY );
gout.set_title( name );
bool whosNext = 1;
bool firstTime = 0;
stringstream ss;
event ev;
while( gin>>ev && !isExiting )
{
if( ev.keycode == key_escape )
isExiting = true;
if(Boss->get_state()=="startScreen")
{
canvas start;
kepbeolvas(start,"welcomescreen.kep",SX,SY);
gout<<stamp(start,0,0);
gout<<refresh;
if( ev.type == ev_key && ev.keycode == key_enter )
{
Boss->set_state("placing");
}
if( ev.type == ev_key && ev.keycode == key_f1 )
{
Boss->set_state("help");
}
}
if(Boss->get_state()=="help")
{
canvas help;
kepbeolvas(help,"f1.kep",SX,SY);
gout<<stamp(help,0,0);
gout<<refresh;
if( ev.type == ev_key && ev.keycode == key_enter )
{
Boss->set_state("placing");
}
}
if(Boss->ready()==true)
{
Boss->set_state("ingame");
}
if(Boss->get_state()=="ingame")
{
if(firstTime == 0)
{
Boss->set_BState();
firstTime = 1;
}
if(Boss->get_AState()==0 && Boss->get_BState()==0)
{
if(whosNext == 1)
{
Boss->set_AState();
}
if(whosNext == 0)
{
Boss->set_BState();
}
whosNext=!whosNext;
}
if(Boss->get_AScore()==15)
{
Boss->set_state("AWon");
}
if(Boss->get_BScore()==15)
{
Boss->set_state("BWon");
}
}
if(Boss->get_state()=="AWon")
{
canvas EndA;
kepbeolvas(EndA,"EndA.kep",SX,SY);
gout<<stamp(EndA,0,0);
gout<<refresh;
}
if(Boss->get_state()=="BWon")
{
canvas EndB;
kepbeolvas(EndB,"EndB.kep",SX,SY);
gout<<stamp(EndB,0,0);
gout<<refresh;
}
if(Boss->get_state()=="placing" || Boss->get_state()=="ingame")
{
/// Fókusz kezelése
if( ev.type == ev_mouse && ev.button==btn_left )
{
focused = -1;
for( size_t i=0; i<widgets.size(); i++ )
{
if( widgets[i]->is_selected(ev.pos_x, ev.pos_y) )
{
focused = i;
}
}
}
for( size_t i=0; i<widgets.size(); ++i )
widgets[i]->set_focus( focused == (int)i );
/// Eseménykezelés
if( focused != -1) // csak a fókuszban lévő widget kapja meg az eseményeket
widgets[focused]->handle( ev );
//for( size_t i=0; i<widgets.size(); ++i ) // a vektorban található összes vezérlõ megkapja az eseményeket
// widgets[i]->handle( ev ); // eseménykezelés widget szinten
/// Vizualizálás
gout << move_to(0, 0) << color(70,90,120) << box(SX, SY);// képernyő törlése
for( size_t i=0; i<widgets.size(); ++i )
widgets[i]->draw(); // képernyő újra rajzolása
gout << refresh; // képernyő frissítése
}
}
}
void Application::shutdown()
{
isExiting = true; // kilépés inicializálása
}