Tic Tac Toe - Version 1.2
I've messing around with Love Lua for some Time now, and just wanted to get some Feedback on my Coding Style (Hobby Programmer all self taught).
Here is my first Submission to the Community. It's a simple 2D Clone of TicTacToe, nothing to complicated.
All Libraries are written from Scratch.
collision.lua used this website: https://2dengine.com/?p=intersections , i've added some stuff and functions.
Bord.lua, Patterns.lua and Helper.lua aren't used and were used in older Versions.
No AI yet and the Options Menu isnt functioning.
Have fun. First Post.
Morbus Kobold.
Tic Tac Toe [WIP] - First Game
-
- Prole
- Posts: 3
- Joined: Fri Jan 15, 2021 3:02 pm
Tic Tac Toe [WIP] - First Game
- Attachments
-
- TicTacToeV1.2.love
- (101.25 KiB) Downloaded 348 times
Re: Tic Tac Toe [WIP] - First Game
How to start the game with mouse only?
Re: Tic Tac Toe [WIP] - First Game
For a self-taught programmer, that as very clean and readable code. You seem to be fluent in any language you study.
My suggestions will sacrifice some of that cleanness for better coding practices.
#1 - There some parts that should make use of love.update. Take menu.update() for an example.
#2 - I'm having trouble suggesting something about your usage of sxBackground, and syBackground. I know what they're for, but I'm too lazy to think of a solution that uses local variables and at the same time not doing it in love.draw().
#3 - I've only recently adjusted from using only dots(.) to semi-colons(:) for tables that use themselves in their functions.
For example, turn this:
Into something like this:
My suggestions will sacrifice some of that cleanness for better coding practices.
#1 - There some parts that should make use of love.update. Take menu.update() for an example.
Code: Select all
function love.update()
if game.state == "menu" then
menu.update()
end
end
...
function love.draw()
...
if game.state == "menu" then
menu.draw()
elseif game.state == "game" then
...
end
...
end
#3 - I've only recently adjusted from using only dots(.) to semi-colons(:) for tables that use themselves in their functions.
For example, turn this:
Code: Select all
function menu.update()
if menu.entry < 1 then
menu.entry = 1
elseif menu.entry > #menu.entries then
menu.entry = #menu.entries
end
...
end
Code: Select all
function menu:update() -- or menu.update(self), but you'll call it as menu:update() anyway
if self.entry < 1 then
self.entry = 1
elseif self.entry > #self.entries then
self.entry = #self.entries
end
...
end
Re: Tic Tac Toe [WIP] - First Game
How to copy such objects with functions without metatables?
Re: Tic Tac Toe [WIP] - First Game
I'm not really a good source for an answer to this, but I currently use normal tables.
Code: Select all
function newObj()
local object = {}
object.sample_var2 = 'blah'
function object:sampleFunction()
--
end
return object
end
Code: Select all
object1 = newObj()
object2 = newObj()
objectN = newObj()
Who is online
Users browsing this forum: Ahrefs [Bot] and 0 guests