none
Small BASIC-TicTacToe Game

    Question

  • CAN SOME ONE HELP ME WITH A TIC TAC TOE GAME. I HAVE THE GRID UP AND EVERYTHING I JUST DONT HAVE ANY THING TO PLAY THE GAME WITH EG. THE O'S OR X'S MOVING AND PLACING THEM ON THE GRID. THIS IS A SERIOUS PROBLEM AND IF I DONT GET IT I WILL FAIL THIS COARSE. HELPP ME IF YOU CARE ABOUT HUMANITY. PLEASE. I'M BEGGING YOU.
    Wednesday, November 21, 2012 6:16 PM

Answers

  • Here, I think this is what you are looking for. It doesn't show who wins yet, though. I just modified your code.

    TextWindow.BackgroundColor= "Yellow"
    TextWindow.Clear ()
    TextWindow.ForegroundColor= "Black"
    
    TextWindow.WriteLine ("Welcome to the game 'Tic-Tac-Toe'! Enter your name here: ")
    name = TextWindow.Read ()
    TextWindow.WriteLine ("Here are the rules to play Tic-Tac-Toe " + name )
    TextWindow.WriteLine  ("Rules: 1) Pick to either be player X or player O. 2) One player will choose to go first and place their symbols in only one of the 9 spaces on the grid. 3) As the second player goes, they are trying to prevent each other from getting three of the same symbols in a row. 4) Continue step 2 & 3 until all nine spaces are full. If no one has won by getting three symbols in a row, it is called a draw or 'Cats Game'. 5) Then play again.")
    TextWindow.WriteLine (" Hey " + name )
    TextWindow.WriteLine (" Do you know how to play?")
    answer = TextWindow.Read()
    If (answer = "yes") Then
      TextWindow.WriteLine ("Perfect! Let's play!")
    EndIf
    
    If (answer = "no") Then
      TextWindow.WriteLine ("You are really dumb " + name + ", and are going no where in life")
    EndIf
    Program.Delay (2000)
    TextWindow.Hide ()
    GraphicsWindow.BackgroundColor = "Red"
    GraphicsWindow.Title = "Tic-Tac-Toe"
    GraphicsWindow.Height = 600
    GraphicsWindow.Width = 900
    
    rows= 3
    columns= 3
    size= 190
    
    offsetX = (GraphicsWindow.Width-rows*size)/2
    offsetY= (GraphicsWindow.Height-columns*size)/2
    
    For r = 1 To rows
    For c = 1 To columns
    GraphicsWindow.BrushColor = "White"
        boxes[r][c] = Shapes.AddRectangle(size,size )
        Shapes.Move(boxes[r][c], offsetX + (r-1)*size, offsetY + (c-1)*size )
      EndFor
    EndFor
    turn = "X"
    GraphicsWindow.MouseDown = MouseDown
    GraphicsWindow.FontSize = size
    GraphicsWindow.BrushColor = "Blue"
    
    Sub MouseDown
      amount_turns = amount_turns+1
      selectedx = Math.Ceiling((GraphicsWindow.MouseX-offsetX)/size)
      selectedy = Math.Ceiling((GraphicsWindow.MouseY-offsetY)/size)
      TextWindow.WriteLine(selectedx)
      TextWindow.WriteLine(selectedy)
      Text[amount_turns] = Shapes.AddText(turn)
      Shapes.Move(Text[amount_turns],Shapes.GetLeft(boxes[selectedx][selectedy])+5,Shapes.GetTop(boxes[selectedx][selectedy])+5)
      TextWindow.WriteLine(Shapes.GetLeft(boxes[selectedx][selectedy]))
      TextWindow.WriteLine(Shapes.GetTop(boxes[selectedx][selectedy]))
      If turn = "X" Then
        turn = "O"
      Else
        turn = "X"
      EndIf
    EndSub


    I am a 10 year old that loves math, games, and computers. 'Binary is as easy as 1, 10, 11.'

    Wednesday, November 21, 2012 7:04 PM

