Skip to content

Commit

Permalink
Merge pull request #7 from Noorani-MM/main
Browse files Browse the repository at this point in the history
Program
  • Loading branch information
Noorani-MM authored Dec 29, 2022
2 parents cd9409f + 038a5b3 commit 08a665a
Show file tree
Hide file tree
Showing 14 changed files with 472 additions and 47 deletions.
15 changes: 13 additions & 2 deletions Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,30 @@ public partial class Form1 : Form
protected string ResourceFile = "Forms/Main.json";
public string Lang { get; set; }
public Form1()
{
DataSet("Fa");
}

public Form1(string lang)
{
DataSet(lang);
}

protected void DataSet(string lang)
{
InitializeComponent();

if (Lang == null || Lang == String.Empty)
Lang = "Fa";
Lang = lang;
string resource = File.ReadAllText($"{Application.StartupPath}/Resources/{Lang}/{ResourceFile}");
_FormModel model = JsonSerializer.Deserialize<_FormModel>(resource);

this.Text = model.Text;
rchTextDescription.Text = model.Description;

btnStart.Text = model.Buttons.Start.Text;
}


private void btnStart_Click(object sender, EventArgs e)
{
new Game(this.Lang).ShowDialog();
Expand Down
78 changes: 44 additions & 34 deletions Game.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

110 changes: 102 additions & 8 deletions Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,121 @@ namespace Typist.App
public partial class Game : Form
{
protected string ResourceFile = "Forms/Game.json";
protected string WordResource = "Words.txt";
protected string Lang{ get; set; }
protected List<string> Words { get; set; }
protected int count_word;
protected int score = 0;
protected int minute = 1;
protected int second = 0;
protected int gift = 0;
protected List<int> SelectedWords { get; set; }
public Game()
{
Lang = "Fa";
DataSet(Lang);
}
public Game(string lang)
{
Lang = lang;
DataSet(Lang);
}

protected void DataSet(string Lang)
{
InitializeComponent();

string resource = File.ReadAllText($"{Application.StartupPath}/Resources/Fa/{ResourceFile}");
string resource = File.ReadAllText($"{Application.StartupPath}/Resources/{Lang}/{ResourceFile}");
_FormModel model = JsonSerializer.Deserialize<_FormModel>(resource);

Words = File.ReadAllLines($"{Application.StartupPath}/Resources/{Lang}/{WordResource}").ToList();

count_word = Words.Count;

this.Text = model.Text;
lblScore.Text = model.Labels.Score.Text;
btnNext.Text = model.Buttons.Next.Text;

SelectedWords = new List<int>();
}
public Game(string Lang)

private void Game_Load(object sender, EventArgs e)
{
InitializeComponent();
ChangeText();
}

string resource = File.ReadAllText($"{Application.StartupPath}/Resources/{Lang}/{ResourceFile}");
_FormModel model = JsonSerializer.Deserialize<_FormModel>(resource);
private void timer1_Tick(object sender, EventArgs e)
{
time_set();
}

this.Text = model.Text;
lblScore.Text = model.Labels.Score.Text;
btnNext.Text = model.Buttons.Next.Text;
private void time_set()
{
if (second == 0)
{
if (minute == 0)
{
timer1.Enabled = false;
string resource = File.ReadAllText($"{Application.StartupPath}/Resources/{Lang}/MessageBoxes.json");
Models.MessageBox.MessageBoxes mbx = JsonSerializer.Deserialize<Models.MessageBox.MessageBoxes>(resource);

mbx.FinishGame.Message = mbx.FinishGame.Message.Replace("{score}", score.ToString("00"));
mbx.FinishGame.Show();

txtAnswer.Enabled = txtTest.Enabled = btnNext.Enabled = false;
return;
}

second = 60;
minute--;
}

second--;

lblMinute.Text = minute.ToString("00");
lblSecound.Text = second.ToString("00");

}

private void btnNext_Click(object sender, EventArgs e)
{
// Your text is correct
if (txtAnswer.Text.Trim().ToUpper() == txtTest.Text.ToUpper())
{
score++;
/*
gift++;
if (gift % 3 == 0)
{
second++;
}
*/
lblScoreValue.Text = score.ToString("00");
ChangeText();
txtAnswer.Text = String.Empty;
txtAnswer.Focus();
}
txtAnswer.SelectAll();
txtAnswer.Focus();
}

private void ChangeText()
{
int index = 0;
Random random = new Random();
do
{
index = random.Next(0, count_word - 1);
} while (selectedBefore(index));

SelectedWords.Add(index);

txtTest.Text = Words[index];
}

private bool selectedBefore(int index)
{
return SelectedWords.Contains(index);
}
}
}
3 changes: 3 additions & 0 deletions Game.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
1 change: 1 addition & 0 deletions Models/Main/_FormModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Typist.App.Models.Main
public class _FormModel
{
public string Text { get; set; }
public string Description { get; set; }
public Button Buttons { get; set; }
}

Expand Down
19 changes: 19 additions & 0 deletions Models/RegisterLanguage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Typist.App.Models
{
public class RegisterLanguage
{
public List<Language> Languages { get; set;}
}

public class Language
{
public string Name { get; set; }
public string Directory { get; set; }
}
}
2 changes: 1 addition & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Application.Run(new SelectLanguage());
}
}
}
Loading

0 comments on commit 08a665a

Please sign in to comment.