Created
June 7, 2020 19:25
-
-
Save ZergsLaw/4b440b371ba301657c79c4c7798f2684 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type Map struct { | |
| Vals [8][8]int | |
| Users []UserHui | |
| } | |
| type UserHui struct { | |
| Name string | |
| Coordinate int | |
| } | |
| type EnumCoordinate uint8 | |
| const ( | |
| North EnumCoordinate = iota | |
| West | |
| South | |
| East | |
| ) | |
| var ( | |
| ErrTakeStep = errors.New("err take step") | |
| ) | |
| func (self *UserHui) Step(destination EnumCoordinate) (currentCoordinate int, err error) { | |
| switch destination { | |
| case North: | |
| currentCoordinate = self.Coordinate - 8 | |
| case West: | |
| currentCoordinate = self.Coordinate - 1 | |
| case South: | |
| currentCoordinate = self.Coordinate + 8 | |
| case East: | |
| currentCoordinate = self.Coordinate + 1 | |
| } | |
| if currentCoordinate <= 0 || currentCoordinate > 64 { | |
| return 0, ErrTakeStep | |
| } | |
| return currentCoordinate, nil | |
| } | |
| func j() { | |
| user1 := UserHui{ | |
| Name: "Edgar", | |
| Coordinate: 11, | |
| } | |
| user2 := UserHui{ | |
| Name: "Vika", | |
| Coordinate: 4, | |
| } | |
| v := Map{ | |
| Vals: [8][8]int{ | |
| {1, 2, 3, 4, 5, 6, 7, 8}, | |
| {9, 10, 11, 12, 13, 14, 15, 16}, | |
| {1, 2, 3, 4, 5, 6, 7, 8}, | |
| {1, 2, 3, 4, 5, 6, 7, 8}, | |
| {1, 2, 3, 4, 5, 6, 7, 8}, | |
| {1, 2, 3, 4, 5, 6, 7, 8}, | |
| {1, 2, 3, 4, 5, 6, 7, 8}, | |
| {1, 2, 3, 4, 5, 6, 7, 8}, | |
| }, | |
| Users: []UserHui{user1, user2}, | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment