Project

General

Profile

Download (3.64 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / effect / UnscrambleEffect.java @ a7012218

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.effect;
21

    
22
import java.lang.reflect.Method;
23

    
24
///////////////////////////////////////////////////////////////////////////////////////////////////
25

    
26
public class UnscrambleEffect
27
{
28
  public enum Type
29
    {
30
    NONE  (UnscrambleEffectNone.class ),
31
    SPIN  (UnscrambleEffectSpin.class ),
32
    ;
33

    
34
    private final Class<? extends UnscrambleEffect> effectClass;
35

    
36
    Type(Class<? extends UnscrambleEffect> effectClass)
37
      {
38
      this.effectClass = effectClass;
39
      }
40
    }
41

    
42
  public static final int NUM_EFFECTS = Type.values().length;
43
  private static final Type[] types;
44

    
45
  static
46
    {
47
    int i=0;
48

    
49
    types = new Type[NUM_EFFECTS];
50

    
51
    for(Type type: Type.values())
52
      {
53
      types[i] = type;
54
      i++;
55
      }
56
    }
57

    
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59

    
60
  public static UnscrambleEffect.Type getType(int ordinal)
61
    {
62
    return types[ordinal];
63
    }
64

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

    
67
  public static UnscrambleEffect create(Type type) throws InstantiationException, IllegalAccessException
68
    {
69
    return type.effectClass.newInstance();
70
    }
71

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

    
74
  public static void enableEffects()
75
    {
76
    Method method=null;
77

    
78
    for(Type type: Type.values())
79
      {
80
      Class<? extends UnscrambleEffect> cls = type.effectClass;
81

    
82
      try
83
        {
84
        method = cls.getMethod("enable");
85
        }
86
      catch(NoSuchMethodException ex)
87
        {
88
        android.util.Log.e("UnscrambleEffect", "exception getting method: "+ex.getMessage());
89
        }
90

    
91
      try
92
        {
93
        method.invoke(null);
94
        }
95
      catch(Exception ex)
96
        {
97
        android.util.Log.e("UnscrambleEffect", "exception invoking method: "+ex.getMessage());
98
        }
99
      }
100
    }
101
}
(13-13/15)