Zoadian преди 10 години
родител
ревизия
1ab2b2c534
променени са 5 файла, в които са добавени 13 реда и са изтрити 33 реда
  1. 1 1
      ccsim.pro.user
  2. 5 7
      mainwindow.cpp
  3. 7 0
      mainwindow.ui
  4. 0 23
      simulator.cpp
  5. 0 2
      simulator.h

+ 1 - 1
ccsim.pro.user

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 3.6.0, 2016-01-20T23:39:28. -->
+<!-- Written by QtCreator 3.6.0, 2016-01-21T22:50:39. -->
 <qtcreator>
  <data>
   <variable>EnvironmentId</variable>

+ 5 - 7
mainwindow.cpp

@@ -7,6 +7,7 @@
 #include <QTextStream>
 #include <QDebug>
 #include <QException>
+#include <QFileDialog>
 #include "parse.h"
 
 MainWindow::MainWindow(QWidget *parent)
@@ -17,13 +18,6 @@ MainWindow::MainWindow(QWidget *parent)
     lblCycles = new QLabel(ui->statusBar);
     ui->statusBar->addWidget(lblCycles);
 
-    loadProgramFromFile("C:\\test.ccp", Qt::red, 10, 10);
-
-
-
-//    simulator.loadProgram(Qt::red, 10, 10);
-//    simulator.loadProgram(Qt::blue, 15, 15);
-
     ui->centralWidget->layout()->addWidget(new Playfield(simulator, ui->centralWidget));
 
     auto timerRepaint = new QTimer(this);
@@ -40,6 +34,10 @@ MainWindow::MainWindow(QWidget *parent)
         simulate();
     });
 
+    connect(ui->actionLoadProgram, &QAction::triggered, this, [this](){
+        auto fileName = QFileDialog::getOpenFileName(this, tr("Open Program"), "/c/", tr("Code Contest Program Files (*.ccp)"));
+        loadProgramFromFile(fileName, Qt::red, 10, 10);
+    });
 
     connect(ui->actionStart, &QAction::triggered, this, [this](){
         timer->start(1);

+ 7 - 0
mainwindow.ui

@@ -33,6 +33,8 @@
    <attribute name="toolBarBreak">
     <bool>false</bool>
    </attribute>
+   <addaction name="actionLoadProgram"/>
+   <addaction name="separator"/>
    <addaction name="actionStart"/>
    <addaction name="actionPause"/>
    <addaction name="actionSingleStep"/>
@@ -53,6 +55,11 @@
     <string>SingleStep</string>
    </property>
   </action>
+  <action name="actionLoadProgram">
+   <property name="text">
+    <string>loadProgram</string>
+   </property>
+  </action>
  </widget>
  <layoutdefault spacing="6" margin="11"/>
  <resources/>

+ 0 - 23
simulator.cpp

@@ -223,29 +223,6 @@ void Simulator::decodeInstructionParameters(Program& program, Task& task, const
     }
 }
 
-void Simulator::loadProgram(QColor color, size_t x, size_t y) {
-    shared_ptr<Team> team = make_shared<Team>(color);
-    teams.push_back(team);
-
-    programs.push_back(Program(team, Right, Position{x, y}, 2, 50, 1));
-    ++team->programCount;
-
-    programs.back().banks[0] = make_shared<Bank>(team, vector<Instruction>{
-                                                     Instruction(BJUMP, LL, 1, 0)
-                                                 });
-
-    programs.back().banks[1] = make_shared<Bank>(team, vector<Instruction>{
-                                                     Instruction(SCAN, V, 1),
-                                                     Instruction(CREATE, LLL, 2, 50, 1),
-                                                     Instruction(TRANS, LL, 1, 1),
-                                                     Instruction(TRANS, LL, 2, 2),
-                                                     Instruction(SET, VL, RemoteActive, 1),
-                                                     Instruction(TURN, L, 0),
-                                                     Instruction(AJUMP, L, 0)
-                                                 });
-
-    programs.back().active = team->id;
-}
 
 Program* Simulator::findProgram(Position position) {
     for(auto& program : programs) {

+ 0 - 2
simulator.h

@@ -30,8 +30,6 @@ struct Simulator {
     void decode(Program& program, Task& task, int& v, int*& var_v, int param);
     void decodeInstructionParameters(Program& program, Task& task, const Instruction& instruction);
 
-    void loadProgram(QColor color, size_t x, size_t y);
-
     Program* findProgram(Position position);
 
     void removeErroneousPrograms();