Skip to content

Commit

Permalink
file save load
Browse files Browse the repository at this point in the history
  • Loading branch information
pac85 committed Oct 3, 2016
1 parent 2a17cbd commit e1714ad
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 3 deletions.
Binary file modified bin/Debug/quadretti.exe
Binary file not shown.
18 changes: 18 additions & 0 deletions castello.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
>
>
f
v
f
<
f
>
>
f
>
v
(f<5)
(>2)
(vf3)
>
>
(^f3)
11 changes: 11 additions & 0 deletions coso.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(>f3)
>
>
v
(<f5)
v
>
(f>3)
v
(<2)
(fv2)
65 changes: 64 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ and may not be redistributed without written permission.*/
#include <iostream>
#include <string.h>
#include <sstream>
#include <fstream>
#include <vector>
#include <thread>
#include <stdlib.h>
#include <atomic>

using namespace std;

Expand Down Expand Up @@ -65,7 +67,7 @@ void init()

int current_index = 0;

icolor colors[NUM_COLORS] = {icolor(0, 0, 0),icolor(30, 30, 30)};
icolor colors[NUM_COLORS] = {icolor(0, 0, 0),icolor(0, 60, 36)};

void next_color()
{
Expand Down Expand Up @@ -148,6 +150,7 @@ void run()

times = atoi(c_times);


for(int t = 0;t < times;t++)
{
for(int ic = 0; ic < 1 + (sizeof(p_text)/sizeof(char)); ic++)
Expand All @@ -165,8 +168,38 @@ void run()
}
}

void load_file(string path)
{
program.clear();
string line;
ifstream savefile(path, ios::in);
if (savefile.is_open())
{
while ( getline (savefile,line) )
{
program.push_back(line);
//program.push_back("\n");
}
savefile.close();
}
}

void save_file(string path)
{
remove(path.c_str());
ofstream savefile(path, ios::out);
for(unsigned int i = 0;i < program.size(); i++)
{
savefile << program[i] << endl;
}
}

void parse_command(string cmd)
{
if(!cmd.compare("#"))
{
return;
}
if(!cmd.compare("list"))
{
for(unsigned int i = 0;i < program.size(); i++)
Expand All @@ -183,6 +216,8 @@ void parse_command(string cmd)
// Clear the entire screen to our selected color.
SDL_RenderClear(renderer);

current_index = 0;

next_color();
next_color();

Expand All @@ -191,8 +226,36 @@ void parse_command(string cmd)
SDL_RenderPresent(renderer);
return;
}
if(!cmd.compare("save"))
{
string path;
cin >> path;
save_file(path);
return;
}
if(!cmd.compare("load"))
{
string path;
cin >> path;
load_file(path);
return;
}
if(!cmd.compare("run"))
{

// Select the color for drawing. It is set to red here.
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
// Clear the entire screen to our selected color.
SDL_RenderClear(renderer);

current_index = 0;

next_color();
next_color();


current_pos = ivec2(0, 0);

run();
return;
}
Expand Down
Binary file modified obj/Debug/main.o
Binary file not shown.
32 changes: 32 additions & 0 deletions pupazzo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
v
nc
(>f3)
v
nc
(f<3)
nc
(fv6)
^
>
f
nc
(^f5)
>
(vf2)
^
(>f2)
nc
(f>6)
nc
(f>4)
^
(<f3)
^
nc
(f>3)
(vf6)
(<f4)
nc
(f<2)
nc
f
4 changes: 3 additions & 1 deletion quadretti.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
<Option output="bin/Debug/quadretti" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Option compiler="sdl_gcc" />
<Compiler>
<Add option="-std=c++11" />
<Add option="-g" />
</Compiler>
</Target>
Expand All @@ -31,6 +32,7 @@
<Compiler>
<Add option="-Wall" />
</Compiler>
<Unit filename="main.cpp" />
<Extensions>
<code_completion />
<envvars />
Expand Down
4 changes: 3 additions & 1 deletion quadretti.depend
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# depslib dependency file v1.0
1475509961 source:c:\users\antonino\desktop\quadretti\main.cpp
1475530328 source:c:\users\antonino\desktop\quadretti\main.cpp
<SDL2/SDL.h>
<stdio.h>
<iostream>
<string.h>
<sstream>
<fstream>
<vector>
<thread>
<stdlib.h>
<atomic>

10 changes: 10 additions & 0 deletions quadretti.layout
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="4780" topLine="198" />
</Cursor>
</File>
</CodeBlocks_layout_file>
21 changes: 21 additions & 0 deletions smile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
>
f
v
f
<
f
v
v
f
v
(>f3)
>
^
f
^
^
f
<
f
^
f
2 changes: 2 additions & 0 deletions test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
>
f

0 comments on commit e1714ad

Please sign in to comment.