summaryrefslogtreecommitdiff
path: root/src/Model/Grid.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Model/Grid.cpp')
-rw-r--r--src/Model/Grid.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/Model/Grid.cpp b/src/Model/Grid.cpp
index b6ef8c4..6fc41c6 100644
--- a/src/Model/Grid.cpp
+++ b/src/Model/Grid.cpp
@@ -91,3 +91,71 @@ int Grid::getNRows(){
int Grid::getNCols(){
return m_table.size();
}
+
+
+std::vector<Cell<StringElement>* > Grid::swipeLine(std::vector<Cell<StringElement>* > line){
+ std::vector<Cell<StringElement>*> newLine = std::vector<Cell<StringElement>*>(4);
+
+
+ for (int j = 0 ; j < 3 ; j++)
+ {
+ if(j>3)
+ break;
+ Cell<StringElement> * cell = new Cell<StringElement>(line.at(j)->getElementValue());
+ Cell<StringElement> * cellp1 = new Cell<StringElement>(line.at(j+1)->getElementValue());
+
+ int a=atoi(cell->getElementValue().c_str());
+ int ap1=atoi(cellp1->getElementValue().c_str());
+
+ std::string s=std::to_string(a);
+ std::string sp1=std::to_string(ap1);
+
+ if(a==ap1 && a!=0){
+ s="";
+ sp1=std::to_string(a+ap1);
+ if(ap1 == 0)
+ newLine[j+1] = new Cell<StringElement>("");
+ else
+ newLine[j+1] = new Cell<StringElement>(sp1);
+ newLine[j] = new Cell<StringElement>(s);
+ j++;
+ }
+ else{
+ if(ap1==0)
+ newLine[j+1] = new Cell<StringElement>("");
+ else
+ newLine[j+1] = new Cell<StringElement>(sp1);
+ if(a==0)
+ newLine[j] = new Cell<StringElement>("");
+ else
+ newLine[j] = new Cell<StringElement>(s);
+
+ }
+ delete cell;
+ delete cellp1;
+
+ }
+
+
+ for (int j = 0 ; j < 3 ; j++){
+
+ if(!newLine[j]->isEmpty()){
+ if(newLine[j+1]->isEmpty()){
+ newLine[j+1]=new Cell<StringElement>(newLine[j]->getElementValue());
+ newLine[j]=new Cell<StringElement>("");
+ }
+ }
+ }
+
+ for(int i=0; i<4;i++){
+
+ std::cout << "|" << newLine[i]->description() << "|";
+ }
+ std::cout << "done";
+ return newLine;
+}
+
+void Grid::swipeRight(){
+ std::vector<Cell<StringElement>*> a=this->swipeLine(m_table.at(0));
+ m_table[0]=a;
+}