Question

In: Computer Science

I am building a game in C programming language where I need to add objects of...

I am building a game in C programming language where I need to add objects of various length into a game board. The game board is 8X8 and we must account for the boundaries for the board and not go over them with our objects. The boards upper left corner is at 0x0 and we must return 1 if it fits and -1 if it does not fit.
I have the following 2 functions to start with:

```int add_object_vert(int r, int s, int len){}```
and
```int add_object_horiz(int r, int s, int len){}```
Thanks in advance!

Solutions

Expert Solution

Output

code


#include <stdio.h>

int add_object_horiz();
int add_object_vert();
int inputrow();
int inputcol();
int inputval();
int x[8][8]={0};
int main()
{
int side=0;
printf("If you want object inset horizontaly press 1 or press 2 for vertically \n");
scanf("%d",&side);

  
if(side==1)
{
add_object_horiz();

}
else{
add_object_vert();

}
  
  
  
  
return 0;
}
int add_object_horiz(){
  
  
int r=inputrow();
int s=inputcol();
int val=inputval();
  
if((r<8)&&(s<8))
{
x[r][s]=val;
add_object_horiz();
}
else{
int i, j;
for ( i = 0; i < 8; i++ ) {

for ( j = 0; j < 8; j++ ) {
printf("x[%d][%d] = %d\n", i,j, x[i][j] );
}
}
return -1;
}
  
  
}
int add_object_vert(){
  
int r=inputrow();
int s=inputcol();
int val=inputval();
  
if((r<8)&&(s<8))
{
x[r][s]=val;
add_object_horiz();
}
else{
int i, j;
for ( i = 0; i < 8; i++ ) {

for ( j = 0; j < 8; j++ ) {
printf("x[%d][%d] = %d\n", i,j, x[i][j] );
}
}
return -1;
}
  
}

int inputrow()
{
int r;
  
printf("Enter the row number\n");
scanf("%d",&r);
return r;
  
}
int inputcol()
{
int s;
  
printf("Enter the column number\n");
scanf("%d",&s);
return s;
}
int inputval()
{
int len;
  
printf("Enter the length\n");
scanf("%d",&len);
return len;
}


Related Solutions

C programming language. **I am aware that I am only supposed to ask one question so...
C programming language. **I am aware that I am only supposed to ask one question so if you cant do all of this could you please do part 2? thank you! This lab, along with your TA, will help you navigate through applying iterative statements in C. Once again we will take a modular approach to designing solutions to the problem below. As part of the lab you will need to decide which C selection structure and iterative structure is...
C programming language. **I am aware that I am only supposed to ask one question so...
C programming language. **I am aware that I am only supposed to ask one question so if you cant do all of this could you please do part 3? thank you! This lab, along with your TA, will help you navigate through applying iterative statements in C. Once again we will take a modular approach to designing solutions to the problem below. As part of the lab you will need to decide which C selection structure and iterative structure is...
How do I add additional command line arguments in C++? I am working on a programming...
How do I add additional command line arguments in C++? I am working on a programming assignment that has the user input a file into the command line and then they have the option to also add a series of other arguments to the command line. I know how to accept the text file from the command line by using: int main(int argc, char *argv[]) { /.../ } Then filename(argv[1]) would be the text file that they put into the...
Note: I need a code and other requirement Note: programming language is c++ If you need...
Note: I need a code and other requirement Note: programming language is c++ If you need more information, please clarify what information you want. consider solving the equation sin(x) - e^(-x) = 0 write a computer program to solve the given equation using: 1- bisection method 2- fixed-point method 3- newton's intervals: {0,1},{1,2},{2,3},{3,4},{4,5},{5,6},{6,7},{7,8},{8,9},{9,10} choose accuracy E = 10^(-5) Make sure you document your program Requirement : 1- Mathematical justification 2- algorithem description 3- code (program) with documentation 4-output: roots ,...
I need programing in C language (not C#,C++) Sheldon Game RPSLS: - Stone: Win against Scissors...
I need programing in C language (not C#,C++) Sheldon Game RPSLS: - Stone: Win against Scissors who destroys and against Lizard who bursts,ties with himself, and loses to Rock Covering Paper and Spock that vaporizes the stone. - Role: Win against Stone who he covers and against Spock who refutes, tie with himself, and loses against Scissors who cut it and against Lizard who eat. - Scissors: Win against Paper who cuts and against Lizard who decapitates, tie with himself,...
Lab 1 Write a program in the C/C++ programming language to input and add two fractions...
Lab 1 Write a program in the C/C++ programming language to input and add two fractions each represented as a numerator and denominator. Do not use classes or structures. Print your result (which is also represented as a numerator/denominator) to standard out. If you get done early, try to simplify your result with the least common denominator. The following equation can be used to add fractions: a/b + c/d = (a*d + b*c)/(b*d) Example: 1/2 + 1/4 = ( 1(4)...
The following is for C programming language: I want to scan for initials in a line...
The following is for C programming language: I want to scan for initials in a line of text. my line of text is as follows: 12345 3.5000 a j 12346 4.1000 s p The first number represents the student ID, the second number represents the gpa, the third character represents the first initial and the fourth character represents the last initial of the student. My text file contains these values. The following is my code: fscanf(fp, "%d %c %c", &studentID,...
Use the Python programming language to complete below (I need the New Answer for this, and...
Use the Python programming language to complete below (I need the New Answer for this, and please provide the screenshot of the source code. Thank you!): Write a function to seek for all even numbers and odd numbers in the middle of two number A and B. Print even and odd numbers in 1 and 2020 (including both these two numbers)
Use the Python programming language to complete below (I need the New Answer for this, and...
Use the Python programming language to complete below (I need the New Answer for this, and please provide the screenshot of the source code. Thank you!): A website requests an user to input his account password. Write a program to examize the validity of the password. The valid password must consists of: At least 1 letter in [a-z] At least 1 number in [0-9] At least a letter in [A-Z] (capital) At least one special letter in [$#@] At least...
Using c# programming language Write a program that mimics a lottery game. Have the user enter...
Using c# programming language Write a program that mimics a lottery game. Have the user enter 3 distinct numbers between 1 and 10 and match them with 3 distinct, randomly generated numbers between 1 and 10. If all the numbers match, then the user will earn $10, if 2 matches are recorded then the user will win $3, else the user will lose $5. Keep tab of the user earnings for, let say 5 rounds. The user will start with...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT