Question: In C#, and using the starting code below, design and implement a program that allows the user to play a version of Concentration that matches

In C#, and using the starting code below, design and implement a program that allows the user to play a version of Concentration that matches synonyms. Concentration, is a card game in which all of the cards are laid face down on a surface and two cards are flipped face up over each turn. The object of the game is to turn over pairs of matching cards. The program should begin by filling an array of strings with 10 pairs of synonyms and shuffling them. The program should display the 4 row by 5 column board with ? # ? for each card face down (where # is the number of the card 1 - 20). The user should be allowed to enter the number of the card that the user wants to turn over and the program should display the word in that location on the board. The user should then be allowed to enter a second card and the word in that location should also be displayed. The pair should be removed from the board when the pair matches and turned face down when they do not. The user continues to play until all 20 cards are removed from the board.

STARTING CODE:

using System;

namespace Concentration

{

class Program

{

const int ROWS = 4;

const int COLUMNS = 5;

const int SIZE = 20;

const int PAUSE = 2;

static void Main(string[] args)

{

string[] board;

string[] words = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" };

string[] matchingWords = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };

int matchesRemaining = 10;

/*

create the board, shuffle the board

do

index1 = -1

index2 = -1

draw the board

get index1

draw the board again so the user can see what they chose

get index2

draw the board again

Pause

if there's a match

display a message

decrement matchesRemaining

set board at index1 and index2 to an empty string

end if

Pause

while there are still words on the board

Display a congratulatory message

*/

}

static string[] CreateBoard(string[] words, string[] matches)

{

string[] board = new string[SIZE];

// add the word and add the matching words

return board;

}

static void Shuffle(string[] board)

{

}

static int GetInt(string label, int min, int max)

{

return 0;

}

static int GetIndex(string[] board, int otherIndex)

{

/*

do

index = getInt

while index != otherIndex and there's an empty string in the board at that index

return the index

*/

return 0;

}

static bool IsMatch(string[] board, string[] words, string[] matchingWords, int index1, int index2)

{

}

static void Pause()

{

System.Threading.Thread.Sleep(TimeSpan.FromSeconds(PAUSE));

}

// these 2 methods can be used for drawing the board on the screen

// center is called by DrawBoard

public static String Center(String text, int len)

{

if (len <= text.Length)

return text.Substring(0, len);

int before = (len - text.Length) / 2;

int after = len - text.Length - before;

return new String(' ', before) + text + new String(' ', after);

}

static void DrawBoard(string[] board, int index1, int index2)

{

Console.Clear();

int index = 0;

string top = ".=============";

string second = "| ";

string middle = "|";

string output;

for (int r = 0; r < ROWS; r++)

{

for (int c = 0; c < COLUMNS; c++)

Console.Write(top);

Console.Write(". ");

for (int c = 0; c < COLUMNS; c++)

Console.Write(second);

Console.Write("| ");

for (int c = 0; c < COLUMNS; c++)

{

if (index == index1 || index == index2)

output = board[index];

else if (board[index] == "")

output = "";

else

output = "?" + (index + 1) + "?";

output = Center(output, 13);

Console.Write(middle + output);

index++;

}

Console.Write("| ");

for (int c = 0; c < COLUMNS; c++)

Console.Write(second);

Console.Write("| ");

}

for (int c = 0; c < COLUMNS; c++)

Console.Write(top);

Console.Write(". ");

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!