Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi! I need help with some of these functions. This program is in LUA. Here is my code below, please use this in your coding:

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Hi! I need help with some of these functions. This program is in LUA. Here is my code below, please use this in your coding:

-- game board display layout

xx = display.contentCenterX;

yy = display.contentCenterY;

local zone = display.newRect(xx, yy, 300, 300)

zone.strokeWidth = 2

zone:setFillColor(0,0.2,0)

zone.isSensor = true

local ver = display.newRect(xx, yy, 100, 300)

ver:setFillColor(0,0,0,0)

ver.strokeWidth = 2

local hor = display.newRect(xx, yy, 300, 100)

hor:setFillColor(0,0,1,0)

hor.strokeWidth = 2

--piece

function piece(type, x, y)

if (type==0) then

shape = display.newCircle (x, y, 50)

shape:setFillColor(1,0,0)

else

shape = display.neRect(x, y, 100, 100)

shape.rotation = 45

shape:setFillColor(1,0,0)

end

return shape

end

--these need to be functions

local board = {}

local player = 0

local function zoneHandler(event)

local x, y = event.target:contentToLocal(event.x, event.y)

x = x + 150

y = y + 150

x = math.ceil(x/100)

y = math.ceil(y/100)

if (gameMark(x,y) == false) then

return

end

checkWin()

end

zone:addEventListener("tap", zoneHandler)

function gameMark (x,y)

if (board[x][y] ~= -1) then

return false

end

board [x][y] = player

local _x, _y = zone:localToContent(event.x, event.y)

piece[x][y] = piece(player, _x,_y)

player = (player + 1) % 2

return true

end

local function checkWin()

for i = 1, 3 do

if (board[i][1] == board[i][2] and

board[i][1] == board[i][3] and

board[i][1] ~= -1) then

local winner = tostring(board[i][1]).."wins!";

display.newText(winner, 100, 200, native.systemFont, 40)

end

end

end

For this assignment, you will implement a simple but fully working 2-player tic-tac-toe game supporting a mobile phone. I am providing an incomplete code (main_assignment1.lua in the File page of our class canvas) which includes required functions and you can start this homework by completing the incomplete codes provided by me, or you can write each function from scratch to create this game. Your main task is to complete the tic-tac-two codes according to the following requirements. Again, you can create each function from scratch, but you must implement them as described. FUNCTIONS to be implemented for the app (check CS371Lecture04 Intro to CoronaSDK P2 eventstransitionaroups.pdf in detail) gameBoard() You must draw a 3x3 layout for the tic-tac-toe game board. Adjust the sizes of the board, diamonds and circles (currently the sizes of these game objects do not fit into the general screen)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

ISBN: B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions

Question

Does it avoid using personal pronouns (such as I and me)?

Answered: 1 week ago