Write an efficient program that, given a color board (provided below), user has to fill up the color board with red ‘r’, green ‘g’ or blue ‘b’. you have to make sure that no color is repeated on connected positions. Ask user for the positions one by one for color filling. If the color filling is appropriate then increase the score, if it conflicts then decrease the score.
Your program should ask the user to enter his or her name before starting the game and show the score at the end. There should be a list of top 10 highest scorer and should be updated after every game. You have to:
· Show the top scorer list on start of the game
· Show the score and remaining tries after each try
· Show the color board, total score and the rank of the user at the end of the game
In the following color board, a ‘0’ indicates not included position, an empty position indicates the place you have to fill colors on.
using System;
namespace ArrayApplication {
class MyArray {
static void Main(string[] args) {
/* an array with 5 rows and 2 columns*/
int[,] a = new int[8, 8] {{01, 02, 03, 04, 05, 06, 07, 08},
{09, 10, 11, 12, 13, 14, 15, 16},
{17, 18, 19, 20, 21, 22, 23, 24},
{25, 26, 27, 28, 29, 30, 31, 32},
{33, 34, 35, 36, 37, 38, 39, 40},
{41, 42, 43, 44, 45, 46, 47, 48},
{49, 50, 51, 52, 53, 54, 55, 56},
{57, 58, 59, 60, 61, 62, 63, 64}};
int i, j;
/* output each array element's value */
for (i = 0; i < 8; i++) {
for (j = 0; j < 8; j++) {
Console.Write(a[i,j] + " ");
}
Console.Write("\n");
}
int score = 0, position, selector;
while (true) {
bool gameOver = false;
Console.WriteLine("Enter position according to above:");
position = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("1. red.");
Console.WriteLine("2. green.");
Console.WriteLine("3. blue");
selector = Convert.ToInt32(Console.ReadLine());
for (i = 0; i < 8; i++) {
for (j = 0; j < 8; j++) {
if (position == a[i, j]) {
a[i, j] = selector;
}
}
}
for (i = 0; i < 8; i++) {
for (j = 0; j < 8; j++) {
if (a[i, j] == a[i, j + 1]) {
gameOver = true;
}
}
}
if (gameOver) {
break;
}
else {
for (i = 0; i < 8; i++) {
for (j = 0; j < 8; j++) {
Console.Write(a[i,j] + " ");
}
Console.Write("\n");
}
score++;
Console.WriteLine(score);
}
}
}
}
}
Comments
Leave a comment