Rectangles and circles that collide, sprites from images, frame animation and scoring.
כותבים בעורך שבכל תרגיל, לוחצים הרצה כדי לראות פלט, ובדיקה כדי שהבודק האוטומטי יבדוק. אפשר גם לעבוד ב-IntelliJ ולסמן פתרתי. ההתקדמות נשמרת.Write in each exercise's editor, press Run to see output and Check for the automatic checker. You can also work in IntelliJ and mark I solved it. Progress is saved.
חימום: 3 שאלותWarm-up: 3 questions
תרגיליםExercises
תרגילExercise 1
מלבניםRectangles
עם Box.intersects מהתזכורת: השחקן (10,10,20,20) מול (29,5,10,10) ומול (30,30,5,5). הדפיסו true false.
With Box.intersects from the refresher: the player (10,10,20,20) against (29,5,10,10) and (30,30,5,5). Print true false.
איך הפלט אמור להיראות?What should the output look like?
true false
Main.java
ההשוואה נעשית בדפדפן מול הפלט האמיתי של הפתרון שלנו. אם הקוד נפל, הדביקו את הודעת השגיאה ותקבלו הסבר.The comparison happens in your browser, against our solution's real output. If the code crashed, paste the error message and get an explanation.
רמזHint 1:השחקן נגמר ב-x=30; (30,30) מתחיל בדיוק שם, ולכן לא חופף.The player ends at x=30; (30,30) starts exactly there, so no overlap.
circles(x1, y1, r1, x2, y2, r2): מתנגשים אם המרחק בין המרכזים ≤ סכום הרדיוסים. בין (0,0) ל-(6,8) המרחק 10: עם רדיוסים 5+5 true, ועם 5+4 false.
circles(x1, y1, r1, x2, y2, r2): they collide if the distance between centres ≤ the sum of radii. Between (0,0) and (6,8) the distance is 10: with radii 5+5 true, with 5+4 false.
איך הפלט אמור להיראות?What should the output look like?
true false
Main.java
ההשוואה נעשית בדפדפן מול הפלט האמיתי של הפתרון שלנו. אם הקוד נפל, הדביקו את הודעת השגיאה ותקבלו הסבר.The comparison happens in your browser, against our solution's real output. If the code crashed, paste the error message and get an explanation.
3 פריימים של 0.2 שנייה. הדפיסו את הפריים בזמנים 0, 0.25, 0.5, 0.75: 0 1 2 0.
3 frames of 0.2 seconds. Print the frame at times 0, 0.25, 0.5, 0.75: 0 1 2 0.
איך הפלט אמור להיראות?What should the output look like?
0 1 2 0
Main.java
ההשוואה נעשית בדפדפן מול הפלט האמיתי של הפתרון שלנו. אם הקוד נפל, הדביקו את הודעת השגיאה ותקבלו הסבר.The comparison happens in your browser, against our solution's real output. If the code crashed, paste the error message and get an explanation.
צייד באגים: נגיעה בקצהBug hunter: touching at the edge
שני מלבנים שרק נוגעים בקצה (אחד נגמר ב-10 והשני מתחיל ב-10) נחשבים כאן התנגשות, כי הבדיקה משתמשת ב-<=. תקנו כך שיודפס false true.
Two rectangles that only touch at the edge (one ends at 10, the other starts at 10) count as a collision here, because the check uses <=. Fix it so it prints false true.
איך הפלט אמור להיראות?What should the output look like?
false true
Main.java
ההשוואה נעשית בדפדפן מול הפלט האמיתי של הפתרון שלנו. אם הקוד נפל, הדביקו את הודעת השגיאה ותקבלו הסבר.The comparison happens in your browser, against our solution's real output. If the code crashed, paste the error message and get an explanation.
רמזHint 1:< במקום <=: נגיעה היא לא חפיפה.< instead of <=: touching isn't overlapping.
שלושה כוכבים נופלים 10 בכל טיק. כוכב שנוגע במשוט (40,90,30,5) נותן 10 נקודות ונעלם; כוכב שעבר את 100 נחשב פספוס ונעלם. אחרי 12 טיקים: score 20, missed 1, left 0.
Three stars fall 10 per tick. A star touching the paddle (40,90,30,5) gives 10 points and disappears; a star past 100 counts as missed and disappears. After 12 ticks: score 20, missed 1, left 0.
איך הפלט אמור להיראות?What should the output look like?
score 20, missed 1, left 0
Main.java
ההשוואה נעשית בדפדפן מול הפלט האמיתי של הפתרון שלנו. אם הקוד נפל, הדביקו את הודעת השגיאה ותקבלו הסבר.The comparison happens in your browser, against our solution's real output. If the code crashed, paste the error message and get an explanation.
רמזHint 1:לולאה מהסוף להתחלה, כי מוחקים תוך כדי.Loop from the end to the start, because you remove as you go.
ההשוואה נעשית בדפדפן מול הפלט האמיתי של הפתרון שלנו. אם הקוד נפל, הדביקו את הודעת השגיאה ותקבלו הסבר.The comparison happens in your browser, against our solution's real output. If the code crashed, paste the error message and get an explanation.
רמזHint 1:עמודה index % columns, שורה index / columns.Column index % columns, row index / columns.
5 עצמים. בדיקה נאיבית של כל זוג היא 10 בדיקות. עם רשת של תאים בגודל 50, בודקים רק זוגות באותו תא. הדפיסו naive 10 checks, grid 2 checks.
5 objects. A naive check of every pair is 10 checks. With a grid of 50-sized cells, check only pairs in the same cell. Print naive 10 checks, grid 2 checks.
איך הפלט אמור להיראות?What should the output look like?
naive 10 checks, grid 2 checks
Main.java
ההשוואה נעשית בדפדפן מול הפלט האמיתי של הפתרון שלנו. אם הקוד נפל, הדביקו את הודעת השגיאה ותקבלו הסבר.The comparison happens in your browser, against our solution's real output. If the code crashed, paste the error message and get an explanation.