-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainForm.cs
107 lines (93 loc) · 2.94 KB
/
MainForm.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Media;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PokiWord
{
public partial class MainForm : Form
{
// Initialize Needed Variables
Pokemon pokemon;
StringBuilder name, image, desc;
SoundPlayer bg = new SoundPlayer(Properties.Resources.bg_music);
public MainForm()
{
InitializeComponent();
bg.PlayLooping();
doubleBuffer(MainPanel);
doubleBuffer(PlayPanel);
}
// Click Play Button
private void play_Click(object sender, EventArgs e)
{
doubleBuffer(answer_box);
doubleBuffer(ok_box);
viewPokemon();
PlayPanel.BringToFront();
}
// Method to Avoid Flickering of Images
public void doubleBuffer(Panel panel)
{
typeof(Panel).InvokeMember("DoubleBuffered", BindingFlags.SetProperty
| BindingFlags.Instance | BindingFlags.NonPublic, null,
panel, new object[] { true });
}
// Clicking the Ok Button
private void ok_box_Click(object sender, EventArgs e)
{
displayMessageBox();
}
// Clicking the Ok Button
private void ok_text_Click(object sender, EventArgs e)
{
displayMessageBox();
}
// Display Pokemon in the Card
public void viewPokemon()
{
pokemon = new Pokemon();
string[] pokemon_data = pokemon.getRandomPokemon();
name = new StringBuilder(pokemon_data[0]);
image = new StringBuilder(pokemon_data[1]);
desc = new StringBuilder(pokemon_data[2]);
poke_name.Text = name.ToString();
poke_image.Image = (Image)Properties.Resources.ResourceManager.GetObject(image.ToString());
poke_description.Text = desc.ToString();
answer.Text = null;
}
// When Clicking Enter
private void answer_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
displayMessageBox();
}
}
// Check if the answer is correct
public string checkAnswer()
{
if (answer.Text.Equals(image.ToString().ToUpper()))
return "Correct";
else
return "Wrong";
}
// Display the Message box if correct or not
public void displayMessageBox()
{
DialogResult result = MessageBox.Show("Want to Guess Again?",
checkAnswer(), MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
viewPokemon();
else
this.Close();
}
}
}