-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDragon.java
More file actions
113 lines (104 loc) · 2.89 KB
/
Dragon.java
File metadata and controls
113 lines (104 loc) · 2.89 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import java.awt.*;
import java.util.Scanner;
import java.awt.Font;
/**
* Write a description of class Dragon here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Dragon
{
// instance variables - replace the example below with your own
private int x;
private int y;
private int size;
private int R;
private int G;
private int B;
private Color c;
private String attackType;
private String dragonText;
private Font myFont;
/**
* Default Constructor for objects of class Dragon
*/
public Dragon()
{
// initialise instance variables
x = 50;
y = 50;
size = 1;
R = 0;
G = 0;
B = 0;
attackType = "Fire";
dragonText = "Hello";
Font myFont = new Font("TimesRoman", Font.PLAIN, 12);
}
/**
* Overloaded Constructors go here
*/
public Dragon(int x,int y, int size, int R ,int G, int B, String attackType, String dragonText){
this.x = x;
this.y = y;
this.size = size;
this.R = R;
this.G = G;
this.B = B;
this.attackType = attackType;
this.dragonText = dragonText;
this.myFont = myFont;
}
/** Accessor Methods
*/
/**
* drawDragon(Graphics g)
* Starting of drawing, complete your Dragon....
*/
public void drawDragon(Graphics g)
{
Color userColor = new Color(R,G,B);
g.setColor(userColor);
g.fillRect(x, y , size * 25, size * 25); //Draw Head
g.fillRect(x+size * 25, y + size*25, size *60, size * 50); //Draw Body
g.fillRect(x+size * 25, (y + size*25) + size * 50, size * 10, size * 30); //Draw Leg #1
g.fillRect(x+size * 75, (y + size*25) + size * 50, size * 10, size * 30); //Draw Leg #1
g.fillRect(x+size *85, y + size * 25, size * 30, size * 10); //Draw Tail
}
private void drawFire(Graphics g)
{
g.setColor(Color.RED);
for(int i = 1; i <= size * 5; i++){
g.fillOval(x + i * -10, y + size * 10, i * 8, i * 8);
}
}
private void drawWater(Graphics g)
{
g.setColor(Color.BLUE);
for(int i = 1; i <= size * 5; i++){
g.fillOval(x + i * -10, y + size * 15, i * 8, i * 8);
}
}
public void dragonElement(Graphics g)
{
if(attackType.equals("Fire"))
drawFire(g);
else if(attackType.equals("Water"))
drawWater(g);
}
public void dragonSpeech(Graphics g)
{
g.setFont(new Font("ComicSans", Font.PLAIN, 12));
g.drawString(dragonText, x + 1, y + size - 30);
}
/**
* Mutator Methods
*/
/**
* toString
*/
public String toString(){
return "x coor: " + x + " y coord: " + y + " size: " + size + " Color: " + R + G + B;
}
}