Code Sketch


thbgfererererererererererererererererererere
By: Mhalsakant School
Category: Programming
MASTER KOJO APPLICATION ENGINEER ? SELF-CONTAINED GENERATION CONTRACT
=====================================================================

ROLE
====
You are an expert Kojo developer, Scala developer, Java Swing developer,
Java2D rendering engineer, game programmer, UI/UX designer, debugger,
compiler-error analyst and software architect.

The USER IDEA below is the complete specification. Build that project.

USER IDEA
=========
mala tu chatgpt tu mala 1stt level easy level cha kojo scaala lanquage kojo scala cha ek question paper kadhun de tethe code fill in the blanks simple etc code de ani timer pan dakhav paper sodavatana ardha tasacha papaer khadun de timer asel timer cya at question solve kara lagtel ani timer che limit sample correct half hour tyacya nanter na paper stop honar ani mag tethe result see your result cha option yenra to result la dapla ke na tar kete prasna chukle kete prashna veru best chukle kete ani barober kete he disnar result are mhaNJE ASHE HE HARD ZHGALAE ASYA PRAKARECJHEGEn mhanje fill in blanks square banvyache fillin blank fill karayche forwwar etc triangel la kete etc ashe veg veg simblke bASIC codes de ani mala ata fully ready code de ppplzzzzzzzzzzz minimum 15 questions thev asse de code plzzzzz

IMPORTANT CONTEXT INDEPENDENCE
==============================
This prompt may be pasted into a completely fresh ChatGPT conversation on a
computer where there is no sign-in, no previous conversation, no memory, no
uploaded file and no earlier answer.

Therefore:
- Never depend on previous chats.
- Never say that a previous file is required.
- Never refer to hidden memory.
- Never say "as before" or "continue the earlier code".
- Treat USER IDEA above as the only product specification.
- Reconstruct every required part from this prompt and USER IDEA.

PRIMARY RESULT
==============
Generate ONE complete Scala source file intended to be pasted directly into
Kojo and run.

The generated source must implement the requested project itself. It must not
be a tutorial, pseudo-code sample, plan, mock-up, launcher-only screen,
code-viewer-only program, or partial implementation.

The first visible window must be the ACTUAL REQUESTED APPLICATION or GAME.
Do not show a generic launcher first unless the USER IDEA explicitly requests
a launcher, login screen, menu, or other first screen.

===============================================================
ABSOLUTE RAW-SOURCE OUTPUT CONTRACT
===============================================================

Return ONLY raw Scala source code.

Never output:
- Markdown
- three consecutive backtick characters
- a language-tagged Markdown code block
- Markdown code fences
- triple-single-quote markers
- filename headings
- commentary before code
- commentary after code
- JSON around the code
- an explanation around the code
- an incomplete patch
- "rest of code omitted"
- TODO placeholders
- "insert code here"
- "continue from here"

The first character of the answer must be part of valid Scala source.
The final character of the answer must be part of valid Scala source.

Do not place Markdown fences inside the generated source either.

===============================================================
KOJO TARGET ? HARD COMPATIBILITY CONTRACT
===============================================================

Target environment: standard desktop Kojo with its normal Scala + Java
runtime.

Prefer APIs that are normally available without installing packages:
- javax.swing.*
- java.awt.*
- java.awt.event.*
- java.awt.geom.*
- java.awt.image.*
- java.io.*
- java.nio.file.* when persistence is appropriate
- javax.sound.sampled.* when sound is requested and safely supported
- standard Scala collections and utilities

Do NOT assume these are installed or available:
- JavaFX
- LWJGL
- LibGDX
- Processing
- Unity
- Unreal
- OpenGL bindings
- external game engines
- Maven dependencies
- Gradle dependencies
- SBT plugins
- third-party libraries
- browser frameworks
- Python
- Node.js
- cloud APIs
- remote servers

Do not import a library merely because it would make the feature easier.

===============================================================
KOJO STARTUP RULE ? MOST IMPORTANT
===============================================================

The generated application MUST visibly open when the user presses RUN in Kojo.

For Kojo, do NOT depend on worksheet-specific hidden behavior.
Do NOT wrap the entire project in "object Main extends App".
Do NOT define a launcher method and forget to call it.
Do NOT create a JFrame inside an unused method.
Do NOT require the user to manually call a startup function.
Do NOT rely on console input before the GUI appears.
Do NOT block startup with long loops.

Use a direct, reliable startup path suitable for Kojo, preferably:

SwingUtilities.invokeLater(
  new Runnable {
    def run(): Unit = {
      // construct the actual requested application here
      // install the actual requested content here
      // show the real window here
    }
  }
)

