结对项目实验报告

结对实验报告

结对人曹文静的地址:

http://www.cnblogs.com/liandiexueying/

一.实践目标:

  • 敏捷方法之结对编程实践
  • 学会与他人合作
  • 基于项目的Github源代码管理
  • 继续学习JUnit4单元测试
  • 形成良好的编码风格

二.结对项目参考题目

连连看小游戏。

三.实验报告内容

1.题目简介

游戏规则是模仿网络上普通的连连看游戏,主要是鼠标两次点击的图片能否消去的问题。当前,前提是点击两张相同的图片,若点击的是同一张图片或者两张不同的图片,则不予处理。在两张想同图片所能连通的所有路径中,如果存在一条转弯点不多于两个的路径,就可以消去;如果没有,则不予处理。 
    该游戏由30张不同的图片组成,游戏开始将会出现30张随机组合的图片,在规则下点击两张相同的图片后图片将会消失。图片全部消完为游戏成功。游戏还将设置退出,再来一局的按钮,并实现该功能,方便用户进行操作。

该游戏将有如下内容:

(1)游戏计分功能

当消去两个相同的图片后分数将增加100分。

(2)退出功能

该功能有一个“退出”按钮,当按下“退出”按钮后,将直接退出游戏。

(3)再来一局功能

该功能有一个“再来一局”的按钮,当按下“再来一局”按钮后,图片将会重新排列,重新开始游戏。

(4)游戏倒计时功能

在游戏界面的上方有一个倒计时的进度条,增加游戏的难度,激发玩家的挑战兴趣。

(5)用户登录注册功能

在进入游戏界面之前,将会出现用户登录界面,如果没有注册的玩家在按下“注册”按钮后将进入注册界面,玩家需要填写用户名,密码,性别等信息完成注册,再进入登录界面,输入用户名和密码按下“确定”后就将进入游戏界面,开始游戏。

2.代码地址:

https://github.com/chudongrui/lianliankan/tree/master

3.结对分工情况

曹文静:主要负责登陆界面,时间到的界面,进度条界面。

初冬瑞:主要负责注册界面,执行界面,查找图片

4.结对实践过程

连连看游戏的设计目标为:

(1)该游戏开始前,将设置一个用户登录注册界面,如果没有注册的玩家在按下“注册”按钮后将进入注册界面,玩家需要填写用户名,密码,性别等信息完成注册,再进入登录界面,输入用户名和密码按下“确定”后就将进入游戏界面,开始游戏。

(2)游戏中将有“退出”功能,选择退出命令后程序将终止执行,关闭窗口。

还将有“再来一局”功能,选择再来一局命令后程序将对图片重新排列,重新开始游戏。该游戏还有一个时间倒计时的进度条,提醒玩家剩余的时间,增加游戏的难度。在界面的顶部有计分功能,当玩家消去图片后就会赢得相应的分数。

 4.1注册界面

关键代码:

private void registerDialog(final JDialog regDialog) {

Box box1 = Box.createVerticalBox();

box1.add(new JLabel("用户名:", JLabel.RIGHT));

box1.add(Box.createVerticalStrut(10));

box1.add(new JLabel("性别:", JLabel.RIGHT));

box1.add(Box.createVerticalStrut(10));

box1.add(new JLabel("密码:", JLabel.RIGHT), -1);

box1.add(Box.createVerticalStrut(10));

box1.add(new JLabel("确认密码:", JLabel.RIGHT));

Box box2 = Box.createVerticalBox();

final JTextField nameTextField = new JTextField(10);

box2.add(nameTextField);

box2.add(Box.createVerticalStrut(8));

final CheckboxGroup cbg = new CheckboxGroup();

Box box21 = Box.createHorizontalBox();

final Checkbox cb1 = new Checkbox("男", cbg, true);

box21.add(cb1);

box21.add(new Checkbox("女", cbg, false));

box2.add(box21);

box2.add(Box.createVerticalStrut(8));

final JPasswordField pass1 = new JPasswordField(10);

box2.add(pass1);

box2.add(Box.createVerticalStrut(8));

final JPasswordField pass2 = new JPasswordField(10);

box2.add(pass2);

Box baseBox = Box.createHorizontalBox();

baseBox.add(box1);

baseBox.add(box2);

regDialog.setLayout(new FlowLayout());

regDialog.add(baseBox);

JButton confirm = new JButton("确定");

JButton cancel  = new JButton("取消");

regDialog.add(confirm);

regDialog.add(cancel);

regDialog.setSize(400, 200);

regDialog.setResizable(false);

regDialog.setLocationRelativeTo(null);

confirm.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0) {

String sex = null;

if (cbg.getSelectedCheckbox() == cb1)

sex = "男";

else

sex = "女";

if (saveUserData(nameTextField.getText().trim(), sex,

new String(pass1.getPassword()), new String(pass2.getPassword())))

regDialog.setVisible(false);

else

JOptionPane.showMessageDialog(regDialog, "输入有误,请检查", "错误提示",

JOptionPane.ERROR_MESSAGE);

}

});

