Informatica Programmabile
Vuoi reagire a questo messaggio? Crea un account in pochi click o accedi per continuare.
Accedi

Ho dimenticato la password

Ultimi argomenti attivi
» argomento
Tris in Visual Basic .Net 2005 EmptyDom Giu 02, 2013 4:30 pm Da ruggiero98

» problema con la funzione SE aiutoooo x favore?????
Tris in Visual Basic .Net 2005 EmptyDom Giu 02, 2013 4:18 pm Da ruggiero98

» aiuto in programma con if
Tris in Visual Basic .Net 2005 EmptyDom Mag 26, 2013 5:39 pm Da ruggiero98

»  CALCOLO PERCENTUALE IN C
Tris in Visual Basic .Net 2005 EmptySab Apr 20, 2013 8:22 pm Da ruggiero98

» Costruire un temporizzatore software per accensione luci a led
Tris in Visual Basic .Net 2005 EmptyLun Mar 25, 2013 2:34 pm Da Cristina Shady

» Ciao a tutti!
Tris in Visual Basic .Net 2005 EmptyGio Mar 22, 2012 4:19 am Da cosmos91

» Virtualbox VS le periferiche USB
Tris in Visual Basic .Net 2005 EmptyMar Apr 06, 2010 1:49 pm Da dandeciani

» PROGRAMMA: BINARY CODE
Tris in Visual Basic .Net 2005 EmptyMar Dic 23, 2008 7:28 pm Da Thalionwen

» saluti a tutti
Tris in Visual Basic .Net 2005 EmptyMar Dic 23, 2008 7:12 pm Da Thalionwen

» GUIDA : CAP 1 LEZIONE 1 Elementi di base dei programmi in C [Prima Parte]
Tris in Visual Basic .Net 2005 EmptySab Nov 29, 2008 11:44 am Da ya89

» un semplice ciao
Tris in Visual Basic .Net 2005 EmptySab Nov 29, 2008 11:38 am Da ya89

» Aiuto per alice 7 mega
Tris in Visual Basic .Net 2005 EmptyVen Nov 14, 2008 4:03 pm Da root

» FORUM: I nuovi banner
Tris in Visual Basic .Net 2005 EmptyVen Nov 14, 2008 2:48 pm Da Thalionwen

» Zooming Ricorsivo, questo sconosciuto.
Tris in Visual Basic .Net 2005 EmptyVen Nov 14, 2008 2:43 pm Da Thalionwen

» GUIDA : LEZIONE 4 : UTILIZZARE GLI ARRAY IN C#
Tris in Visual Basic .Net 2005 EmptyVen Nov 14, 2008 1:54 pm Da ab89

» GUIDA : CAP 1 LEZIONE 1 Elementi di base dei programmi in C [Terza e Ultima Parte]
Tris in Visual Basic .Net 2005 EmptyVen Nov 14, 2008 12:41 am Da ab89

» GUIDA : CAP 1 LEZIONE 1 Elementi di base dei programmi in C [Seconda Parte]
Tris in Visual Basic .Net 2005 EmptyMer Nov 12, 2008 12:59 am Da ab89

» [PS2] Dark Cloud
Tris in Visual Basic .Net 2005 EmptyMar Nov 11, 2008 6:50 pm Da ab89

» [PC] Sacred 2
Tris in Visual Basic .Net 2005 EmptyLun Nov 10, 2008 10:49 pm Da ab89

» GUIDA : CAP 1 LEZIONE 3 INTRODUZIONE AGLI ARRAY
Tris in Visual Basic .Net 2005 EmptyLun Nov 10, 2008 1:37 pm Da ab89

Flusso RSS


Yahoo! 
MSN 
AOL 
Netvibes 
Bloglines 



Tris in Visual Basic .Net 2005

2 partecipanti

Andare in basso

Tris in Visual Basic .Net 2005 Empty Tris in Visual Basic .Net 2005