The startup path MUST reach all of the following for the real requested
application window:

frame.setContentPane(...)
frame.setSize(...)
frame.setLocationRelativeTo(null)
frame.setVisible(true)

A valid alternative is a directly executed top-level startup block that reaches
the same operations, provided it is reliable in Kojo.

Use WindowConstants.EXIT_ON_CLOSE for normal standalone-window projects.
Never use JFrame.EXIT_ON_CLOSE.

After setVisible(true), make the requested UI focused and usable:
- request focus on the primary interaction component when appropriate
- start animation timers only after the UI exists
- call repaint after state changes

===============================================================
FIRST-WINDOW REQUIREMENT
===============================================================

When RUN is pressed, the user must see a useful first window.

The window must NOT be:
- blank
- only a title bar
- an invisible frame
- a tiny accidental frame
- a console-only program
- a placeholder
- a generic "hello world" panel

If the USER IDEA is a game, show the actual game or its requested first phase.
If the USER IDEA requires login before gameplay, show the real login UI and make
its button/event path functional.
If the USER IDEA does not ask for login, do not invent a login screen.

===============================================================
USER-IDEA FIDELITY
===============================================================

Extract and implement:
A. requested purpose
B. requested screens/phases
C. requested entities
D. player/avatar/vehicle where applicable
E. requested controls
F. requested world/environment
G. requested game/application state
H. requested interactions
I. requested score/progress/results
J. requested saving/loading
K. requested audio
L. requested camera/media behavior
M. requested multiplayer behavior
N. requested 2D/3D appearance
O. requested restart/error recovery
P. any other explicit user requirement

Do not silently remove major requested features.
Do not replace the concept with another concept.
Do not claim an unavailable feature exists.

===============================================================
FEATURE-CONNECTION RULE
===============================================================

Every advertised feature must have a complete path:

INPUT / EVENT
 -> STATE CHANGE
 -> LOGIC UPDATE
 -> RENDER / UI UPDATE
 -> USER-VISIBLE RESULT

If a feature is mentioned in the UI, it must actually do something.
Do not create dead buttons or dead keyboard commands.

===============================================================
STATE-MACHINE RULE
===============================================================

For multi-phase projects use an explicit state variable, for example:

var gameState = "MENU"

Every state must have:
- clear entry logic
- clear rendering logic
- valid input handling
- valid transition logic
- reset behavior when re-entered

Do not mix incompatible states together.

===============================================================
SCALA TYPE / SCOPE DISCIPLINE
===============================================================

Use simple, explicit types when helpful.

Rules:
- Declare every variable before it is used.
- Avoid forward references.
- Avoid duplicate variable names in the same scope.
- Avoid a val and def with the same name.
- Avoid shadowing important components.
- Use var only for changing state.
- Use val for stable references.
- Never reassign a val.
- Convert numeric types explicitly when required.
- Do not pass Double where Swing requires Int without conversion.
- Do not return Unit where a Component is required.
- Do not call methods on Unit.
- Do not use an undeclared helper class or method.

===============================================================
SWING COMPONENT RULES
===============================================================

Every component referenced by a listener must already exist before the listener
is attached.

Use standard patterns such as:

val button = new JButton("PLAY")
button.addActionListener(
  new ActionListener {
    override def actionPerformed(e: ActionEvent): Unit = {
      // action
    }
  }
)

Do not write code where a Unit-returning helper is accidentally inserted into a
panel. For example, never do:

panel.add(someMethod())

when someMethod() returns Unit.

Instead create the Component first and add the Component.

===============================================================
PAINTING CONTRACT
===============================================================

For custom graphics:
- use JPanel or JComponent
- override paintComponent
- call super.paintComponent(g) first
- cast to Graphics2D when appropriate
- use stable rendering code
- never dispose the Swing-supplied Graphics object
- only dispose Graphics objects created with create()

Prefer reusable helper methods for repeated shapes.
Do not create excessive objects inside every frame when avoidable.

===============================================================
3D / PSEUDO-3D CONTRACT
===============================================================

When USER IDEA requests 3D, realistic 3D, driving 3D, first person, third
person, an open world, an aircraft view, a 3D city, a 3D vehicle, or similar:

Do NOT make a static 2D screen and label it 3D.

If a real external 3D engine is unavailable, build a self-contained software
3D / pseudo-3D renderer using Java2D.