cancel.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0) {

regDialog.setVisible(false);

}

});

}

private boolean saveUserData(String name, String sex, String password1, String password2) {

if (!password1.equals(password2)) return false;

try {

RandomAccessFile out = new RandomAccessFile("user.dat", "rw");

out.seek(out.length());

out.writeUTF(name);

out.writeUTF(sex);

out.writeUTF(password1);

out.close();

} catch (IOException e) {

e.printStackTrace();

return false;

}

return true;

}

4.3执行界面:

代码:

package jing;

import java.awt.BorderLayout;

import java.awt.Checkbox;

import java.awt.CheckboxGroup;

import java.awt.Color;

import java.awt.Container;

import java.awt.FlowLayout;

import java.awt.Graphics;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.File;

import java.io.FilenameFilter;

import java.io.IOException;

import java.io.RandomAccessFile;

import javax.swing.Box;

import javax.swing.Icon;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import javax.swing.JDialog;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JPasswordField;

import javax.swing.JTextField;

import javax.swing.Timer;

class MyPanel extends JPanel {

int cnt = 0;

public void paint(Graphics g) {

super.paint(g);

g.setColor(Color.red);

g.fillRect(this.getWidth() - cnt, 0, cnt, this.getHeight());

}

public boolean isEnd() {

if (cnt++ > this.getWidth())

return true;

repaint();

return false;

}

}

public class LianLianKan implements ActionListener {

JFrame mainFrame; // 主面板

JDialog login;

MyPanel time;

Container thisContainer;

JPanel centerPanel, southPanel, northPanel; // 子面板

JButton diamondsButton[][] = new JButton[6][5];// 游戏按钮数组

JButton exitButton, newlyButton; // 退出,重列,重新开始按钮

JLabel fractionLable = new JLabel("0"); // 分数标签

JButton firstButton, secondButton; // 分别记录两次被选中的按钮

Timer timer;

int grid[][] = new int[8][7];// 储存游戏按钮位置

static boolean pressInformation = false; // 判断是否有按钮被选中

int x0 = 0, y0 = 0, x = 0, y = 0, fristMsg = 0, secondMsg = 0, validateLV; // 游戏按钮的位置坐标

int i, j, k, n;// 消除方法控制

// =====================================//

// =============调用图片================//

private static Icon[] icons = new ImageIcon[6 * 5];

private static final String imgDir = "c:/img";// 这里填上图片目录全名

static {

try// 发生异常的操作

{

File dir = new File(imgDir);

File[] imgFiles = dir.listFiles(new FilenameFilter() {

public boolean accept(File dir, String name) {

return name.toLowerCase().endsWith(".jpg");

}

});

for (int i = 0; i < 10 * 10; i++) {

icons[i] = new ImageIcon(imgFiles[i].getAbsolutePath());

}

} catch (Exception e) {

e.printStackTrace();// 异常处理

}

}

public void init() {

mainFrame = new JFrame("JKJ连连看");// 设置主面板的名称为"JKJ连连看"

mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 结束窗体所在的应用程序

thisContainer = mainFrame.getContentPane();// 调用getContentPane()方法得到内容面板

thisContainer.setLayout(new BorderLayout());// 设置为BorderLayout()布局

centerPanel = new JPanel();// 设置面板

southPanel = new JPanel();

northPanel = new JPanel();

northPanel.setLayout(new BorderLayout());

thisContainer.add(centerPanel, "Center");// 添加组件

thisContainer.add(southPanel, "South");

thisContainer.add(northPanel, "North");

centerPanel.setLayout(new GridLayout(6, 5));// 设置一个6*5的网格布局

for (int cols = 0; cols < 6; cols++) {

for (int rows = 0; rows < 5; rows++) {

// diamondsButton[cols][rows] = new

// JButton(String.valueOf(grid[cols + 1][rows + 1]));

// ===========设置图片=============//

diamondsButton[cols][rows] = new JButton(

icons[grid[cols + 1][rows + 1] - 1]);

diamondsButton[cols][rows].addActionListener(this);

centerPanel.add(diamondsButton[cols][rows]);

}

}

exitButton = new JButton("退出");// 退出按钮

exitButton.addActionListener(this);

// resetButton = new JButton("重列");

// resetButton.addActionListener(this);

newlyButton = new JButton("再来一局");// 再来一局按钮

newlyButton.addActionListener(this);

southPanel.add(exitButton);// 添加退出按钮

// southPanel.add(resetButton);

southPanel.add(newlyButton);// 添加再来一局按钮

fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable

.getText())));

time = new MyPanel();

northPanel.add(time, BorderLayout.CENTER);

northPanel.add(fractionLable, BorderLayout.WEST);

mainFrame.setSize(500, 450);// 设置主面板的大小

mainFrame.setLocationRelativeTo(null);

mainFrame.setVisible(true);//设置窗口可见

}

public void loginDialog() {//设置登录界面

timer = new Timer(50, this);//创建时间对象

login = new JDialog();//创建对象

login.setTitle("登录");//在文本框中写入名字

login.setLayout(new FlowLayout());//添加流布局

login.add(new JLabel("用户名:"));//添加标签

final JTextField name = new JTextField(10);//设置文本框长度

login.add(name);

login.add(new JLabel("密    码:"));//添加标签

final JPasswordField password = new JPasswordField(10); //设置文本框长度

password.setEchoChar(‘*‘);//密码以*返回

login.add(password);

JButton confirm = new JButton("登录");//添加按钮

confirm.addActionListener(new ActionListener() {//设置一个监视器

public void actionPerformed(ActionEvent e) {

if (compareUserData(name.getText().trim(),

new String(password.getPassword()))) {

login.setVisible(false);

init();

timer.start();

} else {

JOptionPane.showMessageDialog(login, "用户名或密码错误!", "错误提示",

JOptionPane.ERROR_MESSAGE);

}

}

});

整个项目截图如下:

五.测试情况

代码:

package jing;

import static org.junit.Assert.*;

import org.junit.Test;

public class LianLianKanTest {

@Test

public void testMain() {

Double expectedAnswer = Double.valueOf(12);

Double actualAnswer = Double.valueOf(2*6);

assertEquals(expectedAnswer, actualAnswer);

}

}

截图如下:

六.问题及心得

这次连连看小游戏是由我和曹文静共同完成的,这个游戏是水果连连看,在这次游戏中她负责主要负责登陆界面,时间到的界面,进度条界面。我主要负责注册界面,执行界面,查找图片。我们通过上网查资料,通过一次又一次的调试我们才运行成功,测试过程中又出现了很多问题,因为请教同学才可以测试成功。

虽然很过程很痛苦,但我在编程方面又进步了不少,而且通过结对项目我懂得了合作的重要性,以后希望自己和同学们多多加油!

附录全局代码:

package jing;

import java.awt.BorderLayout;

import java.awt.Checkbox;

import java.awt.CheckboxGroup;

import java.awt.Color;

import java.awt.Container;

import java.awt.FlowLayout;

import java.awt.Graphics;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.File;

import java.io.FilenameFilter;

import java.io.IOException;

import java.io.RandomAccessFile;

import javax.swing.Box;

import javax.swing.Icon;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import javax.swing.JDialog;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JPasswordField;

import javax.swing.JTextField;

import javax.swing.Timer;

class MyPanel extends JPanel {

int cnt = 0;

public void paint(Graphics g) {

super.paint(g);

g.setColor(Color.red);

g.fillRect(this.getWidth() - cnt, 0, cnt, this.getHeight());

}

public boolean isEnd() {

if (cnt++ > this.getWidth())

return true;

repaint();

return false;

}

}

public class LianLianKan implements ActionListener {

JFrame mainFrame; // 主面板

JDialog login;

MyPanel time;

Container thisContainer;

JPanel centerPanel, southPanel, northPanel; // 子面板

JButton diamondsButton[][] = new JButton[6][5];// 游戏按钮数组

JButton exitButton, newlyButton; // 退出,重列,重新开始按钮

JLabel fractionLable = new JLabel("0"); // 分数标签

JButton firstButton, secondButton; // 分别记录两次被选中的按钮

Timer timer;

int grid[][] = new int[8][7];// 储存游戏按钮位置

static boolean pressInformation = false; // 判断是否有按钮被选中

int x0 = 0, y0 = 0, x = 0, y = 0, fristMsg = 0, secondMsg = 0, validateLV; // 游戏按钮的位置坐标

int i, j, k, n;// 消除方法控制

// =====================================//

// =============调用图片================//

private static Icon[] icons = new ImageIcon[6 * 5];

private static final String imgDir = "c:/img";// 这里填上图片目录全名

static {

try// 发生异常的操作

{

File dir = new File(imgDir);

File[] imgFiles = dir.listFiles(new FilenameFilter() {

public boolean accept(File dir, String name) {

return name.toLowerCase().endsWith(".jpg");

}

});

for (int i = 0; i < 10 * 10; i++) {

icons[i] = new ImageIcon(imgFiles[i].getAbsolutePath());

}

} catch (Exception e) {

e.printStackTrace();// 异常处理

}

}

public void init() {

mainFrame = new JFrame("JKJ连连看");// 设置主面板的名称为"JKJ连连看"

mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 结束窗体所在的应用程序

thisContainer = mainFrame.getContentPane();// 调用getContentPane()方法得到内容面板

thisContainer.setLayout(new BorderLayout());// 设置为BorderLayout()布局

centerPanel = new JPanel();// 设置面板

southPanel = new JPanel();

northPanel = new JPanel();

northPanel.setLayout(new BorderLayout());

thisContainer.add(centerPanel, "Center");// 添加组件

thisContainer.add(southPanel, "South");

thisContainer.add(northPanel, "North");

centerPanel.setLayout(new GridLayout(6, 5));// 设置一个6*5的网格布局

for (int cols = 0; cols < 6; cols++) {

for (int rows = 0; rows < 5; rows++) {

// diamondsButton[cols][rows] = new

// JButton(String.valueOf(grid[cols + 1][rows + 1]));

// ===========设置图片=============//

diamondsButton[cols][rows] = new JButton(

icons[grid[cols + 1][rows + 1] - 1]);

diamondsButton[cols][rows].addActionListener(this);

centerPanel.add(diamondsButton[cols][rows]);

}

}

exitButton = new JButton("退出");// 退出按钮

exitButton.addActionListener(this);

// resetButton = new JButton("重列");

// resetButton.addActionListener(this);

newlyButton = new JButton("再来一局");// 再来一局按钮

newlyButton.addActionListener(this);

southPanel.add(exitButton);// 添加退出按钮

// southPanel.add(resetButton);

southPanel.add(newlyButton);// 添加再来一局按钮

fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable

.getText())));

