Tic Tac Toe Board
Tic Tac Toe Board
Hey, guys, I need your help. I am a begginer I have to make Tic Tac Toe game, and I am having some problems with the board. I cant created the board. I tried a lot functions and I cant make one that will work allright. I created almost all functions that I need for the game, but I cant create the board. Can someone help with this?
- Jasoco
- Inner party member
- Posts: 3727
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Tic Tac Toe Board
Show us the code you've made so far.
Are you from the same class as Eyedea?
Are you from the same class as Eyedea?
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: Tic Tac Toe Board
Pretty much what Jasoco said. Show us what you've tried, and then we might be able help.
Also, this kind of thing is better posted in the "Support and Development" subforum.
Also, this kind of thing is better posted in the "Support and Development" subforum.
Re: Tic Tac Toe Board
Here is what I have. I hope that you will help me!
Main function
Check win function
Cell click function
Main function
Code: Select all
require "menu"
require "cell"
function love.load()
s={}
medium= love.graphics.newFont(40)
love.graphics.setBackgroundColor(200,150,100)
gamestate="menu"
button_spawn(20,100,"Start","start")
button_spawn(20,250,"Quit", "quit")
end
function love.update()
end
function love.draw()
if gamestate=="playing" then
board()
end
if gamestate=="menu" then
button_draw()
end
end
function love.mousepressed(x,y)
if gamestate=="menu" then
button_click(x,y)
end
end
Code: Select all
function check_win()
for i=1, 3 do
if b(i) ~= nil and b(i) == b(i+3) and b(i) == b(i+6) then
winner = b(i)
elseif b(i-) ~= nil and b(i) == b(i+1) and b(i) == b(i+2) then
winner = b(i)
end
end
if b(1) ~= nil and b(1) == b(5) and b(1) == b(9) then
winner = b(1)
elseif b(3) ~= nil and b(3) == b(5) and b(3) == b(7) then
winner = b(3)
end
if winner ~= nil then
text.text = (winner and 'You win!' or 'Computer wins!')
win = true
end
if win == false and moves == 9 then
win = true
text.text = 'Draw!'
end
end
Code: Select all
function cell_click()
if win == false then
if s.cell ~= true and s.cell ~= false then
moves = moves + 1
s.cell = move
move = not move
check_win() --checks, if someone wins
if move == false and win == false then ai() end
end
else --restart game if someone wins and player clicks on the field
for i = 1, 9 do cells._c[i].cell = nil end
text.text = ''
move = true
win = false
moves = 0
end
end
Re: Tic Tac Toe Board
rendering a board is something like
to make that but if you're wondering how to render the marks at the correct spot from an array from 1 to 9 i would suggest
for the correct rendering and how to check click you can
where p is what index it have.
hope this helps
Code: Select all
for i = 1, 2 do
love.graphics.line(i * size_of_one_square,0,i * size_of_one_square,3 * size_of_one_square)
love.graphics.line(0,i * size_of_one_square,3 * size_of_one_square,i * size_of_one_square)
end
Code: Select all
for i = 1, 9 do
love.graphics.circle("line",math.mod(i - 0.5,3) * size_of_one_square,(math.ceil(i / 3) - 0.5) * size_of_one_square,size_of_one_square / 2,32)
end
Code: Select all
local x = mouse_x / size_of_one_square
local y = mouse_y / size_of_one_square
local p = 3 * math.floor(y) + math.ceil(x)
hope this helps
If you can't fix it, Kill it with fire. ( Preferably before it lays eggs. )
Who is online
Users browsing this forum: No registered users and 1 guest