int main( int argc, char **argv ) { printf("start\n"); for(int i=0;i<N;i++ ) { props[i] = new Prop(); } for( int i=0;i<10;i++) { int hit = countHit(); printf("hit:%d\n", hit ); } }
int game() { int blow=0,hit=0,checknum=0,count=0, i=0; int check,blowh,hith=0,counth=0; char human[10],com[10]; srand((unsigned) time(NULL)); resetNum(); generateNumber(com); while (checknum == 0 && hith!=4) { if (count!=0) { if (trynum()) { printf("入力された値に誤りがあります.最初からやり直します.\n\n"); return 1; } } count++; printf("%d回目\n",count); printf("あなたの番です。数値を入力してください。\n"); do { printf(" 数値 : "); scanf("%s", human); check=checkString(human); } while (check==1); hith = countHit(human,com); blowh = countBlow(human,com); printf(" Hit : %d\n",hith); printf(" Blow : %d\n",blowh); if (hith==4) break; printf("わたしの番です。"); printf("%d%d%d%dのヒット数とブロー数を入力してください.\n",numex[0],numex[1],numex[2],numex[3]); do { printf(" Hit : "); scanf("%d",&hit); printf(" Blow : "); scanf("%d",&blow); } while (!(hit<5 && blow<5)); checkHandB(hit,blow); checknum = checkNum(); } if (checknum !=0){ if (checknum == 1) { printf("入力された値に誤りがあります.最初からやり直します.\n\n"); return 1; } else { printf("私の勝ちです。"); if (checknum < 1000) { printf("答えは0%dです。\n",checknum); } else { printf("答えは%dです。\n",checknum); } return 0; } } else { printf("あなたの勝ちです。%d回の試行で一致しました。\n",count); return 0; } }
int main(int argc, char *argv[]) { QApplication app(argc, argv); //QPushButton *quit = new QPushButton(("&Quit")); QPushButton *quit = new QPushButton(QObject::tr("Quit")); quit->setFont(QFont("Times", 18, QFont::Bold)); QObject::connect(quit, SIGNAL(clicked()), qApp, SLOT(quit())); QGridLayout *gridLayout = new QGridLayout; gridLayout->addWidget(quit, 0,0); // myWidget *previousWidget; // for (int row=1; row<4; ++row){ // for (int col=0; col<3; ++col){ // myWidget *combine = new myWidget(); // gridLayout.addWidget(combine); // // if (!(row ==1 && col ==0)){ // combine->linkPreviousWidget(previousWidget); // } // previousWidget = combine; // } // } myWidget *angle = new myWidget; gridLayout->addWidget(angle, 1, 0, 1, 1); myWidget *force = new myWidget; gridLayout->addWidget(force, 2,0,1,1); CannonField *cannonField = new CannonField; gridLayout->addWidget(cannonField, 1,1, 2, 3); gridLayout->setColumnStretch(1,20); //why we need this? QObject::connect(cannonField, SIGNAL(angleChanged(int)), angle, SLOT(setValue(int))); QObject::connect(cannonField, SIGNAL(forceChanged(int)), force, SLOT(setValue(int))); QObject::connect(angle, SIGNAL(valueChanged(int)), cannonField, SLOT(setAngle(int))); QObject::connect(force, SIGNAL(valueChanged(int)), cannonField, SLOT(setForce(int))); angle->setValue(60); angle->setFocus(); angle->setLabelText("Angle"); force->setValue(15); force->setLabelText("Force"); QPushButton *shoot = new QPushButton(QObject::tr("&Shoot")); shoot->setFont(QFont("Times", 18, QFont::Bold)); QObject::connect(shoot, SIGNAL(clicked()), cannonField, SLOT(shoot())); gridLayout->addWidget(shoot, 3,0); ScoreBoard *scoreBoard = new ScoreBoard; QObject::connect(cannonField, SIGNAL(hit()), scoreBoard, SLOT(countHit())); QObject::connect(cannonField, SIGNAL(missed()), scoreBoard, SLOT(countMiss())); gridLayout->addWidget(scoreBoard, 0, 1, 1, 2); QWidget window; window.setLayout(gridLayout); window.setGeometry(100, 100, 500, 500); window.show(); return app.exec(); }