time = new MyPanel();

northPanel.add(time, BorderLayout.CENTER);

northPanel.add(fractionLable, BorderLayout.WEST);

mainFrame.setSize(500, 450);// 设置主面板的大小

mainFrame.setLocationRelativeTo(null);

mainFrame.setVisible(true);//设置窗口可见

}

public void loginDialog() {//设置登录界面

timer = new Timer(50, this);//创建时间对象

login = new JDialog();//创建对象

login.setTitle("登录");//在文本框中写入名字

login.setLayout(new FlowLayout());//添加流布局

login.add(new JLabel("用户名:"));//添加标签

final JTextField name = new JTextField(10);//设置文本框长度

login.add(name);

login.add(new JLabel("密    码:"));//添加标签

final JPasswordField password = new JPasswordField(10); //设置文本框长度

password.setEchoChar(‘*‘);//密码以*返回

login.add(password);

JButton confirm = new JButton("登录");//添加按钮

confirm.addActionListener(new ActionListener() {//设置一个监视器

public void actionPerformed(ActionEvent e) {

if (compareUserData(name.getText().trim(),

new String(password.getPassword()))) {

login.setVisible(false);

init();

timer.start();

} else {

JOptionPane.showMessageDialog(login, "用户名或密码错误!", "错误提示",

JOptionPane.ERROR_MESSAGE);

}

}

});

login.add(confirm);

final JDialog regDialog = new JDialog(login, "注册", true);

registerDialog(regDialog);

JButton register = new JButton("注册");//添加按钮

register.addActionListener(new ActionListener() {//设置一个监视器

public void actionPerformed(ActionEvent e) {

regDialog.setVisible(true);

}

});

login.add(register);//添加组件

login.setSize(400, 200);//设置登录界面的尺寸

login.setResizable(false);

login.setLocationRelativeTo(null);

login.setVisible(true);//窗口可见

}

