Created
August 4, 2014 01:49
-
-
Save chomado/2a31486256e53ea288d7 to your computer and use it in GitHub Desktop.
P312数当てゲーム。ファイル分割の練習。途中で写経飽きたので途中
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ctime> | |
#include <cstdlib> | |
#include "util.h" | |
using namespace std; | |
static int answer = 0; | |
void initialize() { | |
srand(time(NULL)); | |
} | |
void gen_no() { | |
answer = rand() % (max_no + 1); | |
} | |
int judge(int cand) { | |
if (cand == answer) | |
return 0; | |
else if (cand > answer) | |
return 1; | |
else | |
return 2; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "util.h" | |
using namespace std; | |
static void prompt() { | |
cout << "0 ~ " << max_no << "の数:" | |
} | |
int input(int left) { | |
int val; | |
cout << "のこり" << left << "かい" << endl; | |
do { | |
prompt(); | |
cin >> val; | |
} while(val < 0 || val > max_no); | |
return val; | |
} | |
bool confirm_retry() { | |
int cont; | |
cout << "Continue?\n <Yes..1 / No..0> : " << endl; | |
cin >> cout; | |
return static_cast<bool>(cout); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "util.h" | |
using namespace std; | |
int max_no = 999; | |
/* 以下main()関数。あきた */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// util.h | |
void initialize(); // 乱数の種を現在の時刻に基づいて設定 | |
void gen_no(); // 問題の作成 | |
int judge(int cand); // 正解の判定。candが正解かどうかを判定 | |
int input(int left); // 回答の入力 | |
bool confirm_retry(); // 再ゲームを行うかを確認 | |
extern int max_no; // 当てるべき数の最大値(定義ではなく宣言) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment