GameModel.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package model;
  2. import java.awt.Color;
  3. import main.Window;
  4. import control.GameStateManager;
  5. import control.NetworkHandler;
  6. import control.SongHandler;
  7. public class GameModel {
  8. public static Color[] colors = { Color.GREEN, Color.YELLOW, Color.RED, Color.MAGENTA, Color.CYAN, Color.BLUE };
  9. private static String[] ledStripModes = {"full", "half", "quarter", "random"};
  10. private GameStateManager gsm;
  11. private NetworkHandler ntw;
  12. private int count = 0;
  13. public GameModel(SongHandler sh, GameStateManager gsm, NetworkHandler ntw) {
  14. this.gsm = gsm;
  15. this.ntw = ntw;
  16. }
  17. public void update(float factor) {
  18. gsm.update(factor);
  19. if (Window.ON_ARCADE)
  20. updateLedStrip(factor);
  21. }
  22. private void updateLedStrip(float factor)
  23. {
  24. count += factor;
  25. if(count > 400)
  26. {
  27. String mode = ledStripModes[(int) (Math.random() * (ledStripModes.length - 1) + 1)];
  28. switch(mode)
  29. {
  30. default:
  31. case "full":
  32. Color c = colors[(int) (Math.random() * (colors.length - 1) + 1)];
  33. for (int i = 6; i < 46; i++) {
  34. ntw.setLed(i, c.getRed(), c.getGreen(), c.getBlue());
  35. }
  36. ntw.show();
  37. break;
  38. case "half":
  39. Color c1 = colors[(int) (Math.random() * (colors.length - 1) + 1)];
  40. Color c2 = colors[(int) (Math.random() * (colors.length - 1) + 1)];
  41. while(c1==c2)
  42. c2 = colors[(int) (Math.random() * (colors.length - 1) + 1)];
  43. for (int i = 6; i < 26; i++) {
  44. ntw.setLed(i, c1.getRed(), c1.getGreen(), c1.getBlue());
  45. }
  46. for (int i = 27; i < 46; i++) {
  47. ntw.setLed(i, c2.getRed(), c2.getGreen(), c2.getBlue());
  48. }
  49. ntw.show();
  50. break;
  51. case "quarter":
  52. Color c3 = colors[(int) (Math.random() * (colors.length - 1) + 1)];
  53. Color c4 = colors[(int) (Math.random() * (colors.length - 1) + 1)];
  54. Color c5 = colors[(int) (Math.random() * (colors.length - 1) + 1)];
  55. Color c6 = colors[(int) (Math.random() * (colors.length - 1) + 1)];
  56. while(c3==c4)
  57. c4 = colors[(int) (Math.random() * (colors.length - 1) + 1)];
  58. while(c4==c5)
  59. c5 = colors[(int) (Math.random() * (colors.length - 1) + 1)];
  60. while(c5==c6)
  61. c6 = colors[(int) (Math.random() * (colors.length - 1) + 1)];
  62. for (int i = 6; i < 16; i++) {
  63. ntw.setLed(i, c3.getRed(), c3.getGreen(), c3.getBlue());
  64. }
  65. for (int i = 17; i < 26; i++) {
  66. ntw.setLed(i, c4.getRed(), c4.getGreen(), c4.getBlue());
  67. }
  68. for (int i = 27; i < 36; i++) {
  69. ntw.setLed(i, c5.getRed(), c5.getGreen(), c5.getBlue());
  70. }
  71. for (int i = 37; i <46; i++) {
  72. ntw.setLed(i, c6.getRed(), c6.getGreen(), c6.getBlue());
  73. }
  74. ntw.show();
  75. break;
  76. case "random":
  77. Color c7;
  78. for (int i = 6; i < 46; i++) {
  79. c7 = colors[(int) (Math.random() * (colors.length - 1) + 1)];
  80. ntw.setLed(i, c7.getRed(), c7.getGreen(), c7.getBlue());
  81. }
  82. ntw.show();
  83. break;
  84. }
  85. count = 0;
  86. }
  87. }
  88. }