private boolean compareUserData(String name, String password) {  //异常处理

try {

RandomAccessFile out = new RandomAccessFile("user.dat", "rw");

String fname, fpassword = null;

while (out.getFilePointer() < out.length()) {

fname = out.readUTF();

out.readUTF();

fpassword = out.readUTF();

if (fname.equals(name) && fpassword.equals(password))

return true;

}

out.close();

} catch (IOException e) {

e.printStackTrace();

}

return false;

}

private void registerDialog(final JDialog regDialog) {  //方法定义

Box box1 = Box.createVerticalBox();//创建一个窗口

box1.add(new JLabel("用户名:", JLabel.RIGHT));

box1.add(Box.createVerticalStrut(10));

box1.add(new JLabel("性别:", JLabel.RIGHT));

box1.add(Box.createVerticalStrut(10));

box1.add(new JLabel("密码:", JLabel.RIGHT), -1);

box1.add(Box.createVerticalStrut(10));

box1.add(new JLabel("确认密码:", JLabel.RIGHT));//添加组件

Box box2 = Box.createVerticalBox();//创建另一个窗口

final JTextField nameTextField = new JTextField(10);//设置文本框长度

box2.add(nameTextField);

box2.add(Box.createVerticalStrut(8));//添加组件

final CheckboxGroup cbg = new CheckboxGroup();

Box box21 = Box.createHorizontalBox();

final Checkbox cb1 = new Checkbox("男", cbg, true);

box21.add(cb1);

box21.add(new Checkbox("女", cbg, false));

box2.add(box21);

box2.add(Box.createVerticalStrut(8)); //添加组件

final JPasswordField pass1 = new JPasswordField(10); //设置文本框长度

box2.add(pass1);

box2.add(Box.createVerticalStrut(8)); //添加组件

final JPasswordField pass2 = new JPasswordField(10); //设置文本框长度

box2.add(pass2); //添加组件

Box baseBox = Box.createHorizontalBox();

baseBox.add(box1);

baseBox.add(box2); //添加组件

regDialog.setLayout(new FlowLayout());//创建流布局

regDialog.add(baseBox);

JButton confirm = new JButton("确定");

JButton cancel = new JButton("取消");

regDialog.add(confirm);

regDialog.add(cancel); //添加组件

regDialog.setSize(400, 200);//设置界面的大小

regDialog.setResizable(false);

regDialog.setLocationRelativeTo(null);

confirm.addActionListener(new ActionListener() {//设置监视器

public void actionPerformed(ActionEvent arg0) {

String sex = null;

if (cbg.getSelectedCheckbox() == cb1)

sex = "男";

else

sex = "女";

if (saveUserData(nameTextField.getText().trim(), sex,

new String(pass1.getPassword()),

new String(pass2.getPassword())))

regDialog.setVisible(false);

else

JOptionPane.showMessageDialog(regDialog, "输入有误,请检查",

"错误提示", JOptionPane.ERROR_MESSAGE);

}

});

cancel.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0) {

regDialog.setVisible(false);

}

});

}

private boolean saveUserData(String name, String sex, String password1,

String password2) {

if (!password1.equals(password2))

return false;

try {       //捕捉异常

RandomAccessFile out = new RandomAccessFile("user.dat", "rw");

out.seek(out.length());

out.writeUTF(name);

out.writeUTF(sex);

out.writeUTF(password1);

out.close();

} catch (IOException e) {   //处理异常

e.printStackTrace();

return false;

}

return true;

}

public void randomBuild() // 实例方法声明

