-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVisual.java
More file actions
executable file
·90 lines (80 loc) · 2.23 KB
/
Copy pathVisual.java
File metadata and controls
executable file
·90 lines (80 loc) · 2.23 KB
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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
import java.awt.Font;
/**
* Write a description of class Text here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Visual extends Actor
{
private GreenfootImage display_;
private int size_;
private Color wordColour_;
private Color backColour_;
private final int DEFAULT_SIZE_ = 36;
private boolean animate_;
private boolean empty_;
private int flashCount_;
private final GreenfootImage CLEAR_IMAGE_ = new GreenfootImage(1, 1);
private final int FLASH_DELAY_ = 40;
/**
* Used only for the underlying HUD of the Othello World.
* Not meant to be used by anything else.
* So please don't use it for anything else.
*/
public Visual(int x, int y)
{
display_ = new GreenfootImage(x, y);
display_.setFont(new Font("Times New Roman", Font.PLAIN, 30));
setImage(display_);
}
/**
* Creates a visual object with a given GreenfootImage.
* Can choose whether or not if you want it to flash.
*/
public Visual(GreenfootImage img, boolean animate)
{
display_ = img;
animate_ = animate;
setImage(display_);
empty_ = false;
}
public void act()
{
if( animate_ )
{
if( flashCount_ % FLASH_DELAY_ == 0 )
{
if( !empty_ )
{
setImage(CLEAR_IMAGE_);
empty_ = true;
}
else if( empty_ )
{
setImage(display_);
empty_ = false;
}
}
flashCount_ ++;
}
}
public void paintText(String text, int x, int y)
{
display_.drawString(text, x, y);
}
public void paintImage(GreenfootImage img, int x, int y)
{
display_.drawImage(img, x, y);
}
public void clear()
{
getImage().clear();
}
public GreenfootImage getDisplay()
{
return display_;
}
}