diff --git a/gamelogic.cpp b/gamelogic.cpp index 071808a6e2311d597049b344c6af81859e67f7d3..9a9616fbed6c50925c93490ad422282712389e1f 100644 --- a/gamelogic.cpp +++ b/gamelogic.cpp @@ -56,9 +56,6 @@ bool GameLogic::makeMove( int col){ - - - bool GameLogic::validMove(int col) const{ return col >= 0 && col < COLS && !ColumnFull(col) && !gameover; diff --git a/main.cpp b/main.cpp index d1a4e39dc93bf76efa5c02aecbe6acdf04f9c9ae..be4093bbef7e12a89c1c68cb751deba2951c070a 100644 --- a/main.cpp +++ b/main.cpp @@ -44,6 +44,9 @@ private: start_button = new Button(this, 350, 360, 100, 40, "START"); menu_widgets.push_back(start_button); registerWidget(start_button); + + // gout << move_to(270, 280) << text("J�t�kos 1"); + // gout << move_to(490, 280) << text("J�t�kos 2"); } @@ -188,10 +191,19 @@ private: void showGameStatus(){ if(_game.getWinner()==GameLogic::EMPTY){ - std::cout << "dontetlen"; + std::cout << "dontetlen :("; } else{ - std::cout << _game.getWinner() << " jatekos nyert! \n"; + //std::cout << _game.getWinner(); + if (_game.getWinner()==1){ + std::cout << player1_name << " nyert :)"; + } + else if (_game.getWinner()==2){ + std::cout << player2_name << "nyert :)"; + } + + + } } diff --git a/statictext.cpp b/statictext.cpp deleted file mode 100644 index 2ada04415702e663895b0b02fd96dcd872346abc..0000000000000000000000000000000000000000 --- a/statictext.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include "statictext.hpp" -#include "graphics.hpp" -using namespace genv; - -StaticText::StaticText(int x, int y, int sx, int sy, const std::string& s) - : Widget(x, y, sx, sy), _text(s), _cursor_pos(0), _show_cursor(false), _editable(false) {} - -void StaticText::draw() { - gout << move_to(_x, _y) << color(255, 255, 255) << box(_size_x, _size_y); - gout.load_font("LiberationMono-Regular.ttf", 15); - - gout << move_to(_x+2 + 2, _y+10) << color(0, 0, 0); - - std::string visible_text = _text; - int text_width = gout.twidth(visible_text); - - while (text_width > _size_x - 4 && !visible_text.empty()) { - visible_text.pop_back(); - text_width = gout.twidth(visible_text); - } - - gout << text(visible_text); - - - if (_editable && _show_cursor) { - std::string before_cursor = _text.substr(0, _cursor_pos); - int cursor_x = _x + 2 + gout.twidth(before_cursor); - - - if (cursor_x < _x + _size_x - 2) { - gout << move_to(cursor_x+2, _y + _size_y/4) << color(0, 0, 0) - << line(0, gout.cascent() + gout.cdescent()); - } - } -} - -void StaticText::handle(event ev) { - if (ev.type == ev_mouse && ev.button == btn_left) { - - _editable = is_selected(ev.pos_x, ev.pos_y); - _show_cursor = _editable; - - if (_editable) { - - int click_x = ev.pos_x - _x - 2; - std::string temp; - _cursor_pos = 0; - - for (size_t i = 0; i < _text.length(); i++) { - temp += _text[i]; - if (gout.twidth(temp) > click_x) { - break; - } - _cursor_pos = i + 1; - } - } - } - - if (!_editable) return; - - if (ev.type == ev_key) { - _show_cursor = true; - - if (ev.keycode == key_left && _cursor_pos > 0) { - _cursor_pos--; - } else if (ev.keycode == key_right && _cursor_pos < _text.length()) { - _cursor_pos++; - } else if (ev.keycode == key_backspace && _cursor_pos > 0) { - _text.erase(_cursor_pos - 1, 1); - _cursor_pos--; - } else if (ev.keycode == key_delete && _cursor_pos < _text.length()) { - _text.erase(_cursor_pos, 1); - } else if (ev.keycode >= 32 && ev.keycode < 256) { - std::string temp_text = _text; - temp_text.insert(_cursor_pos, 1, ev.keycode); - if (gout.twidth(temp_text) <= _size_x - 4) { - _text.insert(_cursor_pos, 1, ev.keycode); - _cursor_pos++; - } - } else if (ev.keyutf8 != "") { - std::string temp_text = _text; - temp_text.insert(_cursor_pos, ev.keyutf8); - if (gout.twidth(temp_text) <= _size_x - 4) { - _text.insert(_cursor_pos, ev.keyutf8); - _cursor_pos += ev.keyutf8.length(); - } - } - } -} diff --git a/statictext.hpp b/statictext.hpp deleted file mode 100644 index db2cb3fdb049f24fd776fff9ede2db7216a2013a..0000000000000000000000000000000000000000 --- a/statictext.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef STATICTEXT_HPP -#define STATICTEXT_HPP - -#include "widgets.hpp" -#include <string> - -class StaticText : public Widget { -protected: - std::string _text; - size_t _cursor_pos; - bool _show_cursor; - bool _editable; -public: - StaticText(int x, int y, int sx, int sy, const std::string& s); - virtual void draw() override; - virtual void handle(genv::event ev) override; -}; - -#endif diff --git a/textbox.cpp b/textbox.cpp index c52adf6ca7e0a57eb08fb79e098d71ff0ef3c148..fec2025e4dadd3d6255f73e2ddf54aca3af06558 100644 --- a/textbox.cpp +++ b/textbox.cpp @@ -60,7 +60,7 @@ void Textbox::handle_event(event ev){ int click_x=ev.pos_x-_x - 2; std::string temp; - _cursor_pos=0; + //_cursor_pos=0; for (int i=0; i<_text.length(); i++){ temp+=_text[i]; diff --git a/textedit.cpp b/textedit.cpp deleted file mode 100644 index e9ef1afb760afd773f60a25249cbc5d39f911987..0000000000000000000000000000000000000000 --- a/textedit.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "textedit.hpp" - -TextEdit::TextEdit(int x, int y, int sx, int sy, std::string s) - : Widget(x,y,sx,sy), _text(s) -{} - -using namespace genv; - -void TextEdit::draw() -{ - gout.load_font("LiberationMono-BoldItalic.ttf", 20); - gout <<move_to(_x, _y) << color(255,255,255) << box(_size_x, _size_y) << color(0, 0, 0) << move_to(_x+5, _y+5) << text(_text); -} - -void TextEdit::handle(event ev) -{ - if(ev.type == ev_key) - { - if(ev.keycode==key_backspace) - { - _text=_text.substr(0,_text.size()-1); - } - else - { - _text+=ev.keyutf8; - } - } -} diff --git a/textedit.hpp b/textedit.hpp deleted file mode 100644 index cd1ad64574dbf1ff9dc626d4873912611430e00f..0000000000000000000000000000000000000000 --- a/textedit.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef TEXTEDIT_HPP -#define TEXTEDIT_HPP - -#include "widgets.hpp" - -class TextEdit : public Widget -{ -protected: - std::string _text; -public: - TextEdit(int, int, int, int, std::string); - virtual void draw() override; - virtual void handle(genv::event) override; -}; - -#endif // TEXTEDIT_HPP