Hello Everyone
Please try out my Number Wizard lookalike
Would be over the moon to receive your feedback
I’ve struggled with a few aspects of the game though, notable:
At the start of the game the user answers the question, “Have you had your birthday this year?”
I’ve been unable to prevent the user from answering again using the specified keys! (I’ve tried using nested if statements in void Update() but i’ve failed so far
Looking forward to reading your feedback everyone
Thanks again
Please find below my code
Best Regards,
Bo
using UnityEngine;
using System.Collections;
public class AgeFinder : MonoBehaviour {
//this section declares our variables
int current;
int max;
int min;
int guess;
// Use this for initialization
void Start () {
StartGame() ;
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.Escape)) {
StartGame();
}
if (Input.GetKeyDown (KeyCode.Y)) {
print ("OK you've had your birthday this year! Let's see...");
Guess();
}
if (Input.GetKeyDown (KeyCode.N)) {
print ("OK you've NOT had your birthday this year! Let's see...");
//Guess();
current = current - 1;
Guess();
}
if (Input.GetKeyDown (KeyCode.T)) {
print ("HAPPY BIRTHDAY!");
Guess();
}
if (Input.GetKeyDown (KeyCode.UpArrow)) {
min = guess;
guess = (max + min)/2;
Guess();
}
if (Input.GetKeyDown (KeyCode.DownArrow)) {
max = guess;
guess = (max + min)/2;
Guess();
}
if (Input.GetKeyDown (KeyCode.Return)) {
OnPressEnter();
}
if (Input.GetKeyDown (KeyCode.KeypadEnter)) {
OnPressEnter();
}
}
//call this function to guess the birthyear and ask for a response from the user
void Guess() {
print ("Is your birthyear " + guess + "AD?");
print ("Return = Yes! UpArrow = Sorry, After. DownArrow = Sorry, Before");
}
//call this function when the user presses Return or KeypadEnter
void OnPressEnter() {
print ("Your birthyear is " + guess + "!");
if (current < guess) {
print ("..And you haven't been born!");
}
else if (current >= guess) {
print ("..And you are " + (current - guess) + " year(s) old!");
}
StartGame();
}
//call this function to start the game
void StartGame() {
current = 2017;
max = 2017;
min = 0;
guess = (max + min)/2;
print ("**************************************************************");
print ("Welcome to AgeFinder!");
print ("Let's find your age!");
print ("To do this i'll ask if your birthday has taken place this year!");
print ("I'll also try to guess your birthyear from 0AD to 2017AD..");
print ("..by asking if you could please push some arrow buttons..");
print ("Ready? Let's go!");
print ("Have you had your birthday this year?");
print ("Y = Yes, N = No, T = Birthday is today!");
max = max + 1;
}
}