Вы находитесь на странице: 1из 18

Smarter Version of Classic Snake Game on

Android TEAM 9
Mesbah Uddin
Md. Badruddoja Majumdar
Donald Collins
GAME LAYOUT

Relative Layout

 No fixed position of any element.


 They are specified relative to each other

Custom View

 extends the surface view


 Used for creating an interactive gaming
interface
DRAWING ON CUSTOM VIEW

 Facilitates custom drawing by overriding onDraw(method) of view class


 what to draw, handled with Canvas class

 How to draw, handled by Paint class


DRAWABLE GAME COMPONENTS

 Wall (specifies the boundary for the snake’s world )


 Snake body
 Food
DRAWING MECHANISM

 Stored coordinates(top-left corner) of drawable components in


different array
 Used drawBitmap() method of Canvas class to draw the drawable
components
 Used a tile image as the drawing unit.
GAME VIEW AFTER DRAWING
GAMING MENU

 Start-available when the app starts


 Pause-available when the app on running
 Resume-available when the app on pause
 Restart-available when the game is over
GAMING MECHANISM

 Snake starts from an initial position and length.


 Check collides with body, wall and food
 Treat each collision type differently to take next actions
 Collision with body leads the game to an end
 Collision with wall leads moving out of the opposite wall.
 Collision with food makes the snake grows up by one tiles and
score increases.
IMPLEMENTATION OF RANDOM FOOD
GENERATION

 Foods are generated randomly


 Algorithms developed to make sure it within boundary and does
not coincide with wall and snake body.
ADAPTABLE GAME BOUNDARY

 Game boundary is consistent with screen size of any device


 Screen height and width obtained with getDisplayMetrics()
method of android class Resources.
 Draw only number of boundary tiles that fit within the screen
CONTROL THE SNAKE
In two ways:
1. Shake the phone: Move the phone in up, down, left or right
direction to steer the snake into that direction accordingly.
 An accelerometer gives the coordinates (x, y, z) of the android
device at all times. It can be read using the “SensorManager” class
in android.
 Comparing two back-to-back reading from the accelerometer, the
movement is calculated.
 To minimize power consumption, readings are only taken after a
fixed interval of time. This time interval is very low to be detected by
a human, so it doesn’t harm the real-time play.
CONTROL THE SNAKE
In two ways:
2. Touch gesture: The snake can be controlled by basic touch
gestures also.
 Sliding the finger left, right, up or down also guide the snake in those
directions.
 The gesture starts when the user first touches the screen, continues as
the system tracks the position of the user's finger(s), and ends by
capturing the final event of the user's fingers leaving the screen.
 “MotionEvent” delivered to “onTouchEvent()” function of “Activity”
class provides these information.
SNAKE MOVEMENT
 The whole body of the snake is kept in an array and its head has
the index 0 of that array.
 Depending on the user input, head’s position is updated first.
 Rest of the body just follows the head i.e. snake[1] becomes
snake[0] which is the head, snake[2] becomes snake[1] and so
on.
 When the head touches anywhere in the boundary, it pops out
from the opposite direction.
POINTS CALCULATION
 Both the length and the speed of the snake increases as it eats more
food. However, to keep the speed at a playable level, it doesn’t
increase after reaching the maximum level (5 in this case).
 We keep track of the snake length and use this to increase the level
(difficulty) or speedup of the snake.
 The speedup is implemented by just updating the game layout
faster than before. So the time interval to redraw the snake and food
becomes shorter.
REMOTE CONTROL WITH BLUETOOTH

 One phone controls while the other phone displays.


 All user activity occurs on the controlling phone.
 The displaying phone allows no interaction.
ANDROID.BLUETOOTH

 BluetoothAdapter – This is the entry-point for all Bluetooth


communications. It represents the local adapter.

 BluetoothDevice – This represents the remote device.

 BluetoothSocket – This is the interface between the local device


(BluetoothAdapter), and the remote device (BluetoothDevice).
QUESTIONS?

Вам также может понравиться