First, we will draw two buttons on the canvas. We will use two images for representation, one for regret, and the other for re-start. We will use the shortlist to store every step of our operations, then extract the operations of each step from the worker list.
// Bitmap [] button = new bitmap [2];
// Bind the resource button [0] = bitmapfactory to the two buttons. decoderesource (this. getresources (), R. drawable. restart); button [1] = bitmapfactory. decoderesource (this. getresources (), R. drawable. regret );
// Draw the canvas button. drawbitmap (Button [0], screenwidth/2-30-button [0]. getwidth (), 40, paint); canvas. drawbitmap (Button [1], screenwidth/2 + 30, 40, paint );
Add the record operation statement to the touch event function:
Struct list <Map <string, integer> List = new struct list <Map <string, integer> (); Map <string, integer> map = new hashmap <string, integer> (); map. put ("index_x", index_x); // map the X value in the two-dimensional array. put ("index_y", index_y); // list the values of Y in the two-dimensional array. add (MAP );
Listen on the touch action in the button range:
// Listen to the button event and restart if (touchx> screenwidth/2-30-button [0]. getwidth () & touchx <screenwidth/2-30 & touchy> 40 & touchy <40 + button [0]. getheight () {for (INT I = 0; I <grid_num; I ++) {for (Int J = 0; j <grid_num; j ++) {chess [I] [J] = 0; winflag = false; chess_flag = 0 ;}}} // regret if (touchx> screenwidth/2 + 30 & touchx <screenwidth/2 + 30 + button [1]. getwidth () & touchy> 40 & touchy <40 + button [1]. getheight () {int size = List. size (); If (chess [list. get (size-1 ). get ("index_x")] [list. get (size-1 ). get ("index_y")] = chess_black) {chess_flag = chess_white; chess [list. get (size-1 ). get ("index_x")] [list. get (size-1 ). get ("index_y")] = 0;} else if (chess [list. get (size-1 ). get ("index_x")] [list. get (size-1 ). get ("index_y")] = chess_white) {chess_flag = chess_black; chess [list. get (size-1 ). get ("index_x")] [list. get (size-1 ). get ("index_y")] = 0;} List. removelast (); // Delete the last operation winflag = false ;}
:
After regret: