Tic Tac Toe Board

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
bozanas
Prole
Posts: 2
Joined: Fri Jan 04, 2013 5:33 pm

Tic Tac Toe Board

Post by bozanas »

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?
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Tic Tac Toe Board

Post by Jasoco »

Show us the code you've made so far.

Are you from the same class as Eyedea?
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Tic Tac Toe Board

Post by BlackBulletIV »

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.
bozanas
Prole
Posts: 2
Joined: Fri Jan 04, 2013 5:33 pm

Re: Tic Tac Toe Board

Post by bozanas »

Here is what I have. I hope that you will help me!

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
Check win function

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
Cell click function

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
User avatar
Zer0
Citizen
Posts: 59
Joined: Sat Oct 06, 2012 9:55 am
Location: Sweden
Contact:

Re: Tic Tac Toe Board

Post by Zer0 »

rendering a board is something like

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
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

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
for the correct rendering and how to check click you can

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)
where p is what index it have.

hope this helps
If you can't fix it, Kill it with fire. ( Preferably before it lays eggs. )
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 2 guests