第一次提交

main
Zeno 1 year ago
parent 0887821949
commit f6d7ce667a

@ -0,0 +1,12 @@
------------------------------------------------------------------------
这是这个工程的README文件你可以在这里描述你的工程。告诉读者某些对这个
工程一无所知的人)所有他所需要知道的东西。你的说明通常至少应该包含以下几
个部分:
------------------------------------------------------------------------
工程名:
工程的目标:
版本或者日期:
如何启动这个工程:
作者
使用指南:

Binary file not shown.

@ -0,0 +1,15 @@
#BlueJ class context
comment0.target=card
comment0.text=\r\n\ Write\ a\ description\ of\ class\ card\ here.\r\n\ \r\n\ @author\ (your\ name)\ \r\n\ @version\ (a\ version\ number\ or\ a\ date)\r\n
comment1.params=
comment1.target=void\ act()
comment1.text=\r\n\ Act\ -\ do\ whatever\ the\ card\ wants\ to\ do.\ This\ method\ is\ called\ whenever\r\n\ the\ 'Act'\ or\ 'Run'\ button\ gets\ pressed\ in\ the\ environment.\r\n
comment2.params=
comment2.target=int\ getValue()
comment3.params=
comment3.target=boolean\ getFaceup()
comment4.params=
comment4.target=void\ turnFaceDown()
comment5.params=cardValue
comment5.target=card(int)
numComments=6

@ -0,0 +1,59 @@
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.*;
/**
* Write a description of class card here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class card extends Actor
{
/**
* Act - do whatever the card wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
if(Greenfoot.mouseClicked(this)){
if(!isFaceUp){
setImage(faceUpImage);
isFaceUp = true;
}
}
}
// 获取这张牌的点数
public int getValue(){
return value;
}
// 获取这张牌是否已翻面
public boolean getFaceup(){
return isFaceUp;
}
// 将牌翻成背面朝上
public void turnFaceDown(){
isFaceUp=false;
setImage(faceDownImage);
}
private int value = -1; //初始点数为-1表示还没有生成确定的扑克牌。一旦生成了一张牌其点数就不为-1
private boolean isFaceUp = false; //isFaceUp=true则牌正面朝上否则背面朝上
private GreenfootImage faceUpImage = null;//faceUpImage表示牌的正面图案文件
private GreenfootImage faceDownImage = null;//faceDownImage表示牌的背面面图案文件
//Card类的构造方法
public card(int cardValue) {//cardValue是构造一张Card对象时传入的牌的点数
value = cardValue;
isFaceUp = false; //所有被构造的牌都是背面朝上的
String fileName = "hearts" + value + ".png"; //根据牌点数匹配的正面图案文件名
//生成牌的正面图像对象
faceUpImage = new GreenfootImage(fileName.toLowerCase());
faceDownImage = new GreenfootImage("blueflip.png");
//生成牌的背面图案对象
setImage(faceDownImage);//让牌背面朝上放在牌桌上
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 440 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 623 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 457 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 505 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 474 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 553 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 510 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 610 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 612 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 679 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 388 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 554 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 411 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 440 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 435 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 478 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 463 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 513 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 525 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 533 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 453 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 630 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 474 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 508 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 494 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 578 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 531 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 606 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 625 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 634 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 583 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 596 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 463 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 511 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 486 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 558 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 520 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 609 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 618 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 608 B

@ -0,0 +1,46 @@
#Greenfoot project file
class.card.image=blueflip.png
class.table.image=porkboard.jpg
dependency1.from=table
dependency1.to=card
dependency1.type=UsesDependency
editor.fx.0.height=0
editor.fx.0.width=0
editor.fx.0.x=0
editor.fx.0.y=0
height=584
package.numDependencies=1
package.numTargets=2
project.charset=UTF-8
publish.hasSource=false
publish.locked=true
publish.longDesc=
publish.shortDesc=
publish.tags=
publish.title=
publish.url=
readme.height=60
readme.name=@README
readme.width=49
readme.x=10
readme.y=10
simulation.speed=50
target1.height=70
target1.name=card
target1.showInterface=false
target1.type=ClassTarget
target1.width=120
target1.x=0
target1.y=0
target2.height=70
target2.name=table
target2.showInterface=false
target2.type=ClassTarget
target2.width=120
target2.x=0
target2.y=0
version=3.0.0
width=828
world.lastInstantiated=table
xPosition=271
yPosition=119

Binary file not shown.

@ -0,0 +1,9 @@
#BlueJ class context
comment0.target=table
comment0.text=\r\n\ Write\ a\ description\ of\ class\ table\ here.\r\n\ \r\n\ @author\ (your\ name)\ \r\n\ @version\ (a\ version\ number\ or\ a\ date)\r\n
comment1.params=
comment1.target=table()
comment1.text=\r\n\ Constructor\ for\ objects\ of\ class\ table.\r\n\ \r\n
comment2.params=
comment2.target=void\ act()
numComments=3

@ -0,0 +1,68 @@
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.*;
/**
* Write a description of class table here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class table extends World
{
ArrayList<card> cards=new ArrayList<card>();
/**
* Constructor for objects of class table.
*
*/
public table()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
for (int i=1; i<=5; i++) { //向集合cards中添加两组共10张5点以下的牌
cards.add(new card(i));
cards.add(new card(i));
}
Collections.shuffle(cards); //集合类Collections的混排算法用于打乱集合cards中牌的顺序
int x=100, y=100; //牌桌上摆放牌的起点坐标
for (int i=0; i<5; i++) { //用for循环依次在牌桌上摆放每排5张共两排的扑克牌
addObject(cards.get(i) , x, y);
addObject(cards.get(i+5) , x, y + cards.get(i).getImage().getHeight() + 20);
x += cards.get(i).getImage().getWidth()+20;
}
}
public void act(){
card card1 = null, card2 = null;
int count = 0;
int card1Value = 0, card2Value = 0;
for(int i = 0; i < cards.size(); i++){
if(cards.get(i).getFaceup() == true){
count++;
if(count == 1){
card1 = cards.get(i);
card1Value = card1.getValue();
}
if(count == 2){
card2 = cards.get(i);
card2Value = card2.getValue();
if(card1Value == card2Value)
{
Greenfoot.delay(30);
removeObject(card1);
removeObject(card2);
cards.remove(card1);
cards.remove(card2);
}
else{
Greenfoot.delay(30);
card1.turnFaceDown();
card2.turnFaceDown();
}
}
}
}
}
}
Loading…
Cancel
Save