Aim:
By working on this assignment you should be able to:
● Create and use dynamic arrays
● Create, manipulate and store input in c-style strings
● Accept and parse command-line arguments
● Implement recursion
About this assignment:
For this assignment, you will design and implement a game. You can pick between minesweeper or battleship. If you turn in both, you will get whichever scores the highest points. If you submit the design for one option, but code for another, you would lose all the points on the design.
Problem statement:
The objective of the game is to open/reveal every cell on the board without detonating a mine. Every cell contains a number or a mine. The numbers tell you how many mines surround the cell in the horizontal , vertical , and diagonal directions, e.g. at most, 8 possible mines surrounding a cell. You can flag a cell, which helps you remember where you think there is a mine to not detonate. If you select to open/reveal a cell that has a mine, then you automatically lose the game!
When the user runs the game program, they would pass command-line arguments telling the number of rows, columns and mines that they want in the game. The game would randomly distribute the mines on the board and setup the numbers describing how many adjacent mines are to each cell. After that, the game will display a blank board and ask the user to flag or open a cell on the board until the user selects a cell that contains a mine (losing the game) or selects all the cells free of mines (winning the game).
After the user wins or loses, you will ask the user if they want to play again. If so, you must get the number of rows, columns, and mines for the new game and create a new board for a new game.
When the user decides to quit the game, you would display their score as number of mines the user stepped on and number of mines cleared(the ones they didn’t step on) taking into consideration all the games the user played since the program was run.
Tip: You can display row and column numbers on board to make it easier for the user to read/know which row and column to select!
Requirements:
● You must provide a message telling which command line arguments are acceptable and how to pass them, if the user enters incorrect command-line arguments. Include an example!
● The user should be able to specify command line arguments in any order.
● You must not have functions over 15-20 lines long (-10 automatically)
● You must not use global variables (-10 automatically)
● After the user wins/loses, you must ask if they want to play again ○ If no, then end the game while displaying the total number of mines stepped and cleared for all the attempts the user played the game
○ If yes, then prompt for rows, cols, and mines for new game.
● You must not have any memory leaks (-10 automatically)
● You must detect these errors:
○ Invalid row or column to flag or open
○ Opening a cell that has already been opened
○ Flagging a cell that has been already flagged
Example run:







