Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create examples/2048 #181

Closed
hajimehoshi opened this issue Mar 11, 2016 · 11 comments
Closed

Create examples/2048 #181

hajimehoshi opened this issue Mar 11, 2016 · 11 comments
Milestone

Comments

@hajimehoshi
Copy link
Owner

No description provided.

@hajimehoshi hajimehoshi added this to the v1.3.0 milestone Mar 11, 2016
@hajimehoshi hajimehoshi removed this from the v1.3.0 milestone Apr 13, 2016
@brettchalupa
Copy link

@hajimehoshi I'd be happy to create this example if you haven't started on it already. 😄

@hajimehoshi
Copy link
Owner Author

I've not created yet. I'd be glad if you could help it!

@brettchalupa
Copy link

@hajimehoshi awesome, I will give it a go and share what I end up with.

@hajimehoshi
Copy link
Owner Author

What's going on?

@brettchalupa
Copy link

@hajimehoshi I worked on it for a couple of days but ended up hitting a wall and getting stuck. I haven't made much progress with this. Someone else is welcome to take over if they want to.

@hajimehoshi
Copy link
Owner Author

OK. I was wondering if you could share your code, I'm not sure I have enough time to help this though.

@brettchalupa
Copy link

@hajimehoshi For sure, I would be happy to share what I have so far.

main.go:

package main

import (
    "log"

    "github.com/brettchalupa/ebiten-experiments/2048/twenty48"
    "github.com/hajimehoshi/ebiten"
)

func main() {
    game := twenty48.NewGame()
    update := game.Update
    if err := ebiten.Run(update, twenty48.ScreenWidth, twenty48.ScreenHeight, 1, "2048 (Ebiten Demo)"); err != nil {
        log.Fatal(err)
    }
}

twenty48/board.go:

package twenty48

import (
    "strconv"

    "github.com/hajimehoshi/ebiten"
    "github.com/hajimehoshi/ebiten/ebitenutil"
)

type Board struct {
    size  int
    tiles [][]*Tile
}

func NewBoard(size int) *Board {
    return &Board{
        size: size,
    }
}

func (board *Board) Update() error {
    return nil
}

func (board *Board) Draw(r *ebiten.Image) error {
    ebitenutil.DebugPrint(r, "Board Size: "+strconv.Itoa(board.size))

    return nil
}

twenty48/game.go:

package twenty48

import (
    "github.com/hajimehoshi/ebiten"
)

const ScreenWidth = 420
const ScreenHeight = 600
const DefaultBoardSize = 4

type Game struct {
    board *Board
}

func NewGame() *Game {
    return &Game{
        board: NewBoard(DefaultBoardSize),
    }
}

func (game *Game) Update(r *ebiten.Image) error {
    if err := game.board.Update(); err != nil {
        return err
    }

    if !ebiten.IsRunningSlowly() {
        game.Draw(r)
    }

    return nil
}

func (game *Game) Draw(r *ebiten.Image) error {
    if err := game.board.Draw(r); err != nil {
        return err
    }

    return nil
}

twenty48/tile.go:

package twenty48

const TileSize = 100

type Tile struct {
    value int
    x     int
    y     int
    color string
}

Feel free to use this or adapt it if it is of any help. My apologies for not completing it.

@hajimehoshi
Copy link
Owner Author

Thanks! I'll look into it later.

@hajimehoshi hajimehoshi added this to the v1.4.0 milestone Jul 27, 2016
hajimehoshi added a commit that referenced this issue Jul 27, 2016
@hajimehoshi
Copy link
Owner Author

Based on your files, I've started implementing the game.

@hajimehoshi
Copy link
Owner Author

hajimehoshi commented Jul 28, 2016

2048

Works fine, very roughly though

@hajimehoshi
Copy link
Owner Author

I've not implemented "Game Start", "Game Over", or "Game Clear" messages, but most of 2048 features have been implemented. Let me close this issue. Thank you for your contribution again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants