נבנה על ידיBuilt by Ariel Yohimovich
JavaJava
משחק שלם ואריזה ל-jar ו-jpackageA full game, packed with jar & jpackage
מפגש 48: מחברים הכול למשחק שלם, אורזים ל-jar שרץ בלחיצה כפולה, ויוצרים מתקין עם jpackage.Session 48: Putting it all into a full game, packing a jar that runs on double-click, and making an installer with jpackage.
מחברים הכול למשחק שלם, אורזים ל-jar שרץ בלחיצה כפולה, ויוצרים מתקין עם jpackage. בסוף המפגש מוסיפים צעד לפרויקט המלווה.Putting it all into a full game, packing a jar that runs on double-click, and making an installer with jpackage. At the end we add a step to the companion project.מה נעשה היוםToday's plan
- מונחיםTerms
- המשחק השלם, בלי מסךThe full game, with no screen
- הגדרות מקובץSettings from a file
- גרסה של המשחקThe game's version
- פרויקט מדףShelf project
עוברים על סדר היום ומזכירים את הפרויקט המלווה.Walk through the plan and mention the companion project.המונחים של המפגשThis session's terms
- seed:
new Random(42) מייצר תמיד את אותה סדרה "אקראית".seed: new Random(42) always produces the same "random" sequence. - jar: קובץ zip עם המחלקות המהודרות וקבצי המשאבים (תמונות, צלילים).jar: A zip file with the compiled classes and resource files (images, sounds).
- manifest: קובץ
META-INF/MANIFEST.MF בתוך ה-jar.manifest: The META-INF/MANIFEST.MF file inside the jar. - jpackage: כלי ב-JDK שאורז את ה-jar יחד עם Java עצמה לתוכנה רגילה (app ב-Mac, exe או msi ב-Windows).jpackage: A JDK tool that packs the jar together with Java itself into a regular app (an app on Mac, an exe or msi on Windows).
לפני הקוד, המילים. כל מונח כאן מקושר גם במילון של הקורס.Before the code, the words. Every term here is also linked in the course glossary.נושאTopic 2
המשחק השלם, בלי מסךThe full game, with no screen
המשחק השלם, בלי מסךThe full game, with no screen
- כל מה שבנינו:
State, Input, משוט שזז עם dt ונשאר במסך, כוכבים שנופלים, התנגשות, ניקוד וחיים.Everything we built: State, Input, a paddle moving with dt and staying on screen, falling stars, collisions, score and lives. - עם seed קבוע (42) ו"שחקן" אוטומטי שזז הלוך ושוב, התוצאה זהה בכל הרצה, ולכן אפשר לבדוק אותה.With a fixed seed (42) and an automatic "player" moving back and forth, the result is the same every run, so it can be tested.
כל מה שבנינו: State, Input, משוט שזז עם dt ונשאר במסך, כוכבים שנופלים, התנגשות, ניקוד וחיים. עם seed קבוע (42) ו"שחקן" אוטומטי שזז הלוך ושוב, התוצאה זהה בכל הרצה, ולכן אפשר לבדוק אותה.Everything we built: State, Input, a paddle moving with dt and staying on screen, falling stars, collisions, score and lives. With a fixed seed (42) and an automatic "player" moving back and forth, the result is the same every run, so it can be tested.נושאTopic 3
הגדרות מקובץSettings from a file
הגדרות מקובץSettings from a file
Properties קורא קובץ key=value ומדלג על הערות.Properties reads a key=value file and skips comments.getProperty(key, default) נותן ברירת מחדל כשהמפתח חסר, כך שהמשחק עובד גם בלי קובץ.getProperty(key, default) gives a default when the key is missing, so the game works even without a file.
Properties קורא קובץ key=value ומדלג על הערות. getProperty(key, default) נותן ברירת מחדל כשהמפתח חסר, כך שהמשחק עובד גם בלי קובץ.Properties reads a key=value file and skips comments. getProperty(key, default) gives a default when the key is missing, so the game works even without a file.נושאTopic 4
גרסה של המשחקThe game's version
גרסה של המשחקThe game's version
- גרסאות נכתבות
major.minor.patch ומשווים אותן כמספרים, לא כטקסט: 1.10.0 חדשה מ-1.2.0.Versions are written major.minor.patch and compared as numbers, not text: 1.10.0 is newer than 1.2.0. - את הגרסה שמים ב-manifest כ-
Implementation-Version.The version goes in the manifest as Implementation-Version.
גרסאות נכתבות major.minor.patch ומשווים אותן כמספרים, לא כטקסט: 1.10.0 חדשה מ-1.2.0. את הגרסה שמים ב-manifest כ-Implementation-Version.Versions are written major.minor.patch and compared as numbers, not text: 1.10.0 is newer than 1.2.0. The version goes in the manifest as Implementation-Version.נושאTopic 5
פרויקט מדףShelf project
הצעד של היום בפרויקט מדףToday's step in the Shelf project
- משחק 6: המשחק השלםGame 6: the full game
כתבו את Game מהתזכורת: מצבים, קלט, משוט מוגבל למסך, כוכב חדש כל 0.6 שנייה (עם Random(seed)), נפילה, תפיסה (10 נקודות) ופספוס (חיים). הריצו עם seed 42 ושחקן אוטומטי עד Game Over, והדפיסו את התוצאה. בבית: חברו ל-JPanel מהמפגשים הקודמים.Write Game from the refresher: states, input, a paddle kept on screen, a new star every 0.6 seconds (with Random(seed)), falling, catching (10 points) and missing (lives). Run with seed 42 and an automatic player until game over, and print the result. At home: connect it to the JPanel from earlier sessions.seed: new Random(42) מייצר תמיד את אותה סדרה "אקראית".seed: new Random(42) always produces the same "random" sequence.
המונחים של המפגשThis session's termsjar: קובץ zip עם המחלקות המהודרות וקבצי המשאבים (תמונות, צלילים).jar: A zip file with the compiled classes and resource files (images, sounds).
המונחים של המפגשThis session's termsmanifest: קובץ META-INF/MANIFEST.MF בתוך ה-jar.manifest: The META-INF/MANIFEST.MF file inside the jar.
המונחים של המפגשThis session's termsjpackage: כלי ב-JDK שאורז את ה-jar יחד עם Java עצמה לתוכנה רגילה (app ב-Mac, exe או msi ב-Windows).jpackage: A JDK tool that packs the jar together with Java itself into a regular app (an app on Mac, an exe or msi on Windows).
המונחים של המפגשThis session's termsכל מה שבנינו: State, Input, משוט שזז עם dt ונשאר במסך, כוכבים שנופלים, התנגשות, ניקוד וחיים.Everything we built: State, Input, a paddle moving with dt and staying on screen, falling stars, collisions, score and lives.
המשחק השלם, בלי מסךThe full game, with no screenעם seed קבוע (42) ו"שחקן" אוטומטי שזז הלוך ושוב, התוצאה זהה בכל הרצה, ולכן אפשר לבדוק אותה.With a fixed seed (42) and an automatic "player" moving back and forth, the result is the same every run, so it can be tested.
המשחק השלם, בלי מסךThe full game, with no screenProperties קורא קובץ key=value ומדלג על הערות.Properties reads a key=value file and skips comments.
הגדרות מקובץSettings from a filegetProperty(key, default) נותן ברירת מחדל כשהמפתח חסר, כך שהמשחק עובד גם בלי קובץ.getProperty(key, default) gives a default when the key is missing, so the game works even without a file.
הגדרות מקובץSettings from a fileגרסאות נכתבות major.minor.patch ומשווים אותן כמספרים, לא כטקסט: 1.10.0 חדשה מ-1.2.0.Versions are written major.minor.patch and compared as numbers, not text: 1.10.0 is newer than 1.2.0.
גרסה של המשחקThe game's versionאת הגרסה שמים ב-manifest כ-Implementation-Version.The version goes in the manifest as Implementation-Version.
גרסה של המשחקThe game's versionמשחק 6: המשחק השלםGame 6: the full game
הצעד של היום בפרויקט מדףToday's step in the Shelf projectמה עושה Main-Class ב-manifest?What does Main-Class in the manifest do?
- אומר ל-
java -jar איזו מחלקה להריץTells java -jar which class to run - מכווץ את ה-jarCompresses the jar
- מתקין JavaInstalls Java
- לא עושה כלוםNothing
שואלים את הכיתה ומצביעים. התשובה בשקופית הבאה.Ask the class and take a vote. The answer is on the next slide.אומר ל-java -jar איזו מחלקה להריץTells java -jar which class to run
נכון.Right.למה new Random(42) בבדיקות?Why new Random(42) in tests?
- כדי שהאקראיות תחזור על עצמה והתוצאה תהיה קבועהSo the randomness repeats and the result is fixed
- כי 42 מזלBecause 42 is lucky
- זה מהיר יותרIt's faster
- אסור Random בלי seedRandom without a seed is forbidden
שואלים את הכיתה ומצביעים. התשובה בשקופית הבאה.Ask the class and take a vote. The answer is on the next slide.כדי שהאקראיות תחזור על עצמה והתוצאה תהיה קבועהSo the randomness repeats and the result is fixed
נכון.Right.מה היתרון של jpackage על פני jar?What does jpackage give over a jar?
- Java ארוזה בפנים: לא צריך להתקין JavaJava is packed inside: no need to install Java
- הקוד מהיר יותרThe code is faster
- אין צורך ב-mainNo need for main
- אין הבדלNo difference
שואלים את הכיתה ומצביעים. התשובה בשקופית הבאה.Ask the class and take a vote. The answer is on the next slide.Java ארוזה בפנים: לא צריך להתקין JavaJava is packed inside: no need to install Java
נכון.Right.manifestA manifest
manifest(mainClass, version) בונה את הטקסט של MANIFEST.MF:manifest(mainClass, version) builds the text of MANIFEST.MF:
תרגיל מהעמוד הבא: שואלים איך הייתם מתחילים.An exercise from the practice page: ask how you would start.הגדרות מקובץSettings from a file
Properties קורא קובץ key=value (ומדלג על הערות #).Properties reads a key=value file (skipping # comments).
תרגיל מהעמוד הבא: שואלים איך הייתם מתחילים.An exercise from the practice page: ask how you would start.משחק 6: המשחק השלםGame 6: the full game
- כתבו את
Game מהתזכורת:Write Game from the refresher:
תרגיל מהעמוד הבא: שואלים איך הייתם מתחילים.An exercise from the practice page: ask how you would start.השוואת גרסאותComparing versions
compare(a, b) משווה גרסאות major.minor.patch כמספרים (לא כטקסט:compare(a, b) compares major.minor.patch versions as numbers (not as text:
תרגיל מהעמוד הבא: שואלים איך הייתם מתחילים.An exercise from the practice page: ask how you would start.לארוז ולהריץPack and run
- במחשב שלכם, בתיקיית המשחק:On your computer, in the game folder:
תרגיל מהעמוד הבא: שואלים איך הייתם מתחילים.An exercise from the practice page: ask how you would start.seed אחר, משחק אחרAnother seed, another game
- הריצו את
Game עם seed 7 ועם seed 42 (אותו שחקן אוטומטי), והדפיסו את שתי התוצאות.Run Game with seed 7 and with seed 42 (the same automatic player), and print both results.
תרגיל מהעמוד הבא: שואלים איך הייתם מתחילים.An exercise from the practice page: ask how you would start.ה-jar מבפניםInside the jar
- הסתכלו בתוך ה-jar:Look inside the jar:
תרגיל מהעמוד הבא: שואלים איך הייתם מתחילים.An exercise from the practice page: ask how you would start.כל שורה מסתיימת ב-\n.Each line ends with \n.
manifestA manifestp.getProperty("fps", "60")p.getProperty("fps", "60")
הגדרות מקובץSettings from a fileעם seed קבוע התוצאה זהה בכל הרצה.With a fixed seed the result is the same every run.
משחק 6: המשחק השלםGame 6: the full gamesplit("\\."): הנקודה מיוחדת ב-regex.split("\\."): the dot is special in a regex.
השוואת גרסאותComparing versionsמה למדנוWhat we learned
- seed:
new Random(42) מייצר תמיד את אותה סדרה "אקראית".seed: new Random(42) always produces the same "random" sequence. - כל מה שבנינו:
State, Input, משוט שזז עם dt ונשאר במסך, כוכבים שנופלים, התנגשות, ניקוד וחיים.Everything we built: State, Input, a paddle moving with dt and staying on screen, falling stars, collisions, score and lives. Properties קורא קובץ key=value ומדלג על הערות.Properties reads a key=value file and skips comments.- גרסאות נכתבות
major.minor.patch ומשווים אותן כמספרים, לא כטקסט: 1.10.0 חדשה מ-1.2.0.Versions are written major.minor.patch and compared as numbers, not text: 1.10.0 is newer than 1.2.0. - משחק 6: המשחק השלםGame 6: the full game
כל אחד אומר דבר אחד שלמד היום.Everyone says one thing they learned today.עכשיו לתרגולNow, practice
5 תרגילים ו-2 אתגרים, עם בדיקה אוטומטית5 exercises and 2 challenges, auto-checked
מפנים לעמוד התרגול.Point to the practice page.