Question

Code a game of Ludo between 2 players in c++ in code blocks. Do not use...

Code a game of Ludo between 2 players in
c++ in code blocks. Do not use graphics to print the board but use a 2d array to print a board of Ludo FOR TWO PLAYERS. Explain each step of your code.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the code for Ludo game

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
void main()
{
clrscr();
int totblocks=0,totblocks2=0,a,c=0,b,d=0;
while(totblocks<=56||totblocks2<=56)

{

cout<<"\n\n\tplayer 1 turn";
cout<<"\n\nroll a dice to press any key";
getch();
srand(time(0));
a=1+rand()%6;
if(totblocks==0&&a!=6)
{
cout<<"\n\nThe num is "<<a;
cout<<"\n\nThe totblocks = "<<totblocks;
}
if(a==6&&c==0)
{
cout<<"\n\nThe num is = "<<a;
c++;
}
if(c==1)
{

cout<<"\n\nroll dice again";
getch();
srand(time(0));
a=1+rand()%6;
cout<<"\n\nThe num is="<<a;totblocks=totblocks+a;
cout<<"\n\nThe totblocks= "<<totblocks;
c++;
goto v;
}

if(c>=2)
{

while(a==6)
{
if(a==6)
{
cout<<"\n\nThe num is = "<<a;

if(totblocks==totblocks2)
{totblocks2=0;
d=0;
}totblocks=totblocks+a;
if(totblocks>56)
{totblocks=totblocks-a;

}

if(totblocks==56)
{
cout<<"\n\nPlayer 1 wins";
break;
}
cout<<"\n\nPlz roll the dice again";
getch();
a=1+rand()%6;
continue;
}
cout<<"\n\nThe num = "<<a;
if(totblocks==totblocks2)
{totblocks2=0;
d=0;
}totblocks=totblocks+a;
if(totblocks>56)
{totblocks=totblocks-a;
cout<<"\n\nYour num is greater so you cant enter in your home";
}
cout<<"\n\nThe totblocks = "<<totblocks;
if(totblocks==56)
{
cout<<"\n\nPlayer 1 wins";
break;
}
}


cout<<"\n\nThe num is= "<<a;
if(totblocks==totblocks2)
{totblocks2=0;
d=0;
}totblocks=totblocks+a;
if(totblocks>56)
{totblocks=totblocks-a;
cout<<"\n\nYour num is greater so you cant enter in your home";
}
cout<<"\n\nThe totblocks= "<<totblocks;
if(totblocks==56)
{
cout<<"\n\nPlayer 1 wins";
break;

}
}
v: cout<<"\n\n\tplayer 2 turn";
cout<<"\n\nroll a dice to press any key";
getch();

srand(time(0));
b=1+rand()%6;
if(totblocks2==0&&b!=6)
{
cout<<"\n\nThe num is "<<b;
cout<<"\n\nThe totblocks = "<<totblocks2;
}

if(b==6&&d==0)
{
cout<<"\n\nThe num is = "<<b;
d++;
}
if(d==1)
{

cout<<"\n\nroll dice again";
getch();
srand(time(0));
b=1+rand()%6;
cout<<"\n\nThe num is="<<b;totblocks2=totblocks2+b;
cout<<"\n\nThe totblocks= "<<totblocks2;
d++;
continue;
}

if(d>=2)
{

while(b==6)
{
if(b==6)
{
cout<<"\n\nThe num is = "<<b;

if(totblocks2==totblocks)
{totblocks=0;
c=0;
}totblocks2=totblocks2+b;
if(totblocks2>56)
{totblocks2=totblocks2-b;

}

if(totblocks2==56)
{
cout<<"\n\nPlayer 2 wins";
break;
}
cout<<"\n\nroll the dice again";
getch();
b=1+rand()%6;
continue;
}
cout<<"\n\nThe num = "<<b;
if(totblocks2==totblocks)
{totblocks=0;
c=0;
}totblocks2=totblocks2+b;
if(totblocks2>56)
{totblocks2=totblocks2-b;
cout<<"\n\nYour num is greater so you cant enter in your home";
}
cout<<"\n\nThe totblocks = "<<totblocks2;
if(totblocks2==56)
{
cout<<"\n\nPlayer 2 wins";
break;
}
}


cout<<"\n\nThe num is= "<<b;
if(totblocks2==totblocks)
{totblocks=0;
c=0;
}totblocks2=totblocks2+b;
if(totblocks2>56)
{totblocks2=totblocks2-b;
cout<<"\n\nYour num is greater so you cant enter in your home";
}
cout<<"\n\nThe totblocks= "<<totblocks2;
if(totblocks2==56)
{
cout<<"\n\nPlayer 2 wins";
break;

}
}
}

getch();
}

