Using native iOS Uikit to achieve a simple elimination class game, not fully completed, do not want to continue to do, so write a blog to share the following:
First on the source: http://git.oschina.net/jonear/LianLianDots
-----------------------------------------is a messy split line-----------------------------------------------------
The main is to share the structure of the game design bar, the overall is very simple:
Manager:
Lldgamemanger: Used to manage the current game properties, whether it is successful, whether it can be connected, etc.
Lldgamelevel: To record the requirements of each level, how many points you need to take, and a few steps
Ui:
Lldmainviewcontroller: There is nothing to say about the interface of the check-off.
Lldgameviewcontroller: Game interface, mainly consists of two parts 1. Lldgameview 2.LLDTopBar
Lldgameview: Real Game interface with N*n Llditemview composition, and basic logic control of gestures
Lldtopbar: Top navbar for recording fractions, steps, remaining time, etc.
Llditemview: For each point, there are different colors, click Status and other attributes
-----------------------------------------is a messy split line-----------------------------------------------------
The main look lldgameview, others are very simple.
Map, two-dimensional array
Use a two-dimensional array to record the current situation of the map
_itemarray = [nsarray arraywithobjects:[nsmutablearray array], [ nsmutablearray array], [NSMutableArray array], [ nsmutablearray array], [NSMutableArray array], [ nsmutablearray array], [nsmutablearray array], [NSMutableArray array], [nsmutablearray array], nil];_selecteditemarray = [[nsmutablearray alloc] init];
To update a map:
- (void) updateitems { int row = 0; for (Nsmutablearray *itemarray in _itemarray) { for (int i=0; i<9; i++) { if (itemarray.count <= i) { int randomtop = random ()%10-2 ; llditemview *item = [[llditemview alloc] initwithframe:cgrectmake (row*_itmeWidth, -i*_ Itmewidth-randomtop, _itmewidth, _itmewidth)]; [item setUserInteractionEnabled:NO]; [self addsubview:item]; [itemArray addObject:item]; } } [UIView animateWithDuration:0.3 animations:^{ int i=8; for (Llditemview *item in itemarray) { item.top = i*_itmeWidth; i--; } }]; row ++; }}
Get the coordinates from the gesture and get the point view by the coordinates:
- (llditemview *) Getitematpoint: (cgpoint) point { int row = point.x/_itmeWidth; if (_itemarray.count > row) { NSMutableArray *array = _itemArray[row]; int index = 9-point.y/_itmeWidth; if (Array.count > index) { LLDItemView *view = array[index]; //determine if the point is within a circular area uibezierpath *path = [uibezierpath bezierpathwithroundedrect: view.frame cornerradius:view.width/3]; if ([Path contAinspoint:point]) { return view; } } } return nil;}
Draw the line by judging the dots that are of the same color:
-(void) Addlinetonode: (llditemview *) nodeview { [ Nodeview showtouch]; if (_selecteditemarray.count == 1) { //path move to start point CGPoint startPoint = Nodeview.center; [_polygonallinepath movetopoint: Startpoint]; _polygonallinelayer.path = _ polygonallinepath.cgpath; _polygonallinelayer.strokecolor = nodeview.stylecolor.cgcolor; } Else{ //path add line to point [_polygonallinepath removeallpoints]; CGPoint startPoint = [_selectedItemArray[0] center]; [_polygonalLinePath moveToPoint:startPoint]; for (int i = 1; i < _selecteditemarray.count; ++i) { CGPoint middlePoint = [_selectedItemArray[i] center]; [_polygonallinepath addlinetopoint: middlepoint]; } _polygonallinelayer.path = _polygonallinepath.cgpath; } }
Then let go of removing the selected point:
- (void) checkselecteditem { if (_selecteditemarray.count >= &NBSP;3) { LLDItemViewStyle style = llditemviewstylered; for (LLDItemView *view in _selecteditemarray) { [view removeFromSuperviewWithScore:_selectedItemArray.count*10]; [self removeItemFromArray:view]; style = view.style; } [[lldgamemanager defaultmanager] cleardottype:style count:_selectedItemArray.count]; if (_delegate && [_delegate rEspondstoselector: @selector (didfinishstep)]) { [_delegate didFinishStep]; } }}
-----------------------------------------is a messy split line-----------------------------------------------------
Of course there are write back, drop and other functions also have, are relatively simple, you can see the source code.
Level mode, screen adaptation, level settings and other functions have not yet done, as is the study of the demo bar, have to finish can contact me.
Of course the simple game can be used Uikit, slightly more complex points as far as possible with the game engine Sprikekit, cocos2d, unity or something.
I use Sprikekit to do the Magic Tower demo can recommend the following: Http://git.oschina.net/jonear/Tower_SpriteKit
iOS combat-Eliminate games dots