Example #1
0
void FlipFlap::flip(int p){							//flip the top p pancakes
        ++current_flips;							//increment flips player has made
        for(Pancake* pancake : game_stack_p){					//detach old stack from window
                detach(*pancake);
        }
        auto it = std::next(game_stack_p.begin(), (p-1));			//flip order in the list
        reverse(it,game_stack_p.end());
        for(int i = (p-1); i < game_stack.size(); ++i){
                game_stack_p[i] = new Pancake(game_stack_p[i]->get_size(),i);
        }
        for(Pancake* pancake : game_stack_p){					//re-attach the changed pancakes
                attach(*pancake);
        }
        update_boxes();								//update on-screen counters
        redraw();								//redraw window
        if(check_score()){							//if stack is sorted
                for(Pancake* pancake : game_stack_p){				//detach pancake stack
                        detach(*pancake);
                }
                for(int i = 0; i < (current_level-1); ++i)			//detach flip buttons
                        detach(buttons[i]);
                show_scores(0);							//go to show scores (Win)
        }
       if(calc_score(current_flips) == 0){					//if score has hit 0
         for(Pancake* pancake : game_stack_p){					//detach pancakes
                        detach(*pancake);
                }
                for(int i = 0; i < (current_level-1); ++i)
                        detach(buttons[i]);					//detach flip buttons
                show_scores(1);							//go to show scores (Lose)
       }

}
Example #2
0
void FlipFlap::add_boxes(){							//create counter boxes
  min_box = new Out_box(Point(150,0),25,20,"Can be done in:");			//display minumun needed flips
  flips_box = new Out_box(Point(300,0),30,20,"Current flips:");			//display flips taken
  score_box = new Out_box(Point(450,0),50,20,"Current score:");			//display current score
  attach(*min_box);								//attach boxes
  attach(*flips_box);
  attach(*score_box);
  update_boxes();								//call update
}
Example #3
0
FieldSelect::FieldSelect(Procview *pv, Proc *proc)
            : QDialog(0, "select fields"),
	      nbuttons(proc->cats.size()),
	      disp_fields(nbuttons),
	      procview(pv)
{
    QVBoxLayout *tl = new QVBoxLayout(this, 10, 10);

    updating = FALSE;
    setCaption("qps: select fields");
    buts = new QCheckBox*[nbuttons];

    QGridLayout *l1 = new QGridLayout((nbuttons + 1) / 2, 5, 0);
    tl->addLayout(l1, 1);
    l1->addColSpacing(2, 15);

    int half = (nbuttons + 1) / 2;
    for(int i = 0; i < nbuttons; i++) {
      QCheckBox *but = new QCheckBox(proc->cats[i]->name, this);
	QLabel *desc = new QLabel(proc->cats[i]->help, this);
	but->setMinimumSize(but->sizeHint());
	desc->setMinimumSize(desc->sizeHint());

	if(i < half) {
	  l1->addWidget(but, i, 0);
	  l1->addWidget(desc, i, 1);
	} else {
	  l1->addWidget(but, i-half, 3);
	  l1->addWidget(desc, i-half, 4);
	}
	buts[i] = but;
	connect(but, SIGNAL(toggled(bool)), this, SLOT(field_toggled(bool)));
    }
    update_boxes();

    KButtonBox *bbox = new KButtonBox(this);
    bbox->addStretch(1);
    QPushButton *closebut = bbox->addButton(i18n("Close"));
    closebut->setDefault(TRUE);
    closebut->setFocus();
    closebut->setFixedSize(closebut->sizeHint());
    bbox->layout();
    tl->addWidget(bbox);

    connect(closebut, SIGNAL(clicked()), SLOT(closed()));

    QAccel *acc = new QAccel(this);
    acc->connectItem(acc->insertItem(CTRL + Key_W),
		     this, SLOT(closed()));
    tl->freeze();
}