// Use this for initialization void Start() { if (instance == null) { instance = this; } else if (instance != this) { DestroyObject(gameObject); } //Initialize pieces position //_pieces_pos = Constants.PTRS_POS[GameManager.Instance.get_difficulty_level ( )]; string level_name = GameManager.Instance.get_puzzle(); _rotation = GameManager.Instance.play_with_rotation(); _puzzle_image = Util_Methods.level_name_to_val(level_name); _level = Util_Methods.level_name_to_val(level_name); _pieces_pos = Constants.PTRS_POS[_puzzle_image]; _pieces = GameObject.Find("Pieces"); _pieces_left = new Dictionary <string, GameObject>(); _pieces_solution = new Dictionary <string, GameObject>(); GameObject solution = GameObject.Find("Solution"); int n_pieces = _pieces.transform.childCount; switch (GameManager.Instance.get_difficulty()) { case (int)Difficulty_Levels.EASY: initialize_easy_level(n_pieces, solution); break; case (int)Difficulty_Levels.MEDIUM: initialize_medium_level(n_pieces, solution); break; case (int)Difficulty_Levels.HARD: initialize_hard_level(n_pieces, solution, level_name); break; default: break; } _n_total_pieces = n_pieces; //Locking pieces while game hasn't started; _n_errors = 0; GameManager.Instance.lock_pieces(); }
private void initialize_standalone() { try{ var command_args = System.Environment.GetCommandLineArgs(); string arg, arg_value; for (int i = 1; i < command_args.Length; i += 2) { arg = command_args [i]; arg_value = command_args [i + 1]; bool correct_parse = false; switch (arg) { case "-difficulty": if (arg_value.GetType().Equals(typeof(string))) { _difficulty_level = Util_Methods.difficulty_name_to_val(arg_value); } else if (arg_value.GetType().Equals(typeof(int))) { correct_parse = Int32.TryParse(arg_value, out _difficulty_level); if (!correct_parse) { Debug.LogError("Could not parse value for game level, defaulting to easy level."); _difficulty_level = (int)Difficulty_Levels.EASY; } } break; case "-puzzle": if (arg_value.GetType().Equals(typeof(string))) { if (arg_value.ToLower() == "tangram") { _puzzle = "square"; } else if (arg_value == "") { System.Random r = new System.Random(); Array vals = Enum.GetValues(typeof(Level_Names)); _puzzle = Util_Methods.level_val_to_name(r.Next((int)vals.GetValue(0), (int)vals.GetValue(vals.Length - 1))); } else { _puzzle = arg_value.ToLower(); } } else if (arg_value.GetType().Equals(typeof(int))) { int level; correct_parse = Int32.TryParse(arg_value, out level); if (!correct_parse) { System.Random r = new System.Random(); Array vals = Enum.GetValues(typeof(Level_Names)); _puzzle = Util_Methods.level_val_to_name(r.Next((int)vals.GetValue(0), (int)vals.GetValue(vals.Length - 1))); Debug.LogError("Could not parse value for puzzle, randomizing used puzzle. Puzzle set to: " + _puzzle); } else { _puzzle = Util_Methods.level_val_to_name(level); } } break; case "-robot": if (arg_value.ToLower().Contains("true")) { _robot = true; } else { _robot = false; } break; case "-game_mode": _play_mode = arg_value.ToLower(); break; case "-rotation": if (arg_value.ToLower().Contains("true")) { _rotation = true; } else { _rotation = false; } break; case "-player_number": correct_parse = Int32.TryParse(arg_value, out _n_players); if (!correct_parse) { _n_players = 1; _player_names.Add(command_args[i + 2].ToLower()); Debug.LogError("Invalid number of players, considering only 1 player."); } else { for (int j = 0; j < _n_players; j++) { _player_names.Add(command_args[i + 2 + j]); } } i += _n_players; break; case "-game_nr": correct_parse = Int32.TryParse(arg_value, out _game_nr); if (!correct_parse) { Debug.LogError("Invalid parsing of game number, defaulting to game 1."); _game_nr = 1; } break; case "-use_connection": if (arg_value.ToLower().Contains("true")) { _use_connection = true; } else { _use_connection = false; } break; case "-connection_mode": _connection_mode = arg_value; break; case "-connection_ip": _connection_ip = arg_value; break; case "-connection_port": correct_parse = Int32.TryParse(arg_value, out _connection_port); if (!correct_parse) { _connection_port = 9090; Debug.Log("Invalid or impossible to parse port value, setting to default value."); } break; case "-ros_topic_pub": _ros_pub_topic = arg_value; break; case "-ros_topic_sub": _ros_sub_topic = arg_value; break; default: Debug.Log("Unrecognized input argument: " + arg); break; } } } catch (Exception e) { Debug.LogError("Error reading setup parameters from command line: " + e.ToString()); } }
private bool initialize_android() { try{ string line; string[] words; StreamReader file_reader = new StreamReader(_parameters_text_file, Encoding.Default); using (file_reader){ do { line = file_reader.ReadLine(); if (line != null) { words = line.Split(new[] { ':', ',', '-', '=', ' ' }, StringSplitOptions.RemoveEmptyEntries); string arg = words[0]; string arg_value = words[1]; bool correct_parse = false; switch (arg) { case "difficulty": if (arg_value.GetType().Equals(typeof(string))) { _difficulty_level = Util_Methods.difficulty_name_to_val(arg_value); } else if (arg_value.GetType().Equals(typeof(int))) { correct_parse = Int32.TryParse(arg_value, out _difficulty_level); if (!correct_parse) { Debug.LogError("Could not parse value for game level, defaulting to easy level."); _difficulty_level = (int)Difficulty_Levels.EASY; } } break; case "puzzle": if (arg_value.GetType().Equals(typeof(string))) { if (arg_value.ToLower() == "tangram") { _puzzle = "square"; } else if (arg_value == "") { System.Random r = new System.Random(); Array vals = Enum.GetValues(typeof(Level_Names)); _puzzle = Util_Methods.level_val_to_name(r.Next((int)vals.GetValue(0), (int)vals.GetValue(vals.Length - 1))); } else { _puzzle = arg_value.ToLower(); } } else if (arg_value.GetType().Equals(typeof(int))) { int level; correct_parse = Int32.TryParse(arg_value, out level); if (!correct_parse) { System.Random r = new System.Random(); Array vals = Enum.GetValues(typeof(Level_Names)); _puzzle = Util_Methods.level_val_to_name(r.Next((int)vals.GetValue(0), (int)vals.GetValue(vals.Length - 1))); Debug.LogError("Could not parse value for puzzle, randomizing used puzzle. Puzzle set to: " + _puzzle); } else { _puzzle = Util_Methods.level_val_to_name(level); } } break; case "robot": if (arg_value.ToLower().Contains("true")) { _robot = true; } else { _robot = false; } break; case "game_mode": _play_mode = arg_value.ToLower(); break; case "rotation": if (arg_value.ToLower().Contains("true")) { _rotation = true; } else { _rotation = false; } break; case "player_number": correct_parse = Int32.TryParse(arg_value, out _n_players); if (!correct_parse) { _n_players = 1; _player_names.Add(words[2].ToLower()); Debug.LogError("Invalid number of players, considering only 1 player."); } else { for (int j = 0; j < _n_players; j++) { _player_names.Add(words[2 + j]); } } break; case "game_nr": correct_parse = Int32.TryParse(arg_value, out _game_nr); if (!correct_parse) { Debug.LogError("Invalid parsing of game number, defaulting to game 1."); _game_nr = 1; } break; case "use_connection": if (arg_value.ToLower().Contains("true")) { _use_connection = true; } else { _use_connection = false; } break; case "connection_mode": _connection_mode = arg_value; break; case "connection_ip": _connection_ip = arg_value; break; case "connection_port": correct_parse = Int32.TryParse(arg_value, out _connection_port); if (!correct_parse) { _connection_port = 9090; Debug.Log("Invalid or impossible to parse port value, setting to default value."); } break; case "ros_topic_pub": _ros_pub_topic = arg_value; break; case "ros_topic_sub": _ros_sub_topic = arg_value; break; default: Debug.Log("Unrecognized input argument: " + arg); break; } } } while(line != null); } file_reader.Close(); return(true); } catch (Exception e) { Debug.LogError("Error reading setup parameters from file " + _parameters_text_file + ": " + e.ToString()); return(false); } }