Add TM Randomizer

This commit is contained in:
Kurt
2015-03-08 17:42:02 -07:00
parent b96da229ed
commit 1e8597dc1b
2 changed files with 34 additions and 0 deletions

View File

@@ -32,6 +32,7 @@ private void InitializeComponent()
this.L_TM = new System.Windows.Forms.Label();
this.dgvHM = new System.Windows.Forms.DataGridView();
this.L_HM = new System.Windows.Forms.Label();
this.B_RTM = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dgvTM)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dgvHM)).BeginInit();
this.SuspendLayout();
@@ -82,11 +83,22 @@ private void InitializeComponent()
this.L_HM.TabIndex = 4;
this.L_HM.Text = "HM:";
//
// B_RTM
//
this.B_RTM.Location = new System.Drawing.Point(41, 1);
this.B_RTM.Name = "B_RTM";
this.B_RTM.Size = new System.Drawing.Size(75, 23);
this.B_RTM.TabIndex = 5;
this.B_RTM.Text = "Randomize";
this.B_RTM.UseVisualStyleBackColor = true;
this.B_RTM.Click += new System.EventHandler(this.B_RandomTM_Click);
//
// TMHM
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(504, 332);
this.Controls.Add(this.B_RTM);
this.Controls.Add(this.L_HM);
this.Controls.Add(this.dgvHM);
this.Controls.Add(this.L_TM);
@@ -111,5 +123,6 @@ private void InitializeComponent()
private System.Windows.Forms.Label L_TM;
private System.Windows.Forms.DataGridView dgvHM;
private System.Windows.Forms.Label L_HM;
private System.Windows.Forms.Button B_RTM;
}
}

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using System.Linq;
namespace pk3DS
{
@@ -39,6 +40,7 @@ private void setupDGV()
dgvIndex.Width = 45;
dgvIndex.ReadOnly = true;
dgvIndex.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
dgvIndex.SortMode = DataGridViewColumnSortMode.NotSortable;
}
DataGridViewComboBoxColumn dgvMove = new DataGridViewComboBoxColumn();
{
@@ -49,6 +51,7 @@ private void setupDGV()
dgvMove.Width = 133;
dgvMove.FlatStyle = FlatStyle.Flat;
dgvIndex.SortMode = DataGridViewColumnSortMode.NotSortable;
}
dgvTM.Columns.Add(dgvIndex);
dgvTM.Columns.Add(dgvMove);
@@ -126,5 +129,23 @@ private void formClosing(object sender, FormClosingEventArgs e)
setList();
File.WriteAllBytes(codebin, data);
}
private void B_RandomTM_Click(object sender, EventArgs e)
{
int[] randomMoves = Enumerable.Range(1, movelist.Length - 1).Select(i => (int)i).ToArray();
Util.Shuffle(randomMoves);
int[] banned = { 15, 19, 57, 70, 127, 249, 291, 148 };
int ctr = 0;
for (int i = 0; i < dgvTM.Rows.Count; i++)
{
int val = Array.IndexOf(movelist, dgvTM.Rows[i].Cells[1].Value);
if (banned.Contains(val)) continue;
while (banned.Contains(randomMoves[ctr])) ctr++;
dgvTM.Rows[i].Cells[1].Value = movelist[randomMoves[ctr++]];
}
}
}
}