{

int randoms, cols, rows; // 变量定义

for (int twins = 1; twins <= 15; twins++) {

randoms = (int) (Math.random() * 25 + 1);

for (int alike = 1; alike <= 2; alike++) {

cols = (int) (Math.random() * 6 + 1);

rows = (int) (Math.random() * 5 + 1);

while (grid[cols][rows] != 0) {

cols = (int) (Math.random() * 6 + 1);

rows = (int) (Math.random() * 5 + 1);

}

this.grid[cols][rows] = randoms;

}

}

}

public void fraction()// 方法声明

{

fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable

.getText()) + 100));

}

public void reload()// 方法声明

{

int save[] = new int[30]; // 创建声明数组

int n = 0, cols, rows; // 变量定义

int grid[][] = new int[8][7]; // 创建声明数组

for (int i = 0; i <= 6; i++) {

for (int j = 0; j <= 5; j++) {

if (this.grid[i][j] != 0) {

save[n] = this.grid[i][j];

n++;

}

}

}

n = n - 1;

this.grid = grid; // this出现在实例方法中,表示使用该方法的当前对象

while (n >= 0) // while循环

{

cols = (int) (Math.random() * 6 + 1);

rows = (int) (Math.random() * 5 + 1);

while (grid[cols][rows] != 0)// 循环嵌套

{

cols = (int) (Math.random() * 6 + 1);

rows = (int) (Math.random() * 5 + 1);

}

this.grid[cols][rows] = save[n]; // this出现在实例方法中,表示使用该方法的当前对象

n--;

}

mainFrame.setVisible(false);// 窗口不可见

pressInformation = false; // 这里一定要将按钮点击信息归为初始

init();

for (int i = 0; i < 6; i++)// for循环

{

for (int j = 0; j < 5; j++)// 循环嵌套

{

if (grid[i + 1][j + 1] == 0)

diamondsButton[i][j].setVisible(false);// 窗口不可见

}

}

}

public void estimateEven(int placeX, int placeY, JButton bz)// 有参数的实例方法

{

if (pressInformation == false)// 选择语句

{

x = placeX;

y = placeY;

secondMsg = grid[x][y];

secondButton = bz;

pressInformation = true;

} else {

x0 = x;

y0 = y;

fristMsg = secondMsg;

firstButton = secondButton;

x = placeX;

y = placeY;

secondMsg = grid[x][y];

secondButton = bz;

if (fristMsg == secondMsg && secondButton != firstButton) {

xiao();

}

}

}

public void xiao() // 相同的情况下能不能消去。

{

if ((x0 == x && (y0 == y + 1 || y0 == y - 1))

|| ((x0 == x + 1 || x0 == x - 1) && (y0 == y)))// 判断是否相邻

{

remove();

} else {

for (j = 0; j < 7; j++) {

if (grid[x0][j] == 0)// 判断第一个按钮同行哪个按钮为空

{

if (y > j) // 如果第二个按钮的Y坐标大于空按钮的Y坐标说明第一按钮在第二按钮左边

{

for (i = y - 1; i >= j; i--)// 判断第二按钮左侧直到第一按钮中间有没有按钮

{

if (grid[x][i] != 0) {

k = 0;

break;

} else {

k = 1;

} // K=1说明通过了第一次验证

}

if (k == 1) {

linePassOne();

}

}

if (y < j) // 如果第二个按钮的Y坐标小于空按钮的Y坐标说明第一按钮在第二按钮右边

{

for (i = y + 1; i <= j; i++)// 判断第二按钮左侧直到第一按钮中间有没有按钮

{

if (grid[x][i] != 0) {

k = 0;

break;

} else {

k = 1;

}

}

if (k == 1) {

linePassOne();

}

}

if (y == j) {

linePassOne();

}

}

if (k == 2) {

if (x0 == x) {

remove();

}

if (x0 < x) {

for (n = x0; n <= x - 1; n++) {

if (grid[n][j] != 0) {

k = 0;

break;

}

if (grid[n][j] == 0 && n == x - 1) {

remove();

}

}

}

if (x0 > x) {

for (n = x0; n >= x + 1; n--) {

if (grid[n][j] != 0) {

k = 0;

break;

}

if (grid[n][j] == 0 && n == x + 1) {

remove();

}

}

}

}

}

for (i = 0; i < 8; i++)// 列

{

if (grid[i][y0] == 0) {

if (x > i) {

for (j = x - 1; j >= i; j--) {

if (grid[j][y] != 0) {

k = 0;

break;

} else {

k = 1;

}

}

if (k == 1) {

rowPassOne();

}

}

if (x < i) {

for (j = x + 1; j <= i; j++) {

if (grid[j][y] != 0) {

k = 0;

break;

} else {

k = 1;

}

}

if (k == 1) {

rowPassOne();

}

}

if (x == i) {

rowPassOne();

}

}

if (k == 2) {

if (y0 == y) {

remove();

}

if (y0 < y) {

for (n = y0; n <= y - 1; n++) {

if (grid[i][n] != 0) {

k = 0;

break;

}

if (grid[i][n] == 0 && n == y - 1) {

remove();

}

}

}

if (y0 > y) {

for (n = y0; n >= y + 1; n--) {

if (grid[i][n] != 0) {

k = 0;

break;

}

if (grid[i][n] == 0 && n == y + 1) {

remove();

}

}

}

}

}

}

}

public void linePassOne() {

if (y0 > j)// 第一按钮同行空按钮在左边

{

for (i = y0 - 1; i >= j; i--)// 判断第一按钮同左侧空按钮之间有没按钮

{

if (grid[x0][i] != 0) {

k = 0;

break;

} else {

k = 2;

} // K=2说明通过了第二次验证

}

}

if (y0 < j)// 第一按钮同行空按钮在与第二按钮之间

{

for (i = y0 + 1; i <= j; i++) {

if (grid[x0][i] != 0) {

k = 0;

break;

} else {

k = 2;

}

}

}

}

public void rowPassOne() {

if (x0 > i) {

for (j = x0 - 1; j >= i; j--) {

if (grid[j][y0] != 0) {

k = 0;

break;

} else {

k = 2;

}

}

}

if (x0 < i) {

for (j = x0 + 1; j <= i; j++) {

if (grid[j][y0] != 0) {

k = 0;

break;

} else {

k = 2;

}

}

}

}

public void remove() {

firstButton.setVisible(false); // 不可见

secondButton.setVisible(false);

fraction();

pressInformation = false;

k = 0;

grid[x0][y0] = 0;

grid[x][y] = 0;

}

public void actionPerformed(ActionEvent e) {   //接口实现

if (e.getSource() == newlyButton) {

int grid[][] = new int[8][7];//创建数组

this.grid = grid;

randomBuild();

mainFrame.setVisible(false);//窗口不可见

pressInformation = false;

init();

}

if (e.getSource() == exitButton)

System.exit(0);

if (e.getSource() == timer) {

if (time.isEnd()) {

timer.stop();//时间到的提示

if (JOptionPane.showConfirmDialog(mainFrame,

"时间到了,o(︶︿︶)o \n要再来一局吗?", "提示",

JOptionPane.YES_NO_OPTION)== JOptionPane.OK_OPTION) {

int grid[][] = new int[8][7];

this.grid = grid;

randomBuild();

mainFrame.setVisible(false);//窗口不可见

pressInformation = false;

init();

timer.start();//启动线程

} else

System.exit(0);

}

}

for (int cols = 0; cols < 6; cols++) {

for (int rows = 0; rows < 5; rows++) {

if (e.getSource() == diamondsButton[cols][rows])

estimateEven(cols + 1, rows + 1, diamondsButton[cols][rows]);

}

}

}

public static void main(String[] args) {//主函数

LianLianKan llk = new LianLianKan();//创建对象

llk.randomBuild();//调用方法

llk.loginDialog();//调用方法

}

}

时间: 2025-01-02 00:55:18

结对项目实验报告的相关文章

团队开发项目实验报告

项目开发一 实验要求: 1 git clone 小组项目 2 编译项目,提交编译成功截图(全屏,要有学号信息) 3 提交运行过程中的截图(全屏,要有学号信息) 实验过程: 之前项目小组的组长已经将android游戏开发单独建立了一个项目,小组成员可以直接将项目克隆到Android Studio里,克隆需要调试Android Studio里的git,但编译的过程需要自己进行调试.调试环境可以选择在android studio里建立虚拟安卓手机来运行,也可以连接真实的安卓手机来运行.如果是建立虚拟安

软件工程结对作业实验报告

