none
Determine Player turn

    Question

  • Hello all, my game is a turn based and I want to determine whos turn would it be such as with a coin toss? maybe both players guess a number and whoever is the closest takes the first turn. Something along those lines.

    Does anyone have a good example in a windows form to determine how to determine a players turn?

    For my case I want to craft it along the lines if it hit this then it is players 1 turn and their game board loads up first and vice versa.


    WRA

    Wednesday, April 12, 2017 6:13 PM

Answers

  • Hello all, my game is a turn based and I want to determine whos turn would it be such as with a coin toss? maybe both players guess a number and whoever is the closest takes the first turn. Something along those lines.

    Does anyone have a good example in a windows form to determine how to determine a players turn?

    For my case I want to craft it along the lines if it hit this then it is players 1 turn and their game board loads up first and vice versa.


    WRA

    Hi

    Here is some code that may help as a pointer. Not the way I would choose, but then, I'm not building what you are :)

    ' Form1 with TextBox1, TextBox2 and Button1
    Option Strict On
    Option Explicit On
    Option Infer Off
    Public Class Form1
        Dim rand As New Random
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As EventArgs) Handles MyBase.Load
            Button1.Visible = My.Settings.Check
            Label1.Text = "Choose between 1-100"
        End Sub
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim target As Integer = rand.Next(1, 100)
            Dim p1 As Integer = Math.Abs(target - GetInteger(TextBox1.Text))
            Dim p2 As Integer = Math.Abs(target - GetInteger(TextBox2.Text))
            If p1 < p2 Then
                Label1.Text = "Player1 starts first"
                ' and any other code for Player1
            Else
                Label1.Text = "Player2 starts first"
                ' and any other code for Player2
            End If
        End Sub
        Function GetInteger(s As String) As Integer
            Dim v As Integer = 0
            If Integer.TryParse(s, v) Then Return v
            Return 0
        End Function
    End Class


    Regards Les, Livingston, Scotland


    • Edited by leshay Wednesday, April 12, 2017 6:53 PM
    • Marked as answer by Waliur Rahman Wednesday, April 12, 2017 7:56 PM
    Wednesday, April 12, 2017 6:53 PM

All replies

  • Hello all, my game is a turn based and I want to determine whos turn would it be such as with a coin toss? maybe both players guess a number and whoever is the closest takes the first turn. Something along those lines.

    Does anyone have a good example in a windows form to determine how to determine a players turn?

    For my case I want to craft it along the lines if it hit this then it is players 1 turn and their game board loads up first and vice versa.


    WRA

    Hi

    Here is some code that may help as a pointer. Not the way I would choose, but then, I'm not building what you are :)

    ' Form1 with TextBox1, TextBox2 and Button1
    Option Strict On
    Option Explicit On
    Option Infer Off
    Public Class Form1
        Dim rand As New Random
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As EventArgs) Handles MyBase.Load
            Button1.Visible = My.Settings.Check
            Label1.Text = "Choose between 1-100"
        End Sub
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim target As Integer = rand.Next(1, 100)
            Dim p1 As Integer = Math.Abs(target - GetInteger(TextBox1.Text))
            Dim p2 As Integer = Math.Abs(target - GetInteger(TextBox2.Text))
            If p1 < p2 Then
                Label1.Text = "Player1 starts first"
                ' and any other code for Player1
            Else
                Label1.Text = "Player2 starts first"
                ' and any other code for Player2
            End If
        End Sub
        Function GetInteger(s As String) As Integer
            Dim v As Integer = 0
            If Integer.TryParse(s, v) Then Return v
            Return 0
        End Function
    End Class


    Regards Les, Livingston, Scotland


    • Edited by leshay Wednesday, April 12, 2017 6:53 PM
    • Marked as answer by Waliur Rahman Wednesday, April 12, 2017 7:56 PM
    Wednesday, April 12, 2017 6:53 PM
  • I like it Ieshay I dont want it to be too complex just something that gets the job done :)

    WRA

    Wednesday, April 12, 2017 7:13 PM
  • Best answer Ieshay thank you so much for your reccomendation of this example :) you have a good day.

    WRA

    Wednesday, April 12, 2017 7:57 PM