COMPUTER SCIENCE - 86
PRACTICAL RECORD
2025 - 2026
NAME: B. SHASHANTH
CLASS: XI A
UNIQUE ID: 8458254
INDEX NO:
CARMEL PUBLIC SCHOOL
[Link],veppampattu,Thiruvallur district-602024
PRACTICAL RECORD
COMPUTER SCIENCE
Ceritified that this is a Bonafide record of pratical work done by
[Link] of standard XI during the year 2025-2026.
UNIQUE ID: 8458254
INDEX NO:
Submitted for the year ISC pratical examination held on_________
Date: principal Teacher in charge
External Examiner Internal Examiner
Algorithem
Step 1: Initialize the Game
1. Import required Java libraries ([Link], [Link],
[Link], [Link],
[Link]).
2. Create a class KangarooRunSimulation that extends JPanel and
implements ActionListener and KeyListener.
3. Define kangaroo properties:
o Position (kangarooX, kangarooY)
o Size (kangarooWidth, kangarooHeight)
o Jump parameters (jumpSpeed, gravity, velocityY)
o States (isJumping, gameOver)
4. Create an ArrayList for obstacles and a Random object for spawning.
5. Initialize a timer with a delay (e.g., 20 ms) for the game loop.
6. Set panel properties (size, background color, focusable, key listener).
7. Start the timer.
Step 2: Draw the Game (paintComponent)
1. Clear the panel and set the background.
2. Draw the ground line.
3. Draw the kangaroo as a rectangle at its current position.
4. Draw all obstacles from the obstacles list.
5. If gameOver is true:
o Display “GAME OVER” text.
o Display instruction to restart (“Press R to Restart”).
Step 3: Update Game State (actionPerformed)
1. If the game is not over:
o Update Kangaroo:
▪ If isJumping is true:
▪ Update kangarooY by adding velocityY.
▪ Update velocityY by adding gravity.
▪ If kangaroo touches the ground (kangarooY >=
260), stop jumping (isJumping = false) and
reset Y position.
o Update Obstacles:
▪ For each obstacle in the list:
▪ Move the obstacle left (decrease x by a fixed speed).
▪ If the obstacle moves off-screen (x + width < 0),
remove it from the list.
▪ Check collision with kangaroo using rectangle
intersection:
▪ If collision occurs, set gameOver = true
and stop the timer.
o Spawn New Obstacles:
▪ Increment obstacle spawn timer.
▪ If spawn timer exceeds a random threshold, create a new
obstacle at the right edge and reset spawn timer.
2. Repaint the panel to reflect updated positions.
Step 4: Handle Keyboard Input (keyPressed)
1. If Spacebar is pressed and kangaroo is not jumping and game is not over:
o Set isJumping = true.
o Set velocityY = jumpSpeed.
2. If R key is pressed and the game is over:
o Call resetGame().
Step 5: Reset Game (resetGame)
1. Clear all obstacles from the list.
2. Reset kangaroo position and jump state.
3. Set gameOver = false.
4. Restart the timer.
Step 6: Launch the Game (main method)
1. Create a JFrame window.
2. Add an instance of KangarooRunSimulation to the frame.
3. Set frame properties: size, close operation, non-resizable, centered on
screen.
4. Make the frame visible.
Step 7: Repeat
• The timer continuously calls actionPerformed, creating a loop that
updates game state and graphics until the game ends.
Project Description
Simulation is a method of imitating real-world systems or processes using
computer programs. It allows us to study and understand how a system
behaves without actually performing it in real life. In a simulation,
mathematical models and computer graphics are used to create a virtual
environment that behaves like the real one.
Simulations are widely used in different fields — for example, weather
forecasting, space research, traffic control, video games, and scientific
experiments. They help us to observe, analyse , and predict outcomes in a safe
and controlled way.
In computer science, simulation programs are used to represent dynamic
systems — that is, systems that change over time. These programs respond to
user inputs and follow logical rules to show realistic behaviour .
The Kangaroo Run Simulation is a simple yet engaging 2D game developed
using Java and the Swing framework. It is designed as an endless runner-
style game, where the player controls a kangaroo that moves forward
automatically and must jump over obstacles to survive. The game combines
basic programming concepts, object-oriented design, graphical rendering, and
interactive controls, making it an excellent educational project for
understanding fundamental game development principles in Java.
In this simulation, the player’s character, the kangaroo, is represented as a white
square, and it moves along a fixed horizontal position near the left side of the
screen. Obstacles, depicted as rectangles, are generated randomly on the right
side and move toward the kangaroo from right to left. The primary goal of the
game is to avoid collisions with these obstacles by timing jumps accurately. If
the kangaroo collides with an obstacle, the game ends, and a “Game Over”
message is displayed, along with an option to restart by pressing the R key. This
simple interaction forms the core gameplay mechanic, emphasizing reaction
time, timing, and decision-making.
The game employs a timer-based game loop to update the state of the
simulation at regular intervals. The timer triggers the ‘actionPerformed’
method approximately every 20 milliseconds, which corresponds to about 50
frames per second. Within each loop iteration, the program updates the
kangaroo’s position based on velocity and gravity, moves obstacles across the
screen, detects collisions, and spawns new obstacles at randomized intervals.
The jumping mechanic is implemented using a simple physics model, where the
vertical velocity of the kangaroo is adjusted by a gravity factor, creating a
smooth parabolic motion. This demonstrates how physics concepts can be
simplified and incorporated into game development for realistic movement.
The program is structured using object-oriented principles. The kangaroo is
represented by its coordinates, dimensions, and motion parameters, while each
obstacle is encapsulated in a dedicated class that stores its position and size.
Obstacles are managed using an ArrayList, which allows dynamic addition
and removal as they appear and disappear from the screen. Collision detection is
implemented using Java’s Rectangle class, which provides a straightforward
way to check for intersections between the kangaroo and obstacles. This design
allows for easy modification, such as changing obstacle behavior or adding new
features like scoring or power-ups.
Graphics in the game are intentionally kept simple, with a retro-style black
background, white rectangles for the kangaroo and obstacles, and minimalistic
ground representation. Despite this simplicity, the game successfully illustrates
real-time rendering, dynamic updates, and interactive gameplay. Keyboard
input handling is implemented through the ‘KeyListener’ interface,
allowing the player to trigger jumps with the Spacebar and restart the game
with the R key. This interactivity demonstrates event-driven programming,
which is a core concept in GUI-based applications and games.
The Kangaroo Run Simulation is not only a fun and interactive game but also
a comprehensive learning tool. It introduces programmers to essential game
development concepts, including the use of timers for continuous updates,
simple physics simulation, collision detection, random object generation, and
responsive controls. It also reinforces Java programming fundamentals such as
classes, objects, arrays/lists, loops, conditionals, and event handling. By
combining these elements, the program provides a practical, hands-on example
of how games function internally and how different components interact to
create an engaging experience.
In conclusion, the Kangaroo Run Simulation demonstrates the creation of a
fully functional 2D game using Java, emphasizing both programming and
game design principles. It serves as a stepping stone for learners who want to
explore more complex game development projects, introducing them to
concepts that are widely applicable in both professional and academic contexts.
The simplicity of the graphics and mechanics allows beginners to grasp the
underlying logic without being overwhelmed, while the interactive gameplay
provides an enjoyable and motivating experience. Overall, this program
highlights how programming knowledge can be applied to create dynamic, real-
time simulations, bridging the gap between theory and practical implementation
in an educational and entertaining way.
Source code
import [Link].*;
import [Link].*;
import [Link].*;
import [Link];
import [Link];
import [Link];
public class KangarooRunSimulation extends JPanel implements
ActionListener, KeyListener {
// Timer for game loop
Timer timer;
final int DELAY = 20;
// Kangaroo properties
int kangarooX = 80;
int kangarooY = 260;
int kangarooWidth = 40;
int kangarooHeight = 40;
int jumpSpeed = -13;
int gravity = 1;
int velocityY = 0;
boolean isJumping = false;
boolean gameOver = false;
// Obstacles
class Obstacle {
int x, y, width, height;
Obstacle(int x, int y, int w, int h) {
this.x = x;
this.y = y;
[Link] = w;
[Link] = h;
}
}
ArrayList<Obstacle> obstacles = new ArrayList<>();
Random random = new Random();
int obstacleSpawnTimer = 0;
// Constructor
public KangarooRunSimulation() {
setPreferredSize(new Dimension(600, 350));
setBackground([Link]);
setFocusable(true);
addKeyListener(this);
timer = new Timer(DELAY, this);
[Link]();
}
@Override
public void paintComponent(Graphics g) {
[Link](g);
// Set color to white (retro style)
[Link]([Link]);
// Draw ground
[Link](0, 300, getWidth(), 300);
// Draw kangaroo (simple square)
[Link](kangarooX, kangarooY, kangarooWidth, kangarooHeight);
// Draw obstacles
for (Obstacle o : obstacles) {
[Link](o.x, o.y, [Link], [Link]);
}
// Draw Game Over text
if (gameOver) {
[Link](new Font("Monospaced", [Link], 30));
[Link]("GAME OVER", 210, 180);
[Link](new Font("Monospaced", [Link], 16));
[Link]("Press R to Restart", 225, 210);
}
}
@Override
public void actionPerformed(ActionEvent e) {
if (!gameOver) {
// Update kangaroo
if (isJumping) {
kangarooY += velocityY;
velocityY += gravity;
if (kangarooY >= 260) {
kangarooY = 260;
isJumping = false;
}
}
// Update obstacles
Iterator<Obstacle> it = [Link]();
while ([Link]()) {
Obstacle o = [Link]();
o.x -= 6; // move obstacle left
if (o.x + [Link] < 0) {
[Link](); // remove when out of screen
}
// Collision detection
if (new Rectangle(kangarooX, kangarooY, kangarooWidth,
kangarooHeight)
.intersects(new Rectangle(o.x, o.y, [Link], [Link]))) {
gameOver = true;
[Link]();
}
}
// Spawn obstacles randomly
obstacleSpawnTimer++;
if (obstacleSpawnTimer > 60 + [Link](60)) {
[Link](new Obstacle(600, 280, 20 + [Link](20), 20));
obstacleSpawnTimer = 0;
}
repaint();
}
}
@Override
public void keyPressed(KeyEvent e) {
int key = [Link]();
if (key == KeyEvent.VK_SPACE && !isJumping && !gameOver) {
isJumping = true;
velocityY = jumpSpeed;
}
if (key == KeyEvent.VK_R && gameOver) {
resetGame();
}
}
private void resetGame() {
[Link]();
kangarooY = 260;
isJumping = false;
gameOver = false;
[Link]();
}
@Override
public void keyReleased(KeyEvent e) {}
@Override
public void keyTyped(KeyEvent e) {}
public static void main(String[] args) {
JFrame frame = new JFrame(" Retro Kangaroo Run Simulation");
KangarooRunSimulation game = new KangarooRunSimulation();
[Link](game);
[Link]();
[Link](JFrame.EXIT_ON_CLOSE);
[Link](false);
[Link](null);
[Link](true);
}
}
Variable description
Variable Name Data Type Description / Purpose
Controls the game loop and updates the
timer Timer
simulation at regular time intervals.
Sets the time delay (in milliseconds)
DELAY int
between each frame update.
Stores the x-coordinate (horizontal
=kangarooX int
position) of the big block.
Stores the y-coordinate (vertical position)
kangarooY int
of the big block.
kangarooWidth int Defines the width of the big block.
kangarooHeight int Defines the height of the big block.
Sets the upward speed when the big block
jumpSpeed int
jumps.
Determines how fast the block falls back
gravity int
down after a jump.
Tracks the vertical movement speed of the
velocityY int
block during the jump.
Indicates whether the big block is
isJumping boolean
currently jumping.
True when the block collides with an
gameOver boolean
obstacle and the game stops.
Represents each small block (obstacle)
Obstacle Inner Class
with its position and size.
The position of each small block on the
x, y int
screen.
The width and height of each small block
width, height int
(obstacle).
Stores all the obstacles currently visible in
obstacles ArrayList<Obstacle>
the game.
Used to generate random obstacle sizes
random Random
and positions.
Counts frames to control when a new
obstacleSpawnTimer int
obstacle appears.
The main window where the simulation is
JFrame
displayed.
frame
Input output
The simulation accepts keyboard input from the user:
Spacebar key → Makes the big block jump to avoid small blocks.
Click R to restart the simulation when your screen displays ‘GAME OVER’
Conclusion
The Kangaroo Run Simulation project is a simple yet comprehensive
demonstration of the fundamental concepts of game development using Java
and the Swing framework. Through the development and execution of this
program, multiple important programming principles and real-time simulation
techniques have been effectively implemented and showcased. The game,
which revolves around a kangaroo navigating an endless terrain while avoiding
obstacles, provides both an interactive experience for users and an educational
platform for understanding object-oriented programming, event-driven design,
and basic physics simulation in a graphical environment.
One of the key aspects of this project is the effective use of object-oriented
programming (OOP) principles. The kangaroo, obstacles, and game logic have
been represented as discrete entities with their own attributes and behaviors. For
instance, obstacles are encapsulated within a dedicated class, which allows for
easy creation, movement, and collision detection. The use of ArrayLists to
manage dynamic obstacles demonstrates how collections can be leveraged for
real-time updates in a game environment. These implementations not only
streamline the code but also enhance its modularity and maintainability, which
are crucial skills in software development.
The program also illustrates event-driven programming, particularly through
keyboard input handling. By implementing the KeyListener interface, the
game captures user actions such as pressing the Spacebar to jump and the R
key to restart. This interaction demonstrates how user inputs can dynamically
influence the behavior of objects in a simulation. The game loop, driven by a
Timer object, ensures that updates occur at consistent intervals, creating
smooth animations and real-time responses to user inputs. This combination of
timer-based updates and event-driven actions is a foundational concept in
interactive applications and games.
Another significant feature of the program is the incorporation of simple
physics simulation. The kangaroo’s jumping motion is achieved using a
vertical velocity variable influenced by a gravity factor, producing a realistic
parabolic trajectory. This mechanic, while simple, introduces the concept of
physics-based movement, which is a cornerstone in many modern games. The
collision detection between the kangaroo and obstacles further emphasizes how
spatial relationships and mathematical calculations are used to control game
flow and determine outcomes.
From a graphical perspective, the game employs a retro-style design, with
white rectangles representing both the kangaroo and obstacles against a black
background. While simplistic, this design effectively conveys the core
mechanics and allows the player to focus on gameplay rather than complex
graphics. The program demonstrates how graphical representation can be
integrated with logical programming to create interactive simulations,
highlighting the balance between simplicity and functionality in educational
projects.
Furthermore, this simulation serves as an excellent example of programming
problem-solving and algorithmic thinking. Tasks such as obstacle generation,
movement, and removal, as well as game restart mechanisms, required careful
planning and implementation. The project illustrates the importance of iterative
updates, loop constructs, and conditional logic in building a functional
application.
In conclusion, the Kangaroo Run Simulation is more than just a game—it is a
practical educational tool that bridges theory and application. It reinforces key
programming concepts, including OOP, event handling, timer-based loops, and
simple physics, while providing an engaging and interactive user experience.
The program demonstrates how a well-structured approach can result in a
functional and enjoyable application, even with basic graphics and mechanics.
By completing this project, learners gain valuable insights into game design,
real-time simulations, and Java programming. The skills developed through this
project—such as managing dynamic objects, handling collisions, and
responding to user input—are widely applicable in more complex programming
tasks and future game development projects. Ultimately, the Kangaroo Run
Simulation successfully showcases how fundamental programming principles
can be applied to create an interactive, functional, and enjoyable game, making
it an exemplary project for both educational and practical purposes.