Add a comment
Know the answer?
Add Answer to:
Code a game of Ludo between 2 players in c++ in code blocks. Do not use...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using C Programming: (use printf, scanf) 18. Tic-Tac-Toc Game Write a program that allows two players...

    Using C Programming: (use printf, scanf) 18. Tic-Tac-Toc Game Write a program that allows two players to play a game of tic-tac-toc. Use a two- dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run a loop that Displays the contents of the board array Allows player 1 to select a location on the board for an X. The program should...

  • 18. Tic-Tac-Toe Game rite a program that allows two players to play a game of tic-tac-toe. Use di...

    18. Tic-Tac-Toe Game rite a program that allows two players to play a game of tic-tac-toe. Use dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run a loop that does the following: Write . Displays the contents of the board array. . Allows player 1 to select a location on the board for an X. The program should ask the...

  • In a game of Tic Tac Toe, two players take turns making an available cell in...

    In a game of Tic Tac Toe, two players take turns making an available cell in a 3 x 3 grid with their respective tokens (either X or O). When one player has placed three tokens in a horizontal, vertical, or diagonal row on the grid, the game is over and that player has won. A stalemate occurs when all the cells on the grid have been filled with tokens and neither player has achieved a win. Write a program...

  • C or C++ Project Overview Wild, Wild, West! Dice Game The Wild, Wild, West! is an...

    C or C++ Project Overview Wild, Wild, West! Dice Game The Wild, Wild, West! is an elimination dice game. It can be played by any number of players, but it is ideal to have three or more players. Wild, Wild, West! Requires the use of two dice. At the start of the game, each player receives a paper that will track the number of lives that player has. Each player starts the game with 6 lives. In the first round,...

  • C++ program This program involves writing a VERY simplified version of the card game War. You...

    C++ program This program involves writing a VERY simplified version of the card game War. You may know this game or not but my rules are these 1. Split the deck between player1 and player2. Only the face values matter (2-14) and not the suits 2. Each player puts a card down on the table. The higher face value wins that hand. If the card values match, you will simply indicate tie and neither player wins.The original rules would require...

  • Our project will be a chess game. There will be 2 players and the game will...

    Our project will be a chess game. There will be 2 players and the game will have a pause and start function. Each of chess characters will have its own correct moves for example, the pawn can only move forward and attack on angles not sraight. The game appearance will be 2 players, a board of 8 8, and soldiers. There is only one condition you have to play with another one there is no 1 player mode

  • Use Java language to create this program Write a program that allows two players to play...

    Use Java language to create this program Write a program that allows two players to play a game of tic-tac-toe. Using a two-dimensional array with three rows and three columns as the game board. Each element of the array should be initialized with a number from 1 - 9 (like below): 1 2 3 4 5 6 7 8 9 The program should run a loop that Displays the contents of the board array allows player 1 to select the...

  • In the mixed-strategy Nash equilibrium of the following game in which players randomize between B and...

    In the mixed-strategy Nash equilibrium of the following game in which players randomize between B and C and do not play A at all, what is the probability that each plays B? QUESTION 25 1 points Save Answer In the mixed-strategy Nash equilibrium of the following game in which players randomize between B and C and do not play A at all, what is the probability that each plays B? Player 2 0,5 Player 1 B 50 1, 1 0.0...

  • 2 A Game of UNO You are to develop an interactive game of UNO between a...

    2 A Game of UNO You are to develop an interactive game of UNO between a number of players. The gameplay for UNO is described at https://www.unorules.com/. Your program should operate as follows. 2.1 Setup 1. UNO cards are represented as variables of the following type: typedef struct card_s { char suit[7]; int value; char action[15]; struct card_s *pt; } card; You are allowed to add attributes to this definition, but not to remove any. You can represent colors by...

  • Write a program to Simulate a game of tic tac toe in c#

    Write a program to Simulate a game of tic tac toe. A game of tic tac toe has two players. A Player class is required to store /represent information about each player. The UML diagram is given below.Player-name: string-symbol :charPlayer (name:string,symbol:char)getName():stringgetSymbol():chargetInfo():string The tic tac toe board will be represented by a two dimensional array of size 3 by 3 characters. At the start of the game each cell is empty (must be set to the underscore character ‘_’). Program flow:1)    ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT