It looks like you're new here. If you want to get involved, click one of these buttons!
Console = Core.class(Sprite) function Console:init() self.xbeg = 0 self.ybeg = 0 self.x = 0 self.y = 0 self.xinc = 7 self.yinc = 12 end function Console:incrementY(increment) self.y = self.y + increment if self.y > 320 then self:setY(self:getY()-increment) end self.x = self.xbeg end function Console:printTF(message) local textfield = TextField.new(nil, message) textfield:setPosition(self.x, self.y) self:addChild(textfield) return textfield end function Console:printN(message) if message ~= "" then local textfield = self:printTF(message) end self:incrementY(self.yinc) return textfield end function Console:print(message) local textfield = self:printTF(message) self.x = self.x+self.xinc*string.len(message) return textfield end function Console:printB(message) local textfield = TextField.new(nil, message) local paddingY = 14 local paddingX = 7 local width = textfield:getWidth()+paddingX*2 local height = textfield:getHeight()+paddingY*2 local x = self.x local y = self.y+paddingY self.x = self.x+width+paddingX/2 local shape = Shape.new() shape:setFillStyle(Shape.SOLID, 0xffff00, 1.0) shape:beginPath(Shape.NON_ZERO) shape:moveTo(0, 0) shape:lineTo(0, -height) shape:lineTo(width, -height) shape:lineTo(width, 0) shape:lineTo(0, 0) shape:closePath() shape:endPath() shape:setPosition(x, y) textfield:setPosition(paddingX, -paddingY) shape:addChild(textfield) self:addChild(shape) return shape end console = Console.new() stage:addChild(console) console:setPosition(3, 10) math.randomseed( os.time() ) function makeAGuess(textfield, event) if textfield:hitTestPoint(event.x, event.y) then guess = textfield.number guessesTaken = guessesTaken + 1 if guess == secretNumber then console:printN(textfield.number.." is right! You took this many guesses: "..guessesTaken..".") console:printN("Let's play again.") startGame() else if guess > secretNumber then console:printN(textfield.number.." is too high.") elseif guess < secretNumber then console:printN(textfield.number.." is too low.") end if guessesTaken > 5 then console:printN("You took too long. The number was "..secretNumber) console:printN("Let's play again.") startGame() end end event:stopPropagation() end end function startGame() secretNumber = math.random( 20 ) console:printN("I am thinking of a number between 1 and 20.") console:printN("") local button for ii=1,20,1 do button = console:printB(ii) button.number = ii button:addEventListener(Event.MOUSE_DOWN, makeAGuess, button) end console:incrementY(button:getHeight()) guessesTaken = 0 end startGame() |
Likes: atilim
Comments
Hmm,
I'd created one text field showing number and two arrows to increase it and decrese it and a button to take a guess.
And why do you need to save all previous game information on screen?
But yeah, this kind of interaction would probably require some code
I've already started to make a semi gui with shapes.
Another reason I don't have any graphics is because I haven't customized my Gideros app on my phone with anything but downloading one lua file. I hope to eventually have it download a whole project, kinda like what Gideros Player does with a desktop computer. Don't ask me why I don't program when I'm in front of my laptop/desktop. I just do different things when I'm in front of them and I do Gideros stuff when I've got my iPad in front of me.
My apps: http://www.yummyyellow.com
Thanks!
http://dl.dropbox.com/u/10761501/blog/GiderosAppExport.zip
My apps: http://www.yummyyellow.com