*****IN C# PLEASE*****

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

*****IN C# PLEASE*****

Post by answerhappygod »

*****IN C# PLEASE*****
In C Please 1
In C Please 1 (189.12 KiB) Viewed 13 times
In C Please 2
In C Please 2 (117.05 KiB) Viewed 13 times
Description: In this assignment you'll implement the game Connect 4 in C#. If you've never heard of Connect 4. The following short video will help you understand the game play: The game board has seven (7) columns and six (6) rows. There are two (2) players, Red and Yellow. Each player takes turns dropping a token of their color into one of the columns (it falls to the bottom of the column). The goal is to get 4 of your color in a row either horizontally, vertically or diagonally. Tasks: Create a custom Exception called ColumnFull. • It should have a constructor which takes in a message and calls it's parent's constructor with that message. Create a class ConnectFour it should have: • A two dimensional (2D) array with 6 rows and 7 columns. Each should hold a character. • A string which keeps track of who's turn it is (Red or Yellow) A character which keeps track of the next token to play (R for red or Y for Yellow). • A constructor which takes no parameters o Initialize all spaces in the 2D array to an empty space ** o Set the turn variable to Red, set the token to R • A method called nextTurn which takes no parameters. o If the current turn is Red, set the turn variable to Yellow and the token to Y, otherwise set the turn variable to Red and the token to R. • A method called nextAvailablePosition which takes in a column number and returns an int. o This method should look at the column that was passed in, and find the first empty spot in the column. o I.e. in your 2D array start at the bottom (row 5) in that column and check if that cell is an empty space. If it is, return 5, otherwise check row 4, then 3, then 2, 1 and finally 0. If cell 0 is full return -1 to indicate the column is full. A method called dropPiece which takes in a column and a token. It places the piece into the appropriate row of the 2D array (use nextAvailablePosition to find this). If the row is full, it should throw an exception called ColumnFull. • Add the following override for toString/ToString so you can see the state of the board:
C# public override string ToString() { String to return=" 0 1 2 3 6"; \n"; for(int i=0;i<6;i++) { to_return+="\n---- } } } \n"; to_return+="| "; for(int j = 0; j<7;j++) { to_return+=board[i,j]+" | "; } to_return+="\n--- return to return; 4 5
● In your main method do the following: o Instantiate a Connect4 object o Using a loop keep prompting the user until they enter 9 to exit Which column would Red like to go in (9 to quit) Read in their answer. ■ ■ ■ ■ If they give you a value between 0 and 6: • • Call the dropPiece method in your Connect4 object Call the nextTurn method in your Connect4 object Check to ensure you didn't hit an exception, if you did, let the user know the column is full, and let the SAME user go again. If the user enters 9, exit the loop Note: This version will not notice if you won or not, it's up to the users to keep track of who won. You are not required to determine who won, just allow people to play the game as specified above.
Sample Output: I I I I 0 1 2 | | | 0 I I 0 I I T T Which column would Red like to go in (9 to quit) 3 I T | | | I I T | T 1 2 | I T | T I T I 1 3 | | T 2 3 | I | R | | T | T T | | I | Which column would Yellow like to go in (9 to quit) 4 | 4 5 6 | I I I | I T I 3 T | | | | I I I I | I I | | | 4 5 6 4 5 6 T I 1 | | | | | | | | I | I | | R | Y | | I I I | | I Which column would Red like to go in (9 to quit) 3
Rubric: • Custom Exception "ColumnFull" class (15 points total): o Correctly extends Exception (5 points) o Has an overloaded constructor which takes a string and calls it's parents constructor (10 points) ConnectFour class (70 points total): o Defines the board as a 6x7 2D array of characters (5 points) o Constructor (15 points total) Initializes all cells to (10 points) Sets turn and token variables (5 points) nextTurn() method (10 points total) ■ Correctly flips turn from Red to Yellow and vice versa (10 points) o nextAvailablePosition method (15 points total) Correctly finds the first empty row (10 points) Correctly returns -1 if the column is full (5 points) o dropPiece method (15 points total) ■ Adds the appropriate token to the correct cell of the 2d array (5 points) ■ Correctly throws an exception when the column is full (10 points) otoString override (5 points) ■ Copied and pasted correctly (5 points) Main Method (20 points total) Instantiates the object correctly (2 points) o Correctly sets up a loop which continues until the user enters 9 (5 points) Prompts and reads in the users column choice (5 points) o o Correctly catches any thrown exceptions (8 points)
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply