Mercurial > hg > ristipolku
annotate game/Engine.java @ 194:f8626a142c4d
Adjust scoring method.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 23 Apr 2019 15:43:24 +0300 |
parents | 8dbaa093c562 |
children | ad336d22c3e8 |
rev | line source |
---|---|
0 | 1 /* |
9 | 2 * Ristipolku Game Engine |
189 | 3 * (C) Copyright 2011-2017 Matti 'ccr' Hämäläinen <ccr@tnsp.org> |
0 | 4 */ |
9 | 5 package game; |
6 | |
0 | 7 import java.awt.*; |
8 import java.awt.geom.*; | |
1 | 9 import java.awt.event.*; |
7 | 10 import java.awt.image.*; |
11 import java.awt.event.*; | |
25 | 12 import java.awt.font.*; |
9 | 13 import javax.imageio.*; |
7 | 14 import javax.swing.*; |
1 | 15 import java.util.*; |
131
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
16 import java.util.concurrent.locks.Lock; |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
17 import java.util.concurrent.locks.ReentrantReadWriteLock; |
6 | 18 import java.io.*; |
1 | 19 import game.*; |
37 | 20 import javax.sound.sampled.*; |
21 | 21 |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
22 |
176
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
23 class AboutBox extends IDMContainer |
8 | 24 { |
75 | 25 BufferedImage aboutImg; |
26 | |
27 public AboutBox() | |
28 { | |
29 setPos(150f, 150f); | |
176
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
30 setSize(720f, 470f); |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
31 setModal(true); |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
32 |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
33 add(new BtnOK(500f, 390f)); |
75 | 34 } |
35 | |
36 public void paint(Graphics2D g) | |
37 { | |
115 | 38 g.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.7f)); |
170
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
39 g.fill(new RoundRectangle2D.Float(getScaledX(), getScaledY(), getScaledWidth(), getScaledHeight(), 10, 10)); |
75 | 40 |
76 | 41 setTextFont(G.fonts[3], G.metrics[3]); |
75 | 42 setTextPaint(Color.white); |
173 | 43 setCurrPosScaledRel(20, 35); |
105
75015dfd47ef
Move version number info to G.java.
Matti Hamalainen <ccr@tnsp.org>
parents:
93
diff
changeset
|
44 drawString(g, "RistiPolku (CrossPaths) v"+ G.version +"\n"); |
75 | 45 |
76 | 46 setTextFont(G.fonts[1], G.metrics[1]); |
173 | 47 setTextPaint(Color.yellow); |
48 drawString(g, "(c) Copyright 2011 Tecnic Software productions (TNSP)\n"); | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
49 |
173 | 50 setTextPaint(Color.white); |
51 drawString(g, "Programming, graphics and design by " + | |
52 "Matti 'ccr' Hämäläinen.\n" + | |
53 "Audio from archive.org, used non-commercially.\n \n"); | |
75 | 54 |
173 | 55 setTextPaint(Color.red); |
56 drawString(g, "Controls:\n"); | |
57 | |
58 IDMPoint old = textCurrOffs.copy(); | |
81
8932b1300ba1
Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents:
80
diff
changeset
|
59 |
173 | 60 setTextPaint(Color.white); |
61 drawString(g, | |
62 "Arrow keys / mouse wheel\n"+ | |
63 "Enter / mouse click\n"+ | |
64 "Space bar\n"); | |
81
8932b1300ba1
Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents:
80
diff
changeset
|
65 |
173 | 66 textCurrPos.x += getScaledX(330); |
67 textCurrOffs.y = old.y; | |
68 drawString(g, | |
69 "- Rotate piece\n" + | |
70 "- Place/lock piece\n" + | |
71 "- Swap piece\n"); | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
72 |
173 | 73 textCurrPos.x -= getScaledX(330); |
74 setTextPaint(Color.green); | |
75 drawString(g, | |
76 "\nObjective: Create a path long as possible by rotating\n"+ | |
77 "and placing pieces. More points will be awarded for\n"+ | |
78 "advancing the path by several segments per turn." | |
79 ); | |
179 | 80 |
176
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
81 super.paint(g); |
75 | 82 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
83 |
75 | 84 public void clicked() |
8 | 85 { |
75 | 86 parent.remove(this); |
8 | 87 } |
176
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
88 |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
89 class BtnOK extends IDMButton |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
90 { |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
91 public BtnOK(float x, float y) |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
92 { |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
93 super(x, y, KeyEvent.VK_ESCAPE, G.fonts[1], "OK"); |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
94 } |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
95 |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
96 public void clicked() |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
97 { |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
98 parent.clicked(); |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
99 } |
9d3ff9605555
Change AboutBox to a "dialog" and implement Ok/close button for closing it.
Matti Hamalainen <ccr@tnsp.org>
parents:
175
diff
changeset
|
100 } |
8 | 101 } |
75 | 102 |
0 | 103 |
181
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
104 class NewGameDialog extends IDMContainer |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
105 { |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
106 public NewGameDialog() |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
107 { |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
108 setPos(150f, 350f); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
109 setSize(720f, 200f); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
110 setModal(true); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
111 |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
112 add(new BtnYes(270f, 120f)); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
113 add(new BtnCancel(500f, 120f)); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
114 } |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
115 |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
116 public void paint(Graphics2D g) |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
117 { |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
118 g.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.7f)); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
119 g.fill(new RoundRectangle2D.Float(getScaledX(), getScaledY(), getScaledWidth(), getScaledHeight(), 10, 10)); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
120 |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
121 setTextFont(G.fonts[3], G.metrics[3]); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
122 setTextPaint(Color.white); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
123 setCurrPosScaledRel(25, 35); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
124 drawString(g, "Really start a new game?\n"); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
125 |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
126 super.paint(g); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
127 } |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
128 |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
129 public void clicked() |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
130 { |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
131 parent.remove(this); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
132 } |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
133 |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
134 class BtnYes extends IDMButton |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
135 { |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
136 public BtnYes(float x, float y) |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
137 { |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
138 super(x, y, KeyEvent.VK_Y, G.fonts[1], "Yes"); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
139 } |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
140 |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
141 public void clicked() |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
142 { |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
143 sendMessage("NEWGAME"); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
144 parent.clicked(); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
145 } |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
146 } |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
147 |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
148 class BtnCancel extends IDMButton |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
149 { |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
150 public BtnCancel(float x, float y) |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
151 { |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
152 super(x, y, KeyEvent.VK_ESCAPE, G.fonts[1], "Cancel"); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
153 } |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
154 |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
155 public void clicked() |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
156 { |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
157 parent.clicked(); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
158 } |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
159 } |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
160 } |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
161 |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
162 |
48 | 163 class GameBoard extends IDMWidget |
0 | 164 { |
75 | 165 static final int boardSize = 9; |
166 static final int boardMiddle = 4; | |
2 | 167 Piece[][] board; |
117
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
168 float pscale, ptime; |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
169 |
138
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
170 public boolean flagGameOver, flagBoardIsDirty; |
119
52d79502447c
Make few variables un-public.
Matti Hamalainen <ccr@tnsp.org>
parents:
117
diff
changeset
|
171 int gameScore; |
181
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
172 int moves; |
54 | 173 |
119
52d79502447c
Make few variables un-public.
Matti Hamalainen <ccr@tnsp.org>
parents:
117
diff
changeset
|
174 Piece currPiece, nextPiece; |
41 | 175 int currX, currY, currPoint; |
9 | 176 |
47 | 177 Sound sndPlaced; |
131
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
178 |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
179 private final ReentrantReadWriteLock pointLock = new ReentrantReadWriteLock(); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
180 private ArrayList<AnimatedPointElement> pointElems; |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
181 |
75 | 182 public GameBoard(IDMPoint pos, float ps) |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
183 { |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
184 super(pos); |
75 | 185 pscale = ps; |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
186 |
108
ae66d21d4747
Disable piece placement sound.
Matti Hamalainen <ccr@tnsp.org>
parents:
106
diff
changeset
|
187 // sndPlaced = G.smgr.getSound("sounds/placed.wav"); |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
188 |
131
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
189 pointElems = new ArrayList<AnimatedPointElement>(); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
190 |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
191 startNewGame(); |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
192 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
193 |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
194 public void startNewGame() |
2 | 195 { |
196 board = new Piece[boardSize][boardSize]; | |
197 board[boardMiddle][boardMiddle] = new Piece(PieceType.START); | |
198 | |
41 | 199 currX = boardMiddle; |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
200 currY = boardMiddle; |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
201 currPoint = 0; |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
202 |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
203 currPiece = null; |
54 | 204 nextPiece = new Piece(PieceType.ACTIVE); |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
205 |
65
dc936dba124e
Set game over-flag correctly, so that we reset everything after a game over
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
206 flagGameOver = false; |
138
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
207 flagBoardIsDirty = true; |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
208 pieceFinishTurn(); |
55 | 209 gameScore = 0; |
181
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
210 moves = 0; |
2 | 211 } |
0 | 212 |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
213 public void paintBackPlate(Graphics2D g) |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
214 { |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
215 g.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.2f)); |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
216 g.setStroke(new BasicStroke(5.0f)); |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
217 g.draw(new RoundRectangle2D.Float(getScaledX(), getScaledY(), |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
218 boardSize * pscale, boardSize * pscale, |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
219 pscale / 5, pscale / 5)); |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
220 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
221 |
138
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
222 public void paintBoard(Graphics2D g, boolean drawCurrent) |
2 | 223 { |
224 for (int y = 0; y < boardSize; y++) | |
225 for (int x = 0; x < boardSize; x++) | |
226 if (board[x][y] != null) | |
227 { | |
138
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
228 if ((drawCurrent && board[x][y] == currPiece) || |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
229 (!drawCurrent && board[x][y] != currPiece)) |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
230 { |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
231 board[x][y].paint(g, |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
232 getScaledX() + (x * pscale), |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
233 getScaledY() + (y * pscale), |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
234 pscale - pscale / 10); |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
235 } |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
236 } |
138
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
237 } |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
238 |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
239 public void paint(Graphics2D g) |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
240 { |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
241 paintBoard(g, true); |
117
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
242 |
131
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
243 Lock read = pointLock.readLock(); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
244 read.lock(); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
245 try |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
246 { |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
247 for (AnimatedPointElement elem : pointElems) |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
248 { |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
249 elem.paint(g); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
250 } |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
251 } |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
252 finally |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
253 { |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
254 read.unlock(); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
255 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
256 |
131
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
257 |
117
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
258 if (!flagGameOver) |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
259 { |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
260 if (nextPiece != null) |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
261 { |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
262 // Draw next piece |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
263 AffineTransform save = g.getTransform(); |
154
48b91eabc029
Improve scaling a bit, not completely functional yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
152
diff
changeset
|
264 nextPiece.paint(g, G.screenDim.width * 0.85f - 90.0f/2.0f, G.screenDim.height * 0.43f, 90.0f); |
117
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
265 g.setTransform(save); |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
266 } |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
267 } |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
268 else |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
269 { |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
270 // Game over text |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
271 String text = "Game Over!"; |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
272 int textWidth = G.metrics[2].stringWidth(text); |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
273 g.setFont(G.fonts[2]); |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
274 |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
275 g.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.5f)); |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
276 g.drawString(text, (G.screenDim.width - textWidth) / 2 + 5, G.screenDim.height / 2 + 5); |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
277 |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
278 double f = Math.sin(ptime * 0.1) * 4.0; |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
279 g.setPaint(Color.white); |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
280 g.drawString(text, (G.screenDim.width - textWidth) / 2 + (float) f, G.screenDim.height / 2 + (float) f); |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
281 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
282 |
117
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
283 // Score |
154
48b91eabc029
Improve scaling a bit, not completely functional yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
152
diff
changeset
|
284 String text = ""+ String.format("%05d", gameScore); |
48b91eabc029
Improve scaling a bit, not completely functional yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
152
diff
changeset
|
285 int textWidth = G.metrics[2].stringWidth(text); |
117
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
286 g.setFont(G.fonts[2]); |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
287 g.setPaint(Color.white); |
154
48b91eabc029
Improve scaling a bit, not completely functional yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
152
diff
changeset
|
288 g.drawString(text, (G.screenDim.width * 0.85f) - textWidth / 2, G.screenDim.height * 0.3f); |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
289 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
290 |
75 | 291 public boolean contains(float x, float y) |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
292 { |
76 | 293 return (x >= getScaledX() && |
75 | 294 y >= getScaledY() && |
295 x < getScaledX() + boardSize * pscale && | |
296 y < getScaledY() + boardSize * pscale); | |
2 | 297 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
298 |
138
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
299 public boolean isBoardDirty() |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
300 { |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
301 if (flagBoardIsDirty) |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
302 { |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
303 flagBoardIsDirty = false; |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
304 return true; |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
305 } |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
306 else |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
307 return false; |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
308 } |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
309 |
9 | 310 public void animate(float time) |
311 { | |
148
5b25561855c3
Move next piece animation call into better place.
Matti Hamalainen <ccr@tnsp.org>
parents:
147
diff
changeset
|
312 if (nextPiece != null) |
5b25561855c3
Move next piece animation call into better place.
Matti Hamalainen <ccr@tnsp.org>
parents:
147
diff
changeset
|
313 { |
5b25561855c3
Move next piece animation call into better place.
Matti Hamalainen <ccr@tnsp.org>
parents:
147
diff
changeset
|
314 nextPiece.animate(time); |
5b25561855c3
Move next piece animation call into better place.
Matti Hamalainen <ccr@tnsp.org>
parents:
147
diff
changeset
|
315 } |
179 | 316 |
117
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
317 ptime = time; |
9 | 318 for (int y = 0; y < boardSize; y++) |
319 for (int x = 0; x < boardSize; x++) | |
320 if (board[x][y] != null) | |
321 { | |
322 board[x][y].animate(time); | |
138
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
323 if (board[x][y] != currPiece && board[x][y].active) |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
324 flagBoardIsDirty = true; |
9 | 325 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
326 |
131
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
327 Lock write = pointLock.writeLock(); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
328 write.lock(); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
329 try |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
330 { |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
331 ArrayList<AnimatedPointElement> tmp = new ArrayList<AnimatedPointElement>(); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
332 |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
333 for (AnimatedPointElement elem : pointElems) |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
334 { |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
335 elem.animate(time); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
336 if (elem.active) |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
337 tmp.add(elem); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
338 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
339 |
131
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
340 pointElems = tmp; |
144
f01cb1ea26a5
Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
341 |
f01cb1ea26a5
Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
342 if (time % 32 == 1) |
f01cb1ea26a5
Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
343 { |
f01cb1ea26a5
Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
344 Random rnd = new Random(); |
f01cb1ea26a5
Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
345 pointElems.add(new AnimatedPointElement( |
f01cb1ea26a5
Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
346 new IDMPoint(10 + rnd.nextInt(400), 10 + rnd.nextInt(100)), ".")); |
f01cb1ea26a5
Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
347 } |
131
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
348 } |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
349 finally |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
350 { |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
351 write.unlock(); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
352 } |
9 | 353 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
354 |
32
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
355 public void pieceRotate(Piece.RotateDir dir) |
2 | 356 { |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
357 if (currPiece != null && !flagGameOver) |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
358 { |
41 | 359 currPiece.rotate(dir); |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
360 } |
2 | 361 } |
1 | 362 |
75 | 363 // Change coordinates based on the "outgoing" |
364 // piece connection point. | |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
365 private void pieceMoveTo(int point) |
7 | 366 { |
46 | 367 switch (point) |
368 { | |
369 case 0: currY--; break; | |
370 case 1: currY--; break; | |
371 | |
372 case 2: currX++; break; | |
373 case 3: currX++; break; | |
374 | |
375 case 4: currY++; break; | |
376 case 5: currY++; break; | |
377 | |
378 case 6: currX--; break; | |
379 case 7: currX--; break; | |
380 } | |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
381 } |
9 | 382 |
54 | 383 public void pieceCreateNew() |
384 { | |
385 currPiece = nextPiece; | |
106
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
386 currPiece.changed(); |
54 | 387 nextPiece = new Piece(PieceType.ACTIVE); |
138
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
388 flagBoardIsDirty = true; |
54 | 389 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
390 |
54 | 391 public void pieceSwapCurrent() |
392 { | |
56 | 393 if (!flagGameOver) |
394 { | |
395 Piece tmp = currPiece; | |
396 currPiece = nextPiece; | |
397 nextPiece = tmp; | |
398 board[currX][currY] = currPiece; | |
106
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
399 currPiece.changed(); |
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
105
diff
changeset
|
400 nextPiece.changed(); |
139
be9cc2ee3c16
Minor fixes in updating logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
401 flagBoardIsDirty = true; |
56 | 402 } |
54 | 403 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
404 |
75 | 405 // Check one piece, set connections, find the new placement |
406 // based on piece rotations etc. | |
407 private boolean pieceCheck(Piece piece) | |
48 | 408 { |
53 | 409 if (piece == null) |
48 | 410 { |
411 // Create new piece | |
56 | 412 pieceCreateNew(); |
48 | 413 board[currX][currY] = currPiece; |
414 return true; | |
415 } | |
416 else | |
53 | 417 if (piece.getType() == PieceType.START) |
48 | 418 { |
419 if (currPiece != null) | |
420 { | |
421 // Hit center starting piece, game over | |
422 flagGameOver = true; | |
423 return true; | |
424 } | |
425 else | |
426 { | |
427 // Start piece as first piece means game is starting | |
428 pieceMoveTo(currPoint); | |
54 | 429 pieceCreateNew(); |
48 | 430 board[currX][currY] = currPiece; |
431 return true; | |
432 } | |
433 } | |
434 | |
435 // Mark the current piece as locked | |
53 | 436 piece.setType(PieceType.LOCKED); |
48 | 437 |
438 // Solve connection (with rotations) through the piece | |
53 | 439 currPoint = piece.getRotatedPoint(piece.getMatchingPoint(currPoint)); |
48 | 440 |
441 // Mark connection as active | |
53 | 442 piece.setConnectionState(currPoint, true); |
48 | 443 |
444 // Solve exit point (with rotations) | |
53 | 445 currPoint = piece.getAntiRotatedPoint(piece.getConnection(currPoint)); |
48 | 446 |
447 // Move to next position accordingly | |
448 pieceMoveTo(currPoint); | |
449 return false; | |
450 } | |
451 | |
75 | 452 // Finish one move/turn of the game, resolve path and find placement |
453 // of the next piece, or set "game over" state if required. | |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
454 public void pieceFinishTurn() |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
455 { |
48 | 456 boolean finished = false; |
194 | 457 int connections = 0, addScore = 0; |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
458 |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
459 if (currPiece != null) |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
460 { |
75 | 461 G.smgr.play(sndPlaced); |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
462 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
463 |
48 | 464 while (!finished) |
7 | 465 { |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
466 if (currX >= 0 && currX < boardSize && currY >= 0 && currY < boardSize) |
27 | 467 { |
135
a33fdb1de11c
Fix where the animated point elements appear initially.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
468 int oldX = currX, oldY = currY; |
194 | 469 finished = pieceCheck(board[currX][currY]); |
470 | |
55 | 471 connections++; |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
472 |
131
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
473 if (!finished) |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
474 { |
194 | 475 addScore += connections * connections; |
476 | |
131
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
477 Lock write = pointLock.writeLock(); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
478 write.lock(); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
479 try |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
480 { |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
481 pointElems.add(new AnimatedPointElement( |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
482 new IDMPoint( |
135
a33fdb1de11c
Fix where the animated point elements appear initially.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
483 getScaledX() + ((oldX + 0.5f) * pscale), |
a33fdb1de11c
Fix where the animated point elements appear initially.
Matti Hamalainen <ccr@tnsp.org>
parents:
134
diff
changeset
|
484 getScaledY() + ((oldY + 0.5f) * pscale)), |
194 | 485 "" + addScore)); |
131
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
486 } |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
487 finally |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
488 { |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
489 write.unlock(); |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
490 } |
67b2322fda91
Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents:
124
diff
changeset
|
491 } |
27 | 492 } |
493 else | |
494 { | |
46 | 495 // Outside of the board, game over |
48 | 496 finished = true; |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
497 flagGameOver = true; |
7 | 498 } |
499 } | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
500 |
194 | 501 // Increase number of moves |
502 gameScore += addScore; | |
181
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
503 moves++; |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
504 |
66 | 505 // If game over, clear the game |
53 | 506 if (flagGameOver) |
507 { | |
508 currPiece = null; | |
509 } | |
139
be9cc2ee3c16
Minor fixes in updating logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
510 |
be9cc2ee3c16
Minor fixes in updating logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
138
diff
changeset
|
511 flagBoardIsDirty = true; |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
512 } |
66 | 513 |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
514 public boolean mouseWheelMoved(MouseWheelEvent e) |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
515 { |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
516 int notches = e.getWheelRotation(); |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
517 |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
518 if (notches < 0) |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
519 pieceRotate(Piece.RotateDir.LEFT); |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
520 else |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
521 pieceRotate(Piece.RotateDir.RIGHT); |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
522 |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
523 return true; |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
524 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
525 |
75 | 526 public void clicked() |
527 { | |
77
d17db72ac770
Fix the game continuing after gameover bug again due to refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
528 if (!flagGameOver) |
d17db72ac770
Fix the game continuing after gameover bug again due to refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
529 pieceFinishTurn(); |
75 | 530 } |
47 | 531 |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
532 public boolean keyPressed(KeyEvent e) |
47 | 533 { |
54 | 534 if (flagGameOver) |
535 return false; | |
536 | |
47 | 537 switch (e.getKeyCode()) |
538 { | |
539 case KeyEvent.VK_LEFT: | |
540 case KeyEvent.VK_UP: | |
541 pieceRotate(Piece.RotateDir.LEFT); | |
542 return true; | |
543 | |
544 case KeyEvent.VK_RIGHT: | |
545 case KeyEvent.VK_DOWN: | |
546 pieceRotate(Piece.RotateDir.RIGHT); | |
547 return true; | |
548 | |
549 case KeyEvent.VK_ENTER: | |
550 pieceFinishTurn(); | |
551 return true; | |
552 } | |
553 return false; | |
554 } | |
1 | 555 } |
556 | |
557 | |
9 | 558 public class Engine extends JPanel |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
559 implements Runnable, KeyListener, |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
560 MouseListener, MouseWheelListener |
1 | 561 { |
164 | 562 double startTime; |
144
f01cb1ea26a5
Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
563 float gameUpdates, gameFrames; |
75 | 564 |
8 | 565 Thread animThread; |
566 boolean animEnable = false; | |
25 | 567 |
4 | 568 GameBoard lauta = null; |
69
163232ec225b
Stream music data instead of loading to memory.
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
569 InputStream musa; |
180
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
179
diff
changeset
|
570 IDMWindow widgets; |
75 | 571 AboutBox aboutBox; |
181
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
572 NewGameDialog newGameDialog; |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
573 |
147 | 574 public void dbg(String msg) |
575 { | |
192
8dbaa093c562
Improve debug message handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
576 G.debug("Engine: " + msg); |
147 | 577 } |
578 | |
9 | 579 public Engine() |
2 | 580 { |
25 | 581 // Initialize globals |
192
8dbaa093c562
Improve debug message handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
582 G.debug("Engine() constructor\n"); |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
583 |
37 | 584 // Sound system |
133
881deac2daf8
Some more work on scaling widgets, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
131
diff
changeset
|
585 G.smgr = new SoundManager(new AudioFormat(22050, 16, 1, true, false), 1); |
9 | 586 |
25 | 587 // Load resources |
4 | 588 try |
589 { | |
24 | 590 ResourceLoader res = new ResourceLoader("graphics/board.jpg"); |
75 | 591 G.lautaBG = ImageIO.read(res.getStream()); |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
592 |
25 | 593 try { |
594 res = new ResourceLoader("graphics/font.ttf"); | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
595 |
183
cf0256f13612
Remove global number of fonts static.
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
596 G.fonts = new Font[4]; |
170
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
597 G.baseFont = Font.createFont(Font.TRUETYPE_FONT, res.getStream()); |
179 | 598 |
170
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
599 setupDerivedFonts(1.0f); |
25 | 600 } |
601 catch (FontFormatException e) | |
602 { | |
147 | 603 dbg("Could not initialize fonts.\n"); |
25 | 604 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
605 |
69
163232ec225b
Stream music data instead of loading to memory.
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
606 res = new ResourceLoader("sounds/gamemusic.wav"); |
163232ec225b
Stream music data instead of loading to memory.
Matti Hamalainen <ccr@tnsp.org>
parents:
68
diff
changeset
|
607 musa = res.getStream(); |
4 | 608 } |
609 catch (IOException e) | |
610 { | |
611 JOptionPane.showMessageDialog(null, | |
21 | 612 e.getMessage(), |
4 | 613 "Initialization error", |
614 JOptionPane.ERROR_MESSAGE); | |
37 | 615 |
147 | 616 dbg(e.getMessage()); |
18 | 617 } |
618 | |
52 | 619 // Create IDM GUI widgets |
180
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
179
diff
changeset
|
620 widgets = new IDMWindow(); |
52 | 621 |
117
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
622 lauta = new GameBoard(new IDMPoint(95, 130), 63); |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
623 widgets.add(lauta); |
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
624 |
75 | 625 widgets.add(new BtnSwapPiece(767f, 450f)); |
124
fa1b86b632aa
Slight changes in UI buttons placement to match the graphics changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
119
diff
changeset
|
626 widgets.add(new BtnAbout (767f, 550f)); |
fa1b86b632aa
Slight changes in UI buttons placement to match the graphics changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
119
diff
changeset
|
627 widgets.add(new BtnNewGame (767f, 630f)); |
50 | 628 |
75 | 629 aboutBox = new AboutBox(); |
181
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
630 newGameDialog = new NewGameDialog(); |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
631 |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
632 // Game |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
633 startNewGame(); |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
634 |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
635 // Initialize event listeners |
18 | 636 addKeyListener(this); |
637 addMouseListener(this); | |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
638 addMouseWheelListener(this); |
18 | 639 |
93 | 640 // Start playing background music |
641 G.smgr.play(musa); | |
642 | |
18 | 643 // Get initial focus |
644 if (!hasFocus()) | |
645 { | |
147 | 646 dbg("Requesting focus.\n"); |
18 | 647 requestFocus(); |
4 | 648 } |
93 | 649 |
144
f01cb1ea26a5
Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
650 gameUpdates = 0; |
164 | 651 startTime = System.currentTimeMillis(); |
8 | 652 } |
653 | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
654 public void startNewGame() |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
655 { |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
656 gameFrames = 0; |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
657 lauta.startNewGame(); |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
658 } |
25 | 659 |
170
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
660 public void setupDerivedFonts(float scale) |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
661 { |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
662 G.fonts[0] = G.baseFont.deriveFont(16f * scale); |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
663 G.fonts[1] = G.baseFont.deriveFont(22f * scale); |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
664 G.fonts[2] = G.baseFont.deriveFont(62f * scale); |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
665 G.fonts[3] = G.baseFont.deriveFont(32f * scale); |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
666 } |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
667 |
25 | 668 public void paintComponent(Graphics g) |
669 { | |
670 Graphics2D g2 = (Graphics2D) g; | |
138
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
671 boolean scaleChanged = false, |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
672 updateBoard = lauta.isBoardDirty(); |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
673 |
52 | 674 // Rescale if parent component size has changed |
25 | 675 Dimension dim = getSize(); |
170
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
676 if (G.screenDim == null || !dim.equals(G.screenDim) || G.metrics == null) |
25 | 677 { |
170
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
678 dbg("Scale changed.\n"); |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
679 scaleChanged = true; |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
680 updateBoard = true; |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
681 |
133
881deac2daf8
Some more work on scaling widgets, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
131
diff
changeset
|
682 float dw = dim.width / 1024.0f, |
881deac2daf8
Some more work on scaling widgets, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
131
diff
changeset
|
683 dh = dim.height / 768.0f; |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
684 |
170
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
685 G.screenDim = dim; |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
686 |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
687 // Rescale fonts |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
688 setupDerivedFonts(dw); |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
689 |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
690 // Get font metrics against current Graphics2D context |
183
cf0256f13612
Remove global number of fonts static.
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
691 G.metrics = new FontMetrics[G.fonts.length]; |
cf0256f13612
Remove global number of fonts static.
Matti Hamalainen <ccr@tnsp.org>
parents:
181
diff
changeset
|
692 for (int i = 0; i < G.fonts.length; i++) |
170
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
693 G.metrics[i] = g2.getFontMetrics(G.fonts[i]); |
b9bc493ae53c
Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents:
168
diff
changeset
|
694 |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
695 // Rescale IDM GUI widgets |
133
881deac2daf8
Some more work on scaling widgets, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
131
diff
changeset
|
696 widgets.setScale(dw, dh); |
138
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
697 } |
179 | 698 |
138
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
699 if (updateBoard) |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
700 { |
147 | 701 // dbg("updateBoard()\n"); |
138
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
702 G.lautaBGScaled = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_RGB); |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
703 Graphics2D gimg = G.lautaBGScaled.createGraphics(); |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
704 gimg.setRenderingHint(RenderingHints.KEY_INTERPOLATION, |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
705 RenderingHints.VALUE_INTERPOLATION_BICUBIC); |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
706 |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
707 gimg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
708 RenderingHints.VALUE_ANTIALIAS_ON); |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
709 |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
710 gimg.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
711 RenderingHints.VALUE_TEXT_ANTIALIAS_ON); |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
712 |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
713 gimg.drawImage(G.lautaBG, 0, 0, dim.width, dim.height, null); |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
714 lauta.paintBackPlate(gimg); |
9eb791e2fa17
Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents:
135
diff
changeset
|
715 lauta.paintBoard(gimg, false); |
25 | 716 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
717 |
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
718 |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
719 // Draw background image, pieces, widgets |
75 | 720 g2.drawImage(G.lautaBGScaled, 0, 0, null); |
86
454a9fcd13ca
Turn antialiasing rendering hints on only for the needed elements to improve rendering speed and CPU usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
721 |
454a9fcd13ca
Turn antialiasing rendering hints on only for the needed elements to improve rendering speed and CPU usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
722 // Use antialiasing when rendering the game elements |
454a9fcd13ca
Turn antialiasing rendering hints on only for the needed elements to improve rendering speed and CPU usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
723 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
454a9fcd13ca
Turn antialiasing rendering hints on only for the needed elements to improve rendering speed and CPU usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
724 RenderingHints.VALUE_ANTIALIAS_ON); |
454a9fcd13ca
Turn antialiasing rendering hints on only for the needed elements to improve rendering speed and CPU usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
725 |
454a9fcd13ca
Turn antialiasing rendering hints on only for the needed elements to improve rendering speed and CPU usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
726 g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, |
454a9fcd13ca
Turn antialiasing rendering hints on only for the needed elements to improve rendering speed and CPU usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
727 RenderingHints.VALUE_TEXT_ANTIALIAS_ON); |
454a9fcd13ca
Turn antialiasing rendering hints on only for the needed elements to improve rendering speed and CPU usage.
Matti Hamalainen <ccr@tnsp.org>
parents:
82
diff
changeset
|
728 |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
729 widgets.paint(g2); |
55 | 730 |
75 | 731 |
732 // Frames per second counter | |
155
1ba6f56203f2
Disable FPS counter for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
154
diff
changeset
|
733 /* |
75 | 734 g2.setFont(G.fonts[1]); |
25 | 735 long currTime = new Date().getTime(); |
117
973f567c7b9d
Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents:
116
diff
changeset
|
736 g2.drawString("fps = "+ ((gameFrames * 1000) / (currTime - startTime)), G.screenDim.width - 120, 20); |
155
1ba6f56203f2
Disable FPS counter for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
154
diff
changeset
|
737 */ |
168 | 738 |
739 Toolkit.getDefaultToolkit().sync(); | |
75 | 740 gameFrames++; |
25 | 741 } |
742 | |
8 | 743 public void startThreads() |
744 { | |
147 | 745 dbg("startThreads()\n"); |
8 | 746 if (animThread == null) |
747 { | |
748 animThread = new Thread(this); | |
749 animEnable = true; | |
750 animThread.start(); | |
751 } | |
752 } | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
753 |
8 | 754 public void stopThreads() |
755 { | |
147 | 756 dbg("stopThreads()\n"); |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
757 |
37 | 758 // Stop animations |
8 | 759 if (animThread != null) |
760 { | |
761 animThread.interrupt(); | |
762 animEnable = false; | |
763 animThread = null; | |
764 } | |
22 | 765 |
37 | 766 // Shut down sound manager |
75 | 767 G.smgr.close(); |
2 | 768 } |
0 | 769 |
75 | 770 public void mouseEntered(MouseEvent e) |
771 { | |
772 widgets.mouseEntered(e); | |
773 } | |
774 public void mouseExited(MouseEvent e) | |
775 { | |
776 widgets.mouseExited(e); | |
777 } | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
778 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
779 public void mousePressed(MouseEvent e) |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
780 { |
175
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
781 widgets.mousePressed(e); |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
782 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
783 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
784 public void mouseReleased(MouseEvent e) |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
785 { |
175
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
786 widgets.mouseReleased(e); |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
787 } |
18 | 788 |
789 public void mouseClicked(MouseEvent e) | |
790 { | |
791 if (!hasFocus()) | |
792 { | |
147 | 793 dbg("Requesting focus.\n"); |
18 | 794 requestFocus(); |
795 } | |
59
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
796 } |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
797 |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
798 public void mouseWheelMoved(MouseWheelEvent e) |
fd10a9422b60
Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
57
diff
changeset
|
799 { |
175
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
800 if (widgets.getActiveModalWidget() == null) |
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
801 lauta.mouseWheelMoved(e); |
18 | 802 } |
803 | |
75 | 804 public void keyTyped(KeyEvent e) { } |
805 public void keyReleased(KeyEvent e) { } | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
806 |
9 | 807 public void keyPressed(KeyEvent e) |
2 | 808 { |
175
55ea5821c802
Implement "real" widget modality.
Matti Hamalainen <ccr@tnsp.org>
parents:
173
diff
changeset
|
809 widgets.keyPressed(e); |
2 | 810 } |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
811 |
8 | 812 public void run() |
813 { | |
814 while (animEnable) | |
815 { | |
26
3d4cc47df31a
Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
816 // Progress game animation clock |
144
f01cb1ea26a5
Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
817 gameUpdates++; |
9 | 818 |
26
3d4cc47df31a
Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
819 // Animate components |
164 | 820 int tmp = (int) ((System.currentTimeMillis() - startTime) / 10f); |
821 lauta.animate(tmp); | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
822 |
26
3d4cc47df31a
Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
823 // Repaint with a frame limiter |
168 | 824 if (gameUpdates % 2 == 1) |
10 | 825 repaint(); |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
826 |
26
3d4cc47df31a
Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
827 // Sleep for a moment |
9 | 828 try { |
168 | 829 Thread.sleep(15); |
9 | 830 } |
831 catch (InterruptedException x) { | |
832 } | |
180
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
179
diff
changeset
|
833 |
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
179
diff
changeset
|
834 String msg; |
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
179
diff
changeset
|
835 do { |
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
179
diff
changeset
|
836 msg = widgets.getMessage(); |
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
179
diff
changeset
|
837 if (msg != null && msg == "NEWGAME") |
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
179
diff
changeset
|
838 startNewGame(); |
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
179
diff
changeset
|
839 } while (msg != null); |
8 | 840 } |
841 } | |
134
4c0dec72e2f0
Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
133
diff
changeset
|
842 |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
843 class BtnNewGame extends IDMButton |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
844 { |
51 | 845 public BtnNewGame(float x, float y) |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
846 { |
75 | 847 super(x, y, KeyEvent.VK_ESCAPE, G.fonts[1], "New Game"); |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
848 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
849 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
850 public void clicked() |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
851 { |
181
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
852 if (!lauta.flagGameOver && lauta.moves > 0) |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
853 { |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
854 if (!widgets.containsObject(newGameDialog)) |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
855 widgets.add(newGameDialog); |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
856 } |
2e033eced6e5
Implement "new game" confirmation dialog.
Matti Hamalainen <ccr@tnsp.org>
parents:
180
diff
changeset
|
857 else |
180
fa9f29387cff
Implement a very simplistic message queue system.
Matti Hamalainen <ccr@tnsp.org>
parents:
179
diff
changeset
|
858 sendMessage("NEWGAME"); |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
859 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
860 } |
50 | 861 |
862 class BtnSwapPiece extends IDMButton | |
863 { | |
51 | 864 public BtnSwapPiece(float x, float y) |
50 | 865 { |
75 | 866 super(x, y, KeyEvent.VK_SPACE, G.fonts[1], "Swap"); |
50 | 867 } |
868 | |
869 public void clicked() | |
870 { | |
54 | 871 lauta.pieceSwapCurrent(); |
50 | 872 } |
873 } | |
60
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
874 |
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
875 class BtnAbout extends IDMButton |
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
876 { |
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
877 public BtnAbout(float x, float y) |
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
878 { |
75 | 879 super(x, y, KeyEvent.VK_A, G.fonts[1], "About"); |
60
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
880 } |
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
881 |
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
882 public void clicked() |
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
883 { |
75 | 884 if (!widgets.containsObject(aboutBox)) |
885 widgets.add(aboutBox); | |
60
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
886 } |
4a984e3b27d2
Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
887 } |
0 | 888 } |