All replies

  • Here, I think this is what you are looking for. It doesn't show who wins yet, though. I just modified your code.

    TextWindow.BackgroundColor= "Yellow"
    TextWindow.Clear ()
    TextWindow.ForegroundColor= "Black"
    
    TextWindow.WriteLine ("Welcome to the game 'Tic-Tac-Toe'! Enter your name here: ")
    name = TextWindow.Read ()
    TextWindow.WriteLine ("Here are the rules to play Tic-Tac-Toe " + name )
    TextWindow.WriteLine  ("Rules: 1) Pick to either be player X or player O. 2) One player will choose to go first and place their symbols in only one of the 9 spaces on the grid. 3) As the second player goes, they are trying to prevent each other from getting three of the same symbols in a row. 4) Continue step 2 & 3 until all nine spaces are full. If no one has won by getting three symbols in a row, it is called a draw or 'Cats Game'. 5) Then play again.")
    TextWindow.WriteLine (" Hey " + name )
    TextWindow.WriteLine (" Do you know how to play?")
    answer = TextWindow.Read()
    If (answer = "yes") Then
      TextWindow.WriteLine ("Perfect! Let's play!")
    EndIf
    
    If (answer = "no") Then
      TextWindow.WriteLine ("You are really dumb " + name + ", and are going no where in life")
    EndIf
    Program.Delay (2000)
    TextWindow.Hide ()
    GraphicsWindow.BackgroundColor = "Red"
    GraphicsWindow.Title = "Tic-Tac-Toe"
    GraphicsWindow.Height = 600
    GraphicsWindow.Width = 900
    
    rows= 3
    columns= 3
    size= 190
    
    offsetX = (GraphicsWindow.Width-rows*size)/2
    offsetY= (GraphicsWindow.Height-columns*size)/2
    
    For r = 1 To rows
    For c = 1 To columns
    GraphicsWindow.BrushColor = "White"
        boxes[r][c] = Shapes.AddRectangle(size,size )
        Shapes.Move(boxes[r][c], offsetX + (r-1)*size, offsetY + (c-1)*size )
      EndFor
    EndFor
    turn = "X"
    GraphicsWindow.MouseDown = MouseDown
    GraphicsWindow.FontSize = size
    GraphicsWindow.BrushColor = "Blue"
    
    Sub MouseDown
      amount_turns = amount_turns+1
      selectedx = Math.Ceiling((GraphicsWindow.MouseX-offsetX)/size)
      selectedy = Math.Ceiling((GraphicsWindow.MouseY-offsetY)/size)
      TextWindow.WriteLine(selectedx)
      TextWindow.WriteLine(selectedy)
      Text[amount_turns] = Shapes.AddText(turn)
      Shapes.Move(Text[amount_turns],Shapes.GetLeft(boxes[selectedx][selectedy])+5,Shapes.GetTop(boxes[selectedx][selectedy])+5)
      TextWindow.WriteLine(Shapes.GetLeft(boxes[selectedx][selectedy]))
      TextWindow.WriteLine(Shapes.GetTop(boxes[selectedx][selectedy]))
      If turn = "X" Then
        turn = "O"
      Else
        turn = "X"
      EndIf
    EndSub


    I am a 10 year old that loves math, games, and computers. 'Binary is as easy as 1, 10, 11.'

    Wednesday, November 21, 2012 7:04 PM
  • Hmmm...

    hopefully your instructor does not check the forum and find out that you get your code solution from a 10 year old programmer on the internet :)

    Thursday, November 22, 2012 12:14 AM
  • here is the code...not perfect but mostly there

    GraphicsWindow.MouseDown = myMouseDown

    '-- This section Maximizes the window
    GraphicsWindow.Clear()
    GraphicsWindow.Title = "Small Basic Tic Tac Toe"
    GraphicsWindow.Height = 190*3
    GraphicsWindow.Width = 190*3
    GraphicsWindow.Top = 0
    GraphicsWindow.Left = 0
    GraphicsWindow.CanResize = "False"
    GraphicsWindow.PenWidth = 1/2

    rows= 3
    columns= 3
    size= 190

    offsetX = (GraphicsWindow.Width-rows*size)/2
    offsetY= (GraphicsWindow.Height-columns*size)/2

    For r = 1 To rows
      For c = 1 To columns
        boxes[r][c] = Shapes.AddRectangle(size,size)
        Shapes.Move(boxes[r][c], offsetX + (r-1)*size, offsetY + (c-1)*size )
      EndFor
    EndFor

    turn = "X"
    GraphicsWindow.FontSize = size
    GraphicsWindow.BrushColor = "White"

    inc = 1


    Sub myMouseDown
     
      If inc <= 9 then
       
        amount_turns = amount_turns + 1
        selectedx = Math.Ceiling((GraphicsWindow.MouseX-offsetX)/size)
        selectedy = Math.Ceiling((GraphicsWindow.MouseY-offsetY)/size)
        Text[amount_turns] = Shapes.AddText(turn)
        x = Shapes.GetLeft(boxes[selectedx][selectedy])+30
        y = Shapes.GetTop(boxes[selectedx][selectedy])-30
        Shapes.Move(Text[amount_turns],x,y)
       
        If turn = "X" Then
          turn =  "O"
        Else
          turn = "X"
        EndIf
       
        inc = inc + 1
       
        '-- PC Co-ordinates
        If x + "," + y = "35,-25" Then
          A = turn
        ElseIf x + "," + y = "225,-25" Then
          B = turn
        Elseif x + "," + y = "415,-25" Then
          C = turn
        Elseif x + "," + y  = "35,165" Then
          D = turn
        Elseif x + "," + y  = "225,165" Then
          E = turn
        Elseif x + "," + y  = "415,165" Then
          F = turn
        Elseif x + "," + y  = "35,355" Then
          G = turn
        Elseif x + "," + y  = "225,355" Then
          H = turn
        Elseif x + "," + y  =  "415,355" Then
          I = turn
        EndIf
       
        '-- Web Co-Ordinates
       
        If x + "," + y = "30,-30" Then
          A = turn
        ElseIf x + "," + y = "220,-30" Then
          B = turn
        Elseif x + "," + y = "410,-30" Then
          C = turn
        Elseif x + "," + y  = "30,160" Then
          D = turn
        Elseif x + "," + y  = "220,160" Then
          E = turn
        Elseif x + "," + y  = "410,160" Then
          F = turn
        Elseif x + "," + y  = "30,155" Then
          G = turn
        Elseif x + "," + y  = "220,350" Then
          H = turn
        Elseif x + "," + y  =  "410,350" Then
          I = turn              
        EndIf
       
        '-- Check to see if anyone has won
        If turn = "X" Then
          turn = "O"
        Else
          turn = "X"
        Endif
       
        If A = B And B = c Then
          GraphicsWindow.ShowMessage("User " + Turn + " is the winner!!!", "Winner")
        ElseIf D = E and E = F Then
          GraphicsWindow.ShowMessage("User " + Turn + " is the winner!!!", "Winner")
        ElseIf G = H and H = I Then
          GraphicsWindow.ShowMessage("User " + Turn + " is the winner!!!", "Winner")
        ElseIf A = D and D = G Then
          GraphicsWindow.ShowMessage("User " + Turn + " is the winner!!!", "Winner")
        ElseIf B = E and E = H Then
          GraphicsWindow.ShowMessage("User " + Turn + " is the winner!!!", "Winner")
        ElseIf C = F and F = I Then
          GraphicsWindow.ShowMessage("User " + Turn + " is the winner!!!", "Winner")
        ElseIf A = E and E = I Then
          GraphicsWindow.ShowMessage("User " + Turn + " is the winner!!!", "Winner")
        ElseIf G = E and E = C Then 
          GraphicsWindow.ShowMessage("User " + Turn + " is the winner!!!", "Winner")
        EndIf
       
        If turn = "O" Then
          turn = "X"
        Else
          turn = "O"
        Endif
       
      Else
       
        '-- Do Nothing
       
      Endif
     
    EndSub

    Thursday, November 22, 2012 8:16 AM