Tic Tac Toe
Tic Tac Toe
A Project Report
On
BACHELOR OF TECHNOLOGY
IN
COMPUTER SCIENCE
SUBMITTED BY-
K.Sindhu
23BBTCS105
GUIDED BY-
Prof. K.PRABHAKAR
Assistant Professor,
Dept. of IT,
Bangalore, Karnataka-562149
2024-2025
SCHOOL OF ENGINEERING AND TECHNOLOGY
Chagalahatti, Bengaluru, Karnataka-562149
CERTIFICATE
This is to certify that the Project entitled “Space invader game using C language” has been
successfully carried out by K.Sindhu (23BBTCS105) in partial fulfillment of the requirement
for the award of the degree Bachelor of Technology in Computer Science Engineering of
CMR University, Bengaluru during the academic year 2024-2025.The project report has
been approved as it satisfies the academic requirements in respect of project work
prescribed for the said degree.
____________ ___________
The satisfaction that accompanies the successful completion of this project would be
incomplete without the mention of the people who made it possible, without whose constant
guidance and encouragement would have made efforts go in vain.
I would like to express my thanks to Dr. Rubini.P, Professor and Head, Department of
Computer Science and Engineering, School of Engineering and Technology, CMR University,
Bangalore, for his encouragement that motivated me for the successful completion of Project
work.
i
DECLARATION
Place: Bangalore
Date: 13-11-2024
ii
ABSTRACT
The Space Invader game, when implemented in the C programming language, serves as a
fundamental example of how to create an interactive, arcade-style game using basic
programming concepts. In this game, the player controls a spaceship that moves horizontally
at the bottom of the screen and shoots projectiles to destroy waves of alien invaders descending
from the top. The game is structured around a continuous loop where the alien invaders move
in patterns, and the player must react quickly to shoot them before they reach the bottom. Core
components of the C implementation include handling real-time user input, updating the
display with ASCII-based graphics, and managing game states such as score tracking and
player lives. The spaceship's movement is controlled by user input (typically using arrow keys
or other keyboard keys), while missiles are fired in response to a shooting command. Collision
detection plays a key role, determining when a missile hits an alien or when an alien reaches
the player's spaceship, causing game-over conditions. The use of functions like `printf()` and
`system("cls")` for screen updates, combined with logic for detecting collisions and
maintaining game flow, enables a simple yet engaging gameplay experience. The program is
an excellent exercise in learning how to implement basic game mechanics, such as movement,
firing, and enemy behavior, and offers a solid foundation for more advanced game development
projects. The Space Invader game in C demonstrates how efficient code can deliver an
interactive, dynamic gaming experience with minimal graphical resources, making it a useful
learning tool for budding programmers.
INDEX
1.INTRODUCTION
The "Space Invaders" game is one of the most iconic arcade games developed by Tomohiro
Nishikado in 1978. The objective of the game is to control a spaceship that can move
horizontally and shoot upwards to destroy waves of alien invaders that are descending toward the
player's ship. The player must avoid enemy fire while attempting to destroy all enemies on the
screen.
In this implementation of Space Invaders in C, we'll break down the game into several
components:
1. Player Ship:
- The player controls a spaceship at the bottom of the screen that can move left or right and
shoot projectiles upwards.
2. Aliens (Invaders):
- A grid of alien invaders at the top of the screen moves horizontally across the screen. Once
they reach the edge of the screen, they move downwards and change direction.
3. Projectiles:
- Both the player's spaceship and the aliens can shoot projectiles. The player's projectiles go
upwards, and the alien projectiles move downwards. The player must avoid these projectiles.
4. Collisions:
- When a player's projectile hits an alien, the alien is destroyed, and the score increases.
Similarly, if an alien's projectile hits the player's spaceship, the player loses a life or the game
ends.
SPACE INVADER GAME
- The game continues until all aliens are destroyed or the player loses all lives. The score is
calculated based on how many aliens are destroyed.
Implementation Overview
- Graphics and Display: While C does not have built-in graphics, we can use text-based graphics
for a simple version of the game (using libraries like `ncurses` on Unix-like systems or `conio.h`
on Windows).
- Game Loop: The game will run in a continuous loop where the player can move the spaceship,
shoot, and interact with the invaders in real-time.
- Collision Detection: We'll implement basic collision detection between projectiles and
invaders, as well as the player’s ship and enemy projectiles.
- Input Handling: The player will use keyboard input to move the ship and fire projectiles.
1. initializeGame(): Initializes the player’s ship position, alien positions, and game state (such as
score and lives).
2. drawScreen(): Clears the screen and redraws the player, aliens, and projectiles on the terminal.
3. movePlayer(): Takes input from the player (using `getch()` or similar methods) to move the
ship left or right.
SPACE INVADER GAME
4. shootProjectile(): Detects when the player presses the fire button and creates a new projectile
at the player’s ship position.
5. updateProjectiles(): Updates the positions of the projectiles and checks if they hit any enemies
or go off-screen.
7. checkGameOver(): Checks if the game is over based on whether all aliens are defeated or if
the player has lost all their lives.
SPACE INVADER GAME
2.SOFTWARE REQUIREMENTS
1. C Compiler:
- To compile and run the C code, you'll need a C compiler. Here are some commonly used
compilers:
- GCC (GNU Compiler Collection): Available on Linux, macOS, and Windows (via MinGW
or Cygwin).
- Installation:
- On Windows, you can use MinGW or MSVC. MinGW can be installed via the [MinGW-
w64] website or by using package managers like Chocolatey.
- On Linux, GCC is typically pre-installed or can be installed via the package manager (e.g.,
`sudo apt install gcc` for Ubuntu).
- On macOS, Clang is available by default, or you can install GCC via Homebrew.
- While you can write C code using any text editor, using an Integrated Development
Environment (IDE) can make development easier. Common IDEs for C programming include:
- Code::Blocks: A free, open-source C/C++ IDE that includes a built-in compiler (works
across Windows, Linux, and macOS).
- Dev C++: Another free IDE for Windows with a built-in compiler.
- Visual Studio: A powerful IDE for Windows that supports C/C++ development.
SPACE INVADER GAME
- Eclipse with CDT (C Development Tools): A cross-platform IDE that supports C/C++
development.
- Vim/Emacs: If you prefer a text editor with more control and customizability.
- If you want to add graphical features like images, colors, and animations to your Space
Invaders game, you might want to use a graphics library. However, for a simple text-based
implementation, no graphics library is necessary.
- ncurses: A library for text-based user interfaces, useful for handling keyboard input and
screen updates in a terminal.
- SDL (Simple DirectMedia Layer): A library for handling graphics, events, and audio. It is
more suitable for graphical games and provides functions for rendering 2D images, handling
events, and more.
- OpenGL: A powerful graphics library primarily used for 3D rendering, but it can be used for
2D games as well.
- Allegro: A cross-platform library for game development that supports 2D graphics, sound,
input, and more.
- Windows: Download and install the development libraries from the SDL website, and set up
the development environment in your IDE (e.g., Visual Studio).
- If you're making a text-based game (without graphics), you'll need access to a terminal
(Linux/macOS) or a command prompt (Windows). Most of the IDEs and text editors above
come with integrated terminal windows.
1. Sound Libraries:
If you wish to add sound effects and music to your game, you can use libraries such as:
- SDL_mixer: An extension of SDL for handling audio (supports formats like MP3, WAV,
etc.).
- Git: A version control system is useful if you're working on the game over time or
collaborating with others. Git can help you track changes to your code, revert to previous
versions, and collaborate on projects.
- GitHub or GitLab: Platforms for hosting your code and collaborating with other developers.
You can easily integrate your project with a repository to keep track of changes and share your
game.
SPACE INVADER GAME
3.METHODOLOGY
Before diving into coding, it's crucial to understand the basic mechanics and features of the game.
In Space Invaders, the main elements include:
- Game loop: This will repeatedly check user input, update the game state, and render the screen.
For a text-based game, draw the game state using `printf` or similar functions. For graphical games,
use libraries like SDL or ncurses.
SPACE INVADER GAME
After the player loses all lives or defeats all the aliens, show a game-over screen and provide an
option to restart.
#include <stdio.h>
#include <stdlib.h>
#define SCREEN_WIDTH 50
#define SCREEN_HEIGHT 20
#define ALIEN_ROWS 3
#define ALIEN_COLS 5
#define MAX_PROJECTILES 5
SPACE INVADER GAME
typedef struct {
int lives;
int score;
} Player;
typedef struct {
} Alien;
typedef struct {
} Projectile;
// Global variables
SPACE INVADER GAME
Player player;
Alien aliens[ALIEN_ROWS][ALIEN_COLS];
Projectile projectiles[MAX_PROJECTILES];
// Function prototypes
void initializeGame();
void drawScreen();
void processInput();
void moveAliens();
void moveProjectiles();
void checkCollisions();
void fireProjectile();
void updateGame();
int isGameOver();
void displayGameOver();
// Main function
int main() {
SPACE INVADER GAME
initializeGame();
while (!isGameOver()) {
drawScreen();
processInput();
moveAliens();
moveProjectiles();
checkCollisions();
updateGame();
displayGameOver();
return 0;
void initializeGame() {
player.x = SCREEN_WIDTH / 2;
SPACE INVADER GAME
player.y = SCREEN_HEIGHT - 2;
player.lives = 3;
player.score = 0;
// Initialize aliens
aliens[i][
5.Output
--------------------------------------------------
| A A A A A | A A A A A | A A A A A|
--------------------------------------------------
| |
| |
| |
| |
| |
| P |
SPACE INVADER GAME
--------------------------------------------------
Score: 0 Lives: 3
--------------------------------------------------
--------------------------------------------------
| |
| |
| GAME OVER |
| Your Score: 20 |
| |
| |
--------------------------------------------------
SPACE INVADER GAME
6. CONCLUSION
The Space Invaders game implemented in C provides a simple yet engaging example of how to
develop an interactive, text-based game using fundamental programming concepts. By utilizing
basic structures, loops, conditionals, and handling user input, this project offers valuable insight
into core game development principles.This Space Invaders game in C is a great project for
learning the fundamentals of game development, especially in terms of handling user input,
game state management, and collision detection. Although the game is simple and text-based, it
serves as a solid foundation for more advanced games, and the skills gained from developing this
game can be applied to other game development projects, both in C and other programming
languages. The game demonstrates how a well-designed structure can lead to a functional and
enjoyable game, even within the limitations of a console environment.
19
20
SPACE INVADER GAME
7. REFERENCE
21
20