Skip to content

星屑集め - #271

Open
kyu099 wants to merge 14 commits into
mainfrom
shonben
Open

kyu099 wants to merge 14 commits into
mainfrom
shonben

Conversation

@kyu099

@kyu099 kyu099 commented Jan 22, 2021

Copy link
Copy Markdown
Collaborator

一通りできたので投げます。発表頑張ってください。

@trpfrog trpfrog left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

つよそう

public Background(){
mv = MainView.getInstance();

Path imagePath = Paths.get(".", "resource", "mini_game", "shonben_kozou", "background.jpg");

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

background.jpg、アップロードされてなくないですか?

g.setColor(Color.WHITE);
g.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 25));
g.drawString("score " + model.getCircles().getScore(), mv.getWidth() - 150, 20);
g.drawString(String.format("time %d.%02d",model.getGameTimer().getRemain()/100, model.getGameTimer().getRemain() % 100 ), 0, 20);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

横に長いので

int timeRemaining = model.getGameTimer().getRemain();
String timerStr = String.format("%d.%02d", timeRemaining / 100, timeRemaining % 100);
g.drawString(timerStr, 0, 20);

とすると読みやすくなると思います!

this.model = model;
mv = MainView.getInstance();
size = 20;
vy = r.nextDouble()*36 - 17;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

実は Random#nextDouble() と Math.random() は完全に実装が同じなので、変数を増やさない意味では Math.random() の方を使用した方が良いように思われます。

Comment on lines +37 to +38
setX(getX() + vx);
setY(getY() + vy);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

translate(vx, vy); とも書けます

}

public void addCircle(){
if(model.getGameTimer().getCount() >= 300 && model.getGameTimer().getCount() % 5 == 0 && model.getGameTimer().getCount() < 1300) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int count = model.getGameTimer().getCount(); とおいた方が

if(300 <= count && count < 1300 && count % 5 == 0) {
     // do something
}

と短く書けるので楽そう

Comment on lines +45 to +57
public void repulsion(){
if(getX() > mv.getWidth() - sizeX){
direction = 1;
setX(2 * (double)mv.getWidth() - 3 * (double)sizeX - getX());
vx = -vx;
}

if(getX() < sizeX){
direction = -1;
setX(3 * (double)sizeX - getX());
vx = -vx;
}
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

似たようなコードを置くならSymbolを継承してrepulsionを持ったSymbolクラスを作ってそれをKozouが継承する、というようなことをすると後で管理しやすくなると思います。あと単純に共通化でコピペミス由来のバグを減らせます。

return p;
}

public int getdirection(){

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getDirection のミスに思われます

this.model = model;
sizeX = 112;
sizeY = 267;
direction = -1; // -1のとき右向き。

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これ、-1と1以外使わないならbooleanとかにした方が壊れなそうです。もしくは setAngleDegrees() などを使い向きを指定、 Math.cos(getAngleRadians()) で値を得るなど
またはenumで

public enum FaceTo {
    LEFT(1), RIGHT(-1)
    private int dirVector;
    private FaceTo(int dir) {
        this.dirVector = dir;
    }
    public int getDirVector() {
        return dirVector;
    }
}

など

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants