This repository has been archived by the owner on Mar 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Сделал дз. #7
Open
EugSh
wants to merge
4
commits into
polis-vk:master
Choose a base branch
from
EugSh:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Сделал дз. #7
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,8 @@ | |
import android.animation.ValueAnimator; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Аниматоры стоит сохранять в поля и во время уничтожения активити останавливать анимации |
||
import android.annotation.SuppressLint; | ||
import android.content.Context; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.MotionEvent; | ||
import android.view.VelocityTracker; | ||
import android.view.View; | ||
|
@@ -29,6 +29,7 @@ public class MainActivity extends AppCompatActivity implements View.OnTouchListe | |
private Context context; | ||
private float G = 9800; | ||
private float maxDistance; | ||
ValueAnimator animator; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Можно сделать private |
||
|
||
@SuppressLint("ClickableViewAccessibility") | ||
@Override | ||
|
@@ -79,8 +80,12 @@ void calculateInitialCondition(float x0, float y0, float vx0, float vy0) { | |
} | ||
|
||
void initialiseAnimation() { | ||
if (isScored(startPoint.getX(), fieldView.getHeight() - startPoint.getY())) { | ||
Toast.makeText(context, R.string.cheater, Toast.LENGTH_SHORT).show(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Интересное решение =) |
||
return; | ||
} | ||
float timeStart = 0; | ||
ValueAnimator animator = ValueAnimator.ofFloat(timeStart, motionOfProjectile.getTimeFlight()); | ||
animator = ValueAnimator.ofFloat(timeStart, motionOfProjectile.getTimeFlight()); | ||
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { | ||
@Override | ||
public void onAnimationUpdate(ValueAnimator animation) { | ||
|
@@ -89,13 +94,16 @@ public void onAnimationUpdate(ValueAnimator animation) { | |
ball.setX(currentX - ball.getWidth() / 2); | ||
ball.setY(currentY - ball.getHeight() / 2); | ||
if (isScored(currentX, currentY)) { | ||
Toast.makeText(context, R.string.scored, Toast.LENGTH_SHORT).show(); | ||
Toast.makeText(context, R.string.goll, Toast.LENGTH_SHORT).show(); | ||
maxDistance = Point.getDistance(player.getWidth(), fieldView.getHeight() - player.getHeight(), currentX, currentY); | ||
startPoint.changeVerticalAxisTo(fieldView.getHeight()); | ||
scoreView.setMark(calculateScore(maxDistance, startPoint.getDistance(currentX, currentY))); | ||
|
||
} | ||
fieldView.drawDot(currentX, currentY); | ||
if (animation.getAnimatedValue().equals(motionOfProjectile.getTimeFlight())) { | ||
Toast.makeText(context, R.string.not_goll, Toast.LENGTH_SHORT).show(); | ||
} | ||
} | ||
}); | ||
animator.setInterpolator(new LinearInterpolator()); | ||
|
@@ -105,13 +113,19 @@ public void onAnimationUpdate(ValueAnimator animation) { | |
|
||
private boolean isScored(float x, float y) { | ||
if (x > (hoop.getLeft() + hoop.getWidth() / 2 - hoop.getWidth() / 6) && x < (hoop.getLeft() + hoop.getWidth() / 2 + hoop.getWidth() / 6)) { | ||
if (y > (hoop.getTop() + hoop.getHeight() / 2) && y < (hoop.getTop() + hoop.getHeight() / 2 + hoop.getHeight() / 3)) { | ||
if (y > (hoop.getTop() + hoop.getHeight() / 3) && y < (hoop.getTop() + hoop.getHeight() / 2 + hoop.getHeight() / 3)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
protected void onPause() { | ||
super.onPause(); | ||
animator.cancel(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. animator стоит проверить на нул. Иначе, если не делать бросков и свернуть приложение будет креш |
||
} | ||
|
||
private int calculateScore(float maxDist, float dist) { | ||
int score = (int) (dist / (maxDist / 4)) + 1; | ||
return score > 5 ? 5 : score; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,49 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:id="@+id/frame_layout_container" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".MainActivity"> | ||
<FrameLayout | ||
|
||
<ru.ok.technopolis.basketball.CustomView.FieldView | ||
android:id="@+id/field_view_basketball_field" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:id="@+id/frame_layout_container"> | ||
<ru.ok.technopolis.basketball.CustomView.FieldView | ||
android:id="@+id/field_view_basketball_field" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="@android:color/white" | ||
android:padding="10dp" | ||
app:pointColor="@android:color/holo_orange_dark" | ||
app:pointStrokeWidth="2dp" | ||
app:pointRadius="5dp" | ||
/> | ||
<ru.ok.technopolis.basketball.CustomView.ScoreView | ||
android:id="@+id/score_view_score" | ||
android:layout_width="200dp" | ||
android:layout_height="50dp" | ||
android:padding="5dp" | ||
app:markColor="@android:color/holo_red_dark" | ||
app:markStrokeWidth="2dp" | ||
android:layout_gravity="top|start" | ||
/> | ||
<ImageView | ||
android:id="@+id/image_ball" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:src="@drawable/ball" | ||
android:layout_gravity="bottom|center_horizontal"/> | ||
<ImageView | ||
android:id="@+id/image_player" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:src="@drawable/player" | ||
android:layout_gravity="bottom|start"/> | ||
<ImageView | ||
android:id="@+id/image_hoop" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:src="@drawable/hoop" | ||
android:layout_gravity="top|end"/> | ||
</FrameLayout> | ||
android:background="@android:color/white" | ||
android:padding="10dp" | ||
app:pointColor="@android:color/holo_orange_dark" | ||
app:pointRadius="5dp" | ||
app:pointStrokeWidth="2dp" /> | ||
|
||
<ru.ok.technopolis.basketball.CustomView.ScoreView | ||
android:id="@+id/score_view_score" | ||
android:layout_width="200dp" | ||
android:layout_height="50dp" | ||
android:layout_gravity="top|start" | ||
android:padding="5dp" | ||
app:markColor="@android:color/holo_red_dark" | ||
app:markStrokeWidth="2dp" /> | ||
|
||
<ImageView | ||
android:id="@+id/image_ball" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="bottom|center_horizontal" | ||
android:src="@drawable/ball" /> | ||
|
||
<ImageView | ||
android:id="@+id/image_player" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="bottom|start" | ||
android:src="@drawable/player" /> | ||
|
||
</android.support.constraint.ConstraintLayout> | ||
<ImageView | ||
android:id="@+id/image_hoop" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="top|end" | ||
android:src="@drawable/hoop" /> | ||
</FrameLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<dimen name="default_point_stroke_width">5dp</dimen> | ||
<dimen name="default_point_radius">5dp</dimen> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
<resources> | ||
<string name="app_name">basketball_homework</string> | ||
<string name="scored">Забил гол!</string> | ||
<string name="goll">Забил гол!</string> | ||
<string name="not_goll">Не забил.</string> | ||
<string name="cheater">Играй честно.</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Sun Mar 24 00:28:03 MSK 2019 | ||
#Tue May 21 19:39:42 MSK 2019 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Что бы каждый раз не делать +0.5f и не забывать про это, лучше сделать метод для перевода из dp в px