Game
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define PLAYERS 4
#define WIN_POS 30
// Color Codes
#define RED "\033[1;31m"
#define GREEN "\033[1;32m"
#define YELLOW "\033[1;33m"
#define BLUE "\033[1;34m"
#define RESET "\033[0m"
void showBoard(int pos[]) {
printf("\n=============================\n");
printf(RED "Player 1 Position : %d\n" RESET, pos[0]);
printf(GREEN "Player 2 Position : %d\n" RESET, pos[1]);
printf(YELLOW "Player 3 Position : %d\n" RESET, pos[2]);
printf(BLUE "Player 4 Position : %d\n" RESET, pos[3]);
printf("=============================\n");
}
int main() {
int pos[PLAYERS] = {0,0,0,0};
int turn = 0;
int dice;
srand(time(NULL));
printf("\nš® COLORFUL LUDO GAME š®\n");
while(1) {
printf("\n-----------------------\n");
// Player Turn Color
if(turn == 0)
printf(RED "Player 1 Turn\n" RESET);
else if(turn == 1)
printf(GREEN "Player 2 Turn\n" RESET);
else if(turn == 2)
printf(YELLOW "Player 3 Turn\n" RESET);
else
printf(BLUE "Player 4 Turn\n" RESET);
// Dice Roll
dice = rand() % 6 + 1;
printf("š² Dice Rolled : %d\n", dice);
// Update Position
pos[turn] += dice;
if(pos[turn] > WIN_POS)
pos[turn] = WIN_POS;
showBoard(pos);
// Winner Check
if(pos[turn] == WIN_POS) {
printf("\nš ");
if(turn == 0)
printf(RED "Player 1 Wins!\n" RESET);
else if(turn == 1)
printf(GREEN "Player 2 Wins!\n" RESET);
else if(turn == 2)
printf(YELLOW "Player 3 Wins!\n" RESET);
else
printf(BLUE "Player 4 Wins!\n" RESET);
break;
}
// Next Turn
turn++;
if(turn >= PLAYERS)
turn = 0;
printf("\nPress Enter For Next Turn...");
getchar();
}
return 0;
}