0% found this document useful (0 votes)
92 views

Micro-Project CGR Report

1. The document describes a micro-project to code a tic-tac-toe game to improve concentration and as basic strategy building. It includes the source code for the game. 2. The methodology involved online planning meetings due to lockdown, distributing tasks, gathering information, and multiple review meetings. 3. Outputs include developing games using computer graphics and skill development in coding, graphics, and interfaces.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views

Micro-Project CGR Report

1. The document describes a micro-project to code a tic-tac-toe game to improve concentration and as basic strategy building. It includes the source code for the game. 2. The methodology involved online planning meetings due to lockdown, distributing tasks, gathering information, and multiple review meetings. 3. Outputs include developing games using computer graphics and skill development in coding, graphics, and interfaces.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Micro - Project Report

1. Rational :-

Students are able to demonstrate the personal abilities and skills


required to produce and present an extended piece of work.

Students also engage in personal inquiry, action and reflection on


specific topics and issues. Communication and interaction with others
is improved and experience is gained which makes it easier to work in
any situation with anyone.

2. Aims/Benefits of the Micro-Project :-


i. To code a tic tac toe game
ii. To improve concentration
iii. For entertainment
iv. Basic strategy building
3. Course Outcomes Addressed :-
a. Developed a game using Computer Graphics.

4. Actual Methodology Followed :-


When we got the topic for Micro-project, we needed a
discussion about the planning of the Micro-project. But
because of lockdown, it was not possible to meet directly
and discuss. Hence we had taken an online meeting on the
'Google meet' app and then we planned how to make
Micro-Project. We distributed the different tasks of
Micro-Project to the group members. First, we gathered
all the information regarding the Micro-Project. After
collecting information we prepared a presentation of
Micro-Project. Then we had again taken the meeting on
the same app 'Google meet' and discussed what
corrections we have to do. After rectifying the corrections
we edited and designed the document of Micro-Project for
final submission. In this way, we completed our Micro-
Project.

5. Actual Resources Used :-

Sr. Name of Specification Quantity


No. Resource/Material

1. Laptop Windows 11 1

2. Internet Google Chrome, 1


Wikipedia

3. Microsoft Word Typing 1


information
4. Textbook Computer Graphics

5. VS code Generating Code. 1

6. Outputs of the Micro-Project :-


a. We can develop games using Computer Graphics.

7. Skill Developed/ Learning Outcomes of the Micro-


Project :-
i. Coding efficiently
ii. Use of graphic function with game logic, loops
iii. User friendly graphical interface

8. Applications of the Micro-Project :-


i. Computer Art
ii. Computer Aided Drawing
iii. Presentation Graphics
iv. Entertainment
v. Education
vi. Visualization
vii. Image Processing
viii. Machine Drawing
ix. Graphical User Interface
CERTIFICATE

This is to certify that the following students of ‘Computer


Engineering’ of Third semester have successfully completed a micro
project on the topic of “Tic-tac-toe” in subject Computer Graphics
for the year 2021-22.

Sr.no Roll Enrollment no Name of the student


no

1. 69 1901160097 Jadhav Advaitya Shardul

2. 06 2001160170 Patil Apurva Arun

3. 22 2001160186 Patil Sakshi Chandrakant

4. 36 2001160200 Rane Parth Kishor

Subject teacher:-

Mrs. Poonam Chaudhari


1. Source Code:-

#include <stdio.h>

#include <conio.h>

#include <graphics.h>

#define GRID_SIZE 450

#define GRID_UNIT_SIZE 150

#define XP_SIZE 100

#define OP_SIZE 55

#define P_SIZE 100

#define GRID_XOFF 130

#define GRID_YOFF 15

#define AIR 0

#define P1 4

#define P2 1

#define DRAW 8

#define LEFT_KEY 75

#define RIGHT_KEY 77

#define UP_KEY 72

#define DOWN_KEY 80

#define ENTER_KEY 13

#define Q_KEY 113

#define E_STATE -1

#define M_STATE 0

#define G_STATE 1

#define O_STATE 2
#define P1W_TXT "PLAYER1 WINS!"

#define P2W_TXT "PLAYER2 WINS!"

#define P1T_TXT "Player1 'X'"

#define P2T_TXT "Player2 'O'"

#define GAME_TXT "TIC TAC TOE"

#define DRAW_TXT "GAME DRAW!"

#define HELP1_TXT "|ARROW KEYS|"

#define HELP2_TXT "| TO MOVE |"

#define HELP3_TXT "| ENTER TO |"

#define HELP4_TXT "| SELECT |"

#define HELP5_TXT "Press 'Q' for Menu"

#define HELP6_TXT "Turn:"

#define PLAY_TXT "PLAY"

#define EXIT_TXT "EXIT"

//to select grid unit and place 'X' or 'O'

struct Pointer {

int x, y;

int turn, lastTurn;

} ptr;

//to access input key

struct Keyboard {

int key, lastKey;

} kboard;

//to access screen state and grid

struct Game {

int state, grid[3][3], renderNxt;

char* c;

} g;
void init();

void tick();

int render();

int isGameover(int);

int getWinner();

void drawMenu(int);

void drawGrid();

void drawX(int, int);

void drawO(int, int);

void hud();

void animatePointer();

void animateWin(int, int, int, int);

int main() {

//initializing graphmode

int gd = DETECT, gm;

detectgraph(&gd, &gm);

initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");

//initializing variables

init();

//loops game

while(g.state != E_STATE) {

//render() function returns value whether to skip tick() function for this loop or not

if(g.renderNxt == 0) tick();
g.renderNxt = render();

closegraph();

return 0;

void init() {

g.state = M_STATE;

kboard.key = UP_KEY;

g.renderNxt = 1;

ptr.turn = P1;

void tick() {

//key input

kboard.lastKey = kboard.key;

kboard.key = getch();

//key 'q' to open menu

if(kboard.key == Q_KEY) {

//changes screen state to menu

g.state = M_STATE;

//resets grid

for(int i = 0; i < 3; i++) {

for(int j = 0; j < 3; j++)

g.grid[i][j] = AIR;

//resets player
ptr.turn = P1;

ptr.lastTurn = P2;

return;

if(g.state == G_STATE) {

//pointer movement

if(kboard.key == UP_KEY)

ptr.y -= 1;

if(kboard.key == DOWN_KEY)

ptr.y += 1;

if(kboard.key == LEFT_KEY)

ptr.x -= 1;

if(kboard.key == RIGHT_KEY)

ptr.x += 1;

//clamps pointer to grid

ptr.x = ptr.x > 2 ? 2 : ptr.x < 0 ? 0 : ptr.x;

ptr.y = ptr.y > 2 ? 2 : ptr.y < 0 ? 0 : ptr.y;

//adds 'X' or 'O' and animates pointer if key 'enter' and grid unit is empty

if(kboard.key == ENTER_KEY && g.grid[ptr.x][ptr.y] == AIR) {

animatePointer();

g.grid[ptr.x][ptr.y] = ptr.turn;

ptr.lastTurn = ptr.turn;

//switch player's turn

ptr.turn = ptr.turn == P1 ? P2 : ptr.turn == P2 ? P1 : ptr.turn;

}
int render() {

if(g.state == O_STATE) return 0; //returns if on game over screen

cleardevice(); //clears screen for new frame

//keybind txt

settextstyle(10, 0, 1);

setcolor(DARKGRAY);

outtextxy(0, 30+300, HELP1_TXT);

outtextxy(0, 50+300, HELP2_TXT);

outtextxy(0, 100+300, HELP3_TXT);

outtextxy(0, 120+300, HELP4_TXT);

if(g.state == M_STATE) { //condtion - if in menu

if(kboard.key == ENTER_KEY) { //play/exit game logic

g.state = kboard.lastKey == UP_KEY ? G_STATE : kboard.lastKey == DOWN_KEY ?


E_STATE : g.state;

return g.state;

drawMenu(kboard.key);

if(g.state == G_STATE) { //condtion - if playing game

drawGrid();

//condition - checks if game is over

//code - changes screen state to game over

if(isGameover(getWinner()) != AIR) {

g.state = O_STATE;

return 0;
}

hud();

return 0;

int isGameover(int winner) {

if(winner == AIR) //returns if any unit is empty

return winner;

//winner txt

if(winner == P1) g.c = P1W_TXT;

else if(winner == P2) g.c = P2W_TXT;

else g.c = DRAW_TXT;

settextstyle(10, 0, 4);

setcolor(winner);

outtextxy(getmaxx()/2 - 125, getmaxy()/2 - 50, g.c);

outtextxy(getmaxx()/2 - 165, getmaxy()/2, HELP5_TXT);

//returns winning player

return winner;

int getWinner() {

//loops all grid units

for(int i = 0; i < 3; i++) {

//condition - checks if all the columns are equal

//code - animates a line and returns the winning player (same for all conditions)
if(g.grid[i][0] != AIR && g.grid[i][0] == g.grid[i][1] && g.grid[i][1] == g.grid[i][2]) {

animateWin(i, 0, i, 2);

return g.grid[i][0];

//condition - checks if all the rows are equal

if(g.grid[0][i] != AIR && g.grid[0][i] == g.grid[1][i] && g.grid[1][i] == g.grid[2][i]) {

animateWin(0, i, 2, i);

return g.grid[0][i];

//condition - checks if diagonals are equal

if(g.grid[0][0] != AIR && g.grid[0][0] == g.grid[1][1] && g.grid[1][1] == g.grid[2][2]) {

animateWin(0, 0, 2, 2);

return g.grid[0][0];

if(g.grid[2][0] != AIR && g.grid[2][0] == g.grid[1][1] && g.grid[1][1] == g.grid[0][2]) {

animateWin(2, 0, 0, 2);

return g.grid[2][0];

//condition - checks for any empty grid unit and returns an empty grid value

for(int i = 0; i < 3; i++) {

for(int j = 0; j < 3; j++) {

if(g.grid[i][j] == AIR) return AIR;

//if no empty grids and nobody wins, returns draw value

return DRAW;
}

void drawMenu(int k) {

int cx = getmaxx()/2; //center x of screen

int cy = getmaxy()/2; //center y of screen

//title txt

settextstyle(10, 0, 6);

setcolor(YELLOW);

outtextxy(cx-170, cy-210, GAME_TXT);

//ui txt

settextstyle(10, 0, 8);

setcolor(k == UP_KEY ? WHITE : DARKGRAY);

outtextxy(cx-100, cy-100, PLAY_TXT);

setcolor(k == DOWN_KEY ? WHITE : DARKGRAY);

outtextxy(cx-100, cy+70, EXIT_TXT);

void drawGrid() {

//draws grid layout

setcolor(WHITE);

rectangle(GRID_XOFF, GRID_YOFF, GRID_XOFF+GRID_SIZE, GRID_YOFF+GRID_SIZE);

line(GRID_XOFF+GRID_SIZE/3, GRID_YOFF, GRID_XOFF+GRID_SIZE/3,


GRID_YOFF+GRID_SIZE);

line(GRID_XOFF+GRID_SIZE/1.5, GRID_YOFF, GRID_XOFF+GRID_SIZE/1.5,


GRID_YOFF+GRID_SIZE);

line(GRID_XOFF, GRID_YOFF+GRID_SIZE/3, GRID_XOFF+GRID_SIZE,


GRID_YOFF+GRID_SIZE/3);

line(GRID_XOFF, GRID_YOFF+GRID_SIZE/1.5, GRID_XOFF+GRID_SIZE,


GRID_YOFF+GRID_SIZE/1.5);

//draws 'X's and 'O's


for(int i = 0; i < 3; i++) {

for(int j = 0; j < 3; j++) {

if(g.grid[i][j] == P1) drawX(i, j);

if(g.grid[i][j] == P2) drawO(i, j);

void drawX(int xOff, int yOff) {

int x = GRID_XOFF + (GRID_UNIT_SIZE-XP_SIZE)/2 + GRID_UNIT_SIZE*xOff; //calcs x


coord of lines as per grid coords

int y = GRID_YOFF + (GRID_UNIT_SIZE-XP_SIZE)/2 + GRID_UNIT_SIZE*yOff; //calcs y


coord of lines as per grid coords

//draws 'X'

line(x, y, x+XP_SIZE, y+XP_SIZE);

line(x+XP_SIZE, y, x, y+XP_SIZE);

void drawO(int xOff, int yOff) {

int x = GRID_XOFF + GRID_UNIT_SIZE/2 + GRID_UNIT_SIZE*xOff; //calcs center(x, y) of the


circle as per grid coords

int y = GRID_YOFF + GRID_UNIT_SIZE/2 + GRID_UNIT_SIZE*yOff;

circle(x, y, OP_SIZE);

void hud() {

//player's turn txt

if(ptr.turn == P1) g.c = P1T_TXT;

if(ptr.turn == P2) g.c = P2T_TXT;

settextstyle(10, 0, 1);

setcolor(ptr.turn);
outtextxy(5, 200, HELP6_TXT);

outtextxy(5, 225, g.c);

int x = GRID_XOFF + (GRID_UNIT_SIZE-P_SIZE)/2 + GRID_UNIT_SIZE*ptr.x; //calcs pointer's


x coord as per grid coords

int y = GRID_YOFF + (GRID_UNIT_SIZE-P_SIZE)/2 + GRID_UNIT_SIZE*ptr.y; //calcs pointer's


Y coord as per grid coords

//draws pointer

setcolor(ptr.turn);

rectangle(x, y, x+P_SIZE, y+P_SIZE);

void animatePointer() {

int x = GRID_XOFF + (GRID_UNIT_SIZE-P_SIZE)/2 + GRID_UNIT_SIZE*ptr.x; //top left of


pointer (rectangle)

int y = GRID_YOFF + (GRID_UNIT_SIZE-P_SIZE)/2 + GRID_UNIT_SIZE*ptr.y; //bottom right


of pointer (rectangle)

//variables used to lerp current coords to dest coords

float size = P_SIZE;

int x2 = x;

int y2 = y;

while(size < 120) {

//draw rectangle of player color with lerped values

setcolor(ptr.turn);

rectangle(x, y, x2+size, y2+size);

delay(30);

//draw black(bg color) rectangle with same values to hide the last one

setcolor(BLACK);

rectangle(x, y, x2+size, y2+size);


//lerp

size = (125 - size) * 0.2 + size;

x = ((x2-(GRID_UNIT_SIZE-XP_SIZE)/2) - x) * 0.2 + x;

y = ((y2-(GRID_UNIT_SIZE-XP_SIZE)/2) - y) * 0.2 + y;

void animateWin(int startX, int startY, int destX, int destY) {

int x = GRID_XOFF + GRID_UNIT_SIZE/2 + GRID_UNIT_SIZE*startX; //start x of line

int y = GRID_YOFF + GRID_UNIT_SIZE/2 + GRID_UNIT_SIZE*startY; //start Y of line

float currentEndX = x; //changing x of line

float currentEndY = y; //changing y of line

int x2 = GRID_XOFF + GRID_UNIT_SIZE/2 + GRID_UNIT_SIZE*destX; //destination x of line

int y2 = GRID_YOFF + GRID_UNIT_SIZE/2 + GRID_UNIT_SIZE*destY; //destination y of line

setcolor(ptr.lastTurn);

//while condition - loops until line is drawn

while((currentEndY < y2-1 || currentEndY > y2+1 && startY != y2) || (currentEndX < x2-1 ||
currentEndX > x2+1 && startX != x2)) {

currentEndX = (x2 - currentEndX) * 0.2 + currentEndX; //lerp currentEndX to destX

currentEndY = (y2 - currentEndY) * 0.2 + currentEndY; //lerp currentEndY to destY

//condition - Checks if the line to be drawn is vertical

//code - Draw lines with offset for thickness

if(startX == 0 && destX == 2) {

line(x, y+1, currentEndX, currentEndY+1);

line(x, y-1, currentEndX, currentEndY-1);


line(x, y+2, currentEndX, currentEndY+2);

line(x, y-2, currentEndX, currentEndY-2);

} else {

line(x+1, y, currentEndX+1, currentEndY);

line(x-1, y, currentEndX-1, currentEndY);

line(x+2, y, currentEndX+2, currentEndY);

line(x-2, y, currentEndX-2, currentEndY);

line(x, y, currentEndX, currentEndY);

delay(30);

printf("\nstartX: %d, startY: %d, destX: %d, destY: %d", startX, startY, destX, destY);

}
2. Output of the microproject:-

You might also like