-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgamePanel.java
153 lines (133 loc) · 4.33 KB
/
gamePanel.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author
*/
import java.awt.*;
import java.awt.event.*;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.awt.Color;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import java.lang.*;
public class gamePanel extends JPanel implements MouseListener {
private Graphics2D g2d;
private othelo game;
public int depth;
Runtime r ;
public gamePanel(int x, int y, int w, int h,int response) {
super();
setSize(550, 550);
addMouseListener(this);
if(response==0) depth=1;
else if(response==1) depth=3;
else depth=5;
game = new othelo(x, y, w, h,depth);
r = Runtime.getRuntime();
r.gc();
////////////////////////////////////////////
}
public char getPlayer() {
return this.game.getPlayer();
}
public void setPlayer() {
game.setPlayer();
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
g2d = (Graphics2D) g;
this.setBackground(new Color(0,123,0));
g2d.setStroke(new BasicStroke(3.0f));
for (int j = 0; j < 8; j++) {
for (int i = 0; i < 8; i++) {
g2d.setColor(Color.BLACK);
g2d.draw(new Rectangle2D.Double(game.getSquare(j, i).getX(), game.getSquare(j, i).getY(), game.getSquare(j, i).getW(), game.getSquare(j, i).getH()));
if (game.getSquare(j, i).getCircle() == 'W') {
g2d.setColor(Color.WHITE);
g2d.fillOval(game.getSquare(j, i).getX() + 5, game.getSquare(j, i).getY() + 5, 30, 30);
}
if (game.getSquare(j, i).getCircle() == 'B') {
g2d.setColor(Color.BLACK);
g2d.fillOval(game.getSquare(j, i).getX() + 5, game.getSquare(j, i).getY() + 5, 30, 30);
}
g2d.setColor(Color.BLACK);
}
}
int x=70,y=30;
int a=1;
String c=a+" ";
for(int j=0;j<8;j++)
{
c=a+" ";
g2d.setColor(Color.WHITE);
g2d.draw(new Rectangle2D.Double(x,y,40,40));
g2d.drawString(c,40f,20f+x);
x=x+40;
a++;
}
x=30;y=70;
a=65;
c=(char)a+" ";
for(int j=0;j<8;j++)
{
c=(char)a+" ";
g2d.setColor(Color.WHITE);
g2d.draw(new Rectangle2D.Double(x,y,40,40));
g2d.drawString(c,20f+y,50f);
a++;
y=y+40;
}
g2d.setColor(Color.RED);
game.setBlackcircles();
game.setWhitecircles();
int black=game.getBlackcircles();
int white=game.getWhitecircles();
g2d.drawString("Black circles: "+black,70f,15f);
g2d.drawString("White circles: "+white,300f,15f);
String player;
if(game.now=='B') player="Black";
else player="White";
g2d.drawString("Player: "+player,190f,15f);
g2d.setColor(Color.BLACK);
g2d.fillOval(50,5,13,13);
g2d.setColor(Color.WHITE);
g2d.fillOval(280,5,13,13);
g2d=null;
r.gc();
}
public void mouseClicked(MouseEvent event) {
if (this.game.getPlayer() == 'B') {
event.translatePoint(-70, -70);
int gety, getx;
getx = event.getX() / 40;
gety = event.getY() / 40;
if(!this.game.getSquare(gety,getx).getAdd_circle()) JOptionPane.showMessageDialog(this,"You can not place a circle here");
if ((getx >= 0) && (gety >= 0) && (getx <= 7) && (gety <= 7) && (this.game.getSquare(gety, getx).getAdd_circle())) {
this.game.makeMove(gety, getx, this.game.getPlayer());
//for(int i=0;i<this.game.getSquare(gety,getx).getChangesSize();i++)System.out.println("allages B: " + (int) this.game.getSquare(gety, getx).getChange(i).getX() + " ," + (int) this.game.getSquare(gety, getx).getChange(i).getY());
this.game.setPlayer();
this.repaint();
}
}
this.repaint();
//this.game.setPlayer();
r.gc();
}
public void mousePressed(MouseEvent event) {
}
public void mouseReleased(MouseEvent event) {
}
public void mouseEntered(MouseEvent event) {
}
public void mouseExited(MouseEvent event) {
}
public void mouseDragged(MouseEvent event) {
}
public void mouseMoved(MouseEvent event) {
}
}