Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

星屑集め #271

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

星屑集め #271

wants to merge 14 commits into from

Conversation

kyu099
Copy link
Collaborator

@kyu099 kyu099 commented Jan 22, 2021

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

Copy link
Owner

@trpfrog trpfrog left a comment

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
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
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
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
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
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
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
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
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;
    }
}

など

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