Hi Leute ... ICh habe versucht in mein Spiel einen Chat einzubauen aber das geht i-wie nicht ...
Also hier is mal der Code :
Also ich weiß nicht warum das nicht funktioniert ... Da steht immer Verbindung zum Server nicht möglich.
Dabei hab ich diesen Multiserver laufen ...
EDIT: ich seh grad das sind nur 22 zeilen ... das war keine absicht sry ... ich hoffe ihr könnt es trotzdem entziffern
Edit by ~blaze~:
*Thema umbenannt*
Also hier is mal der Code :
VB.NET-Quellcode
- Imports System.Net.SocketsImports System.IO
- Public Class Form1 Private stream As NetworkStream Private streamw As StreamWriter Private streamr As StreamReader Private client As New TcpClient Private t As New Threading.Thread(AddressOf Listen) Private Delegate Sub DAddItem(ByVal s As String) Private nick As String = "unknown" Dim myx As Integer = -5 Dim myy As Integer = 10
- Private Sub AddItem(ByVal s As String) Dim arr = s.Split(",") Dim list = arr.ToList Dim i = ListView1.Items.Add(list.Item(0)) Dim one As String = list.Item(1) Dim two As String = list.Item(2) i.SubItems.Add(one) i.SubItems.Add(two) PictureBox1.Refresh() ListBox1.Items.Add(s) End Sub
- Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown 'Hoch If e.KeyCode = Keys.Up Then PictureBox1.Location = New Point(PictureBox1.Location.X + 0, PictureBox1.Location.Y - 2) End If 'Runter If e.KeyCode = Keys.Down Then PictureBox1.Location = New Point(PictureBox1.Location.X + 0, PictureBox1.Location.Y + 2) End If 'Rechts If e.KeyCode = Keys.Right Then PictureBox1.Location = New Point(PictureBox1.Location.X + 2, PictureBox1.Location.Y + 0) End If 'Links If e.KeyCode = Keys.Left Then PictureBox1.Location = New Point(PictureBox1.Location.X - 2, PictureBox1.Location.Y + 0) End If myx = PictureBox1.Location.X myy = PictureBox1.Location.Y streamw.WriteLine(nick & "," & myx & "," & myy) streamw.Flush()
- End Sub Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown Try client.Connect("127.0.0.1", 8000) ' hier die ip des servers eintragen. ' da dieser beim testen wohl lokal läuft, hier die loopback-ip 127.0.0.1. If client.Connected Then stream = client.GetStream streamw = New StreamWriter(stream) streamr = New StreamReader(stream)
- streamw.WriteLine(nick) ' das ist optional. streamw.Flush()
- t.Start() Else MessageBox.Show("Verbindung zum Server nicht möglich!") Application.Exit() End If Catch ex As Exception MessageBox.Show("Verbindung zum Server nicht möglich!") Application.Exit() End Try End Sub
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim posx_rnd As New Random Dim posy_rnd As New Random Dim posx = posx_rnd.Next(15, Me.Width - 15) Dim posy = posy_rnd.Next(15, Me.Height - 15) myx = posx myy = posy nick = InputBox("Gib einen Spielernamen ein!") Me.KeyPreview = True Try client.Connect("127.0.0.1", 8000) If client.Connected Then stream = client.GetStream streamw = New StreamWriter(stream) streamr = New StreamReader(stream)
- streamw.WriteLine(nick) streamw.Flush()
- t.Start() Else MessageBox.Show("Verbindung zum Server nicht möglich!") Application.Exit() End If Catch ex As Exception MessageBox.Show("Verbindung zum Server nicht möglich!") Application.Exit() End Try End Sub Private Sub Listen() While client.Connected Try Me.Invoke(New DAddItem(AddressOf AddItem), streamr.ReadLine) Catch MessageBox.Show("Verbindung zum Server nicht möglich!") Application.Exit() End Try End While End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click streamw.WriteLine(TextBox1.Text) streamw.Flush() TextBox1.Clear() End Sub Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
- For Each item As ListViewItem In ListView1.Items Dim rnd1 As New Random Dim rnd2 As New Random Dim rnd3 As New Random
- Dim clr1 = rnd1.Next(1, 255) Dim clr2 = rnd2.Next(1, 255) Dim clr3 = rnd2.Next(1, 255)
- Dim nm_ As String = item.ToString nm_ = nm_.Replace("ListViewItem: {", "") nm_ = nm_.Replace("}", "") Dim nm As String = nm_
- Dim x_ As String = item.SubItems(1).ToString x_ = x_.Replace("ListViewSubItem: {", "") x_ = x_.Replace("}", "") Dim x As Single = x_
- Dim y_ As String = item.SubItems(2).ToString y_ = y_.Replace("ListViewSubItem: {", "") y_ = y_.Replace("}", "") Dim y As Single = y_
- Next
- End Sub
- End Class
Also ich weiß nicht warum das nicht funktioniert ... Da steht immer Verbindung zum Server nicht möglich.
Dabei hab ich diesen Multiserver laufen ...
EDIT: ich seh grad das sind nur 22 zeilen ... das war keine absicht sry ... ich hoffe ihr könnt es trotzdem entziffern
Edit by ~blaze~:
*Thema umbenannt*
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „~blaze~“ ()