ANDROID PRACTICE M08UF1
- A first version of the game will have an initial activity showing a welcome screen, displaying the scores in a list, and featuring a button to play.
In this version, the word search is displayed and the user has to try to solve it. The letters are stored in a two-dimensional matrix. Under no circumstances is this about implementing a word search solving or generation algorithm.
It consists, then, of a matrix or collection of characters defined as constants. Visually, the selected letters and found words are indicated. Time is not involved and there is no scoring algorithm. (4 points)
Initial screen:

The layout is declared in an XML file; in the code, we only find the logic for what to do when selecting the button, or options… In the middle, you can see the scores stored in a database; in this exercise, however, none would appear because we haven't implemented any algorithm for resolution with scores.
Here we can observe the creation in the code:
|
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_inici);
Button Juga= (Button) findViewById(R.id.bJuga);
listPuntuacions = (ListView) findViewById(R.id.listPuntuacions);
Juga.setOnClickListener(
new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(inici.this, Sopa_Lletres.class);
startActivity(intent);
}
}
);
}
|
GAME

The algorithm affecting the score is implemented, but if we set the points equal to 0 it is as if it weren't there; this is done to make it easier to demonstrate that it works without scoring.
ONCREATE
chronometer = (Chronometer) findViewById(R.id.chronometer);
chronometer.setBase(SystemClock.elapsedRealtime());
chronometer.stop();
grid = (GridLayout) findViewById(R.id.layout);
grid.setColumnCount(columna);
grid.setRowCount(fila);
paraulesTrobades=(GridLayout) findViewById(R.id.ParaulesTrobades);
vDefineixArrayList();
vFicaParaules(Paraules);
vCrear(texts);
Puntuacion = (TextView) findViewById(R.id.Puntuacio);
//eliminar bd
PuntsH=0;
PuntsV=0;
PuntsR=0;
public void vDefineixArrayList()
We have vDefinexArrayList which adds the desired words to the Paraules list, this way we can continue with the following function:
public void vFicaParaules(ArrayList<String>)
The vFicaParaules function requires an ArrayList; this function puts the words to be inserted into a matrix, in this case it will be the Paraules ArrayList.
public void vCrear(TextView[][])
Finally, we copy the inserted words into the TextViews found in the grid; this way, if we haven't placed any letter at a point, we put a random one.
We set the points to 0; in the code, it is already implemented from a later activity so its operation will be explained later—setting it to 0 means it won't work.
- The game is improved by externalizing the words of the word search into an XML string descriptor.
This way, words can be modified more easily. (1 point)
We add to OnCreate, removing vDefineixArrayList():
String [] items = getResources().getStringArray(R.array.items);
for(String paraula : items){
Paraules.add(paraula);
}

XML Words:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="items">
<item>Francisco</item>
<item>Marc</item>
<item>Jenny</item>
<item>Calomarde</item>
<item>Montuliu</item>
<item>Sergi</item>
<item>Laura</item>
<item>Collados</item>
</string-array>
</resources>
- Scoring logic is incorporated and saved in the SQLite database. This version saves the scores. When starting the game, a screen (Activity) appears showing all the scores and the date on which they were obtained. (2 points)
vGuardarEnDB()
This function saves the scores and the date to the SQLite database.

- In this version, the game gets the words from the user's contact list. (1.5 points)
public ArrayList<String> ObtenirContactes()
Gets the ArrayList from the contact list.

- A Help button is incorporated to explain how the game works. This help is in HTML files within the app package itself and is shown using the WebView class. This help is located in an action bar and opens a new screen with the help (1.5 points)
private void obrirWebView()
Opens the WebView in a dialog.