题目简介: 设计一个名为MyPoint的类,表示一个带x坐标和y坐标的点.该类包括:? 两个带get方法的数据域x和y,分别表示它们的坐标.? 一个创建点(0,0)的无参构造方法.? 一个创建特定坐标点的构造方法.? 两个数据域x和y各自的get方法.? 一个名为distance的方法,返回MyPoint类型的两个点之间的距离.? 一个名为distance的方法,返回指定x和y坐标的两个点之间的距离. 二.结对分工及过程 : 结对:张萍萍,程志张萍萍:程序的分析和程序的测试及测试代码的编写程志:

结对作业 实验报告

题目:简单计算器 代码地址:https://github.com/xiaosong777/homework/tree/master 结对:略 测试: 心得体会:通过这次实验我更加熟悉了这门课程.碰到一些较难的地方还是有些不明白,以后还会努力的.

取款机项目实验报告

一.题目简介: 为了了解并掌握结对编程,熟悉敏捷编程,就和队友做了个控制台下的ATM存取款机项目. 二.结对分工及过程:        过程:我和田培培用一台计算机大概用了12个小时完成了项目及测试部分 分工:我主要在编写项目代码方面做得多一点,田培培主要负责代码的测试 三.代码地址: https://github.com/joanyy/ATM 四.代码及运行结果截图: 1 package com.yt.atm ; 2 3 import java.util.Scanner; 4 5 public

结对作业实验报告

实验名称:五子棋 https://github.com/ryansongod521/- 第1章:需求分析 五子棋需求分析和流程设计 本程序设计为人与人对弈,一方执黑棋,一方执白棋,轮流走棋,每方都试图在游戏结束前让自己的棋子五子相连,首先实现五子相连的一方获胜.程序执行过程中,要求棋盘.棋子时时可见,游戏界面有提示信息轮到何方下棋,人可以通过按键盘按键移动光标,再点击enter键摆放棋子,并且每落一子都有系统声音,创新之处是可以提供悔棋功能. 2程序流程设计 根据程序需求分析结果,可以得出程序的

201571030319 201571030322 小学四则运算结对项目

GitHub源码地址:https://github.com/nigulasiletai/Demo2 1.需求分析: (1)随机选择20道混合运算: (2)用户输入答案,给出结果: (3)程序检查答案结果,正确计5分,错误不计分: (4)20道测试题结束给出总分: (5)带括号算式,真分数算式: (6)程序允许用户进行多轮测试,给出多轮测试分数柱状图: (7)程序记录用户答题结果,当程序退出再启动的时候,可为用户显示最后一次结果,并询问用户可否进行新一轮测试: (8)测试有记时功能,动态显示答题后

实验报告结对项目

实验报告 一.程序题是: 有1.2.3.4.5.6.7个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? 二.程序分析:输出的是无重复数字的三位数,那么首先应该解决在一个数组中,一个数字绝对不能出现两次,那么我们就写两个方法来完成,第一个方法 printNum1 先把第一位i找出来,然后在定义一个长度为比上一个数组少一位的数组的方法getArray 三.源代码托管地址 https://github.com/13695318582/software/tree/master 四.程序截图

实验四:201571030116/201571030106《小学四则运算练习软件需求说明》结对项目报告

任务1:以实验二个人项目.实验三结对项目所开发的小学生四则运算练习软件作为原型,实施小学生四则运算练习软件用户调研活动. 由于上次作业小伙伴很机智的把软件的操作过程录成了gif动图,所以在做基于原型的用户需求调查时减少了很多麻烦.对于这个任务我们采用了三种方法做用户需求调查:1.线上问卷调查 2.真实用户线上访谈 3.会议研讨 1.线上问卷调查:地址: 我们通过前两次作业整理了一些问题,用"问卷星"做了一份线上问卷调查,为了更精确的区分不同真实用户对软件的需求,我们把问卷调查分成了三个

2015710301120/201571030119《小学四则运算练习软件》结对项目报告

一.项目源码 Github地址:https://github.com/myGitHub1018/Student_Comput3.git 二.项目报告 1.需求分析 (1)由计算机从题库文件中随机选择20道加减乘除混合算式,用户输入算式答案,程序检查答案是否正确,每道题正确计5分,错误不计分,20道题测试结束后给出测试总分: (2)题库文件可采用实验二的方式自动生成,也可以手工编辑生成,文本格式如下: (3)程序为用户提供三种进阶四则运算练习功能选择:百以内整数算式(必做).带括号算式.真分数算式