// 起動処理 void Start() { int difficulty = DifficultySelector.GetDifficulty(); // 難易度取得 string scorefile = ""; // スコア格納ファイルを指定するための変数宣言 // 難易度による初期化処理 switch (difficulty) { case 0: // EASY scorefile = Application.streamingAssetsPath + "/easyscore"; using (StreamReader reader = new StreamReader(scorefile, Encoding.GetEncoding("UTF-8"))) { bestScore = int.Parse(reader.ReadLine()); } break; case 1: // HARD maxHp /= 2; scorefile = Application.streamingAssetsPath + "/hardscore"; using (StreamReader reader = new StreamReader(scorefile, Encoding.GetEncoding("UTF-8"))) { bestScore = int.Parse(reader.ReadLine()); } break; case 2: // IMPOSSIBLE maxHp = 1; scorefile = Application.streamingAssetsPath + "/owatascore"; using (StreamReader reader = new StreamReader(scorefile, Encoding.GetEncoding("UTF-8"))) { bestScore = int.Parse(reader.ReadLine()); } break; default: // なにかの都合で難易度指定できなかったとき用 hp = maxHp; bestScore = 0; break; } hp = maxHp; // 体力初期化 score = 0; // スコア初期化 bestScoreText.text = bestScore.ToString(); // ベストスコア表示 }
// 毎フレームごとの処理 void Update() { // 入力を取得 float inputLR = Input.GetAxisRaw("Horizontal"); float inputUD = Input.GetAxisRaw("Vertical"); float inputSlow = Input.GetAxisRaw("Fire3"); float speed; if (inputSlow == 0) { speed = 0.1f; } else { speed = 0.05f; } // 移動 if (inputLR > 0 && transform.position.x < 0.75) { transform.Translate(speed, 0, 0); // 右 } else if (inputLR < 0 && transform.position.x > -7.75) { transform.Translate(-speed, 0, 0); // 左 } if (inputUD > 0 && transform.position.y < 4.75) { transform.Translate(0, speed, 0); // 下 } else if (inputUD < 0 && transform.position.y > -4.75) { transform.Translate(0, -speed, 0); // 上 } // 弾発射 if (Input.GetAxisRaw("Fire1") == 1) { // 発射 if (shotTimer == 0) { Fire(); } // 発射からの時間加算 shotTimer += Time.deltaTime; if (shotTimer >= shotInterval) { shotTimer = 0; // 指定した時間が経過したら発射できるようにする } } else { shotTimer = 0; // 発射ボタンを離したら即発射可能に } // レベル変更 double level_d = score / 1000; // スコアを1000で割ったものがレベルの参考値 // 内部的なレベルは難易度によって変動 int difficulty = DifficultySelector.GetDifficulty(); switch (difficulty) { case 0: // EASY level = (int)Math.Floor(level_d) + 1; // 参考値に1を足して切り捨て break; case 1: // HARD level = (int)Math.Floor(level_d) + 3; // 参考値に3を足して切り捨て break; case 2: // IMPOSSIBLE level = (int)Math.Floor(level_d) + 5; // 参考値に5を足して切り捨て break; default: // 難易度選択ができなかった場合EASYと同じに level = (int)Math.Floor(level_d) + 1; break; } levelText.text = ((int)Math.Floor(level_d) + 1).ToString(); // 表示するレベルは難易度に関係なく基準値に1を足して切り捨てたもの // 時間経過でのスコア増加 scoreTimer += Time.deltaTime; if (scoreTimer >= scoreWithTimeInterval) { score += (int)Math.Floor(level_d) + 1; scoreTimer = 0; } // 各種表示類 scoreText.text = score.ToString(); // スコア表示 hpText.text = hp.ToString(); // HP表示 (数字) slider.value = (float)hp / (float)maxHp; // HP表示 (バー) GameObject[] tagObjects = GameObject.FindGameObjectsWithTag("Enemy"); // 敵の数のカウント enemyCountText.text = (tagObjects.Length).ToString(); // 敵の数を表示 }
// Start is called before the first frame update void Start() { int difficulty = DifficultySelector.GetDifficulty(); int score = PlayerController.GetScore(); string line; int[] scores = new int[10]; string output = ""; string scorefile = ""; switch (difficulty) { case 0: scorefile = Application.streamingAssetsPath + "/easyscore"; break; case 1: scorefile = Application.streamingAssetsPath + "/hardscore"; break; case 2: scorefile = Application.streamingAssetsPath + "/owatascore"; break; } using (StreamReader reader = new StreamReader(scorefile, Encoding.GetEncoding("UTF-8"))) { int loop = 0; while ((line = reader.ReadLine()) != null) { scores[loop] = int.Parse(line); loop++; } } for (int i = 0; i <= 9; i++) { if (score > scores[i]) { for (int j = 8; j >= i; j--) { scores[j + 1] = scores[j]; } scores[i] = score; ranking += score.ToString() + " ← Here\n"; for (int j = i + 1; j <= 8; j++) { ranking += scores[j].ToString() + "\n"; } ranking += scores[9].ToString(); break; } else { ranking += scores[i].ToString() + "\n"; if (i == 9) { ranking += "--------\n" + score.ToString() + " ← Here"; } } } for (int i = 0; i <= 8; i++) { output += scores[i].ToString() + "\n"; } output += scores[9].ToString(); using (FileStream fs = new FileStream(scorefile, FileMode.Open)) { fs.SetLength(0); StreamWriter writer = new StreamWriter(fs); writer.Write(output); writer.Close(); } Invoke("ShowRanking", 5f); }