C sharp - memorama

 
Vista:
Imágen de perfil de memorama
Val: 3
Ha aumentado su posición en 17 puestos en C sharp (en relación al último mes)
Gráfica de C sharp

memorama

Publicado por memorama (3 intervenciones) el 03/06/2019 18:49:39
tengo un juego de memorama pero quiero que al encontrar las parejas estos desaparescan.. alguna ayuda. se les agradece.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Joan
Val: 372
Plata
Ha disminuido 1 puesto en C sharp (en relación al último mes)
Gráfica de C sharp

memorama

Publicado por Joan (3 intervenciones) el 03/06/2019 19:27:30
si, claro... pero.... podrías mostrar el código?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de memorama
Val: 3
Ha aumentado su posición en 17 puestos en C sharp (en relación al último mes)
Gráfica de C sharp

memorama

Publicado por memorama (3 intervenciones) el 03/06/2019 19:30:41
1
2
3
4
5
6
7
8
9
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections;
using System.Media;
 
namespace Seleccion_de_Cartas_Juego
{
    public partial class Juego1 : Form
    {
 
 
 
        public Juego1()
        {
            InitializeComponent();
 
        }
 
        private void Juego1_Load(object sender, EventArgs e)
        {
            InicioDeJuego();
        }
 
        public void InicioDeJuego()
        {
            timer1.Enabled = false;
            timer1.Stop();
 
            cantidadeM.Text = "0";
            mostrarmsj.Text = " ";
 
            cartasVolteadas = 0;
            Movimientos = 0;
            panelJuego.Controls.Clear();
            CartasNumeradas = new List<string>();
            CartaRevueltas = new List<string>();
            CartaSeleccionadas = new ArrayList();
            for (int i = 0; i < 6; i++)
            {
                CartasNumeradas.Add(i.ToString());
                CartasNumeradas.Add(i.ToString());
                //CartasNumeradas.Add(i.ToString());
 
            }
 
            var numAleatorio = new Random();
            var resultado = CartasNumeradas.OrderBy(item => numAleatorio.Next());
 
            foreach (string valorCarta in resultado)
            {
                CartaRevueltas.Add(valorCarta);
            }
            var juegoPanel = new TableLayoutPanel();
 
            juegoPanel.RowCount = Filas;
            juegoPanel.ColumnCount = Filas;
 
            juegoPanel.RowCount = Columnas;
            juegoPanel.ColumnCount = Columnas;
 
 
            for (int i = 0; i < Columnas; i++)
            {
                var porcentaje = 150F / (float)Columnas - 10;
                juegoPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, porcentaje));
                juegoPanel.RowStyles.Add(new RowStyle(SizeType.Percent, porcentaje));
            }
 
            for (int j = 0; j < Filas; j++)
            {
                var porcentaje = 150F / (float)Filas - 10;
                juegoPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, porcentaje));
                juegoPanel.RowStyles.Add(new RowStyle(SizeType.Percent, porcentaje));
 
            }
 
 
 
 
 
            int fichas = 1;
 
            for (int i = 0; i < Columnas; i++)
            {
 
                for (int j = 0; j < Filas; j++)
                {
                    var cartasJuego = new PictureBox();
                    cartasJuego.Name = string.Format("{0}", fichas);
 
                    cartasJuego.Dock = DockStyle.Fill;
                    cartasJuego.SizeMode = PictureBoxSizeMode.StretchImage;
                    cartasJuego.Image = Properties.Resources.fondo;
                    cartasJuego.Cursor = Cursors.Hand;
                    cartasJuego.Click += carta_Click;
                    juegoPanel.Controls.Add(cartasJuego, i, j);
                    fichas++;
 
 
 
                }
            }
 
            juegoPanel.Dock = DockStyle.Fill;
            panelJuego.Controls.Add(juegoPanel);
        }
 
        private void carta_Click(object sender, EventArgs e)
        {
            if (CartaSeleccionadas.Count < 2)
            {
                SoundPlayer Player = new SoundPlayer();
                Player.SoundLocation = @"C:\sonido\carta.wav";
                Player.Play();
 
                Movimientos++;
                cantidadeM.Text = Convert.ToString(Movimientos);
                var seleccionadasPorUsuario = (PictureBox)sender;
 
                actualCarta = Convert.ToInt32(CartaRevueltas[Convert.ToInt32(seleccionadasPorUsuario.Name) - 1]);
 
                seleccionadasPorUsuario.Image = recucuperarImagen(actualCarta);
                CartaSeleccionadas.Add(seleccionadasPorUsuario);
 
                if (CartaSeleccionadas.Count == 2)
                {
                    CartaTemporal1 = (PictureBox)CartaSeleccionadas[0];
                    CartaTemporal2 = (PictureBox)CartaSeleccionadas[1];
                    //CartaTemporal3 = (PictureBox)CartaSeleccionadas[2];
 
                    int carta1 = Convert.ToInt32(CartaRevueltas[Convert.ToInt32(CartaTemporal1.Name) - 1]);
                    int carta2 = Convert.ToInt32(CartaRevueltas[Convert.ToInt32(CartaTemporal2.Name) - 1]);
                    //int carta3 = Convert.ToInt32(CartaRevueltas[Convert.ToInt32(CartaTemporal3.Name) - 1]);
 
 
                    if (carta1 != carta2 /*|| carta2!=carta3*/)
                    {
                        timer1.Enabled = true;
                        timer1.Start();
 
                    }
                    else
                    {
                        cartasVolteadas++;
                        if (cartasVolteadas == 6)
                        {
                            mostrarmsj.Text = "Juego Completado";
                        }
 
                        CartaSeleccionadas.Clear();
 
                        CartaTemporal1.Enabled = false;
                        CartaTemporal2.Enabled = false;
                        //CartaTemporal3.Enabled = false;
 
                    }
 
 
 
 
                }
            }
 
        }
 
        public Bitmap recucuperarImagen(int numeroImagen)
        {
            Bitmap tiempImagen = new Bitmap(200, 100);
            switch (numeroImagen)
            {
                case 0: tiempImagen = Properties.Resources.img6;
                    break;
 
 
 
                default: tiempImagen = (Bitmap)Properties.Resources.ResourceManager.GetObject("img" + numeroImagen);
                    break;
            }
            return tiempImagen;
 
        }
 
        private void Timer1_Tick(object sender, EventArgs e)
        {
            int virarCarta = 1;
            if (virarCarta == 1)
            {
                CartaTemporal1.Image = Properties.Resources.fondo;
                CartaTemporal2.Image = Properties.Resources.fondo;
                //CartaTemporal3.Image = Properties.Resources.fondo;
 
                CartaSeleccionadas.Clear();
                virarCarta = 0;
 
                timer1.Stop();
 
 
 
 
            }
        }
 
        private void Mm_Click(object sender, EventArgs e)
        {
 
        }
 
        private void Mostrarmsj_Click(object sender, EventArgs e)
        {
 
        }
 
        List<string> CartaRevueltas;
        ArrayList CartaSeleccionadas;
        int Movimientos = 0;
 
        int Columnas = 4;
         int Filas = 3;
        int cartasVolteadas = 0;
        List<string> CartasNumeradas;
        PictureBox CartaTemporal2;
        PictureBox CartaTemporal1;
        //PictureBox CartaTemporal3;
 
        int actualCarta = 0;
 
        private void Reiniciar_Click_1(object sender, EventArgs e)
        {
            InicioDeJuego();
        }
 
        private void PictureBox1_Click(object sender, EventArgs e)
        {
            Form Menu = new Menu();
            this.Hide();
            Menu.ShowDialog();
 
 
        }
    }
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar