MT Assignment1
MT Assignment1
Allahabad
Department of Computer Science &
Engineering
Multimedia Technology Lab (CS17201)
#include <GL/glut.h>
void init() {
glMatrixMode(GL_PROJECTION);
glBegin(GL_LINES);
glVertex2f(x, y);
glVertex2f(x + 1, y + 1);
glVertex2f(x, y + 1);
glVertex2f(x + 1, y);
glEnd();
}
void drawO(float x, float y) {
glBegin(GL_LINE_LOOP);
glEnd();
void display() {
glClear(GL_COLOR_BUFFER_BIT);
// Draw grid
glBegin(GL_LINES);
glVertex2f(i, 0);
glVertex2f(i, 3);
glVertex2f(0, i);
glVertex2f(3, i);
glEnd();
// Draw Xs and Os
}
glFlush();
int checkWin() {
return 0;
if (grid[row][col] == 0) {
grid[row][col] = turn;
turn = (turn == 1) ? 2 : 1;
if (winner) {
grid[i][j] = 0;
turn = 1;
glutPostRedisplay();
}
}
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutCreateWindow("Tic-Tac-Toe");
init();
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
return 0;
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int rollDice() {
return (rand() % 6) + 1;
int ladder[] = {3, 8, 28, 58, 75, 80}; // Ladders start positions
int ladderEnd[] = {22, 26, 84, 77, 86, 99}; // Ladders end positions
int snake[] = {17, 52, 57, 88, 62, 95}; // Snakes start positions
int snakeEnd[] = {7, 29, 40, 18, 22, 56}; // Snakes end positions
if (position == ladder[i]) {
return ladderEnd[i];
return snakeEnd[i];
return position;
void playGame() {
int currentPlayer = 1;
int diceRoll;
getchar();
diceRoll = rollDice();
if (currentPlayer == 1) {
player1 += diceRoll;
if (player1 == BOARD_SIZE) {
printf("Player 1 wins!\n");
break;
currentPlayer = 2;
} else {
player2 += diceRoll;
player2 = movePlayer(player2);
if (player2 == BOARD_SIZE) {
printf("Player 2 wins!\n");
break;
currentPlayer = 1;
}
}
int main() {
srand(time(0));
playGame();
return 0;