-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInfoPanel.java
117 lines (101 loc) · 3.04 KB
/
InfoPanel.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package javarominoes;
import java.awt.*;
import javax.swing.*;
/**
*
* @author dylan
*/
public class InfoPanel extends JPanel
{
private int incPiece;
private int incRotation;
private int currentScore;
private final GamePanel game;
public InfoPanel( GamePanel g )
{
this.setBackground( Color.GRAY );
game = g;
currentScore = 0;
incPiece = game.nextPiece;
incPiece = game.nextRotation;
}
public void updateIncomingPieceInfo( int p, int r )
{
incPiece = p;
incRotation = r;
repaint();
}
public int getLineClearScore( int numLines )
{
return switch ( numLines )
{
case 1 -> 100;
case 2 -> 300;
case 3 -> 500;
case 4 -> 800;
default -> 0;
};
}
public void increaseScore( int points )
{
currentScore += points;
repaint();
}
// initially takes average of linear and logarithmic curve
public int deltaTTD()
{
double linear = ( ( -currentScore / 37 ) + 700 );
double logCurve = ( 700 - ( 180 * Math.log10( ( currentScore / 120 ) + 1 ) ) );
if ( currentScore < 13735 )
return (int)( ( logCurve + linear ) / 2);
return (int)logCurve;
}
@Override
public void paintComponent( Graphics g )
{
super.paintComponent( g );
this.drawIncomingPiece( g );
this.drawScoreAndSpeed( g );
}
public void drawIncomingPiece( Graphics g )
{
int lowerLim = this.getHeight() / 2;
int displayBoxLength = ( lowerLim * 3 ) / 4;
int vertPad = displayBoxLength / 8;
int horizPad = ( this.getWidth() - displayBoxLength ) / 2;
g.setColor( Color.WHITE );
g.drawRect( horizPad, vertPad, displayBoxLength, displayBoxLength );
g.setColor( Color.BLACK );
g.fillRect( horizPad + 1, vertPad + 1, displayBoxLength - 1, displayBoxLength - 1 );
int cellL = displayBoxLength / 5;
g.setColor( game.fetchBlockColor( incPiece ) );
for ( int x = 0; x < 5; x++ )
{
for ( int y = 0; y < 5; y++ )
{
if ( Pieces.getBlockType( incPiece, incRotation, x, y ) != 0 )
{
int cellX = ( x * cellL ) + ( horizPad + 2 );
int cellY = ( y * cellL ) + ( vertPad + 2 );
g.fill3DRect( cellX, cellY, cellL, cellL, true );
}
}
}
}
public void drawScoreAndSpeed( Graphics g )
{
g.setColor( Color.WHITE );
g.setFont( new Font( "Arial", Font.BOLD, 16 ) );
// draw the current score
String scoreText = "Score: " + currentScore;
g.drawString( scoreText, 10, this.getHeight() - 60 );
// draw the current drop speed in milliseconds
int currentSpeed = deltaTTD();
String speedText = "Drop Speed: " + currentSpeed + " ms";
g.drawString( speedText, 10, this.getHeight() - 30 );
}
}