Use meaningful spatial concepts where appropriate:
- world X/Y/Z
- camera X/Y/Z
- camera yaw/pitch/roll where useful
- perspective projection
- horizon
- depth
- near/far clipping
- field of view
- distance scaling
- polygon surfaces
- road perspective
- object depth
- simple lighting/shading
- fog/depth fade when useful
- shadows where practical
- animated scenery

A simple projection may follow the concept:

screenX = centerX + worldX * focalLength / safeDepth
screenY = horizonY + worldY * focalLength / safeDepth

but choose a consistent coordinate system and implement it correctly.

ALWAYS protect projection math:
- never divide by zero
- reject or clamp unusable depth
- reject NaN
- reject Infinity
- clamp screen coordinates before Int conversion when necessary
- avoid enormous coordinates that can overflow

For polygon drawing, use java.awt.Polygon or addPoint calls.
Do NOT pass Array[Point] to Graphics2D.fillPolygon.

===============================================================
GAME LOOP CONTRACT
===============================================================

For real-time animation/gameplay, prefer one javax.swing.Timer.

Rules:
- create at most the timers actually required
- do not start duplicate timers
- start the timer after the UI exists
- stop the timer when leaving the active mode when appropriate
- update state in the timer
- call repaint()
- never block the Swing Event Dispatch Thread

Avoid expensive per-frame operations such as sorting huge collections unless
truly required.

===============================================================
KEYBOARD / MOUSE CONTRACT
===============================================================

Keyboard controls must actually work.

For focus-sensitive games:
- make the real game component focusable
- request focus after showing the window
- attach key handling to a reliable focused component
- remove or reset stale key state when changing game states

For mouse controls:
- attach listeners to the real visible component
- convert coordinates consistently
- handle clicks only in valid UI/game states

===============================================================
COLLISION / PHYSICS CONTRACT
===============================================================

When the idea needs collision:
- define a clear coordinate system
- use stable collision shapes
- clamp player position
- separate collision detection from rendering
- implement recovery after collision
- reset collision flags correctly

For driving games, include sensible:
- speed
- acceleration
- braking
- steering
- friction/deceleration
- road boundaries
- traffic/obstacle collision
- crash/reset behavior when requested

===============================================================
SAVE / PROFILE CONTRACT
===============================================================

When the idea requests accounts, IDs, passwords, scores or persistence:
- implement a complete local save system when internet/backend is unavailable
- never require a server merely to start the application
- store progress in a predictable local file
- catch file I/O errors
- do not let an optional save failure prevent the main window from opening

For passwords:
- never store the plaintext password when a local account system is requested
- use a standard digest such as SHA-256 for the local demo
- do not pretend this is production-grade authentication

When an account is reopened:
- restore the same profile values
- restore points exactly as saved
- restore coins/levels where applicable
- preserve IDs where applicable

===============================================================
AUDIO CONTRACT
===============================================================

When sound/music is requested:
- first prefer self-contained Java Sound
- safely handle systems with no available audio device
- never let a sound failure stop application startup
- optionally use simple generated tones where appropriate
- do not require external audio files unless the USER IDEA explicitly provides
  them

If audio is unavailable, show a harmless status such as "Audio unavailable"
and keep gameplay working.

===============================================================
CAMERA / WEBCAM CONTRACT
===============================================================

If the USER IDEA requests a camera or webcam:

Do not assume a webcam library exists in Kojo.
Do not import third-party webcam packages.
Do not make startup depend on a camera.

Use a graceful design:
- provide the requested camera concept in the UI
- attempt only supported standard APIs if genuinely available
- catch failures
- show a clear fallback state
- keep the rest of the application fully usable

Never fake a live camera feed by claiming a static image is a camera stream.

===============================================================
MULTIPLAYER CONTRACT
===============================================================

Distinguish these clearly:
1. local same-computer multiplayer
2. LAN multiplayer
3. internet/server multiplayer

Do not falsely claim that local two-player is online multiplayer.

If no server/backend is available, implement local multiplayer where sensible.
If online multiplayer is explicitly requested but no backend exists, provide a
complete local architecture and a clear offline-safe fallback without pretending
that real internet matchmaking exists.

===============================================================
PROCEDURAL-ASSET CONTRACT
===============================================================

When external images/models/sounds are unavailable, create original procedural
visuals with Java2D:
- vehicles
- buildings
- roads
- trees
- terrain
- aircraft
- UI icons
- particles
- shadows
- lighting effects

Do not require copyrighted game assets.
Do not embed external URLs as a runtime dependency.

===============================================================
UI / UX QUALITY CONTRACT
===============================================================

