0% found this document useful (0 votes)
21 views2 pages

Cod Joc Memorue

This document contains code for a memory game application written in C#. It defines classes and methods to initialize the game, display random images on picture boxes, start and reset a timer, handle clicks on the picture boxes to reveal matches, and reset the game. Key aspects include randomly assigning and hiding image resources on picture boxes, tracking matches with tags, and using timers to track game progress and trigger a reset after time expires.

Uploaded by

Diana DD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

Cod Joc Memorue

This document contains code for a memory game application written in C#. It defines classes and methods to initialize the game, display random images on picture boxes, start and reset a timer, handle clicks on the picture boxes to reveal matches, and reset the game. Key aspects include randomly assigning and hiding image resources on picture boxes, tracking matches with tags, and using timers to track game progress and trigger a reset after time expires.

Uploaded by

Diana DD
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

using

using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;

namespace joc_de_memorie
{
public partial class Form1 : Form
{
private bool _allowClick = true;
private PictureBox _primaghicire;
private readonly Random _random = new Random();
private readonly Timer _clickTimer = new Timer();
int ticks = 30;
readonly Timer timer = new Timer { Interval = 1000 };
public Form1()
{
InitializeComponent();
SetRandomImages();
HideImages();
StartGameTimer();
_clickTimer.Interval = 1000;
_clickTimer.Tick += _clickTimer_Tick;
}
private PictureBox{} PictureBoxes
{
get { return Controls.OfType<PictureBox>().ToArray();}
}
private static IEnumerable<Image> Images
{ get
{ return new Image[]
{ Resources.Img1,
Resources.Img2,
Resources.Img3,
Resources.Img4,
Resources.Img5,
Resources.Img6,
Resources.Img7,
Resources.Img8
};
}
}
private void StartGameTimer()
{ timer.Start();
timer.Tick += delegate
{ ticks --;
if(ticks == -1;
{ timer.Stop();
MessageBox.Show("Timpul a expirat.", "Joc de memorie", MessageBoxButton.OK,
MessageBoxIcon.Exclamation);
ResetImages();

}
var time = TimeSpan.FromSeconds(ticks);
lblTime.Text="00:" + timetoString("ss");
};
}
private void ResetImages()
{ foreach( var pic in PictureBoxes)
{pic.Tag=null;
pic.Visible=true;
}
HideImages();
SetRandomImages();
ticks=30;
timer.Start();
}
private void HideImages()
{ foreach ( var pic in PictureBoxes)
{ pic.Image= Resources.Img0;
}
}
private PictureBox GetFreeSlot()
{ int num;
do
{ num=_random.Next(0, PictureBoxes.Count());
}
while (PictureBoxes[num].Tag != null);
return PictureBoxes[num];
}
private void SetRandomImages()
{
foreach( var image in Images)
{ GetFreeSlot().Tag=image;
GetFreeSlot().Tag=image;
}
}
private void ClickImage(object sender, EventArgs e)

You might also like