Messaggio Da ab89 Gio Ott 02, 2008 10:24 pm

Ecco come realizzare il gioco del TRIS

AUTORE : ab89
FORUM : Informatica Programmabile
LINGUAGGIO : VB 2005

Ciò
che segue permette di realizzare il gioco del Tris, nota bene che è
Umano Vs Umano, senza l'implementazione dell'intelligenza artificiale.
Il primo a partire, il Giocatore 1, ha la Croce, il secondo, il Giocatore 2, il Cerchio.


Per realizzare il gioco del Tris dovete creare un Form .
All'interno del form create un panel 302x302 e con name = "Panel1"
Poi impostate la proprietà BorderStyle su FixedSingle
Poi copiate il seguente codice

Codice:

Public Class Form1
    Private statoCaselle(2, 2) As Integer
    Private areaCaselle(2, 2) As Rectangle
    Private turnoGiocatore1, turnoGiocatore2 As Boolean
    Private numeroMosse As Integer = 0


    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
        e.Graphics.DrawLine(Pens.Black, 101, 0, 101, 302)
        e.Graphics.DrawLine(Pens.Black, 202, 0, 202, 302)
        e.Graphics.DrawLine(Pens.Black, 0, 101, 302, 101)
        e.Graphics.DrawLine(Pens.Black, 0, 202, 302, 202)
        For i As Integer = 0 To statoCaselle.GetLength(0) - 1
            For j As Integer = 0 To statoCaselle.GetLength(1) - 1
                Select Case (statoCaselle(i, j))
                    Case 0 : e.Graphics.DrawEllipse(Pens.Black, areaCaselle(i, j).X + 10, areaCaselle(i, j).Y + 10, 80, 80)
                    Case 1 : e.Graphics.DrawLine(Pens.Black, areaCaselle(i, j).X + 10, areaCaselle(i, j).Y + 10, areaCaselle(i, j).X + 90, areaCaselle(i, j).Y + 90)
                        e.Graphics.DrawLine(Pens.Black, areaCaselle(i, j).X + 90, areaCaselle(i, j).Y + 10, areaCaselle(i, j).X + 10, areaCaselle(i, j).Y + 90)
                End Select
            Next
        Next
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For i As Integer = 0 To statoCaselle.GetLength(0) - 1
            For j As Integer = 0 To statoCaselle.GetLength(1) - 1
                statoCaselle(i, j) = -1
                areaCaselle(i, j) = New Rectangle(i * 101, j * 101, 100, 100)
            Next
        Next
        turnoGiocatore1 = True
        turnoGiocatore2 = False
        numeroMosse = 0
    End Sub

    Private Sub Panel1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Panel1.Click
     
    End Sub

    Private Sub Panel1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseClick
        Dim x, y As Integer
        x = -1
        y = -1

        For i As Integer = 0 To statoCaselle.GetLength(0) - 1
            For j As Integer = 0 To statoCaselle.GetLength(1) - 1
                If (areaCaselle(i, j).Contains(e.X, e.Y)) Then
                    x = i
                    y = j
                End If
            Next
        Next
        If (statoCaselle(x, y) = -1) Then
            numeroMosse = numeroMosse + 1
            statoCaselle(x, y) = Convert.ToInt32(turnoGiocatore1)
            turnoGiocatore1 = Not turnoGiocatore1
            turnoGiocatore2 = Not turnoGiocatore2
        Else
            MsgBox("errore, casella occupata")
        End If

        Dim simbolo As Integer = -1
        Panel1.Refresh()
        If (finePartita(simbolo)) Then
            Dim s As String = ""
            If (simbolo = 0) Then
                s = "cerchio"
                MsgBox("Il vincitore è il giocatore che usa il simbolo : " + s)
            ElseIf (simbolo = 1) Then
                s = "croce"
                MsgBox("Il vincitore è il giocatore che usa il simbolo : " + s)
            Else
                MsgBox("la partita è finita in parità")
            End If

            If (MsgBox("Vuoi giocare una nuova partita ? ", MsgBoxStyle.YesNo) = MsgBoxResult.Yes) Then
                Me.Form1_Load(Me, New EventArgs())
                Panel1.Refresh()
            Else
                Application.Exit()
            End If
        End If


    End Sub
    Private Function finePartita(ByRef simboloVincente As Integer) As Boolean
        Dim rigaV As Boolean = True
        Dim colonnaV As Boolean = True
        Dim fine As Boolean = False
        Dim simbolo As Integer = -1
        simboloVincente = -1
        If (numeroMosse < 9) Then
            For i As Integer = 0 To statoCaselle.GetLength(0) - 1
                Dim contatore As Integer = 0
                simbolo = statoCaselle(i, 0)
                For j As Integer = 0 To statoCaselle.GetLength(1) - 1
                    If (simbolo = statoCaselle(i, j) And Not simbolo = -1) Then
                        contatore = contatore + 1
                    End If
                Next
                If (contatore = 3) Then
                    fine = True
                    simboloVincente = simbolo
                    Continue For
                End If

            Next
            If (Not fine) Then
                For i As Integer = 0 To statoCaselle.GetLength(0) - 1
                    Dim contatore As Integer = 0
                    simbolo = statoCaselle(0, i)
                    For j As Integer = 0 To statoCaselle.GetLength(1) - 1
                        If (simbolo = statoCaselle(j, i) And Not simbolo = -1) Then
                            contatore = contatore + 1
                        End If
                    Next
                    If (contatore = 3) Then
                        fine = True
                        simboloVincente = simbolo
                        Continue For
                    End If
                Next
            End If
            If (Not fine) Then
                Dim contatore As Integer = 0
                simbolo = statoCaselle(0, 0)
                For i As Integer = 0 To statoCaselle.GetLength(0) - 1
                    If (simbolo = statoCaselle(i, i) And Not simbolo = -1) Then
                        contatore = contatore + 1
                    End If
                    If (contatore = 3) Then
                        fine = True
                        simboloVincente = simbolo
                        Continue For
                    End If
                Next
            End If
            If (Not fine) Then
                Dim contatore As Integer = 0
                simbolo = statoCaselle(2, 0)
                For i As Integer = 0 To statoCaselle.GetLength(0) - 1
                    If (simbolo = statoCaselle(2 - i, i) And Not simbolo = -1) Then
                        contatore = contatore + 1
                    End If
                    If (contatore = 3) Then
                        fine = True
                        simboloVincente = simbolo
                        Continue For
                    End If
                Next
            End If
        Else
            fine = True
        End If
       
        finePartita = fine

    End Function
End Class





NB: Il codice è liberamente utilizzabile a patto che venga citato l'autore e il forum dove lo si è trovato, in questo caso ab89 Informatica Programmabile.
ab89
ab89
Admin
Admin

Numero di messaggi : 74
Età : 35
Località : Rovigo
Data d'iscrizione : 29.09.08

Scheda personaggio
PF:

Torna in alto Andare in basso

Tris in Visual Basic .Net 2005 Empty RE: Tris in VB 2005

Messaggio Da Eine The Phantom Mer Ott 15, 2008 9:02 pm

:O
bello Very Happy
davvero,
niente male.. se non erro ci sono anche altri modi per fare i controlli
sulle combinazioni del tris, ma già quello ke hai fatto non è male Very Happy
magari appena ho tempo te lo posto fatto in C Very Happy
buona serata Very Happy
Eine The Phantom
Eine The Phantom
Admin
Admin

Numero di messaggi : 37
Data d'iscrizione : 28.09.08

https://infonprog.forumattivo.it

Torna in alto Andare in basso

Torna in alto


 
Permessi in questa sezione del forum:
Non puoi rispondere agli argomenti in questo forum.