diff options
author | emkael <emkael@tlen.pl> | 2012-11-14 12:17:24 +0000 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2012-11-14 12:17:24 +0000 |
commit | 258f973cf4e3f46f6983c2d6a1218f87b8fa3d0d (patch) | |
tree | 1b77b54db836bc88fec18444ecb878af57d80e9b | |
parent | 0e48a8da24e2d534947730a31babdaaf8c3ad8fb (diff) |
* .dealer file generating
git-svn-id: https://svn.emkael.info/an9k@5 05ec0d5d-773b-4d93-9e23-c81a7ac79feb
-rw-r--r-- | Analizator9000/Analizator9000.sln | 4 | ||||
-rw-r--r-- | Analizator9000/Analizator9000/DealerParser.cs | 40 | ||||
-rw-r--r-- | Analizator9000/Analizator9000/Form1.Designer.cs | 21 | ||||
-rw-r--r-- | Analizator9000/Analizator9000/Form1.cs | 31 | ||||
-rw-r--r-- | Analizator9000/Analizator9000/Program.cs | 1 |
5 files changed, 85 insertions, 12 deletions
diff --git a/Analizator9000/Analizator9000.sln b/Analizator9000/Analizator9000.sln index 90596ad..3497658 100644 --- a/Analizator9000/Analizator9000.sln +++ b/Analizator9000/Analizator9000.sln @@ -4,6 +4,10 @@ Microsoft Visual Studio Solution File, Format Version 11.00 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Analizator9000", "Analizator9000\Analizator9000.csproj", "{9E1F05BE-2798-488B-9A4C-C1C25665BDDD}"
EndProject
Global
+ GlobalSection(SubversionScc) = preSolution
+ Svn-Managed = True
+ Manager = AnkhSVN - Subversion Support for Visual Studio
+ EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
diff --git a/Analizator9000/Analizator9000/DealerParser.cs b/Analizator9000/Analizator9000/DealerParser.cs index 2d512c0..ee3ea17 100644 --- a/Analizator9000/Analizator9000/DealerParser.cs +++ b/Analizator9000/Analizator9000/DealerParser.cs @@ -108,5 +108,45 @@ namespace Analizator9000 }
}
}
+ public String saveFile()
+ {
+ String filename = "an9k-" + DateTime.Now.ToString("yyyyMMddHHmmssFFF") + ".dealer";
+ StreamWriter file = new StreamWriter("files\\"+filename);
+ String predealStr = "";
+ String suitLetters = "SHDC";
+ foreach (KeyValuePair<String, String[]> pre in this.predeal)
+ {
+ List<String> hand = new List<String>();
+ for (int i = 0; i < pre.Value.Length; i++)
+ {
+ if (pre.Value[i].Trim().Length > 0)
+ {
+ hand.Add(suitLetters[i] + pre.Value[i].Trim());
+ }
+ }
+ if (hand.Count > 0)
+ {
+ predealStr += pre.Key + " " + hand.Aggregate((a, b) => a + ", " + b) + "\n";
+ }
+ }
+ if (predealStr.Length > 0)
+ {
+ file.WriteLine("predeal");
+ file.Write(predealStr);
+ }
+ if (this.condition.Trim().Length > 0)
+ {
+ file.WriteLine("condition");
+ file.Write(this.condition);
+ }
+ file.WriteLine("generate");
+ file.WriteLine(this.generate);
+ file.WriteLine("produce");
+ file.WriteLine(this.produce);
+ file.WriteLine("action");
+ file.WriteLine("printoneline");
+ file.Close();
+ return filename;
+ }
}
}
diff --git a/Analizator9000/Analizator9000/Form1.Designer.cs b/Analizator9000/Analizator9000/Form1.Designer.cs index 8180b97..5c086d5 100644 --- a/Analizator9000/Analizator9000/Form1.Designer.cs +++ b/Analizator9000/Analizator9000/Form1.Designer.cs @@ -31,7 +31,7 @@ System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.conditionBox = new System.Windows.Forms.RichTextBox();
- this.button2 = new System.Windows.Forms.Button();
+ this.generateButton = new System.Windows.Forms.Button();
this.produceBox = new System.Windows.Forms.TextBox();
this.label12 = new System.Windows.Forms.Label();
this.generateBox = new System.Windows.Forms.TextBox();
@@ -87,7 +87,7 @@ // groupBox1
//
this.groupBox1.Controls.Add(this.conditionBox);
- this.groupBox1.Controls.Add(this.button2);
+ this.groupBox1.Controls.Add(this.generateButton);
this.groupBox1.Controls.Add(this.produceBox);
this.groupBox1.Controls.Add(this.label12);
this.groupBox1.Controls.Add(this.generateBox);
@@ -113,14 +113,15 @@ this.conditionBox.TabIndex = 11;
this.conditionBox.Text = "";
//
- // button2
+ // generateButton
//
- this.button2.Location = new System.Drawing.Point(10, 398);
- this.button2.Name = "button2";
- this.button2.Size = new System.Drawing.Size(497, 40);
- this.button2.TabIndex = 10;
- this.button2.Text = "GENERUJ";
- this.button2.UseVisualStyleBackColor = true;
+ this.generateButton.Location = new System.Drawing.Point(10, 398);
+ this.generateButton.Name = "generateButton";
+ this.generateButton.Size = new System.Drawing.Size(497, 40);
+ this.generateButton.TabIndex = 10;
+ this.generateButton.Text = "GENERUJ";
+ this.generateButton.UseVisualStyleBackColor = true;
+ this.generateButton.Click += new System.EventHandler(this.generateButton_Click);
//
// produceBox
//
@@ -688,7 +689,7 @@ private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.Label label10;
- private System.Windows.Forms.Button button2;
+ private System.Windows.Forms.Button generateButton;
private System.Windows.Forms.TextBox produceBox;
private System.Windows.Forms.Label label12;
private System.Windows.Forms.TextBox generateBox;
diff --git a/Analizator9000/Analizator9000/Form1.cs b/Analizator9000/Analizator9000/Form1.cs index 3f067ab..7c090e2 100644 --- a/Analizator9000/Analizator9000/Form1.cs +++ b/Analizator9000/Analizator9000/Form1.cs @@ -11,9 +11,12 @@ namespace Analizator9000 {
public partial class Form1 : Form
{
+ private DealerParser parser;
+
public Form1()
{
InitializeComponent();
+ this.parser = new DealerParser();
}
private void button1_Click(object sender, EventArgs e)
@@ -23,9 +26,9 @@ namespace Analizator9000 private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
- DealerParser parser = new DealerParser();
try
{
+ this.parser = new DealerParser();
parser.loadFile(generateFileDialog.FileName);
if (parser.produce > 0) produceBox.Text = parser.produce.ToString();
if (parser.generate > 0) generateBox.Text = parser.generate.ToString();
@@ -65,5 +68,31 @@ namespace Analizator9000 MessageBox.Show("Błąd wczytywania pliku: " + ex.Message, "Błąd wczytywania pliku", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
+
+ private void generateButton_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ this.parser.generate = Convert.ToInt64(generateBox.Text);
+ this.parser.produce = Convert.ToInt64(produceBox.Text);
+ parser.condition = conditionBox.Text;
+ parser.predeal["north"] = new String[] { predealNorthSpadesBox.Text, predealNorthHeartsBox.Text, predealNorthDiamondsBox.Text, predealNorthClubsBox.Text };
+ parser.predeal["south"] = new String[] { predealSouthSpadesBox.Text, predealSouthHeartsBox.Text, predealSouthDiamondsBox.Text, predealSouthClubsBox.Text };
+ parser.predeal["west"] = new String[] { predealWestSpadesBox.Text, predealWestHeartsBox.Text, predealWestDiamondsBox.Text, predealWestClubsBox.Text };
+ parser.predeal["east"] = new String[] { predealEastSpadesBox.Text, predealEastHeartsBox.Text, predealEastDiamondsBox.Text, predealEastClubsBox.Text };
+ foreach (KeyValuePair<String, String[]> predeal in parser.predeal)
+ {
+ for (int i = 0; i < predeal.Value.Length; i++)
+ {
+ predeal.Value[i] = predeal.Value[i].ToUpper().Replace('D', 'Q').Replace('W', 'J').Replace("10", "T");
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("Błąd wprowadzania danych: " + ex.Message, "Błąd wprowadzania danych", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ String outputFileName = parser.saveFile();
+ }
}
}
diff --git a/Analizator9000/Analizator9000/Program.cs b/Analizator9000/Analizator9000/Program.cs index 5dcdd94..79dc994 100644 --- a/Analizator9000/Analizator9000/Program.cs +++ b/Analizator9000/Analizator9000/Program.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq;
using System.Windows.Forms;
-
namespace Analizator9000
{
static class Program
|