Ich versuche gerade, ein Spiel ähnlich dem Spiel "Solo Noble" zu machen, in dem du eine Anzahl von Bällen hast und du musst die niedrigste erreichbare Punktzahl erhalten. Ich versuche gerade, ein Array von schwarzen & weißen Tasten, die in Form einer Binärdatei in einer externen Textdatei geformt sind, zu machen. Im Moment habe ich dies:Binär aus einer Textdatei lesen und in Schaltflächen umwandeln C#
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WindowsFormsApplication9.Properties;
namespace WindowsFormsApplication9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Marble();
}
public void Marble()
{
int ButtonWidth = 40;
int ButtonHeight = 40;
int Distance = 20;
int start_x = 10;
int start_y = 10;
int y = 0;
int x = 0;
int delX = x + (y * 2);
for (x = 0; x < 8; x++)
{
for (y = 0; y < 8; y++)
{
GameButton tmpButton = new GameButton();
tmpButton.BackColor = Color.Black;
tmpButton.Top = start_x + (x * ButtonHeight + Distance);
tmpButton.Left = start_y + (y * ButtonWidth + Distance);
tmpButton.Width = ButtonWidth;
tmpButton.Height = ButtonHeight;
tmpButton.Text = "X: " + x.ToString() + " Y: " + y.ToString();
tmpButton.MouseUp += TmpButton_MouseUp;
tmpButton.Row = x;
tmpButton.Column = y;
tmpButton.Currentcolor = false;
if (x == 4 && y == 6) {
tmpButton.BackColor = Color.White;
}
else
{
this.Controls.Add(tmpButton);
}
}
}
}
private void TmpButton_MouseUp(object sender, MouseEventArgs e)
{
GameButton Mygamebutton = (GameButton) sender;
Mygamebutton.Currentcolor = !Mygamebutton.Currentcolor;
if (Mygamebutton.Currentcolor == true)
{
Mygamebutton.BackColor = Color.Black;
}
else
{
Mygamebutton.BackColor = Color.White;
}
}
}
}
Aber ich versuche, so etwas zu bekommen:
byte[] fileBytes = File.ReadAllBytes(inputFilename);
StringBuilder sb = new StringBuilder();
foreach(byte b in fileBytes)
{
sb.Append(Convert.ToString(b, 2).PadLeft(8, '0'));
}
File.WriteAllText(outputFilename, sb.ToString());
Ich bin nicht ganz sicher, wie das binäre Array aus der TXT-Datei in Schaltflächen zu drehen, zum Beispiel Eine 0 ist keine Schaltfläche und eine 1 ist eine Schaltfläche.
Wie erstellen Sie dieses binäre fie? – Artiom
Sie beziehen sich auf Ihre Datei sowohl als "binär" als auch als "Text", was verwirrend ist. Sprechen Sie vielleicht über eine Textdatei, die nur "0" und "1" Zeichen enthält? Wie auch immer, mit was genau haben Sie Probleme? Die Datei lesen? Oder wie man den Dateilese- und Tastenerstellungscode verbindet? –