#include<stdio.h>
#include<stdlib.h>
int main(void){
int option = 3;
int r=0, c=0, m=0;
int R=0, C=0;
int**ar;
char p='|';
char s=' ';
char f='!';
char choice[3]=" ";
int i=0;
int j=0;
int x=0;
int y=0;
while(1){
D: printf(" Enter the number of rows, columns and
mines you want in the game\n");
printf("Example 9 9 9\n");
scanf("%d %d %d",&r,&c,&m);
A: if(m<=0 || r<=0 || c<=0){
printf("The number of rows, columns
and mines must be greater than zero\n");
printf("Re-enter the number of
rows,cols and mines\n");
scanf("%d %d
%d",&r,&c,&m);
goto A;
}
B: if(m>r*c){
printf("The number of mines should
be less than or equal to rxc \n");
printf("if r = 2 , c = 3, then m
should be less than or equal to 2x3 = 6\n");
printf("Re-enter the number of
mines\n");
scanf("%d",&m);
goto B;
}
E: for(i=0;i<r;i++){
for(j=0;j<=c;j++){
ar[i][j]=
-1;
printf("%c%c",p,s);
}
printf("\n");
}
for(i=0;i<r;i++){
for(j=0;j<=c;j++){
for(r=0;r<=m;r++){
x=(rand()%m)+1;
y=(rand()%m)+1;
}
if(ar[x][y]!=0){
ar[x][y]=0;
}
}
printf("\n");
}
printf("Flag(1) or Open(2)\n");
printf("Enter row, col: ");
scanf("%d %d",&R,&C);
if(ar[R+1][C+1]==0){
printf("You stepped on a mine!!!
You lose!");
for(i=0;i<r;i++){
for(j=0;j<=c;j++){
printf("%c%d%c",p,ar[i][j],s);
}
}
C: printf("Do you want to play
again? (1-yes, 2-no)\n");
scanf("%s",&choice);
if(choice == "yes"){
goto D;
}
else if(choice == "n"){
exit(0);
}else{
printf("you have
entered wrong choice\n");
goto C;
}
}
switch(option){
case 1:
if(ar[R+1][C+1]!=0){
ar[R+1][C+1]= -2;
for(i=0;i<r;i++){
for(j=0;j<=c;j++){
if(ar[r+1][c+1]== -2){
printf("%c%c%c",p,s,f);
}
printf("%c%d%c",p,ar[i][j],s);
}
}
}
break;
case 2:
if(ar[R+1][C+1]==0){
printf("You stepped on a mine!!!
You lose!");
for(i=0;i<r;i++){
for(j=0;j<=c;j++){
printf("%c%d%c",p,ar[i][j],s);
}
}
}
case 3:
goto E;
break;
default: printf("choice entered is
other tha 1 or 2\n");
break;
}
}
return 0;
}
Aim: By working on this assignment you should be able to: ● Create and use dynamic arrays ● Create, manipulate and store...
Program is in C++, program is called airplane reservation. It is suppose to display a screen of seating chart in the format 1 A B C D E F through 10. I had a hard time giving the seats a letter value. It displays a correct screen but when I reserve a new seat the string seats[][] doesn't update to having a X for that seat. Also there is a file for the struct called systemUser.txt it has 4 users...
Using java :
In this exercise, you need to implement a class that encapsulate
a Grid. A grid is a useful concept in creating board-game
applications. Later we will use this class to create a board game.
A grid is a two-dimensional matrix (see example below) with the
same number of rows and columns. You can create a grid of size 8,
for example, it’s an 8x8 grid. There are 64 cells in this grid. A
cell in the grid...
In Java Please Create A Program For The Following; Please Note: This program should be able accept changes to the values of constants ROWS and COLS when testing the codes. Switch2DRows Given a 2D array with ROWS rows and COLS columns of random numbers 0-9, re-order the rows such that the row with the highest row sum is switched with the first row. You can assume that 2D arrau represents a rectangular matrix (i.e. it is not ragged). Sample run:...
(C++) Please create a tic tac toe game. Must write a Player class to store each players’ information (name and score) and to update their information (increase their score if appropriate) and to retrieve their information (name and score).The players must be called by name during the game. The turns alternate starting with player 1 in the first move of round 1. Whoever plays last in a round will play second in the next round (assuming there is one).The rows...
Concepts tested by the program:
Working with one dimensional parallel arrays
Use of functions
Use of loops and conditional statements
Description
The Lo Shu Magic Square is a grid with 3 rows and 3 columns
shown below.
The Lo Shu Magic Square has the following properties:
The grid contains the numbers 1 – 9 exactly
The sum of each row, each column and each diagonal all add up
to the same number.
s is shown below:
Write a program that...
This program is in C++ which reserves flight seats. It uses a file imported to get the seat chart called "chartIn.txt" which looks like this 1 A B C D E F 2 A B C D E F It continues until row 10. Sorry unable to provide the chartIn.txt file. I am having issues with function displaySeats, it displays then but when it comes to 10 the row looks like this 1 0 A B C D E ,...
Can someone tell me why this is not printing in the screen. I know i commented out the first couple functions but the last one is not working. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- #include <stdio.h> #include <stdlib.h> #include <time.h> #define ROWS 5 #define COLS 5 #define FREE 2 #define SCALE 15 #define SHIFT 1 #define MAXVAL 75 #define FALSE 0 #define TRUE 1 void welcomeScreen(); void clearScreen(); void displayExplicitCard(); void displayCard(); void displayRandomCard(); void fillCardRand(); void setValue(); void displayBingoCard(); void initializeArrays (); int main...
I need a basic program in C to modify my program with
the following instructions:
Create a program in C that will:
Add an option 4 to your menu for "Play Bingo"
-read in a bingo call (e,g, B6, I17, G57, G65)
-checks to see if the bingo call read in is valid (i.e., G65 is
not valid)
-marks all the boards that have the bingo call
-checks to see if there is a winner, for our purposes winning
means...
Can I get help with adding the following to this code please? 1. When buying multiple tickets, if one of the seats selected is already taken, give a message like "Sorry, one or more of the seats selected is already taken." and prompt the user to select the seats all over. (Or if possible to make it suggest a location where the seats are together that the user can select instead) 2. Print the total cost after all of the...