Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class game_main : MonoBehaviour {
- [Header("Buttons")]
- public Button key_1_btn;
- public Button key_2_btn;
- public Button key_3_btn;
- public Button key_4_btn;
- public Button key_5_btn;
- public Button key_6_btn;
- public Button key_7_btn;
- public Button key_8_btn;
- public Button key_9_btn;
- public Button key_0_btn;
- public Button key_clear_btn;
- public Button key_enter_btn;
- [Header("Text")]
- public Text guess_text;
- public Text timer_text;
- public Text tries_text;
- private int upper_limit;
- private int answer;
- private int number_of_guesses;
- private string current_guess;
- private float timeLeft = 123.0f;
- //Here you setup the component you are on right now (the "this" object). You should use Awake to set up references between scripts.
- void Awake() {
- current_guess = "";
- guess_text.text = current_guess;
- number_of_guesses = 0;
- upper_limit = 1000000;
- answer = Random.Range(0,upper_limit);
- tries_text.text = "Tries: " + number_of_guesses.ToString();
- }
- //Here you setup things that depend on other components. Use Start to pass any information back and forth.
- void Start() {
- Button btn_1 = key_1_btn.GetComponent<Button>();
- btn_1.onClick.AddListener(key_1_btn_task);
- Button btn_2 = key_2_btn.GetComponent<Button>();
- btn_2.onClick.AddListener(key_2_btn_task);
- Button btn_3 = key_3_btn.GetComponent<Button>();
- btn_3.onClick.AddListener(key_3_btn_task);
- Button btn_4 = key_4_btn.GetComponent<Button>();
- btn_4.onClick.AddListener(key_4_btn_task);
- Button btn_5 = key_5_btn.GetComponent<Button>();
- btn_5.onClick.AddListener(key_5_btn_task);
- Button btn_6 = key_6_btn.GetComponent<Button>();
- btn_6.onClick.AddListener(key_6_btn_task);
- Button btn_7 = key_7_btn.GetComponent<Button>();
- btn_7.onClick.AddListener(key_7_btn_task);
- Button btn_8 = key_8_btn.GetComponent<Button>();
- btn_8.onClick.AddListener(key_8_btn_task);
- Button btn_9 = key_9_btn.GetComponent<Button>();
- btn_9.onClick.AddListener(key_9_btn_task);
- Button btn_0 = key_0_btn.GetComponent<Button>();
- btn_0.onClick.AddListener(key_0_btn_task);
- Button btn_clear = key_clear_btn.GetComponent<Button>();
- btn_clear.onClick.AddListener(key_clear_btn_task);
- Button btn_enter = key_enter_btn.GetComponent<Button>();
- btn_enter.onClick.AddListener(key_enter_btn_task);
- }
- //Use this when applying physics forces as this function relies on the physics engine.
- void FixedUpdate() {
- //
- }
- //Update is called once per frame, it's speed depends on the load on the graphics engine.
- void Update() {
- if (Input.GetKeyDown(KeyCode.Keypad1)) { key_1_btn_task(); }
- if (Input.GetKeyDown(KeyCode.Keypad2)) { key_2_btn_task(); }
- if (Input.GetKeyDown(KeyCode.Keypad3)) { key_3_btn_task(); }
- if (Input.GetKeyDown(KeyCode.Keypad4)) { key_4_btn_task(); }
- if (Input.GetKeyDown(KeyCode.Keypad5)) { key_5_btn_task(); }
- if (Input.GetKeyDown(KeyCode.Keypad6)) { key_6_btn_task(); }
- if (Input.GetKeyDown(KeyCode.Keypad7)) { key_7_btn_task(); }
- if (Input.GetKeyDown(KeyCode.Keypad8)) { key_8_btn_task(); }
- if (Input.GetKeyDown(KeyCode.Keypad9)) { key_9_btn_task(); }
- if (Input.GetKeyDown(KeyCode.Keypad0)) { key_0_btn_task(); }
- if (Input.GetKeyDown(KeyCode.KeypadEnter)) { key_enter_btn_task(); }
- if (Input.GetKeyDown(KeyCode.KeypadPeriod)) { key_clear_btn_task(); }
- if (Input.GetKeyDown(KeyCode.KeypadMinus)) { key_back_btn_task(); }
- timeLeft -= Time.deltaTime;
- float min = (timeLeft/60);
- float sec = timeLeft % 60;
- float mil = 0;
- //timer_text.text = string.Format("{0:0}:{1:00}:{2:00}", min, sec, mil);
- timer_text.text = min + ":" + sec + ":" + mil;
- }
- void key_1_btn_task() {
- if (current_guess.Length >= 10) {
- //Debug.Log ("END");
- }else{
- //Debug.Log ("1");
- current_guess = current_guess + "1";
- guess_text.text = current_guess;
- }
- }
- void key_2_btn_task() {
- if (current_guess.Length >= 10) {
- //Debug.Log ("END");
- }else{
- //Debug.Log ("2");
- current_guess = current_guess + "2";
- guess_text.text = current_guess;
- }
- }
- void key_3_btn_task() {
- if (current_guess.Length >= 10) {
- //Debug.Log ("END");
- }else{
- //Debug.Log ("3");
- current_guess = current_guess + "3";
- guess_text.text = current_guess;
- }
- }
- void key_4_btn_task() {
- if (current_guess.Length >= 10) {
- //Debug.Log ("END");
- }else{
- //Debug.Log ("4");
- current_guess = current_guess + "4";
- guess_text.text = current_guess;
- }
- }
- void key_5_btn_task() {
- if (current_guess.Length >= 10) {
- //Debug.Log ("END");
- }else{
- //Debug.Log ("5");
- current_guess = current_guess + "5";
- guess_text.text = current_guess;
- }
- }
- void key_6_btn_task() {
- if (current_guess.Length >= 10) {
- //Debug.Log ("END");
- }else{
- //Debug.Log ("6");
- current_guess = current_guess + "6";
- guess_text.text = current_guess;
- }
- }
- void key_7_btn_task() {
- if (current_guess.Length >= 10) {
- //Debug.Log ("END");
- }else{
- //Debug.Log ("7");
- current_guess = current_guess + "7";
- guess_text.text = current_guess;
- }
- }
- void key_8_btn_task() {
- if (current_guess.Length >= 10) {
- //Debug.Log ("END");
- }else{
- //Debug.Log ("8");
- current_guess = current_guess + "8";
- guess_text.text = current_guess;
- }
- }
- void key_9_btn_task() {
- if (current_guess.Length >= 10) {
- //Debug.Log ("END");
- }else{
- //Debug.Log ("9");
- current_guess = current_guess + "9";
- guess_text.text = current_guess;
- }
- }
- void key_0_btn_task() {
- if (current_guess.Length >= 10) {
- //Debug.Log ("END");
- }else{
- //Debug.Log ("0");
- current_guess = current_guess + "0";
- guess_text.text = current_guess;
- }
- }
- void key_back_btn_task() {
- //Debug.Log ("back");
- current_guess = current_guess.Substring(0, current_guess.Length - 1);
- guess_text.text = current_guess;
- }
- void key_clear_btn_task() {
- //Debug.Log ("clear");
- current_guess = "";
- guess_text.text = current_guess;
- }
- void key_enter_btn_task() {
- //Debug.Log ("ENTER!");
- //Debug.Log ("GUESS: " + current_guess);
- int temp_guess = System.Int32.Parse(current_guess);
- if (temp_guess == answer) {
- Debug.Log ("CORRECT!");
- }else{
- if (answer > temp_guess) {
- Debug.Log ("HIGHER!");
- }else{
- Debug.Log ("LOWER!");
- }
- }
- Debug.Log ("GUESS: " + current_guess);
- current_guess = "";
- guess_text.text = current_guess;
- number_of_guesses++;
- tries_text.text = "Tries: " + number_of_guesses.ToString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement