public void cleanThreatToggles() { Threat1.GetComponentInChildren <Toggle>().isOn = false; Threat2.GetComponentInChildren <Toggle>().isOn = false; Threat3.GetComponentInChildren <Toggle>().isOn = false; Threat4.GetComponentInChildren <Toggle>().isOn = false; }
///////////////////////////////////////////////////////// // THE THREAT TEXT // THREATS PANEL // Prepare an array with the threats selected to show // ///////////////////////////////////////////////////////// public void TheThreatText() { string conn1 = "URI=file:" + Application.dataPath + "/plugins/insector.db"; IDbConnection dbconn1; dbconn1 = (IDbConnection) new SqliteConnection(conn1); dbconn1.Open(); int i, q; for (i = (RandThreatNumer - 1), q = 0; i < (RandThreatNumer + 2) && q < 3; i++, q++) { IDbCommand dbcmd1 = dbconn1.CreateCommand(); //string sqlQuery1 = "SELECT THREAT_TXT ," + nameDevice + " from THREATS where THREAT_ID = " + i; string sqlQuery1 = "SELECT THREAT_TXT ," + nameDevice + " from THREATS where THREAT_ID = " + i + " and SCENERY_ID =" + sceneryNumber; dbcmd1.CommandText = sqlQuery1; IDataReader reader1 = dbcmd1.ExecuteReader(); while (reader1.Read()) { threatDataA.threats[q] = new ThreatData { threatText = (reader1.GetString(0)), ofThreat = (reader1.GetInt32(1)) }; tDisplayText[q].text = threatDataA.threats[q].threatText; } Threat4.GetComponentInChildren <Text>().text = "Nothing to do with this device"; reader1.Close(); reader1 = null; dbcmd1.Dispose(); dbcmd1 = null; } dbconn1.Close(); dbconn1 = null; }
///////////////////////////////////////////////////////// // SHOW THREATS // THREATS PANEL // Get the pannel ready and show the list of threats // ///////////////////////////////////////////////////////// public void ShowThreats() { Threat1.GetComponentInChildren <Toggle>().isOn = false; Threat2.GetComponentInChildren <Toggle>().isOn = false; Threat3.GetComponentInChildren <Toggle>().isOn = false; Threat4.GetComponentInChildren <Toggle>().isOn = false; randThreatNumber(); TheThreatText(); }
///////////////////////////////////////////////////////// // THE CORRECTIONS TEXT // CORRECTIONS PANEL // Selection of different options of corections to the proposed threat // and get ready the threats and corrections panels // ///////////////////////////////////////////////////////// public void TheCorrectionsText() //Se sacan da la base de datos Tabla THREAT_SOLUTION las correcciones de las amenazas //Para probar sacamos tres amenazas a lo bruto sin tener en cuenta la amenaza ni el dispositvo ni el nivel del juego //Primero pongo en blando las etiquetas y los toggles que o son la amenaza en cuestion //Selecciono de la base de datos tres correciones y compruebo si son correctas para la amenaza //Cuento las correctas o un punto si ninguna //Vuelvo a llamar a show threats { //se obtiene el id de la selected threat string conn1 = "URI=file:" + Application.dataPath + "/plugins/insector.db"; IDbConnection dbconn1; dbconn1 = (IDbConnection) new SqliteConnection(conn1); dbconn1.Open(); IDbCommand dbcmd1 = dbconn1.CreateCommand(); string sqlQuery1 = "SELECT THREAT_ID from THREATS where THREAT_TXT = '" + selectedThreat + "';"; dbcmd1.CommandText = sqlQuery1; IDataReader reader1 = dbcmd1.ExecuteReader(); while (reader1.Read()) { selectedThreatId = (reader1.GetInt32(0)); } //Es asi porque voy a sacar la amenaza que sale del numero aleatorio, la siguiente y la anterior (siempre tendre disponible la primera y la ultima) RandThreatNumer = UnityEngine.Random.Range(2, threatCount - 1); Debug.Log("el valor de RandThreatNumber es...." + RandThreatNumer); reader1.Close(); reader1 = null; dbcmd1.Dispose(); dbcmd1 = null; dbconn1.Close(); dbconn1 = null; //Con el valor de la selectedThreat ya se pueden hacer las busquedas de las correcciones aleatoriamente hideGameInstructionsPanel(); Threat4.GetComponentInChildren <Text>().text = ""; Threat4.GetComponentInChildren <Toggle>().isOn = false; if (Threat1.GetComponentInChildren <Text>().text != selectedThreat) { Threat1.GetComponentInChildren <Text>().text = ""; Threat1.GetComponentInChildren <Toggle>().isOn = false; } if (Threat2.GetComponentInChildren <Text>().text != selectedThreat) { Threat2.GetComponentInChildren <Toggle>().isOn = false; Threat2.GetComponentInChildren <Text>().text = ""; } if (Threat3.GetComponentInChildren <Text>().text != selectedThreat) { Threat3.GetComponentInChildren <Toggle>().isOn = false; Threat3.GetComponentInChildren <Text>().text = ""; } string conn = "URI=file:" + Application.dataPath + "/plugins/insector.db"; IDbConnection dbconn; dbconn = (IDbConnection) new SqliteConnection(conn); dbconn.Open(); int t; for (t = 0; t < 3; t++) { IDbCommand dbcmd = dbconn.CreateCommand(); //select de tres correciones. El numero de correctas será aleatorio. Se hara con dos select //una para las aleatorias correctas y otra para las aleatorias incorrectas ( A las correctas //les pondremos isCorrect a 1. La posicion con las que se presentarán en la pantalla será tambien aleatoria //string sqlQuery = "SELECT THREAT_SOLUTION_TXT, THREAT_CORRECTION_ID, VALID_FOR_THREAT FROM THREAT_SOLUTION where ROUTER = 1 and THREAT_CORRECTION_LEVEL = 1 AND instr ( VALID_FOR_THREAT, '1-') ORDER BY random() LIMIT 1;"; //Primero se prueba si seleccionar la correccion //string sqlQuery = "SELECT THREAT_SOLUTION_TXT, THREAT_CORRECTION_ID, VALID_FOR_THREAT FROM THREAT_SOLUTION where " +nameDevice +"= 1 and THREAT_CORRECTION_LEVEL = 1 ORDER BY random() LIMIT 1;"; string sqlQuery = "SELECT THREAT_SOLUTION_TXT, THREAT_CORRECTION_ID, VALID_FOR_THREAT FROM THREAT_SOLUTION where THREAT_CORRECTION_LEVEL = " + playerLevel + " ORDER BY random() LIMIT 1;"; dbcmd.CommandText = sqlQuery; IDataReader reader = dbcmd.ExecuteReader(); while (reader.Read()) { validForThreats = (reader.GetString(2)); if (validForThreats.Contains(selectedThreatId + "-")) { tCorrectionDataA.corrections[t] = new TCorrectionData { threatCorrectionText = (reader.GetString(0)), isCorrect = 1 }; } else { tCorrectionDataA.corrections[t] = new TCorrectionData { threatCorrectionText = (reader.GetString(0)), isCorrect = 0 }; } tCorrectionDisplayText[t].text = tCorrectionDataA.corrections[t].threatCorrectionText; } reader.Close(); reader = null; dbcmd.Dispose(); dbcmd = null; } dbconn.Close(); dbconn = null; }
///////////////////////////////////////////////////////// // PROPER THREATS // THREAT PANEL. PROPER SELECTION // Check if the player selection is the appropiate for the device // ///////////////////////////////////////////////////////// public void properThreats() { //Se recogen los Toggles activados y se comprueba si se han activado correctamente y se cuentan properCount = 0; if (threatDataA.threats[0].ofThreat == 1 && Threat1.GetComponent <Toggle>().isOn == true) { proper1 = true; correct1 = true; } if (threatDataA.threats[0].ofThreat == 0 && Threat1.GetComponent <Toggle>().isOn == false) { proper1 = false; correct1 = true; } if (threatDataA.threats[1].ofThreat == 1 && Threat2.GetComponent <Toggle>().isOn == true) { proper2 = true; correct2 = true; } if (threatDataA.threats[1].ofThreat == 0 && Threat2.GetComponent <Toggle>().isOn == false) { proper2 = false; correct2 = true; } if (threatDataA.threats[2].ofThreat == 1 && Threat3.GetComponent <Toggle>().isOn == true) { proper3 = true; correct3 = true; } if (threatDataA.threats[2].ofThreat == 0 && Threat3.GetComponent <Toggle>().isOn == false) { proper3 = false; correct3 = true; } if (proper1 == false && proper2 == false && proper3 == false && Threat4.GetComponent <Toggle>().isOn == true) { proper4 = true; correct4 = true; } if (proper1 == true || proper2 == true || proper3 == true && Threat4.GetComponent <Toggle>().isOn == false) { proper4 = false; correct4 = true; } if (correct1 == true && correct2 == true && correct3 == true && correct4 == true && proper4 == true) { Debug.Log("Salida 1"); Debug.Log("Apropiados" + proper1 + " " + proper2 + " " + proper3 + " " + proper4); Debug.Log("Pulsado" + correct1 + " " + correct2 + " " + correct3 + " " + correct4); properCount = properCount + 1; threatsScore = threatsScore + properCount; tScoreDisplayText.text = threatsScore.ToString(); Debug.Log("deberia ejecutar showThreats"); cleanCorrectionsToggles(); hideCorrectionsPanel(); tryAgain(); } else if (correct1 == true && correct2 == true && correct3 == true && correct4 == true && proper4 != true) { Debug.Log("Salida 2"); Debug.Log("Apropiados" + proper1 + " " + proper2 + " " + proper3 + " " + proper4); Debug.Log("Pulsado" + correct1 + " " + correct2 + " " + correct3 + " " + correct4); if (proper1 == true) { properCount = properCount + 1; } if (proper2 == true) { properCount = properCount + 1; } if (proper3 == true) { properCount = properCount + 1; } //randProper = UnityEngine.Random.Range(1, properCount); while (threatDataA.threats[randProper].ofThreat != 1) { randProper = UnityEngine.Random.Range(1, properCount); } //Se selecciona la amenaza para la que se van a presentar correciones selectedThreat = threatDataA.threats[randProper].threatText; threatsScore = threatsScore + properCount; tScoreDisplayText.text = threatsScore.ToString(); ShowCorrections(); } else { Debug.Log("Salida 3"); Debug.Log("Apropiados" + proper1 + " " + proper2 + " " + proper3 + " " + proper4); Debug.Log("Pulsado" + correct1 + " " + correct2 + " " + correct3 + " " + correct4); SetThreatErrorPanel(); } }