I already implemented the scrabble but i dont know how to implement a multiplayer base player 1 and player 2 on scrabble.. can you give idea anyone here? I really need your help :( heres the code: local d = require "data" local widget = require "widget" local sfx = require "sfx" local db = require "db" --------------------------------------------------------------------------------- local composer = require( "composer" ) local scene = composer.newScene() local loadsave = require("loadsave") --M = require "clock" --------------------------------------------------------------------------------- --// setup variables //------------ ----------------------------------- local bg, scoreboard, rack, statusBar, turn, submitBtn, clearBtn, p1ScoreTxt, p2Scoretxt, endGame, tilesRemainingTxt, board local p1Score, p2Score, tilesRemaining, tilePiecesPerRack, piecesNeededInrack = 0, 0, 90, 7 local boardTile, letterTile, player1, player2, onBoardTiles = {}, {}, {}, {}, {} --tables local tileCounter = 0 --tile counter local exchange = false local remakeBlankTile local tempBlankTile = {} ------------------------------------- local distributions = {9, 2, 1, 4, 12, 3, 2, 9, 4, 2, 6, 8, 2, 6, 4, 6, 4, 2, 2, 2} local points = {1, 3, 5, 2, 1, 2, 4, 1, 1, 3, 1, 1, 3, 1, 1, 1, 1, 4, 4, 0} --points for every letter local letters = {"A", "B", "K", "D", "E", "G", "H", "I", "L", "M", "N", "O", "P", "R", "S", "T", "U", "W", "Y", " "} --letter value ---------------------------------------------- local onSubmit, onClear, onDrag, onDrop, onDragBoard, onCancel, onReturnBlankTile local passBtn, cancelBtn, positionBoardTiles, positionLetterTiles --functions local showTiles, hideTiles, checkWord, putLetterForBlankTile --function local player1Adjust = 0 local player2Adjust = 0 local boardGroup = display.newGroup( ) local list = {} -------------------------------------------------------------------------------- function scene:create( event ) local sceneGroup = self.view -------------------------------------------------------------- --// setup interface //--------------------------------------- -------------------------------------------------------------- --initialize interface local function initInterface( ) board = display.newImageRect( "img/board.png", 550, 625 ) board.x = d.centerX board.y = d.centerY board:addEventListener( "touch", onDragBoard ) createBoardTiles() scoreboard = display.newRect( sceneGroup, d.centerX, 27.5, d.w, 55 ) scoreboard:setFillColor( 0.90, 0.74, 0.57 ) scoreboard.strokeWidth = 5 scoreboard:setStrokeColor( 1, 1, 1 ) rack = display.newRect( sceneGroup, d.centerX, d.h - 27.5, d.w, 55 ) rack:setFillColor( 0.90, 0.74, 0.57 ) rack.strokeWidth = 5 rack:setStrokeColor( 1, 1, 1 ) statusBar = display.newRect( sceneGroup, rack.x, rack.y - rack.height + 3, d.w, 40 ) statusBar.strokeWidth = 7 statusBar:setStrokeColor( 0.90, 0.74, 0.57 ) turn = display.newEmbossedText( sceneGroup, "Player 1", d.centerX, statusBar.y, "IMPACT", 20 ) turn:setFillColor( 0.35, 0.35, 0.35 ) submitBtn = widget.newButton( { defaultFile = "img/submit.png", overFile = "img/submitOver.png", font = "IMPACT", width = 105, height = 45, onRelease = onSubmit } ) submitBtn.x = d.w - submitBtn.width/2 submitBtn.y = turn.y submitBtn.alpha = 0 sceneGroup:insert( submitBtn ) passBtn = widget.newButton( { defaultFile = "img/pass.png", overFile = "img/passOver.png", font = "IMPACT", width = 105, height = 45, onRelease = onPass } ) passBtn.x = d.w - passBtn.width/2 passBtn.y = turn.y passBtn.alpha = 1 sceneGroup:insert( passBtn ) cancelBtn = widget.newButton( { defaultFile = "img/cancel.png", overFile = "img/cancelOver.png", font = "IMPACT", width = 105, height = 45, onRelease = onCancel } ) cancelBtn.x = d.w - cancelBtn.width/2 cancelBtn.y = turn.y cancelBtn.alpha = 0 sceneGroup:insert( cancelBtn ) clearBtn = widget.newButton( { defaultFile = "img/clear.png", overFile = "img/clearOver.png", font = "IMPACT", width = 105, height = 45, onRelease = onClear } ) clearBtn.x = clearBtn.width/2 clearBtn.y = turn.y clearBtn.alpha = 0 sceneGroup:insert( clearBtn ) exchangeBtn = widget.newButton( { defaultFile = "img/exchange.png", overFile = "img/exchangeOver.png", font = "IMPACT", width = 105, height = 45, onRelease = onExchange } ) exchangeBtn.x = exchangeBtn.width/2 exchangeBtn.y = turn.y sceneGroup:insert( exchangeBtn ) p1ScoreTxt = display.newEmbossedText( sceneGroup, "P1: "..p1Score, 0, 0, "IMPACT", 18 ) p1ScoreTxt:setFillColor( 0.3, 0.3, 0.3 ) p1ScoreTxt.anchorX = 1 p1ScoreTxt.x = p1ScoreTxt.width + 10 p1ScoreTxt.y = p1ScoreTxt.height/1.5 p2ScoreTxt = display.newEmbossedText( sceneGroup, "P2: "..p2Score, 0, 0, "IMPACT", 18 ) p2ScoreTxt:setFillColor( 0.3, 0.3, 0.3 ) p2ScoreTxt.anchorX = 1 p2ScoreTxt.x = p2ScoreTxt.width + 10 p2ScoreTxt.y = p1ScoreTxt.y + p2ScoreTxt.height endGame = widget.newButton( { width = 70, height = 70, font = "IMPACT", defaultFile = "img/agkola.png", overFile = "img/agkolaOver.png", onRelease = function ( ) --adjust() local options = { effect = "zoomOutInFade", time = 200, isModal = true, params = {p1Score = p1Score, p2Score = p2Score, p1ScoreAdjust = player1Adjust, p2ScoreAdjust=player2Adjust} } composer.showOverlay( "gameOver", options ) timer.cancel(gameTimer) timerDisplay:removeSelf() end } ) endGame.x = d.w - endGame.width/2 endGame.y = scoreboard.y sceneGroup:insert( endGame ) local text = display.newEmbossedText( sceneGroup, "Keran Tiles", d.centerX, scoreboard.y/2, "IMPACT", 16 ) text:setFillColor( 0.3, 0.3, 0.3 ) tilesRemainingTxt = display.newEmbossedText( sceneGroup, tilesRemaining, d.centerX, text.y + text.height, "IMPACT", 18) tilesRemainingTxt:setFillColor( 0.3, 0.3, 0.3 ) local time = 300 timerDisplay = display.newText("5:00", 0, 0, native.systemFont, 18) --timerDisplay:setReferencePoint(display.CenterReferencePoint) timerDisplay.x, timerDisplay.y =230, 17 timerDisplay:setTextColor(150,16,33) sceneGroup:insert(timerDisplay) local mins = 4 local secs = 60 local function updateTime(event) time = time-1 secs = secs-1 if secs \< 10 and secs \> 0 then secsText = "0" ..secs elseif secs \< 1 then secsText = "00" if mins \> 0 then secs = 59 end mins = mins - 1 minsText = min else secsText = secs end if mins \> 1 then minsText = mins elseif mins \< 1 then minsText = "0" mins = 0 end if secs == 0 then local options = { effect = "zoomOutInFade", time = 200, isModal = true, params = {p1Score = p1Score, p2Score = p2Score, p1ScoreAdjust = player1Adjust, p2ScoreAdjust=player2Adjust} } composer.showOverlay( "gameOver", options) timer.cancel(gameTimer) timerDisplay:removeSelf() end timerDisplay.text = mins.. ":" ..secsText end gameTimer = timer.performWithDelay(1000, updateTime, 0) end --onCreate board tiles function createBoardTiles ( ) for i=1, 225 do boardTile[i] = display.newImageRect( boardGroup, "img/boardTile.png", board.width/15, board.height/15 ) boardTile[i].index = i --board tile index boardTile[i].on = false --tells if the board tile is in use-for debugging purposes only end boardGroup:insert( board ) positionBoardTiles() sceneGroup:insert( boardGroup ) --insert to main group end --get a random letter local function getLetter( ) --decrement tiles total number//\*\* number remaining in bag -- --spriteSheet data local sheetData = { width = 50, height = 45, numFrames = 20, sheetContentWidth = 250, sheetContentHeight = 180 } --get spriteSheet local letterSheet = graphics.newImageSheet( "img/pangasinanLetters.png", sheetData ) local ran local letter local flag = false if (tilesRemaining\>=0) then while flag == false do ran = math.random( 20 ) if (distributions[ran] ~= 0) then distributions[ran] = distributions[ran] - 1 flag = true else flag = false end end letter = display.newImageRect( sceneGroup, letterSheet, ran, 45, 50 ) --ran is the index of frame in the spritesheet letter.points = points[ran] --designated point letter.letter = letters[ran] --designated letter letter.ran = ran --distribution index letter.alpha = 1 --alpha letter.tileNum = 0 --index //tile number of board tile letter.status = "active" --status active letter.defaultWidth = letter.width --store default width letter.defaultHeight = letter.height --store default height letter:addEventListener( "touch", onDrag ) --add event listener end tilesRemaining = tilesRemaining - 1 --decrement the total tiles tilesRemainingTxt.text = tilesRemaining --set text return letter --return value end --create letter tiles that will display to the rack local function createLetters( player ) local x, y = -20, d.h for i=1,tilePiecesPerRack do tileCounter = tileCounter + 1 --increment counter player[i] = getLetter() --create a lettertile and decrements the total tiles player[i].index = tileCounter player[i].x = x + player[i].width --x position player[i].rackIndex = i --rack index position player[i].y = y + player[i].height/2 --y position player[i].xOriginPos = player[i].x --store its rack x position player[i].yOriginPos = player[i].y - player[i].height --store its rack y position x = player[i].x --get current x value letterTile[tileCounter] = player[i] end return player end local function showTiles( tiles ) for i=1,#tiles do if (tiles[i].tileNum == 0 and tiles[i].status == "inActive" ) then transition.to( tiles[i], {y = tiles[i].yOriginPos, alpha = 1, time = 200} ) tiles[i].status = "active" end end return true end local function hideTiles( tiles ) for i=1,#tiles do if (tiles[i].tileNum == 0 and tiles[i].status == "active" ) then transition.to( tiles[i], {y = tiles[i].yOriginPos + tiles[i].height, alpha = 0, time = 200} ) tiles[i].status = "inActive" end end return true end --display all objects function displayAll( ) initInterface() player1 = createLetters(player1) player2 = createLetters(player2) hideTiles(player1) hideTiles(player2) timer.performWithDelay( 500, function ( ) showTiles(player1) end ) end --positioning board tiles function positionBoardTiles( ) local initX = board.x - board.width/2 - ((board.width/15)/2) local initY = board.y - board.height/2 + ((board.height/15)/2) local column = 0 --number of column for i=1,#boardTile do column = column + 1 --increment column --on the 16th column, restart column count to 1 if (column == 16 ) then column = 1 --restart column to 1 initX = board.x - board.width/2 - boardTile[i].width/2 --x coordinate will be reset initY = initY + boardTile[i].height --add y coordinate end boardTile[i].x = initX + boardTile[i].width boardTile[i].y = initY initX = boardTile[i].x initY = boardTile[i].y end end --this will let the letters to be drag along with the board if the letter tile is on the board local function positionLetterTiles( ) for i=1,tileCounter do if (letterTile[i].tileNum ~= 0) then letterTile[i].x = boardTile[letterTile[i].tileNum].x letterTile[i].y = boardTile[letterTile[i].tileNum].y end end return true end ----------------------------------------------------------------------------- --// drag and drop function setup //----------------------------------------- ----------------------------------------------------------------------------- --function for pinchZoom gesture from corona sample codes local function calculateDelta( previousTouches, event ) local id,touch = next( previousTouches ) if event.id == id then id,touch = next( previousTouches, id ) assert( id ~= event.id ) end local dx = touch.x - event.x local dy = touch.y - event.y return dx, dy end --make the board draggable onDragBoard = function ( e ) local t = e.target local phase = e.phase ------------------------------------------------------------ --from corona pinchZoom gesture sample codes local previousTouches = t.previousTouches local numTotalTouches = 1 if ( previousTouches ) then -- add in total from previousTouches, subtract one if event is already in the array numTotalTouches = numTotalTouches + t.numPreviousTouches if previousTouches[e.id] then numTotalTouches = numTotalTouches - 1 end end --------------------------------------------------------- if (phase == "began") then --------//---from pinchZoom gesture corona sample codes -- Very first "began" e if ( not t.isFocus ) then -- Subsequent touch es will target button even if they are outside the contentBounds of button display.getCurrentStage():setFocus( t ) t.isFocus = true previousTouches = {} t.previousTouches = previousTouches t.numPreviousTouches = 0 elseif ( not t.distance ) then local dx,dy if previousTouches and ( numTotalTouches ) \>= 2 then dx,dy = calculateDelta( previousTouches, e ) end -- initialize to distance between two touches if ( dx and dy ) then local d = math.sqrt( dx\*dx + dy\*dy ) if ( d \> 0 ) then t.distance = d t.widthOriginal = t.width t.heightOriginal = t.height end end end if not previousTouches[e.id] then t.numPreviousTouches = t.numPreviousTouches + 1 end previousTouches[e.id] = e ------------------------------------------------------- t.x0 = e.x - t.x t.y0 = e.y - t.y elseif t.isFocus then if "moved" == phase then --//--from pinchZoom gesture corona sample codes////////////////////////////// if ( t.distance ) then local dx,dy if previousTouches and ( numTotalTouches ) \>= 2 then dx,dy = calculateDelta( previousTouches, e ) end if ( dx and dy ) then local newDistance = math.sqrt( dx\*dx + dy\*dy ) local scale = newDistance / t.distance if ( scale \> 0 and scale \< 5) then t.width = t.widthOriginal \* scale t.height = t.heightOriginal \* scale t.x = d.centerX t.y = d.centerY if (t.width \<= 300) then t.width = 300 t.height = 375 elseif t.width\>=800 then t.width = 800 t.height = 875 end for i=1,#boardTile do boardTile[i].width = board.width/15 boardTile[i].height = board.height/15 end positionBoardTiles() for i=1,#letterTile do if (letterTile[i].tileNum~=0) then letterTile[i].width = board.width/15 letterTile[i].height = board.height/15 end end positionLetterTiles() end end end if not previousTouches[e.id] then t.numPreviousTouches = t.numPreviousTouches + 1 end previousTouches[e.id] = e --/////////////////////////////////////////////////////////////// local y = e.y - t.y0 local x = e.x - t.x0 local xLimit = (t.width - d.w )/2 local yLimit = (t.height - d.h + 180 )/2 if (d.centerX + xLimit + 25 \>= x and d.centerX - xLimit - 25 \<= x) then t.x = x end if (d.centerY + yLimit \>= y and d.centerY - yLimit - 50 \<= y) then t.y = y end positionBoardTiles() -- call function to reposition boardTiles positionLetterTiles() --call function to reposition letterTiles on board elseif "ended" == phase or "cancelled" == phase then if previousTouches[e.id] then t.numPreviousTouches = t.numPreviousTouches - 1 previousTouches[e.id] = nil end if ( #previousTouches \> 0 ) then -- must be at least 2 touches remaining to pinch/zoom t.distance = nil else -- previousTouches is empty so no more fingers are touching the screen -- Allow touch es to be sent normally to the objects they "hit" display.getCurrentStage():setFocus( nil ) t.isFocus = false t.distance = nil t.widthOriginal = nil t.heightOriginal = nil -- reset array t.previousTouches = nil t.numPreviousTouches = nil end end end return true end --choose letter for blank tile putLetterForBlankTile = function ( params ) local options = { effect = "zoomOutInFade", time = 200, isModal = true, params = params, } composer.showOverlay( "blank", options ) end --make letters draggable onDrag = function ( e ) local t = e.target local phase = e.phase if (phase == "began") then t.isFocus = true display.getCurrentStage( ):setFocus( t ) t:toFront( ) --display it to the front layer t.x0 = e.x - t.x t.y0 = e.y - t.y --check if the tile tapped is already in the board if (t.tileNum~=0) then sceneGroup:insert( t ) --insert to sceneGroup boardGroup:remove( t ) --remove to boardGroup boardTile[t.tileNum].on = false --reset the boardTile.on end elseif t.isFocus then if "moved" == phase then t.y = e.y - t.y0 t.x = e.x - t.x0 --resize the tile before putting to the board if ( t.y \< d.h - rack.height - statusBar.height) then t.width = boardTile[1].width t.height = boardTile[1].height else t.width = t.defaultWidth --resize to default width t.height = t.defaultHeight --resize to default height end elseif "ended" == phase or "cancelled" == phase then --check if the player returned it to the rack or the tile piece in an invalid location if (t.y \>= d.h - rack.height - statusBar.height) then --if yes, return to rack if (t.y \>= d.h - rack.height - statusBar.height and t.y \< d.h + t.height) then t.width = t.defaultWidth --resize to default width t.height = t.defaultHeight --resize to default height local player = {} if (turn.text == "Player 1") then player = player1 else player = player2 end local from, to for i=1, #player do local xArea = player[i].xOriginPos - t.x local yArea = player[i].yOriginPos - t.y if (xArea \<= player[i].width/2 and xArea \>= -player[i].width/2 and player[i].status == t.status) then to = i from = t.rackIndex end end if (from) then if player[to].tileNum~=0 then local temp = {} temp = player[to].rackIndex player[to].rackIndex = player[from].rackIndex player[from].rackIndex = temp temp = player[to].xOriginPos player[to].xOriginPos = player[from].xOriginPos player[from].xOriginPos = temp temp = player[to] player[to] = player[from] player[from] = temp elseif (from\>to) then for j=from,to+1,-1 do if (j-to~=0) then local temp = {} temp = player[j].rackIndex player[j].rackIndex = player[j-1].rackIndex player[j-1].rackIndex = temp temp = player[j].xOriginPos player[j].xOriginPos = player[j-1].xOriginPos player[j-1].xOriginPos = temp temp = player[j] player[j] = player[j-1] player[j-1] = temp end end else for j=from,to-1 do if (j+from~=0) then local temp = {} temp = player[j].rackIndex player[j].rackIndex = player[j+1].rackIndex player[j+1].rackIndex = temp temp = player[j].xOriginPos player[j].xOriginPos = player[j+1].xOriginPos player[j+1].xOriginPos = temp temp = player[j] player[j] = player[j+1] player[j+1] = temp end end end end for i=1,#player do if (player[i].tileNum==0) then transition.to( player[i], {y = player[i].yOriginPos, x = player[i].xOriginPos, time = 100} ) else if (t.points == 0) then t = remakeBlankTile(t.index) sceneGroup:insert(t) end transition.to( t, {y = t.yOriginPos, x = t.xOriginPos, time = 200} ) t.width = t.defaultWidth --resize to default width t.height = t.defaultHeight --resize to default height t.tileNum = 0 --reset the player.tileNum to 0 end end end elseif t.y \<= scoreboard.y + scoreboard.height/2 then --if tile piece is in an invalid location if (t.tileNum~=0) then --its already on board --paste it to its current position transition.to( t, {y = boardTile[t.tileNum].y, x = boardTile[t.tileNum].x, time = 200} ) boardTile[t.tileNum].on = true --set the boardTile state to true boardGroup:insert( t ) --insert to the boardGroup else --its on the rack --if no, return it to the rack transition.to( t, {y = t.yOriginPos, x = t.xOriginPos, time = 200} ) t.width = t.defaultWidth --resize to default width t.height = t.defaultHeight --resize to default height t.tileNum = 0 --reset the player.tileNum to 0 boardTile[t.tileNum].state = nil --reset the boardTile.state boardTile[t.tileNum].letter = nil --reset the boardTile.letter boardTile[t.tileNum].points = nil --reset the boardTile.points end--end if else onDrop(e) end t.isFocus = false display.getCurrentStage( ):setFocus( nil ) end end return true end --onDrop letter onDrop = function ( e ) local t = e.target local position = false --flag for position is validity --loop to the boardTiles to check whether that boardTile is near our letterTile for i=1,#boardTile do local xArea = boardTile[i].x - t.x --x padding of the boardTile local yArea = boardTile[i].y - t.y --y padding of the boardTile -- --if found a boardTile near the letterTile if (xArea \<= boardTile[i].width/2 and xArea \>= -boardTile[i].width/2 and yArea \<= boardTile[i].height/2 and yArea \>= -boardTile[i].height/2 and boardTile[i].on == false) then position = true --flag // --valid position t.tileNum = i --get the index of the boardTile found boardTile[i].on = true --states that the bordTile will be used boardTile[i].state = "new" --put state to "new" to separate newly dropped tiles --transfer information of letter tile to board tile so that we can loop to the board tiles --with information of the letter tiles in them boardTile[i].letter = t.letter --trnsfer letter value boardTile[i].points = t.points --transfer points value boardGroup:insert( t ) --insert to the boardGroup end --end if end --end for --if the position is valid, if (position == true) then --paste it to the boardTile piece sfx.play(sfx.tap) --play a tap sound transition.to( t, {x = boardTile[t.tileNum].x, y = boardTile[t.tileNum].y, time = 100, onComplete = function ( ) if (t.letter == " ") then putLetterForBlankTile(t) end end} ) else --if not, check if the letterTile is already in the board if (t.tileNum~=0) then --if yes, paste it to its current position transition.to( t, {y = boardTile[t.tileNum].y, x = boardTile[t.tileNum].x, time = 200} ) boardTile[t.tileNum].on = true --set the boardTile state to true boardGroup:insert( t ) --insert to the boardGroup else transition.to( t, {y = t.yOriginPos, x = t.xOriginPos, time = 200} ) t.width = t.defaultWidth --resize to default width t.height = t.defaultHeight --resize to default height end end --------------------------------------------------------------------------- --------------------------------------------------------------------------- return t end ----------------------------------------------------------------------------- --//Runtime// check if the board has new tiles on board function checkNewTiles( ) local newTilesCount = 0 for i=1,#boardTile do if (boardTile[i].on) then if (boardTile[i].state == "new") then newTilesCount = newTilesCount + 1 end end end if (newTilesCount==0) then passBtn.alpha = 1 submitBtn.alpha = 0 clearBtn.alpha = 0 exchangeBtn.alpha = 1 else passBtn.alpha = 0 submitBtn.alpha = 1 clearBtn.alpha = 1 exchangeBtn.alpha = 0 end end ----------------------------------------------------------------------------- --// submit, clear, check answer //------------------------------------------ ----------------------------------------------------------------------------- --blank tile remakeBlankTile = function ( i ) local tempTile = letterTile[i] local player = {} local l local tempTile = letterTile[i] letterTile[i]:removeSelf( ) letterTile[i] = nil if (turn.text == "Player 1") then player = player1 else player = player2 end local sheetData = { width = 50, height = 45, numFrames = 20, sheetContentWidth = 250, sheetContentHeight = 180 } local letterSheet = graphics.newImageSheet( "img/pangasinanLetters.png", sheetData ) player[tempTile.rackIndex] = display.newImageRect( boardGroup, letterSheet, 20, 45, 50 ) --ran is the index of frame in the spritesheet player[tempTile.rackIndex].points = 0 --designated point player[tempTile.rackIndex].letter = letters[20] --designated letter player[tempTile.rackIndex].ran = tempTile.ran --distribution index player[tempTile.rackIndex].status = tempTile.status --status active player[tempTile.rackIndex].tileNum = tempTile.tileNum player[tempTile.rackIndex].width = 45 player[tempTile.rackIndex].height = 50 player[tempTile.rackIndex].defaultWidth = 45 player[tempTile.rackIndex].defaultHeight = 50 player[tempTile.rackIndex]:addEventListener( "touch", onDrag ) --add event listener letterTile[i] = player[tempTile.rackIndex] letterTile[i].index = tempTile.index letterTile[i].x = tempTile.x letterTile[i].y = tempTile.y letterTile[i].rackIndex = tempTile.rackIndex letterTile[i].xOriginPos = tempTile.xOriginPos letterTile[i].yOriginPos = tempTile.yOriginPos letterTile[i]:toFront( ) return letterTile[i] end --popUp msgs function popUp( text ) --invalid entry of tiles local square = display.newRoundedRect( sceneGroup, d.centerX, d.centerY/2, d.w - 20, 80, 10 ) square:setFillColor( 0.90, 0.74, 0.57 ) square.strokeWidth = 5 square:setStrokeColor( 1, 1, 1 ) local txt = display.newEmbossedText( sceneGroup, text, d.centerX, d.centerY/2, "IMPACT", 16 ) txt:setFillColor( 0.3, 0.3, 0.3 ) local r1 local function r( e ) local t = e.target local phase = e.phase if (phase == "began") then square:removeSelf( ); square = nil txt:removeSelf( ); txt = nil timer.cancel( r1 ) r1 = nil end return true end local function r2( ) square:removeSelf( ); square = nil txt:removeSelf( ); txt = nil timer.cancel( r1 ) r1 = nil end square:addEventListener( "touch", r ) r1 = timer.performWithDelay( 2000, r2 ) end --check tile if gaps occcur and if tiles are at one row or column local first = 0 --keeps the index of the first new tile by column local last = 0 --keeps the index of the last new tile by column local distance = 0 --number of tiles between first and last new tiles function checkGapsRowColumn( ) local result = true d.numOfNewTiles = 0 --reset counting every time player drop a tile to the board --get the index of first new tile in the column for i=1,#boardTile do if (boardTile[i] and boardTile[i].on and boardTile[i].state == "new") then first = i --look for new tile that comes first break; --breaks the loop once we found the first tile end end --count new tiles onboard --get the index of last new tile for i=1,#boardTile do if (boardTile[i] and boardTile[i].on and boardTile[i].state == "new") then last = i --look for new tile that comes first d.numOfNewTiles = d.numOfNewTiles + 1 --count only those newly dropped tiles end end --get the number of tiles between the first and last newly dropped tiles local columnLimit = 0 if (d.numOfNewTiles\>=2) then distance = last - first --get distance/ number of tiles in between first and last columnLimit = 15 - (first%15) --count column left end --check if the last tile is in a column or a row --if yes, then its in a column if (distance\<=columnLimit) then --search for a gap if any for i=first,last, 1 do if (boardTile[i] and not boardTile[i].on) then popUp("Ag to sarag so nan buwang!") result = false break; end end --else, its in a row elseif (distance\>columnLimit) then local allInRow = true --set a flag that will tell us that all tiles are in a row --check if some tiles are not in a row or column for i=first,last do if ((i - first)%15 ~= 0 ) then if (boardTile[i] and boardTile[i].on and boardTile[i].state == "new") then popUp("Dapat aka hilera so tiles!") result = false allInRow = false break; end end end --separate loop for search of gaps for i=first,last do --check if there are some gaps if ((i - first)%15 == 0 ) and allInRow then if (boardTile[i] and not boardTile[i].on ) then popUp("Ag to sarag so nan buwang!") result = false break; end end end end -- d.first = first d.last = last return result end --next turn, change the current player local function nxtTurn( ) --check which player is active if (turn.text == "Player 1") then hideTiles(player1) --hide player1's tiles showTiles(player2) --show player2's tiles turn.text = "Player 2" --change text else hideTiles(player2) --hide player2's tiles showTiles(player1) --show player1's tiles turn.text = "Player 1" --change text end end --------------------- local player = {} local function getPlayer( ) if (turn.text == "Player 1") then player = player1 else player = player2 end end ---------------------- local numOfLettersToExchange = 0 local square, text local \_x, \_y = -20, d.centerY + 10 --cancel exchange of letters onCancel = function ( e ) getPlayer() numOfLettersToExchange = 0 if (exchange) then -- set exchange to false exchange = false --reset x and y values \_x, \_y = -20, d.centerY + 10 --remove overlaylike box square:removeSelf(); square = nil text:removeSelf(); text = nil --hide cancelBtn/show submitbtn submitBtn.alpha = 1 cancelBtn.alpha = 0 --return tiles onExchange for i=1,#player do if (player[i].temp) then player[i]:removeEventListener( "touch", exchangeTile ) player[i]:addEventListener( "touch", onDrag ) transition.to( player[i], {x = player[i].xOriginPos, y = player[i].yOriginPos, time = 100} ) player[i].temp = nil else player[i]:removeEventListener( "touch", exchangeTile ) player[i]:addEventListener( "touch", onDrag ) end end end return true end --exchange letters and lose a turn onExchange = function ( e ) getPlayer() local exchangeTiles = {} if (not exchange) then --change exchange to true exchange = true --show overlaylike box square = display.newRoundedRect( sceneGroup, d.centerX, d.centerY, d.w, 80, 10 ) square:setFillColor( 0.90, 0.74, 0.57 ) square.strokeWidth = 5 square:setStrokeColor( 1, 1, 1 ) text = display.newText( sceneGroup, "Mangisalat na Letra", d.centerX, square.y - square.height/1.5, "IMPACT", 18 ) text:setFillColor( 0.3, 0.3, 0.3 ) text.y = text.y + text.height --hide submit/display cancel submitBtn.alpha = 0 cancelBtn.alpha = 1 --onreturn exchange function function returnExchange( e ) local t = e.target local phase = e.phase if (phase == "began") then if (t.temp == numOfLettersToExchange) then t:removeEventListener( "touch", returnExchange ) transition.to( t, {x = t.xOriginPos, y = t.yOriginPos, time = 100, onComplete = function ( self ) self:addEventListener( "touch", exchangeTile ) end} ) t.temp = nil numOfLettersToExchange = numOfLettersToExchange - 1 \_x = \_x - t.width end end return true end --add tiles an exchangeTiles listener function exchangeTile( e ) local t = e.target local phase = e.phase if (phase == "began") then t:removeEventListener( "touch", exchangeTile ) numOfLettersToExchange = numOfLettersToExchange + 1 t.temp = numOfLettersToExchange t:toFront( ) transition.to( t, {x = \_x + t.width, y = \_y, time = 100, onComplete = function ( self ) self:addEventListener( "touch", returnExchange ) end}) \_x = \_x + t.width end return true end for i=1,#player do if (player[i].tileNum==0) then player[i]:removeEventListener( "touch", onDrag ) player[i]:addEventListener( "touch", exchangeTile ) end end else if (numOfLettersToExchange~=0 and tilesRemaining \>= numOfLettersToExchange) then exchange = false --reset exchange square:removeSelf( ); square = nil --remove objects added text:removeSelf( ); text = nil --remove objects added \_x, \_y = -20, d.centerY + 10 --reset x and y reference for i=1,#player do if (player[i].temp) then --tiles that are exchanged need to go back to their rack positions transition.to(player[i], {x =player[i].xOriginPos, y =player[i].yOriginPos, time = 100} ) exchangeTiles[i] = player[i] --put the exchanged tiles to a temporary table else player[i]:removeEventListener( "touch", exchangeTile ) --remove; tiles that remains player[i]:addEventListener( "touch", onDrag ) --add; tiles that remains end end for i=1,#player do if (player[i].temp) then --index tiles with temporary reference distributions[player[i].ran] = distributions[player[i].ran] + 1 --return to distribution since player will not use it tilesRemaining = tilesRemaining + 1 -- add it also to the remaining tiles since player exchanged it letterTile[player[i].index]:removeSelf( ); letterTile[player[i].index] = nil --remove from table; so that we can put another one player[i]:removeSelf( ); player[i] = nil -- player[i] = getLetter() --get new letter player[i].index = exchangeTiles[i].index --get the current index player[i].status = exchangeTiles[i].status --get current status player[i].rackIndex = exchangeTiles[i].rackIndex --get current rackindex player[i].xOriginPos = exchangeTiles[i].xOriginPos --get current xOriginPos player[i].yOriginPos = exchangeTiles[i].yOriginPos --get current yOriginPos player[i].x = player[i].xOriginPos --x position player[i].rackIndex = exchangeTiles[i].rackIndex -- get rack index player[i].y = player[i].yOriginPos + player[i].height --y position letterTile[player[i].index] = player[i] --replace the tile removed exchangeTiles[i] = nil --remove object to the temporaty table end end nxtTurn() --since player exchanged tiles, player will lose a turn cancelBtn.alpha = 0 --hide cancel btn passBtn.alpha = 1 --show pass btn numOfLettersToExchange = 0 --reset number of tiles exchanged else popUp("Angapo la o kulang lay Tiles\nya pangisalatan!") end end return true end --compute all the tiles in the rack and subtract it to the players' score function adjust( ) for i=1,#player1 do if (player1[i].tileNum == 0) then player1Adjust = player1Adjust + player1[i].points end end for i=1,#player2 do if (player2[i].tileNum == 0) then player2Adjust = player2Adjust + player2[i].points end end p1Score = p1Score - player1Adjust p2Score = p2Score - player2Adjust p1ScoreTxt.text = "P1: "..p1Score p2ScoreTxt.text = "P2: "..p2Score p1ScoreTxt.anchorX = 1 p1ScoreTxt.x = p1ScoreTxt.width + 10 p2ScoreTxt.anchorX = 1 p2ScoreTxt.x = p2ScoreTxt.width + 10 end --when a player passed; he/she will lose a turn local passCount1 = 0 --count passes of players local passCount2 = 0 onPass = function ( e ) if (turn.text == "Player 1") then passCount1 = passCount1 + 1 else passCount2 = passCount2 + 1 end nxtTurn() if (passCount2 \>= 3 and passCount1 \>= 3) then adjust() local options = { effect = "zoomOutInFade", time = 200, isModal = true, params = {p1Score = p1Score, p2Score = p2Score, p1ScoreAdjust = player1Adjust, p2ScoreAdjust=player2Adjust} } composer.showOverlay( "gameOver", options ) end end ------------------------------------------------------------------------------------------------ --============================================================================================= --============================================================================================= --============================================================================================= --============================================================================================= --============================================================================================= --============================================================================================= --============================================================================================= --============================================================================================= --clear all tiles from board that are currently put by the player onClear = function ( e ) --return tiles to rack for i=1,tileCounter do if (letterTile[i].tileNum~=0 and not letterTile[i].m) then if (letterTile[i].points == 0) then remakeBlankTile(i) end transition.to( letterTile[i], {y = letterTile[i].yOriginPos, x = letterTile[i].xOriginPos, time = 200}) letterTile[i].width = letterTile[i].defaultWidth --resize to default width letterTile[i].height = letterTile[i].defaultHeight --resize to default height boardTile[letterTile[i].tileNum].on = false --reset the boardTile.on boardTile[letterTile[i].tileNum].state = nil --reset the boardTile.state boardTile[letterTile[i].tileNum].letter = nil --reset the boardTile.letter boardTile[letterTile[i].tileNum].points = nil --reset the boardTile.points letterTile[i].tileNum = 0 --reset the letterTile.tileNum to 0 sceneGroup:insert( letterTile[i] ) --insert to sceneGroup boardGroup:remove( letterTile[i] ) --remove to boardGroup end end return true end --this function will disable events of letter tiles once the player submit a word successfully local function removeEventsAndPlaceNewTiles( ) local player = {} if (turn.text == "Player 1") then player = player1 else player = player2 end local m = 0 --remove event listener for i=1, #player do --paste the tile permanently to the board if (player[i].tileNum~=0 ) then player[i]:removeEventListener( "touch", onDrag ) if (not player[i].m) then boardTile[player[i].tileNum].state = "old" player[i].m = true boardTile[player[i].tileNum].m = true print( player[i].tileNum ) m = m + 1 print( m ) onBoardTiles[m] = player[i] --insert to onBoard table --temporary insert to table to get their stats and positions later end end end --get the xOrigin and yOrigin of the tile paste permanently, so that we can get another tile --and put it to the rack with the position of the current tile for i=1,m do if (tilesRemaining\>0) then tileCounter = tileCounter + 1 --increment counter player[onBoardTiles[i].rackIndex] = nil player[onBoardTiles[i].rackIndex] = getLetter() --create a lettertile and decrements the total tiles player[onBoardTiles[i].rackIndex].index = tileCounter player[onBoardTiles[i].rackIndex].x = onBoardTiles[i].xOriginPos --x position player[onBoardTiles[i].rackIndex].rackIndex = onBoardTiles[i].rackIndex --rack index position player[onBoardTiles[i].rackIndex].y = onBoardTiles[i].yOriginPos + onBoardTiles[i].height --y position player[onBoardTiles[i].rackIndex].xOriginPos = onBoardTiles[i].xOriginPos --store its rack x position player[onBoardTiles[i].rackIndex].yOriginPos = onBoardTiles[i].yOriginPos --store its rack y position letterTile[tileCounter] = player[onBoardTiles[i].rackIndex] onBoardTiles[i].xOriginPos = 0 --set to 0 to avoid conflict in swapping tiles in rack onBoardTiles[i].yOriginPos = 0 onBoardTiles[i].rackIndex = 0 end end m = nil --remove its data onBoardTiles = {} end --after the first word, next turns must link to an existing word local function linkWords( ) local result = false local j = first --horizontal if (boardTile[j - 1] and boardTile[j - 1].on ) then while boardTile[j-1] and boardTile[j-1].on do j = j - 1 end while boardTile[j] and boardTile[j].on do if (boardTile[j].state == "old") then result = true break; else if (boardTile[j-15] and boardTile[j-15].on) then while boardTile[j-15] and boardTile[j-15].on do j = j - 15 end while boardTile[j] and boardTile[j].on do if (boardTile[j].state == "old") then result = true break; end j = j + 15 end elseif (boardTile[j+15] and boardTile[j+15].on) then while boardTile[j] and boardTile[j].on do if (boardTile[j].state == "old") then result = true break; end j = j + 15 end end end j = j + 1 end elseif (boardTile[j+1] and boardTile[j+1].on) then while boardTile[j] and boardTile[j].on do if (boardTile[j].state == "old") then result = true break; else if (boardTile[j-15] and boardTile[j-15].on) then while boardTile[j-15] and boardTile[j-15].on do j = j - 15 end while boardTile[j] and boardTile[j].on do if (boardTile[j].state == "old") then result = true break; end j = j + 15 end elseif (boardTile[j+15] and boardTile[j+15].on) then while boardTile[j] and boardTile[j].on do if (boardTile[j].state == "old") then result = true break; end j = j + 15 end end end j = j + 1 end end j = first --vertical if (boardTile[j-15] and boardTile[j-15].on) then while boardTile[j-15] and boardTile[j-15].on do j = j - 15 end while boardTile[j] and boardTile[j].on do if (boardTile[j].state == "old") then result = true break; else if (boardTile[j - 1] and boardTile[j - 1].on ) then while boardTile[j-1] and boardTile[j-1].on do j = j - 1 end while boardTile[j] and boardTile[j].on do if (boardTile[j].state == "old") then result = true break; end j = j + 1 end elseif (boardTile[j+1] and boardTile[j+1].on) then while boardTile[j] and boardTile[j].on do if (boardTile[j].state == "old") then result = true break; end j = j + 1 end end end j = j + 15 end elseif (boardTile[j+15] and boardTile[j+15].on) then while boardTile[j] and boardTile[j].on do if (boardTile[j].state == "old") then result = true break; else if (boardTile[j - 1] and boardTile[j - 1].on ) then while boardTile[j-1] and boardTile[j-1].on do j = j - 1 end while boardTile[j] and boardTile[j].on do if (boardTile[j].state == "old") then result = true break; end j = j + 1 end elseif (boardTile[j+1] and boardTile[j+1].on) then while boardTile[j] and boardTile[j].on do if (boardTile[j].state == "old") then result = true break; end j = j + 1 end end end j = j + 15 end end return result end --compute double or triple letter score function letterPointMultiplier( index ) local computed\_score = 0 if (boardTile[index].state == "new") then --get indexes of double letter score if (index == 4 or index == 12 or index == 37 or index == 39 or index == 46 or index == 53 or index == 60 or index == 93 or index == 97 or index == 99 or index == 103 or index == 109 or index == 117 or index == 123 or index == 127 or index == 129 or index == 133 or index == 166 or index == 173 or index == 180 or index == 187 or index == 189 or index == 214 or index == 222) then computed\_score = boardTile[index].points \* 2 --compare index, triple letter score elseif (index == 21 or index == 25 or index == 77 or index == 81 or index == 85 or index == 89 or index == 137 or index == 141 or index == 145 or index == 149 or index == 201 or index == 205) then computed\_score = boardTile[index].points \* 3 else computed\_score = boardTile[index].points end else computed\_score = boardTile[index].points end return computed\_score end --compute double or triple word score local wordMultiplier = 1 function wordPointMultiplier( index ) if (boardTile[index].state == "new") then --word wordMultiplier if (index == 17 or index == 33 or index == 49 or index == 65 or index == 71 or index == 57 or index == 43 or index == 29 or index == 197 or index == 183 or index == 169 or index == 155 or index == 161 or index == 177 or index == 193 or index == 209 or index == 113) then wordMultiplier = 2 elseif (index == 1 or index == 8 or index == 15 or index == 120 or index == 225 or index == 218 or index == 211 or index == 106 )then wordMultiplier = 3 end end return wordMultiplier end --check player's formed word placed to the board checkWord = function ( word ) local result = true if (not db.getWord(word)) then result = false else result = true end return result end --collect words formed hoizontally and vertically with their corresponding points local function collectWords( ) local result = true local j = first --for collecting points local score = 0 local scoreText local scoreCollected = {} local horizontalScore = 0 local verticalScore = 0 --for collecting words local wordsCollected = {} local horizontalWord = "" local verticalWord = "" --counter local wordCount = 0 --get horizontal words if the newly tiles are placed horizontally, then check if there are vertical tiles on it then get the vertical words if (boardTile[j-1] and boardTile[j-1].on and boardTile[j].state == "new") then --if there are tiles before the newly dropped tile, loop backwards to start to the very first while boardTile[j-1] and boardTile[j-1].on do j = j - 1 end while boardTile[j] and boardTile[j].on do --check if there are vertically aligned to the tile above and below the new tile local k = j if (boardTile[j-15] and boardTile[j-15].on and boardTile[j].state == "new") then --if above, then loop upward while boardTile[k-15] and boardTile[k-15].on do k = k - 15 end while boardTile[k] and boardTile[k].on do verticalWord = verticalWord .. boardTile[k].letter verticalScore = verticalScore + letterPointMultiplier(k) wordMultiplier = wordPointMultiplier(k) k = k + 15 end wordCount = wordCount + 1 scoreCollected[wordCount] = verticalScore \* wordMultiplier wordsCollected[wordCount] = verticalWord verticalWord = "" wordMultiplier = 1 elseif (boardTile[j+15] and boardTile[j+15].on and boardTile[j].state == "new") then --if below, then loop downward while boardTile[k] and boardTile[k].on do verticalWord = verticalWord .. boardTile[k].letter verticalScore = verticalScore + letterPointMultiplier(k) wordMultiplier = wordPointMultiplier(k) k = k + 15 end wordCount = wordCount + 1 scoreCollected[wordCount] = verticalScore \* wordMultiplier wordsCollected[wordCount] = verticalWord verticalWord = "" wordMultiplier = 1 end horizontalWord = horizontalWord..boardTile[j].letter horizontalScore = horizontalScore + letterPointMultiplier(j) wordMultiplier = wordPointMultiplier(j) j = j + 1 end wordCount = wordCount + 1 scoreCollected[wordCount] = horizontalScore \* wordMultiplier wordsCollected[wordCount] = horizontalWord horizontalWord = "" wordMultiplier = 1 --if before the tile is empty, then check if there are tiles after it elseif boardTile[j+1] and boardTile[j+1].on and boardTile[j].state == "new" then --loop forward while boardTile[j] and boardTile[j].on do --check if there are vertically aligned to the tile above and below local k = j if (boardTile[j-15] and boardTile[j-15].on and boardTile[j].state == "new") then --if above, then loop upward while boardTile[k-15] and boardTile[k-15].on do k = k - 15 end while boardTile[k] and boardTile[k].on do verticalWord = verticalWord .. boardTile[k].letter verticalScore = verticalScore + letterPointMultiplier(k) wordMultiplier = wordPointMultiplier(k) k = k + 15 end wordCount = wordCount + 1 scoreCollected[wordCount] = verticalScore \* wordMultiplier wordsCollected[wordCount] = verticalWord verticalWord = "" wordMultiplier = 1 elseif (boardTile[j+15] and boardTile[j+15].on and boardTile[j].state == "new") then --if below, then loop downward while boardTile[k] and boardTile[k].on do verticalWord = verticalWord .. boardTile[k].letter verticalScore = verticalScore + letterPointMultiplier(k) wordMultiplier = wordPointMultiplier(k) k = k + 15 end wordCount = wordCount + 1 scoreCollected[wordCount] = verticalScore \* wordMultiplier wordsCollected[wordCount] = verticalWord verticalWord = "" wordMultiplier = 1 end horizontalWord = horizontalWord..boardTile[j].letter horizontalScore = horizontalScore + letterPointMultiplier(j) wordMultiplier = wordPointMultiplier(j) j = j + 1 end wordCount = wordCount + 1 scoreCollected[wordCount] = horizontalScore \* wordMultiplier wordsCollected[wordCount] = horizontalWord horizontalWord = "" wordMultiplier = 1 -- j = first --next, if words are vertically arranged, check if there are horizontal words link into it then get the vertical owrds elseif (boardTile[j-15] and boardTile[j-15].on and boardTile[j].state == "new") then while boardTile[j-15] and boardTile[j-15].on do j = j - 15 end while boardTile[j] and boardTile[j].on do --check if there are horizontal words link to new tiles local k = j if (boardTile[j-1] and boardTile[j-1].on and boardTile[j].state == "new") then while boardTile[k-1] and boardTile[k-1].on do k = k - 1 end while boardTile[k] and boardTile[k].on do horizontalWord = horizontalWord..boardTile[k].letter horizontalScore = horizontalScore + letterPointMultiplier(k) wordMultiplier = wordPointMultiplier(k) k = k + 1 end wordCount = wordCount + 1 scoreCollected[wordCount] = horizontalScore \* wordMultiplier wordsCollected[wordCount] = horizontalWord horizontalWord = "" wordMultiplier = 1 elseif (boardTile[j+1] and boardTile[j+1].on and boardTile[j].state == "new") then while boardTile[k] and boardTile[k].on do horizontalWord = horizontalWord..boardTile[k].letter horizontalScore = horizontalScore + letterPointMultiplier(k) wordMultiplier = wordPointMultiplier(k) k = k + 1 end wordCount = wordCount + 1 scoreCollected[wordCount] = horizontalScore \* wordMultiplier wordsCollected[wordCount] = horizontalWord horizontalWord = "" wordMultiplier = 1 end verticalWord = verticalWord .. boardTile[j].letter verticalScore = verticalScore + letterPointMultiplier(j) wordMultiplier = wordPointMultiplier(j) j = j + 15 end wordCount = wordCount + 1 scoreCollected[wordCount] = verticalScore \* wordMultiplier wordsCollected[wordCount] = verticalWord verticalWord = "" wordMultiplier = 1 elseif (boardTile[j+15] and boardTile[j+15].on and boardTile[j].state == "new" ) then while boardTile[j] and boardTile[j].on do local k = j if (boardTile[j-1] and boardTile[j-1].on and boardTile[j].state == "new") then while boardTile[k-1] and boardTile[k-1].on do k = k - 1 end while boardTile[k] and boardTile[k].on do horizontalWord = horizontalWord..boardTile[k].letter horizontalScore = horizontalScore + letterPointMultiplier(k) wordMultiplier = wordPointMultiplier(k) k = k + 1 end wordCount = wordCount + 1 scoreCollected[wordCount] = horizontalScore \* wordMultiplier wordsCollected[wordCount] = horizontalWord horizontalWord = "" wordMultiplier = 1 elseif (boardTile[j+1] and boardTile[j+1].on and boardTile[j].state == "new") then while boardTile[k] and boardTile[k].on do horizontalWord = horizontalWord..boardTile[k].letter horizontalScore = horizontalScore + letterPointMultiplier(k) wordMultiplier = wordPointMultiplier(k) k = k + 1 end wordCount = wordCount + 1 scoreCollected[wordCount] = horizontalScore \* wordMultiplier wordsCollected[wordCount] = horizontalWord horizontalWord = "" wordMultiplier = 1 end verticalWord = verticalWord .. boardTile[j].letter verticalScore = verticalScore + letterPointMultiplier(j) wordMultiplier = wordPointMultiplier(j) j = j + 15 end wordCount = wordCount + 1 scoreCollected[wordCount] = verticalScore \* wordMultiplier wordsCollected[wordCount] = verticalWord verticalWord = "" wordMultiplier = 1 end j = first --check if its a separated single tile on board if (boardTile[j-1] and not boardTile[j-1].on) and (boardTile[j+1] and not boardTile[j+1].on) and (boardTile[j-15] and not boardTile[j-15].on) and (boardTile[j+15] and not boardTile[j+15].on) then wordCount = wordCount + 1 wordsCollected[wordCount] = boardTile[j].letter end -------------------------------- -------------------------------- local allWordsValid = true --check words if valid for i=1,#wordsCollected do result = checkWord(wordsCollected[i]) if (not result) then popUp("say salitan \""..wordsCollected[i].."\"\net anggapo ed diksyonaryo!") allWordsValid = false break; end end if (allWordsValid) then for i=1,#scoreCollected do score = score + scoreCollected[i] end if (turn.text == "Player 1") then if (d.numOfNewTiles==7) then p1Score = p1Score + 50 popUp("BINGO!") end p1Score = p1Score + score p1ScoreTxt.text = "P1: "..p1Score p1ScoreTxt.anchorX = 1 p1ScoreTxt.x = p1ScoreTxt.width + 10 else if (d.numOfNewTiles==7) then p2Score = p2Score + 50 popUp("BINGO!") end p2Score = p2Score + score p2ScoreTxt.text = "P2: "..p2Score p2ScoreTxt.anchorX = 1 p2ScoreTxt.x = p2ScoreTxt.width + 10 end end wordMultiplier = 1 return result end --onSubmit; check the word and score it depending to the tile it is placed local firstWord onSubmit = function ( e ) if (checkGapsRowColumn()) then if (boardTile[113].on ) then if (not firstWord) then if (collectWords()) then firstWord = true removeEventsAndPlaceNewTiles() if (turn.text == "Player 1") then passCount1 = 0 else passCount2 = 0 end nxtTurn() end elseif (firstWord) then if (linkWords()) then if (collectWords()) then removeEventsAndPlaceNewTiles() if (turn.text == "Player 1") then passCount1 = 0 else passCount2 = 0 end nxtTurn() end else popUp("Akakonekta dapat so balon\n tiles mo ed daan!") end end else popUp("Say unaan ya galaw nepeg\n ya wala ed sentro!") end end return true end ------------------------------------------------------------------------- --//\*\* \*\*//-------------------------------------------------------------- function scene:exit( ) composer.gotoScene("menu", "flip", 150) end function scene:setBlankLetter( params ) local player = {} local l local tempTile = letterTile[params.index] letterTile[params.index]:removeSelf( ) letterTile[params.index] = nil if (turn.text == "Player 1") then player = player1 else player = player2 end local sheetData = { width = 50, height = 45, numFrames = 20, sheetContentWidth = 250, sheetContentHeight = 180 } local letterSheet = graphics.newImageSheet( "img/blankTiles.png", sheetData ) l = display.newImageRect( boardGroup, letterSheet, params.letterIndex, 45, 50 ) --ran is the index of frame in the spritesheet l.points = 0 --designated point l.letter = letters[params.letterIndex] --designated letter l.ran = params.letterIndex --distribution index l.tileNum = params.boardIndex --index //tile number of board tile l.status = tempTile.status --status active l.defaultWidth = tempTile.width --store default width l.defaultHeight = tempTile.height --store default height l.width = boardTile[1].width l.height = boardTile[1].height l:addEventListener( "touch", onDrag ) --add event listener boardTile[params.boardIndex].letter = l.letter boardTile[params.boardIndex].points = l.points player[tempTile.rackIndex]:removeSelf( ) player[tempTile.rackIndex] = nil player[tempTile.rackIndex] = l player[tempTile.rackIndex].index = tempTile.index player[tempTile.rackIndex].x = tempTile.x player[tempTile.rackIndex].y = tempTile.y player[tempTile.rackIndex].rackIndex = tempTile.rackIndex player[tempTile.rackIndex].xOriginPos = tempTile.xOriginPos player[tempTile.rackIndex].yOriginPos = tempTile.yOriginPos letterTile[params.index] = player[tempTile.rackIndex] end function scene:playAgain( ) local time = 300 timerDisplay = display.newText("5:00", 0, 0, native.systemFont, 18) --timerDisplay:setReferencePoint(display.CenterReferencePoint) timerDisplay.x, timerDisplay.y =230, 17 timerDisplay:setTextColor(150,16,33) sceneGroup:insert(timerDisplay) local mins = 4 local secs = 60 local function updateTime(event) time = time-1 secs = secs-1 if secs \< 10 and secs \> 0 then secsText = "0" ..secs elseif secs \< 1 then secsText = "00" if mins \> 0 then secs = 59 end mins = mins - 1 minsText = min else secsText = secs end if mins \> 1 then minsText = mins elseif mins \< 1 then minsText = "0" mins = 0 end if secs == 0 then local options = { effect = "zoomOutInFade", time = 200, isModal = true, params = {p1Score = p1Score, p2Score = p2Score, p1ScoreAdjust = player1Adjust, p2ScoreAdjust=player2Adjust} } composer.showOverlay( "gameOver", options) timer.cancel(gameTimer) timerDisplay:removeSelf() end timerDisplay.text = mins.. ":" ..secsText end gameTimer = timer.performWithDelay(1000, updateTime, 0) distributions = {9, 2, 1, 4, 12, 3, 2, 9, 4, 2, 6, 8, 2, 6, 4, 6, 4, 2, 2, 2} \_x, \_y = -20, d.centerY + 10 firstWord = false turn.text = "Player 1" player = {} exchange = false passBtn.alpha = 1 submitBtn.alpha = 0 cancelBtn.alpha = 0 exchangeBtn.alpha = 1 clearBtn.alpha = 0 if (square) then square:removeSelf(); square = nil text:removeSelf(); text = nil end board.x = d.centerX board.y = d.centerY board.width = 550 board.height = 625 for i=1,#boardTile do boardTile[i].width = board.width/15 boardTile[i].height = board.height/15 if (boardTile[i].on) then boardTile[i].on = false end end positionBoardTiles() for i=1,#letterTile do letterTile[i]:removeSelf( ); letterTile[i] = nil end player1Adjust = 0 player2Adjust = 0 passCount1 = 0 passCount2 = 0 tilesRemaining = 90 tilesRemainingTxt.text = tilesRemaining p1Score = 0 p1ScoreAdjust = 0 p1ScoreTxt.text = "P1: "..p1Score p2Score = 0 p2ScoreAdjust = 0 p2ScoreTxt.text = "P2: "..p2Score p1ScoreTxt.anchorX = 1 p1ScoreTxt.x = p1ScoreTxt.width + 10 p2ScoreTxt.anchorX = 1 p2ScoreTxt.x = p2ScoreTxt.width + 10 tileCounter = 0 player1, player2 = {}, {} player1 = createLetters(player1) player2 = createLetters(player2) hideTiles(player1) hideTiles(player2) timer.performWithDelay( 500, function ( ) showTiles(player1) end ) end end --------------------------------------------------------------------------------- function scene:show( event ) local sceneGroup = self.view local phase = event.phase if phase == "will" then system.activate( "multitouch" ) displayAll() elseif phase == "did" then Runtime:addEventListener( "enterFrame", checkNewTiles ) end end -------------------------------------------------------------------------------- function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if event.phase == "will" then Runtime:removeEventListener( "enterFrame", checkNewTiles ) composer.removeScene("game") elseif phase == "did" then end end -------------------------------------------------------------------------------- function scene:destroy( event ) local sceneGroup = self.view for i=1,#boardTile do boardTile[i]:removeSelf( ); boardTile[i] = nil end for i=1,#letterTile do letterTile[i]:removeSelf( ); letterTile[i] = nil end end --------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) --------------------------------------------------------------------------------- return scene
- I don’t think anyone is going to read all that code. If the future, for big code questions you’d be better off zipping the project and sharing it with us on dropbox.
However, that will be waste this time. Nobody is going to give you some magic code to turn your single-player game into multi-player. Therefore we don’t need to see the code.
- Fortunately, Gamesparks just did multi-player game example: https://docs.gamesparks.com/tutorials/game-engine-integrations/corona-1v1-asynchronous-match.html
You can probably work through that example(s) and then hopefully use that learning on your game.
Good luck!
tnx for this kind of help… this situation makes me feel bad…this is so very important to me, because this game is under on my project study for my masters degree just a little bit code that i want to expect just like the other language… if i have some enough money i will hire a freelance game developer… but im only through this thing because of scholarship…if no one can give some idea how to do this… its ok… im just making a try whos gonna help… godbless…
Note: I should also have previously said, congrats on completing your game and thanks for posting a formatted code block.
As far as your project, if it’s for your masters degree I don’t see how it makes sense for someone else to code the MP part?
What degree are you going after?
Whatever the case, adding MP support is no small task for all but the simplest of games, and even then should generally be architected into the project from the beginning. i.e. Adding it later doesn’t always work easily.
Let me add to this.
There are generally several ways to implement two player multi-player games. If you’re building for iOS you would maybe want to use GameCenter to implement it. If you’re building an Android App, you might want to use Google Play Game Services. If you need to be cross platform or if this is for a desktop, look at GameSparks like @roaminggamer suggested.
Rob
Thanks for the shout outs Rob and Roaminggamer!
Hi Gwapo,
Gamesparks is completely free to evaluate and prototype, so you could try implementing multiplayer like in the example Roaminggamer linked above to see if it works for you without the commitment to publish your game using GameSparks.
If you do decide to use GameSparks, and you are a student, you can apply for the Indie & Student Programme which would give you the first 100,000 MAUs completely free which may very well suit your situation of creating this game for your masters degree.
If you have any questions about GameSparks and our multiplayer you can contact our support team via - https://support.gamesparks.net/support/home
Best of luck with your project!
Clare
As roaminggamer says, it’s not ‘just a little bit of code’ in any language to change a local game to a networked multiplayer one.
However it is a task I would hope studying a masters degree in Computer Science would prepare you for!
I don’t see how hiring someone to do it helps you, as you then have a false qualification and you might land a job way beyond your skill level. Better to learn how to do it now while you can’t be sacked!
- I don’t think anyone is going to read all that code. If the future, for big code questions you’d be better off zipping the project and sharing it with us on dropbox.
However, that will be waste this time. Nobody is going to give you some magic code to turn your single-player game into multi-player. Therefore we don’t need to see the code.
- Fortunately, Gamesparks just did multi-player game example: https://docs.gamesparks.com/tutorials/game-engine-integrations/corona-1v1-asynchronous-match.html
You can probably work through that example(s) and then hopefully use that learning on your game.
Good luck!
tnx for this kind of help… this situation makes me feel bad…this is so very important to me, because this game is under on my project study for my masters degree just a little bit code that i want to expect just like the other language… if i have some enough money i will hire a freelance game developer… but im only through this thing because of scholarship…if no one can give some idea how to do this… its ok… im just making a try whos gonna help… godbless…
Note: I should also have previously said, congrats on completing your game and thanks for posting a formatted code block.
As far as your project, if it’s for your masters degree I don’t see how it makes sense for someone else to code the MP part?
What degree are you going after?
Whatever the case, adding MP support is no small task for all but the simplest of games, and even then should generally be architected into the project from the beginning. i.e. Adding it later doesn’t always work easily.
Let me add to this.
There are generally several ways to implement two player multi-player games. If you’re building for iOS you would maybe want to use GameCenter to implement it. If you’re building an Android App, you might want to use Google Play Game Services. If you need to be cross platform or if this is for a desktop, look at GameSparks like @roaminggamer suggested.
Rob
Thanks for the shout outs Rob and Roaminggamer!
Hi Gwapo,
Gamesparks is completely free to evaluate and prototype, so you could try implementing multiplayer like in the example Roaminggamer linked above to see if it works for you without the commitment to publish your game using GameSparks.
If you do decide to use GameSparks, and you are a student, you can apply for the Indie & Student Programme which would give you the first 100,000 MAUs completely free which may very well suit your situation of creating this game for your masters degree.
If you have any questions about GameSparks and our multiplayer you can contact our support team via - https://support.gamesparks.net/support/home
Best of luck with your project!
Clare
As roaminggamer says, it’s not ‘just a little bit of code’ in any language to change a local game to a networked multiplayer one.
However it is a task I would hope studying a masters degree in Computer Science would prepare you for!
I don’t see how hiring someone to do it helps you, as you then have a false qualification and you might land a job way beyond your skill level. Better to learn how to do it now while you can’t be sacked!