Skip to content

Instantly share code, notes, and snippets.

@MechMK1
Created November 9, 2016 18:03
Show Gist options
  • Select an option

  • Save MechMK1/ee95f285602d37b6a2b28922ac85c4b7 to your computer and use it in GitHub Desktop.

Select an option

Save MechMK1/ee95f285602d37b6a2b28922ac85c4b7 to your computer and use it in GitHub Desktop.
Memory implemented in C#
using System;
namespace Memory
{
class Program
{
/// <summary>
/// Motives of the pairs
/// </summary>
private static char[] displaySymbols = { '@', '☺', '☻', '●', 'Ⱡ', '♫', '♪', '♦', '♥', '♣', '♠', '♂', '♀', '☼', '█', '▲', '℗', 'Ω' };
/// <summary>
/// Size of the play field
/// </summary>
private static int size = 4;
static void Main(string[] args)
{
//Represents where each pair is located. This should only be read from during gameplay, not being written to
char[,] gameArray = new char[size, size];
//Represents what the player sees. Should only be written to and not being read from during gameplay
char[,] displayArray = new char[size, size];
PrintWelcome();
FillGameArray(gameArray);
FillDisplayArray(displayArray, '?');
PlayGame(gameArray, displayArray);
}
/// <summary>
/// Prints a welcome message
/// </summary>
private static void PrintWelcome()
{
Console.WriteLine("Herzlich Willkommen zu meinem Memory Spiel");
Console.WriteLine("------------------------------------------");
Console.WriteLine("Bitte geben Sie jeweils 2 Koordinaten ein, die Sie vergleichen wollen.");
Console.WriteLine("z.B.: 3132 vergleicht (3,1) mit (3,2)");
Console.WriteLine();
}
/// <summary>
/// Fills the gameArray with pairs of symbols
/// </summary>
/// <param name="gameArray">The array containing the pairs</param>
private static void FillGameArray(char[,] gameArray)
{
int x;
int y;
Random random = new Random();
for (int pairs = 0; pairs < (size*size)/2; pairs++)
{
for (int i = 0; i < 2; i++)
{
do
{
x = random.Next(size);
y = random.Next(size);
} while (gameArray[x, y] != 0);
gameArray[x, y] = displaySymbols[pairs];
}
}
}
/// <summary>
/// Fills the displayArray with placeholder characters
/// </summary>
/// <param name="displayArray">The array which the player sees</param>
/// <param name="placeholder">The placeholder indicating a "face-down" card</param>
private static void FillDisplayArray(char[,] displayArray, char placeholder)
{
for (int y = 0; y < size; y++)
{
for (int x = 0; x < size; x++)
{
displayArray[x, y] = placeholder;
}
}
}
/// <summary>
/// The main loop for the game
/// </summary>
/// <param name="gameArray">The array containing all the pairs</param>
/// <param name="displayArray">The array which the user sees</param>
private static void PlayGame(char[,] gameArray, char[,] displayArray)
{
//TODO: Implementiere das Spiel Memory
//Tipp: Wenn du Probleme hast, sieh dir dazu meine Musterlösung an.
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment