Skip to content

Commit

Permalink
Game is ready
Browse files Browse the repository at this point in the history
  • Loading branch information
tombracho committed Dec 20, 2017
1 parent 5f72c5b commit f0b8358
Show file tree
Hide file tree
Showing 19 changed files with 860 additions and 52 deletions.
16 changes: 13 additions & 3 deletions HSE_VS_MSU.pro
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,22 @@ SOURCES += main.cpp\
customescene.cpp\
target.cpp\
bullet.cpp \
shooter.cpp
shooter.cpp \
registration.cpp \
objvec.cpp \
authorization.cpp

HEADERS += widget.h \
customescene.h\
target.h\
bullet.h \
shooter.h
shooter.h \
registration.h \
objvec.h \
authorization.h


FORMS += widget.ui \
registration.ui \
authorization.ui

FORMS += widget.ui
2 changes: 1 addition & 1 deletion HSE_VS_MSU.pro.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.2.1, 2017-12-17T22:44:51. -->
<!-- Written by QtCreator 4.2.1, 2017-12-19T16:45:19. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down
71 changes: 71 additions & 0 deletions authorization.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include "authorization.h"
#include "ui_authorization.h"
#include "registration.h"
#include "widget.h"
#include <QFile>
#include <QDebug>
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonDocument>

Authorization::Authorization(QWidget *parent) :
QWidget(parent),
ui(new Ui::Authorization)
{
ui->setupUi(this);
QRegExp exp("[a-zA-Z]{3,15}[0-9]{0,15}[.,_]{0,5}");
ui->login->setValidator(new QRegExpValidator(exp, this));
ui->password->setValidator(new QRegExpValidator(exp, this));
connect(ui->login, SIGNAL(textChanged(QString)),this, SLOT(VhodEnabled()));
connect(ui->password, SIGNAL(textChanged(QString)),this, SLOT(VhodEnabled()));
}

Authorization::~Authorization()
{
delete ui;
}

bool Authorization::CheckValid(){
if (ui->login->hasAcceptableInput() && ui->password->hasAcceptableInput()){
return true;
} else return false;
}

void Authorization::VhodEnabled(){
ui->buttonEnt->setEnabled(CheckValid());
}

void Authorization::on_buttonEnt_clicked()
{
QFile f("./pasw_log.txt");
if (!f.exists()){
f.open(QFile::WriteOnly);
}
f.close();
QFile mFile ("./pasw_log.txt");
if(!mFile.open(QFile::ReadOnly | QFile::Text)){
ui->info->setText("<font color=red>Ошибка регистрации.</font>");
return;
}
QString val = mFile.readAll();
QJsonDocument doc = QJsonDocument::fromJson(val.toUtf8());
QJsonArray JSArray(doc.array());
mFile.close();
foreach (auto now, JSArray) {
if (now.toObject()["Login"].toString() == ui->login->text()
&& now.toObject()["Password"].toString() == ui->password->text()){
int scores = now.toObject()["Scores"].toString().toInt();
Widget * w = new Widget(now.toObject()["Login"].toString(), scores, 0);
w->show();
this->close();
}
}
ui->info->setText("<font color=red>Incorrect login or password.</font>");
}

void Authorization::on_buttonReg_clicked()
{
Registration w;
w.show();
w.exec();
}
30 changes: 30 additions & 0 deletions authorization.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef AUTHORIZATION_H
#define AUTHORIZATION_H

#include <QWidget>

namespace Ui {
class Authorization;
}

class Authorization : public QWidget
{
Q_OBJECT

public:
explicit Authorization(QWidget *parent = 0);
~Authorization();
bool CheckValid();

private slots:
void VhodEnabled();

void on_buttonEnt_clicked();

void on_buttonReg_clicked();

private:
Ui::Authorization *ui;
};

#endif // AUTHORIZATION_H
120 changes: 120 additions & 0 deletions authorization.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Authorization</class>
<widget class="QWidget" name="Authorization">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>260</width>
<height>182</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Authorization</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Username</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="login"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="password">
<property name="cursor">
<cursorShape>IBeamCursor</cursorShape>
</property>
<property name="echoMode">
<enum>QLineEdit::Normal</enum>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="buttonEnt">
<property name="text">
<string>Enter</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>46</width>
<height>13</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1">
<widget class="QLabel" name="info">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QPushButton" name="buttonReg">
<property name="text">
<string>Registration</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
4 changes: 0 additions & 4 deletions bullet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,3 @@ void Bullet::slotTimerBullet()
}
}

//void Bullet::setCallbackFunc(void (*func)(QGraphicsItem *))
//{
// callbackFunc = func;
//}
23 changes: 22 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
#include "widget.h"
#include <QApplication>

#include "registration.h"
#include "objvec.h"
#include "authorization.h"
int main(int argc, char *argv[])
{
ObjVec <int> vec;
vec.append(1);
vec.append(2);
vec.append(3);
vec.append(4);
vec.append(5);
vec.append(6);
vec.append(7);
vec.append(8);
vec.remove(7);
if (vec.isEmpty())
qDebug() << "net";
else
qDebug() << "da";
size_t n = vec.size();
for (int i = 0; i < n; ++i){
qDebug() << vec[i] << "\n";
}
QApplication a(argc, argv);
Widget w;
Authorization w;
w.show();

return a.exec();
Expand Down
3 changes: 3 additions & 0 deletions objvec.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "objvec.h"


Loading

0 comments on commit f0b8358

Please sign in to comment.