-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.cs
More file actions
121 lines (94 loc) · 3.04 KB
/
code.cs
File metadata and controls
121 lines (94 loc) · 3.04 KB
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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
namespace SimonSays
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int onInList = 0;
List<int> pattern = new List<int>{};
Random rand = new Random();
bool playingBack = false;
void playback()
{
playingBack = true;
foreach (int color in pattern)
{
switch (color)
{
case 0:
RED.BackColor = Color.Red;
Thread.Sleep(400);
RED.BackColor = Color.Transparent;
break;
case 1:
YELLOW.BackColor = Color.Yellow;
Thread.Sleep(400);
YELLOW.BackColor = Color.Transparent;
break;
case 2:
GREEN.BackColor = Color.Green;
Thread.Sleep(400);
GREEN.BackColor = Color.Transparent;
break;
case 3:
BLUE.BackColor = Color.Blue;
Thread.Sleep(400);
BLUE.BackColor = Color.Transparent;
break;
}
Thread.Sleep(600);
}
playingBack = false;
}
void testCorrect(int color)
{
if (playingBack)
return;
if (pattern[onInList] == color)
onInList++;
else
{
MessageBox.Show($"WRONG PATTERN! FINAL SCORE: {pattern.Count.ToString()}");
onInList = 0;
pattern = new List<int>();
this.Close();
}
if (onInList >= pattern.Count)
{
pattern.Add(rand.Next(0, 4));
onInList = 0;
new Thread(playback).Start();
}
ScoreLabel.Text = ($"Score: {pattern.Count.ToString()}");
PatternLabel.Text = ($"Item within pattern: {onInList.ToString()}");
}
private void Form1_Load(object sender, EventArgs e)
{
pattern.Add(rand.Next(0,4));
new Thread(playback).Start();
}
private void RED_Click(object sender, EventArgs e)
{
testCorrect(0);
}
private void YELLOW_Click(object sender, EventArgs e)
{
testCorrect(1);
}
private void GREEN_Click(object sender, EventArgs e)
{
testCorrect(2);
}
private void BLUE_Click(object sender, EventArgs e)
{
testCorrect(3);
}
}
}