给你一道参考题
/
filename: Gamejava
author: jellen
/
import javaawt;
import javaawtevent;
import javaxswing;
import javaawtgeom;
import javautil;
class PaintPanel extends JPanel
{
ArrayList Items = new ArrayList();
public PaintPanel()
{
setLayout(new BorderLayout());
ButtonPanel buttonPanel = new ButtonPanel();
add(buttonPanel, BorderLayoutSOUTH);
addMouseListener(new MouseHandler());
}
public void paintComponent(Graphics g)
{
int startX = 50;
int startY = 50;
boolean isMy = false;
superpaintComponent(g);
Graphics2D g2 = (Graphics2D)g;
for(int i=0; i<16; i++) {
g2draw(new Line2DDouble(startX, startY+20i, startX+300, startY+20i));
g2draw(new Line2DDouble(startX+20i, startY, startX+20i, startY+300));
}
for(int i=0; i<Itemssize(); i++) {
isMy = !isMy;
if(isMy)
g2setColor(ColorBLACK);
else
g2setColor(ColorWHITE);
g2fill((Ellipse2D)Itemsget(i));
}
}
void myRepaint() {
repaint();
}
private class MouseHandler extends MouseAdapter
{
public void mousePressed(MouseEvent event)
{
int x = eventgetX();
int y = eventgetY();
paintItem(x, y);
repaint();
}
void paintItem(int x, int y)
{
if(x > 50 && x < 350 && y >50 && y < 350)
{
int X = x / 20;
int Y = y / 20;
int centerX = X20 + 10;
int centerY = Y20 + 10;
Ellipse2D ellipse = new Ellipse2DDouble();
ellipsesetFrameFromCenter(centerX, centerY, centerX+8, centerY+8);
Itemsadd(ellipse);
}
}
}
private class ButtonPanel extends JPanel
{
public ButtonPanel()
{
JButton reset = new JButton("Reset");
add(reset);
JButton quit = new JButton("Quit");
add(quit);
ResetEvent listenerR = new ResetEvent();
resetaddMouseListener(listenerR);
QuitEvent listenerQ = new QuitEvent();
quitaddMouseListener(listenerQ);
}
private class QuitEvent extends MouseAdapter
{
public void mouseClicked(MouseEvent event)
{
Systemexit(1);
}
}
private class ResetEvent
extends MouseAdapter {
public void mouseClicked(MouseEvent event) {
Itemsclear();
myRepaint();
}
}
}
}
class GameFrame extends JFrame
{
public GameFrame()
{
setTitle("A Little Game");
setSize(400, 500);
setResizable(false);
PaintPanel panel = new PaintPanel();
getContentPane()add(panel);
}
}
public class Game
{
public static void main(String[] args) {
GameFrame frame = new GameFrame();
framesetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
frameshow();
}
}
foe(i=-4;i<=4;i++)
是
for(i=-4;i<=4;i++) 吧
绘9纵9横的棋盘 /绘制水平方向的线/
line(max_x/2-440 ,max_y/2+i40, max_x/2+440, max_y/2+i40)
起点x ,起点y,终点x,终点y 因为水平,所以第2 4个计算式是一样的
而且设计者设置了每行/每列间距为40 则棋盘正中间为最大x/2 最大y/2
每一行所在y为 最大y/2+行距(40)行位(-4~+4 +/-表示在中间的上或下)
每一行X起止为 最大x/2±棋盘最大的一半(840/2)
竖线分析相同
不太清楚棋盘大小,你自己修改下宽和高
#include <stdioh>
#define W_LEN 16
#define L_LEN 8
void main()
{
int flag=0;
for (int i=0;i<W_LEN;i++)
{ flag=i%2;
for (int j=0;j<L_LEN;j++)
{
if (flag==0)
{
printf(" ");
printf("█");
}
else
{
printf("█");
printf(" ");
}
}
以上就是关于五子棋 (Go Moku)程序——命令行界面棋盘描绘全部的内容,包括:五子棋 (Go Moku)程序——命令行界面棋盘描绘、我是初学C语言的,用C语言编黑白棋游戏绘制8*8棋盘书上说的看不懂请高手帮忙、C语言程序设计在屏幕上绘制国际象棋棋盘等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)