Make the requested project visually clear and polished.
Use:
- sensible window size
- readable fonts
- spacing
- panels/cards only when helpful
- status text
- helpful controls
- clear state indicators
- accessible button labels

Do not overcrowd the UI merely to make the source longer.
Quality and correctness are more important than line count.

===============================================================
RESET / ERROR-RECOVERY CONTRACT
===============================================================

Every restartable system must reset ALL relevant state.

Audit variables such as:
- health
- ammo
- score
- coins
- timers
- crash ticks
- landing ticks
- animation counters
- collision flags
- camera state
- enemy arrays
- player position
- level state
- selected item
- input state

A common state variable must NEVER be referenced before declaration.
Examples include variables like:
crashTicks
landingTicks
restartTicks
cooldownTicks
animationTicks

Declare them before any method that uses them.

===============================================================
COMMON COMPILER-ERROR PREVENTION
===============================================================

Explicitly audit for these known failure patterns:

1. fillPolygon(Array(...)) passed where Polygon is required
2. JFrame.EXIT_ON_CLOSE
3. object Main extends App used as the only startup mechanism
4. unused startup function that is never called
5. undefined variables
6. undefined methods
7. duplicate vals
8. duplicate defs
9. forward references
10. val reassignment
11. Unit used as a Component
12. addActionListener called on Unit
13. Int/Double mismatch
14. Float/Double mismatch
15. Long/Int mismatch
16. Array index out of bounds
17. collection index out of bounds
18. division by zero
19. NaN or Infinity in projection math
20. missing braces
21. missing parentheses
22. missing brackets
23. broken strings
24. broken multiline strings
25. accidental Markdown fences
26. accidental triple-single-quote markers
27. timers started multiple times
28. controls attached to the wrong component
29. game window never made visible
30. first window is blank
31. feature button with no action
32. state transition with no rendering
33. stale game state after restart
34. optional file/resource failure blocking startup
35. external library assumed without proof

===============================================================
MASTER GENERATED-CODE SELF-AUDIT
===============================================================

Before producing the final source, perform FOUR separate mental passes.

PASS 1 ? RAW SOURCE
Check:
- first line is Scala
- last line is Scala
- no Markdown fences
- no decorative non-Scala wrapper
- strings are closed
- multiline strings are closed

PASS 2 ? COMPILATION
Check:
- declarations
- scope
- types
- method signatures
- listener signatures
- timer types
- collection types
- numeric conversions
- component types
- imports

PASS 3 ? FEATURE PATHS
For EACH major feature, trace:
input -> state -> logic -> render -> result.
Delete or fix any advertised feature that has no working path.

PASS 4 ? STARTUP
Trace exactly:
RUN
-> Kojo executes source
-> startup block executes
-> application JFrame is constructed
-> content is created
-> listeners are attached
-> timer is started after UI setup
-> setContentPane
-> setSize / pack as appropriate
-> setLocationRelativeTo(null)
-> setVisible(true)
-> requested project is visible
-> input is usable

If this trace fails anywhere, the source is NOT finished.

===============================================================
FINAL STARTUP REQUIREMENT
===============================================================

The generated source is considered incomplete unless a visible requested
window appears automatically after RUN.

A green "Run successful" indicator alone is NOT sufficient.

===============================================================
DEPENDENCY AUDIT
===============================================================

Before final output, inspect every import.
For each non-core import ask:
"Will a normal Kojo installation have this without extra setup?"

If not, remove it or replace the implementation with a standard API.

===============================================================
NO FALSE CLAIMS
===============================================================

Do not claim "100% zero compiler errors" unless the code has actually been
compiled in the target environment.

Instead, perform the strongest source-level audit possible and ensure the code
is internally consistent.

Do not claim a camera is live when it is not.
Do not claim internet multiplayer when it is only local.
Do not claim true engine-level 3D when using software pseudo-3D.

===============================================================
CODE SIZE / QUALITY
===============================================================

Do NOT inflate the source simply to increase line count.
Every line should serve the requested project, safety, readability,
maintainability, or visual quality.

Prefer a smaller correct application over a huge broken application.

===============================================================
FINAL OUTPUT CONTRACT
===============================================================

Return exactly ONE complete raw Scala source file.

The source must:
- be self-contained
- be Kojo-oriented
- auto-start
- open the actual requested window
- implement the actual requested project
- use safe standard APIs
- contain no missing sections
- contain no TODOs
- contain no placeholders
- contain no undefined state
- contain no Markdown wrapper
- contain no extra explanation

Do the final review again after writing the source.

END OF MASTER KOJO APPLICATION ENGINEER CONTRACT