IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Application Memory Android


Sujet :

Android

  1. #101
    Nouveau membre du Club
    Inscrit en
    Avril 2011
    Messages
    104
    Détails du profil
    Informations forums :
    Inscription : Avril 2011
    Messages : 104
    Points : 25
    Points
    25
    Par défaut
    C'est ce que j'ai fais
    Je commence à comprendre quand utiliser ou non le mode debug, mais je n'ai rien du tout ...

  2. #102
    Membre confirmé
    Homme Profil pro
    IUT Informatique
    Inscrit en
    Mars 2011
    Messages
    412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : IUT Informatique

    Informations forums :
    Inscription : Mars 2011
    Messages : 412
    Points : 486
    Points
    486
    Par défaut
    Ah ...Ben utilise un System.out.println. Dans ton onClick tu rajoute au tout début

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    System.out.println.("je clique");
    Et tu regarde après avoir cliquer si la ligne apparait dans ton code

  3. #103
    Nouveau membre du Club
    Inscrit en
    Avril 2011
    Messages
    104
    Détails du profil
    Informations forums :
    Inscription : Avril 2011
    Messages : 104
    Points : 25
    Points
    25
    Par défaut
    ... Et bien cela ne m'affiche rien, donc je ne rentre pas dedans c'est vérifie ! youpi.

  4. #104
    Membre confirmé
    Homme Profil pro
    IUT Informatique
    Inscrit en
    Mars 2011
    Messages
    412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : IUT Informatique

    Informations forums :
    Inscription : Mars 2011
    Messages : 412
    Points : 486
    Points
    486
    Par défaut
    Je viens de remarquer un truc par rapport à ce post. Si ton code est toujours le même je pense savoir pourquoi il ne fait pas l'action, à aucun moment tu instancie tes boutons...A mon avis ca vient de la

    Edit: Au passage, tu appel ou ta méthode creationCarte(...)??
    Parce qu'à mon avis il y aurai aussi un souci ici...

  5. #105
    Nouveau membre du Club
    Inscrit en
    Avril 2011
    Messages
    104
    Détails du profil
    Informations forums :
    Inscription : Avril 2011
    Messages : 104
    Points : 25
    Points
    25
    Par défaut
    non mon code n'a pas bougé, mais les boutons ont été pris en compte non ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    int u;
    	int p;
    	private Card carte1;
    	private Card carte2;
    	private Card carte3;
    	private Card carte4;
    	private Card carte5;
    	private Card carte6;
    	private Card carte7;
    	private Card carte8;
    	private Card carte9;
    	private Card carte10;
    	private Card carte11;
    	private Card carte12;
    	private Card carte13;
    	private Card carte14;
    	private Card carte15;
    	private Card carte16;
    	private Card carte17;
    	private Card carte18;
    	private Card carte19;
    	private Card carte20;
    	private Card carte21;
    	private Card carte22;
    	private Card carte23;
    	private Card carte24;
    	private Card carte25;
    	private Card carte26;
    	private Card carte27;
    	private Card carte28;
    	private Card carte29;
    	private Card carte30;
    	private Card carte31;
    	private Card carte32;
    	private Card carte33;
     
    	private int backImage;
    	private List<Card> tableaudepart;
    	private List<Card> tableaufinal;
    	private List<Button> boutton;
    	Button button1;
    	Button button2;
    	Button button3;
    	Button button4;
    	Button button5;
    	Button button6;
    	Button button7;
    	Button button8;
    	Button button9;
    	Button button10;
    	Button button11;
    	Button button12;
    	Button button13;
    	Button button14;
    	Button button15;
    	Button button16;
    	private UpdateCardsHandler handler;
    	private static Object lock = new Object();
    	public boolean premierClic = true;
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    public void booton(){
    		//tableau de bouton pour faire le lien avec celui des cartes
    		boutton = new ArrayList<Button>();
    		boutton.add(button1);
    		boutton.add(button2);
    		boutton.add(button3);
    		boutton.add(button4);
    		boutton.add(button5);
    		boutton.add(button6);
    		boutton.add(button7);		
    		boutton.add(button8);
    		boutton.add(button9);
    		boutton.add(button10);
    		boutton.add(button11);
    		boutton.add(button12);
    		boutton.add(button13);
    		boutton.add(button14);
    		boutton.add(button15);
    		boutton.add(button16);
     
    		button1.setOnClickListener(this);
    		button2.setOnClickListener(this);
    		button3.setOnClickListener(this);
    		button4.setOnClickListener(this);
    		button5.setOnClickListener(this);
    		button6.setOnClickListener(this);
    		button7.setOnClickListener(this);
    		button8.setOnClickListener(this);
    		button9.setOnClickListener(this);
    		button10.setOnClickListener(this);
    		button11.setOnClickListener(this);
    		button12.setOnClickListener(this);
    		button13.setOnClickListener(this);
    		button14.setOnClickListener(this);
    		button15.setOnClickListener(this);
    		button16.setOnClickListener(this);
     
    	}
    Ou sinon je n'ai pas compris ce que voulait dire instancier...

  6. #106
    Membre confirmé
    Homme Profil pro
    IUT Informatique
    Inscrit en
    Mars 2011
    Messages
    412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : IUT Informatique

    Informations forums :
    Inscription : Mars 2011
    Messages : 412
    Points : 486
    Points
    486
    Par défaut
    Initialiser tes variables si tu preferes, il faudrait que quelques part, dans ton onCreate() par exemple tu ai un truc du style:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    button1 = new Button();
    button2 = new Button();
    button3 = new Button();
    ...
    A moins que t'as déjà placer tes boutons dans un layout, dans ce cas là tu utilise le findViewById...

  7. #107
    Nouveau membre du Club
    Inscrit en
    Avril 2011
    Messages
    104
    Détails du profil
    Informations forums :
    Inscription : Avril 2011
    Messages : 104
    Points : 25
    Points
    25
    Par défaut
    Oh quel ..., okay merci je vais faire cela.
    Effectivement mes boutons sont déjà crées sur un layout.

    Je te tiens au courant de l'avancement.

  8. #108
    Membre confirmé
    Homme Profil pro
    IUT Informatique
    Inscrit en
    Mars 2011
    Messages
    412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : IUT Informatique

    Informations forums :
    Inscription : Mars 2011
    Messages : 412
    Points : 486
    Points
    486
    Par défaut
    Ok, ben passe par le findViewById, et ca devrai déjà un peu mieux fonctionner ^^

  9. #109
    Nouveau membre du Club
    Inscrit en
    Avril 2011
    Messages
    104
    Détails du profil
    Informations forums :
    Inscription : Avril 2011
    Messages : 104
    Points : 25
    Points
    25
    Par défaut
    Et bien non !!!!!!
    Je ne rentre toujours pas dans la boucle (le println ne s'affiche pas)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
     
     
            setContentView(R.layout.jeux1);
            button1 = (Button)findViewById(R.id.button1)  ;
            button2 = (Button)findViewById(R.id.button2)  ;
            button3 = (Button)findViewById(R.id.button3)  ;
            button4 = (Button)findViewById(R.id.button4)  ;
            button5 = (Button)findViewById(R.id.button5)  ;
            button6 = (Button)findViewById(R.id.button6)  ;
            button7 = (Button)findViewById(R.id.button7)  ;
            button8 = (Button)findViewById(R.id.button8)  ;
            button9 = (Button)findViewById(R.id.button9)  ;
            button10 = (Button)findViewById(R.id.button10)  ;
            button11 = (Button)findViewById(R.id.button11)  ;
            button12 = (Button)findViewById(R.id.button12)  ;
            button13 = (Button)findViewById(R.id.button13)  ;
            button14 = (Button)findViewById(R.id.button14)  ;
            button15 = (Button)findViewById(R.id.button15)  ;
            button16 = (Button)findViewById(R.id.button16)  ;
     
     
     
            }
    voila mon bout de code on sait jamais mais bon.

    Je remet l'intégralité ensuite si jamais ...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    package com.aviy.memory;
     
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Random;
    import java.util.Timer;
    import java.util.TimerTask;
     
    import com.aviy.memory.Jeu1.UpdateCardsHandler;
    import android.os.Handler;
    import android.app.Activity;
    import android.graphics.drawable.Drawable;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.Menu;
    import android.view.MenuInflater;
    import android.view.MenuItem;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.Toast;
     
    public class Jeu extends Activity implements OnClickListener{
     
    	int u;
    	int p;
    	private Card carte1;
    	private Card carte2;
    	private Card carte3;
    	private Card carte4;
    	private Card carte5;
    	private Card carte6;
    	private Card carte7;
    	private Card carte8;
    	private Card carte9;
    	private Card carte10;
    	private Card carte11;
    	private Card carte12;
    	private Card carte13;
    	private Card carte14;
    	private Card carte15;
    	private Card carte16;
    	private Card carte17;
    	private Card carte18;
    	private Card carte19;
    	private Card carte20;
    	private Card carte21;
    	private Card carte22;
    	private Card carte23;
    	private Card carte24;
    	private Card carte25;
    	private Card carte26;
    	private Card carte27;
    	private Card carte28;
    	private Card carte29;
    	private Card carte30;
    	private Card carte31;
    	private Card carte32;
    	private Card carte33;
     
    	private int backImage;
    	private List<Card> tableaudepart;
    	private List<Card> tableaufinal;
    	private List<Button> boutton;
    	Button button1;
    	Button button2;
    	Button button3;
    	Button button4;
    	Button button5;
    	Button button6;
    	Button button7;
    	Button button8;
    	Button button9;
    	Button button10;
    	Button button11;
    	Button button12;
    	Button button13;
    	Button button14;
    	Button button15;
    	Button button16;
    	private UpdateCardsHandler handler;
    	private static Object lock = new Object();
    	public boolean premierClic = true;
     
    	//debut menu
    	public boolean onCreateOptionsMenu(Menu menu){
        	MenuInflater inflater =getMenuInflater();
        	inflater.inflate(R.menu.monmenu, menu);
        	return true;
    	}
     
    	public boolean onMenuItemSelected(int featureId,MenuItem item){
     
        	switch (item.getItemId()){
           	case R.id.Regles:
           		Toast.makeText(this,"Sélectionnez un niveau de difficulté",Toast.LENGTH_SHORT).show();
           		return true;
     
           	case R.id.Quitter:
           		finish();
           		return true;
     
           	case R.id.Auteur:
           		Toast.makeText(this,"EcoCO2",Toast.LENGTH_SHORT).show();
     
           	}
           	return super.onMenuItemSelected(featureId, item);
     
           	}
    		//fin menu
     
     
     
    	public void creationcarte(Button button,int IDpaire, int y, int x, int image){
    		//on crée les cartes
    		carte1=new Card(button,x,y,IDpaire=1 ,image = R.drawable.card1);
    		carte2=new Card(button,x,y,IDpaire=1 ,image = R.drawable.card2);
    		carte3=new Card(button,x,y,IDpaire=2 ,image = R.drawable.card3);
    		carte4=new Card(button,x,y,IDpaire=2 ,image = R.drawable.card4);
    		carte5=new Card(button,x,y,IDpaire=3 ,image = R.drawable.card5);
    		carte6=new Card(button,x,y,IDpaire=3 ,image = R.drawable.card6);
    		carte7=new Card(button,x,y,IDpaire=4 ,image = R.drawable.card7);
    		carte8=new Card(button,x,y,IDpaire=4 ,image = R.drawable.card8);
    		carte9=new Card(button,x,y,IDpaire=5 ,image = R.drawable.card9);
    		carte10=new Card(button,x,y,IDpaire=5 ,image = R.drawable.card10);
    		carte11=new Card(button,x,y,IDpaire=6 ,image = R.drawable.card11);
    		carte12=new Card(button,x,y,IDpaire=6 ,image = R.drawable.card12);
    		carte13=new Card(button,x,y,IDpaire=7 ,image = R.drawable.card13);
    		carte14=new Card(button,x,y,IDpaire=7 ,image = R.drawable.card14);
    		carte15=new Card(button,x,y,IDpaire=8 ,image = R.drawable.card15);
    		carte16=new Card(button,x,y,IDpaire=8 ,image = R.drawable.card16);
    		carte18=new Card(button,x,y,IDpaire=1 ,image = R.drawable.card18);
    		carte19=new Card(button,x,y,IDpaire=2 ,image = R.drawable.card19);
    		carte20=new Card(button,x,y,IDpaire=2 ,image = R.drawable.card20);
    		carte21=new Card(button,x,y,IDpaire=3 ,image = R.drawable.card21);
    		carte22=new Card(button,x,y,IDpaire=3 ,image = R.drawable.card22);
    		carte23=new Card(button,x,y,IDpaire=4 ,image = R.drawable.card29);
    		carte24=new Card(button,x,y,IDpaire=4 ,image = R.drawable.card24);
    		carte25=new Card(button,x,y,IDpaire=5 ,image = R.drawable.card25);
    		carte26=new Card(button,x,y,IDpaire=5 ,image = R.drawable.card26);
    		carte27=new Card(button,x,y,IDpaire=6 ,image = R.drawable.card27);
    		carte28=new Card(button,x,y,IDpaire=6 ,image = R.drawable.card28);
    		carte29=new Card(button,x,y,IDpaire=7 ,image = R.drawable.card29);
    		carte30=new Card(button,x,y,IDpaire=7 ,image = R.drawable.card30);
    		carte31=new Card(button,x,y,IDpaire=8 ,image = R.drawable.card31);
    		carte32=new Card(button,x,y,IDpaire=8 ,image = R.drawable.card32);
    		carte33=new Card(button,x,y,IDpaire=8 ,image = R.drawable.card33);
     
    		//tableau pour les ranger dans l'ordre
    		tableaudepart = new ArrayList<Card>();
    		tableaudepart.add(carte1);
    		tableaudepart.add(carte2);
    		tableaudepart.add(carte3);
    		tableaudepart.add(carte4);
    		tableaudepart.add(carte5);
    		tableaudepart.add(carte6);
    		tableaudepart.add(carte7);		
    		tableaudepart.add(carte8);
    		tableaudepart.add(carte9);
    		tableaudepart.add(carte10);
    		tableaudepart.add(carte11);
    		tableaudepart.add(carte12);
    		tableaudepart.add(carte13);
    		tableaudepart.add(carte14);
    		tableaudepart.add(carte15);
    		tableaudepart.add(carte16);
    		tableaudepart.add(carte17);
    		tableaudepart.add(carte18);
    		tableaudepart.add(carte19);
    		tableaudepart.add(carte20);
    		tableaudepart.add(carte21);
    		tableaudepart.add(carte22);
    		tableaudepart.add(carte23);		
    		tableaudepart.add(carte24);
    		tableaudepart.add(carte25);
    		tableaudepart.add(carte26);
    		tableaudepart.add(carte27);
    		tableaudepart.add(carte28);
    		tableaudepart.add(carte29);
    		tableaudepart.add(carte30);
    		tableaudepart.add(carte31);
    		tableaudepart.add(carte32);
    		tableaudepart.add(carte33);
     
     
    	}
     
    	public void placement(){
    		//on choisit une place aléatoire dans le tableau pour chaque carte en mélangeant le premier tableau
            setContentView(R.layout.jeux1);
     
            for (int i=33; i>0; i--){
    	        int a =1;
    	        int b=i;
    	        int random = (int)(Math.random() * (b-a));
     
    	        tableaufinal.add(tableaudepart.get(random));
    	        tableaudepart.remove(random);   
            }
    	}                           
     
    	public void booton(){
    		//tableau de bouton pour faire le lien avec celui des cartes
    		boutton = new ArrayList<Button>();
    		boutton.add(button1);
    		boutton.add(button2);
    		boutton.add(button3);
    		boutton.add(button4);
    		boutton.add(button5);
    		boutton.add(button6);
    		boutton.add(button7);		
    		boutton.add(button8);
    		boutton.add(button9);
    		boutton.add(button10);
    		boutton.add(button11);
    		boutton.add(button12);
    		boutton.add(button13);
    		boutton.add(button14);
    		boutton.add(button15);
    		boutton.add(button16);
     
    		button1.setOnClickListener(this);
    		button2.setOnClickListener(this);
    		button3.setOnClickListener(this);
    		button4.setOnClickListener(this);
    		button5.setOnClickListener(this);
    		button6.setOnClickListener(this);
    		button7.setOnClickListener(this);
    		button8.setOnClickListener(this);
    		button9.setOnClickListener(this);
    		button10.setOnClickListener(this);
    		button11.setOnClickListener(this);
    		button12.setOnClickListener(this);
    		button13.setOnClickListener(this);
    		button14.setOnClickListener(this);
    		button15.setOnClickListener(this);
    		button16.setOnClickListener(this);
     
    	}
     
    	public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
     
     
            setContentView(R.layout.jeux1);
            button1 = (Button)findViewById(R.id.button1)  ;
            button2 = (Button)findViewById(R.id.button2)  ;
            button3 = (Button)findViewById(R.id.button3)  ;
            button4 = (Button)findViewById(R.id.button4)  ;
            button5 = (Button)findViewById(R.id.button5)  ;
            button6 = (Button)findViewById(R.id.button6)  ;
            button7 = (Button)findViewById(R.id.button7)  ;
            button8 = (Button)findViewById(R.id.button8)  ;
            button9 = (Button)findViewById(R.id.button9)  ;
            button10 = (Button)findViewById(R.id.button10)  ;
            button11 = (Button)findViewById(R.id.button11)  ;
            button12 = (Button)findViewById(R.id.button12)  ;
            button13 = (Button)findViewById(R.id.button13)  ;
            button14 = (Button)findViewById(R.id.button14)  ;
            button15 = (Button)findViewById(R.id.button15)  ;
            button16 = (Button)findViewById(R.id.button16)  ;
     
     
     
            }
     
     
    	@Override
    	public void onClick(View v) {
    		System.out.println("je clique");
     
    		if (premierClic){
     
    		if (v == button1)
    		{
    			Card a = tableaufinal.get(1);
    			u = a.IDpaire;
    			backImage = a.image;	
    			button1.setBackgroundColor(backImage);
    		}
    		else if (v == button2)
     
    		{
    			Card a = tableaufinal.get(2);
    			u = a.IDpaire;
    			backImage = a.image;	
    			button2.setBackgroundColor(backImage);
    		}
    		else if (v == button3)
    		{
    			Card a = tableaufinal.get(3);
    			u = a.IDpaire;
    			backImage = a.image;	
    			button3.setBackgroundColor(backImage);
    		}
    		else if (v == button4)
    		{
    			Card a = tableaufinal.get(4);
    			u = a.IDpaire;
    			backImage = a.image;	
    			button4.setBackgroundColor(backImage);
    		}
    		else if (button5.getId()==((Button)v).getId()) 
    		{
    			Card a = tableaufinal.get(5);
    			u = a.IDpaire;
    			backImage = a.image;	
    			button5.setBackgroundColor(backImage);
    		}
    		else if (button6.getId()==((Button)v).getId()) 
    		{
    			Card a = tableaufinal.get(6);
    			u = a.IDpaire;
    			backImage = a.image;	
    			button6.setBackgroundColor(backImage);
    		}
    		else if (button7.getId()==((Button)v).getId()) 
    		{
    			Card a = tableaufinal.get(7);
    			u = a.IDpaire;
    			backImage = a.image;	
    			button7.setBackgroundColor(backImage);
    		}
    		else if (button8.getId()==((Button)v).getId()) 
    		{
    			Card a = tableaufinal.get(8);
    			u = a.IDpaire;
    			backImage = a.image;	
    			button8.setBackgroundColor(backImage);
    		}
    		else if (button9.getId()==((Button)v).getId()) 
    		{
    			Card a = tableaufinal.get(9);
    			u = a.IDpaire;
    			backImage = a.image;	
    			button9.setBackgroundColor(backImage);
    		}
    		else if (button10.getId()==((Button)v).getId()) 
    		{
    			Card a = tableaufinal.get(10);
    			u = a.IDpaire;
    			backImage = a.image;	
    			button10.setBackgroundColor(backImage);
    		}
    		else if (button11.getId()==((Button)v).getId()) 
    		{
    			Card a = tableaufinal.get(11);
    			u = a.IDpaire;
    			backImage = a.image;	
    			button11.setBackgroundColor(backImage);
    		}
    		else if (button12.getId()==((Button)v).getId()) 
    		{
    			Card a = tableaufinal.get(12);
    			u = a.IDpaire;
    			backImage = a.image;	
    			button12.setBackgroundColor(backImage);
    		}
    		else if (button13.getId()==((Button)v).getId()) 
    		{
    			Card a = tableaufinal.get(13);
    			u = a.IDpaire;
    			backImage = a.image;	
    			button13.setBackgroundColor(backImage);
    		}
    		else if (button14.getId()==((Button)v).getId()) 
    		{
    			Card a = tableaufinal.get(14);
    			u = a.IDpaire;
    			backImage = a.image;	
    			button14.setBackgroundColor(backImage);
    		}
    		else if (button15.getId()==((Button)v).getId()) 
    		{
    			Card a = tableaufinal.get(15);
    			u = a.IDpaire;
    			backImage = a.image;	
    			button15.setBackgroundColor(backImage);
    		}
    		else if (button16.getId()==((Button)v).getId()) 
    		{
    			Card a = tableaufinal.get(16);
    			u = a.IDpaire;
    			backImage = a.image;	
    			button16.setBackgroundColor(backImage);
    		}
    		premierClic = false;
     
    		}
     
    		else {
    			if(v==button1){
    		           Card a = tableaufinal.get(1);
    		           if(u == a.IDpaire)
    		             {
    		                 // Cacher les cartes 
    		       		//timer
    		       		TimerTask tt = new TimerTask() {
     
    		       			@Override
    		       			public void run() {
    		       				try{
    		       					synchronized (lock) {
    		       					  handler.sendEmptyMessage(0);
    		       					}
    		       				}
    		       				catch (Exception e) {
    		       					Log.e("E1", e.getMessage());
    		       				}
    		       			}
    		       		};
     
    		       		  Timer t = new Timer(false);
    		       	        t.schedule(tt, 1300);
     
    		       	        //on verifie les idpaires		      
    		       				button1.setVisibility(View.INVISIBLE);
    		       				button5.setVisibility(View.INVISIBLE);
    		       			}
    		             }
     
    			else {
    				Card a=null;
    				u=0;
    			}
     
    			if(v==button2){
    		           Card a = tableaufinal.get(2);
    		           if(u == a.IDpaire)
    		             {
    		                 // Cacher les cartes 
    		       		//timer
    		       		TimerTask tt = new TimerTask() {
     
    		       			@Override
    		       			public void run() {
    		       				try{
    		       					synchronized (lock) {
    		       					  handler.sendEmptyMessage(0);
    		       					}
    		       				}
    		       				catch (Exception e) {
    		       					Log.e("E1", e.getMessage());
    		       				}
    		       			}
    		       		};
     
    		       		  Timer t = new Timer(false);
    		       	        t.schedule(tt, 1300);
     
    		       	        //on verifie les idpaires		      
    		       				button2.setVisibility(View.INVISIBLE);
    		       				button6.setVisibility(View.INVISIBLE);
    		       			}
    		             }
     
    			else {
    				Card a=null;
    				u=0;
    			}
    			if(v==button3){
    		           Card a = tableaufinal.get(3);
    		           if(u == a.IDpaire)
    		             {
    		                 // Cacher les cartes 
    		       		//timer
    		       		TimerTask tt = new TimerTask() {
     
    		       			@Override
    		       			public void run() {
    		       				try{
    		       					synchronized (lock) {
    		       					  handler.sendEmptyMessage(0);
    		       					}
    		       				}
    		       				catch (Exception e) {
    		       					Log.e("E1", e.getMessage());
    		       				}
    		       			}
    		       		};
     
    		       		  Timer t = new Timer(false);
    		       	        t.schedule(tt, 1300);
     
    		       	        //on verifie les idpaires		      
    		       	        	button3.setVisibility(View.INVISIBLE);
    		       				button7.setVisibility(View.INVISIBLE);
    		       			}
    		             }
     
    			else {
    				Card a=null;
    				u=0;
    			}
    			premierClic = true;
    		}
    	}		
    	};

  10. #110
    Membre confirmé
    Homme Profil pro
    IUT Informatique
    Inscrit en
    Mars 2011
    Messages
    412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : IUT Informatique

    Informations forums :
    Inscription : Mars 2011
    Messages : 412
    Points : 486
    Points
    486
    Par défaut
    Ok, alors d'abord, c'est à quel moment que tu fais appel à creationcarte(Button button,int IDpaire, int y, int x, int image), booton() et placement() ???

  11. #111
    Nouveau membre du Club
    Inscrit en
    Avril 2011
    Messages
    104
    Détails du profil
    Informations forums :
    Inscription : Avril 2011
    Messages : 104
    Points : 25
    Points
    25
    Par défaut
    exact, j'ai oublié de les remettre après mes changements ...

    Je les appelles dans le OnCreate non ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
     
     
            setContentView(R.layout.jeux1);
     
            creationcarte(button, IDpaire,  y,  x,  image); 
            booton(); 
            placement();
     
            button1 = (Button)findViewById(R.id.button1)  ;
            button2 = (Button)findViewById(R.id.button2)  ;
            button3 = (Button)findViewById(R.id.button3)  ;
            button4 = (Button)findViewById(R.id.button4)  ;
            button5 = (Button)findViewById(R.id.button5)  ;
            button6 = (Button)findViewById(R.id.button6)  ;
            button7 = (Button)findViewById(R.id.button7)  ;
            button8 = (Button)findViewById(R.id.button8)  ;
            button9 = (Button)findViewById(R.id.button9)  ;
            button10 = (Button)findViewById(R.id.button10)  ;
            button11 = (Button)findViewById(R.id.button11)  ;
            button12 = (Button)findViewById(R.id.button12)  ;
            button13 = (Button)findViewById(R.id.button13)  ;
            button14 = (Button)findViewById(R.id.button14)  ;
            button15 = (Button)findViewById(R.id.button15)  ;
            button16 = (Button)findViewById(R.id.button16)  ;
     
     
     
            }
    Mais si je fais cela l'application n'aime pas trop et plante ...

  12. #112
    Nouveau membre du Club
    Inscrit en
    Avril 2011
    Messages
    104
    Détails du profil
    Informations forums :
    Inscription : Avril 2011
    Messages : 104
    Points : 25
    Points
    25
    Par défaut
    logcat :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    06-06 12:38:07.724: WARN/KeyCharacterMap(1217): No keyboard for id 0
    06-06 12:38:07.734: WARN/KeyCharacterMap(1217): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
    06-06 12:38:09.278: INFO/ActivityManager(51): Starting activity: Intent { cmp=com.aviy.memory/.Jeu }
    06-06 12:38:19.352: WARN/ActivityManager(51): Launch timeout has expired, giving up wake lock!
    06-06 12:38:19.354: WARN/ActivityManager(51): Activity idle timeout for HistoryRecord{438ec560 com.aviy.memory/.Jeu}
    06-06 12:38:24.444: DEBUG/dalvikvm(186): GC freed 104 objects / 4448 bytes in 78ms
    06-06 12:38:29.654: DEBUG/dalvikvm(94): GC freed 3134 objects / 175392 bytes in 193ms

  13. #113
    Membre confirmé
    Homme Profil pro
    IUT Informatique
    Inscrit en
    Mars 2011
    Messages
    412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : IUT Informatique

    Informations forums :
    Inscription : Mars 2011
    Messages : 412
    Points : 486
    Points
    486
    Par défaut
    Je t'avoue que je comprend pas trop le logCat mais c'est normal qu'elle plante.

    Avant de lancer tes fonctions tout d'abord, tu dois avoir tes variables instancier, donc tu dois le faire tout à la fin, puis quand dans le onCreate tu fais

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    creationcarte(button, IDpaire,  y,  x,  image);
    Ton compilateur ne connait aucune des variables que tu passe en paramètre.
    C'est un des problèmes que je voulais soulever, tu fais une méthode creationCarte avec des paramètres, mais tu n'utilise pas vraiment ces variables, quoi tu les utiliser quand tu fais des news cards mais en suivant tes variables tu peux vite te rendre compte du problème.

    Imaginons que t'ai des variable button, IDpaire, y, x et image qui sont instancier. Déjà quand tu crées une cartes dans la méthode ton code va être de ce style:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    carte1=new Card(button,x,y,IDpaire=1 ,image = R.drawable.card1);
    Donc mettre en paramètre IDpaire et image ne sert à rien. Ensuite si on suit les variables x, y. Imaginons instancier à 0. Donc tu appel creationcarte avec x et y égal à 0.
    le code de création revient à

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    carte1=new Card(button,0,0,IDpaire=1 ,image = R.drawable.card1);
    		carte2=new Card(button,0,0,IDpaire=1 ,image = R.drawable.card2);
    		carte3=new Card(button,0,0,IDpaire=2 ,image = R.drawable.card3);
    ...
    Donc la il y a forcément un souci, vu que tu ne boucle pas, code tout en dur dur dur c'est à dire mettre

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    carte1=new Card(button1,0,0,IDpaire=1 ,image = R.drawable.card1);
    		carte2=new Card(button2,0,1,IDpaire=1 ,image = R.drawable.card2);
    		carte3=new Card(button3,0,3,IDpaire=2 ,image = R.drawable.card3);
    ...
    Je sais pas si j'ai bien expliqué, mais si tu comprend pas dit le ^^

  14. #114
    Nouveau membre du Club
    Inscrit en
    Avril 2011
    Messages
    104
    Détails du profil
    Informations forums :
    Inscription : Avril 2011
    Messages : 104
    Points : 25
    Points
    25
    Par défaut
    La seule chose qui ne va pas serait donc les "x" et "y" ?
    J'ai donc mis toutes ces valeurs à 0 ... Cependant l’application plante encore.

    Mon histoire pour mélanger le tableaux est elle bien faite ? le problème vient peut être de la ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    	public void placement(){
    		//on choisit une place aléatoire dans le tableau pour chaque carte en mélangeant le premier tableau
            setContentView(R.layout.jeux1);
     
            for (int i=33; i>0; i--){
    	        int a =1;
    	        int b=i;
    	        int random = (int)(Math.random() * (b-a));
     
    	        tableaufinal.add(tableaudepart.get(random));
    	        tableaudepart.remove(random);   
            }
    	}

  15. #115
    Membre confirmé
    Homme Profil pro
    IUT Informatique
    Inscrit en
    Mars 2011
    Messages
    412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : IUT Informatique

    Informations forums :
    Inscription : Mars 2011
    Messages : 412
    Points : 486
    Points
    486
    Par défaut
    Non tu n'as pas réellement compris ce que je voulais dire. Pour une carte x, y et button représentent quoi?

    Et euu je me souvient plus comment fonctionne le random, je vérifierai une fois chez moi j'ai un exemple, mais à la limite le placement aléatoire tu devrais te pencher dessus une fois que ton projet si tu les places les unes à la suite des autres...

  16. #116
    Nouveau membre du Club
    Inscrit en
    Avril 2011
    Messages
    104
    Détails du profil
    Informations forums :
    Inscription : Avril 2011
    Messages : 104
    Points : 25
    Points
    25
    Par défaut
    x et y ne me servent à rien ... Mais je dois les garder car je les utilises à un autre endroit.
    Pour button, cela signifie juste qu'une carte à un bouton qui lui est attribué.

    Je ne peux pas attribuer un bouton à chaque carte, car celles ci sont plus nombreuses que mon nombre de bouton.

    J'ai changé mon code en ne prenant que 16 cartes, donc attribué direct aux 16 boutons. Et en enlevant le "placement".

    Mais l'application plante toujours au départ, sans avoir d'erreurs spécifiques dans le logcat. Juste un : Source not found. dans "Activity Thread.perfo"

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    public void creationcarte(Button button,int IDpaire, int y, int x, int image){
    		//on crée les cartes
    		carte1=new Card(button1,0,0,IDpaire=1 ,image = R.drawable.card1);
    		carte2=new Card(button2,0,0,IDpaire=1 ,image = R.drawable.card2);
    		carte3=new Card(button3,0,0,IDpaire=2 ,image = R.drawable.card3);
    		carte4=new Card(button4,0,0,IDpaire=2 ,image = R.drawable.card4);
    		carte5=new Card(button5,0,0,IDpaire=3 ,image = R.drawable.card5);
    		carte6=new Card(button6,0,0,IDpaire=3 ,image = R.drawable.card6);
    		carte7=new Card(button7,0,0,IDpaire=4 ,image = R.drawable.card7);
    		carte8=new Card(button8,0,0,IDpaire=4 ,image = R.drawable.card8);
    		carte9=new Card(button9,0,0,IDpaire=5 ,image = R.drawable.card9);
    		carte10=new Card(button10,0,0,IDpaire=5 ,image = R.drawable.card10);
    		carte11=new Card(button11,0,0,IDpaire=6 ,image = R.drawable.card11);
    		carte12=new Card(button12,0,0,IDpaire=6 ,image = R.drawable.card12);
    		carte13=new Card(button13,0,0,IDpaire=7 ,image = R.drawable.card13);
    		carte14=new Card(button14,0,0,IDpaire=7 ,image = R.drawable.card14);
    		carte15=new Card(button15,0,0,IDpaire=8 ,image = R.drawable.card15);
    		carte16=new Card(button16,0,0,IDpaire=8 ,image = R.drawable.card16); ...

  17. #117
    Membre confirmé
    Homme Profil pro
    IUT Informatique
    Inscrit en
    Mars 2011
    Messages
    412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : IUT Informatique

    Informations forums :
    Inscription : Mars 2011
    Messages : 412
    Points : 486
    Points
    486
    Par défaut
    Si tu en a pas besoin lorsque tu les instancie (donc si tu dois pas forcément définir un x et y) ne les met pas en paramètre de Card. De même pour bouton si c'est le cas.

    Après pour être franc je ne sais pas c'est quoi comme type d'erreur celle que ton logCat te présente...

    Les deux classes que tu m'a montrer sont les seules de ton projet? Si ca te dérange pas, je récupère le code pour tester de mon coté et je te dit si je trouve le problème à ton problème...

  18. #118
    Nouveau membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2011
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Juin 2011
    Messages : 16
    Points : 32
    Points
    32
    Par défaut
    Salut,

    [HS]
    J'ai créé un Memory. En revanche, je n'ai pas utilisé de Button pour simuler les cartes... Je l'ai fait de manière jeu 2D avec Canvas...
    [/HS]

    Pourquoi ne fais tu pas une classe Card qui hérite de Button ?
    Tu mets ensuite toutes tes cartes dans un ArrayList<Card> que tu mélanges facilement avec une méthode de la classe Collections (Collections.shuffle).
    Puis tu récupères au clique d'une carte (bouton), l'id (ou l'objet qui a été cliqué) pour ensuite faire la comparaison.

    C'est une idée, j'ai lu le topic en diagonale... j'espère ne pas être à coté de la plaque.

  19. #119
    Membre confirmé
    Homme Profil pro
    IUT Informatique
    Inscrit en
    Mars 2011
    Messages
    412
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : IUT Informatique

    Informations forums :
    Inscription : Mars 2011
    Messages : 412
    Points : 486
    Points
    486
    Par défaut
    Non t'es pas du tout à coté de la plaque, il a préféré coder en dur pustot que de passer par des listes. Mais la méthode de classe Collection collection.shuffle() est très interessante, ca pourrai bien aider je pense.

  20. #120
    Nouveau membre du Club
    Inscrit en
    Avril 2011
    Messages
    104
    Détails du profil
    Informations forums :
    Inscription : Avril 2011
    Messages : 104
    Points : 25
    Points
    25
    Par défaut
    Salut,

    Merci de ta réponse

    Non tu n'es pas à coté de la plaque. Cependant tu me donnes nouvel axe de réflexion et j'ai déjà bien du mal à suivre ce proposés pour m'aider ...

    Je ne sais même pas si je comprend bien ta remarque lol. En tout cas je vais essayer d'y réfléchir un peu ce soir, histoire de voir si je peux y arriver

+ Répondre à la discussion
Cette discussion est résolue.
Page 6 sur 7 PremièrePremière ... 234567 DernièreDernière

Discussions similaires

  1. Serveur d'application pour android et iphone
    Par tlili_info dans le forum API standards et tierces
    Réponses: 6
    Dernier message: 18/03/2013, 10h41
  2. Réponses: 4
    Dernier message: 04/05/2011, 15h06
  3. connexion entre une Base de données et Application sur Android
    Par clubist dans le forum API standards et tierces
    Réponses: 12
    Dernier message: 27/11/2009, 12h01

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo