2017-12-27 12 views
0

皆さん、私の割り当ての一環として、flooditゲーム用のアンドロイドスタジオでグリッドを生成しようとしています。 Genereatedグリッドは毎回ランダムでなければならないので、以下に示すように色を生成するためにswitch文とpaint文を使用しています。キャンバスグリッドのランダム生成が生成されない

Paint paint1 = new Paint (getResources().getColor(R.color.color1)); 
     Paint paint2 = new Paint (getResources().getColor(R.color.color2)); 
     Paint paint3 = new Paint (getResources().getColor(R.color.color3)); 
     Paint paint4 = new Paint (getResources().getColor(R.color.color4)); 
     Paint paint5 = new Paint (getResources().getColor(R.color.color5)); 
     Paint paint6 = new Paint (getResources().getColor(R.color.color6)); 


     for (int col = 0; col < mGame.getHeight(); col++) { 
      for (int row = 0; row < mGame.getWidth(); row++) { 
       Random random = new Random(6); 
       int num = 1; 
       int randomResult = random.nextInt(); 

       float cx = separator + (diameterx + separator) * col + diameterx/2; 
       float cy = separator + (diametery + separator) * row + diametery/2; 
       canvas.drawRect(cx, cy, availableWidth, availableHeight, paint6); 
       switch (randomResult) { 
        case 0: 
         canvas.drawRect(cx, cy, availableWidth/2, availableHeight/2, paint1); 
         break; 
        case 1: 
         canvas.drawRect(cx, cy, availableWidth, availableHeight, paint2); 
         break; 
        case 2: 
         canvas.drawRect(cx, cy, availableWidth, availableHeight, paint3); 
         break; 
        case 3: 
         canvas.drawRect(cx, cy, availableWidth, availableHeight, paint4); 
         break; 
        case 4: 
         canvas.drawRect(cx, cy, availableWidth, availableHeight, paint5); 
         break; 
        case 5: 
         canvas.drawRect(cx, cy, availableWidth, availableHeight, paint6); 
         break; 

       } 


      } 
     } 

問題があるswitch文内のコードは動作しませんが(デモために)だけでswitch文上記canvas.drawRect(cx, cy, availableWidth, availableHeight, paint6);はそれが私が理解することができないんだ、そのブロック内のいくつかの問題ですので、正常に動作するようです。どんな助けもありがとう。

種類は、すべての塗料用に設定してください

答えて

0

について:試みのため

paint.setStrokeWidth(20); 
paint.setStyle(Paint.Style.STROKE); 
paint.setAntiAlias(true); 
+0

おかげで、それは残念ながら何もしませんでした。 – Deadraa

+0

'cx'、' cy'、 'availableWidth'と' availableHeight'は正しい値を持っていますか? – BullyBoo

+0

また、あなたはRandomクラスを使って間違っています。 試してください: 'ランダムランダム=新しいランダム(); int randomResult = random.nextInt(6); ' – BullyBoo

関連する問題