A
A
Alexander Sinitsyn2019-03-21 19:28:52
Software design
Alexander Sinitsyn, 2019-03-21 19:28:52

Who can show for example the process of developing the architecture of the game "Snake"?

I am reading "Clean Architecture", I have not yet comprehended enlightenment ... I decided to try it on a simple application, but the thought constantly climbs into libraries, GUIs, classes, but architecture is not about that. Can anyone show the train of thought from the task to the point where you can move on to development?
PS: "Snake" is where boas crawl, eat fruits and grow, dying in any collision. One is controlled by the user, the rest "rummage around" themselves ...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Saboteur, 2019-03-22
@saboteur_kiev

You divide the architecture into parts:
Storage of information about fruits and your own snake itself
Logic of the movement of the snake
Management
Visualization (drawing, which can be performed depending on the device, for example, with different resolutions).
Separately - the launch menu and maybe, for example, a table of records.
Maybe even a table of records with the transfer of information to the Internet, for a global ranking.

A
Alexander N++, 2019-03-21
@sanchezzzhak

https://habr.com/ru/post/334434/
Imagine in your head or on paper what objects you need for development and describe each as an object in the code.
1 field is most often stored in the form of a matrix, as we can write a matrix in our PL, in the form of simple arrays or vectors, if any. in the case of a snake, we can simply use a 300 by 300 canvas where each pixel is a cell in the matrix.
(Matrix in the form of arrays is always used in games like Match3; it is easier to come up with algorithms)
2 player, how can we write the player in the PL as an object with a bunch of parameters
speed: float
diriction: num 1..4 movement direction 1 top 2 left 3 down 4 to the right (todo put into constants, the god of constants needs more constants)
x: num
y: num
lv: num
score: num
height: num
width: : num
3 food same as player.
speed: float - food can also run away
lv: num food level, 1 give one cell to the snake 3 3 cells give to the snake. (you can fantasize with the parameter and come up with the gameplay of the game. for example, if the food has more lvl than the snake, you can’t eat)
x: num position on the canvas
y: num
height: num cell size on the canvas
width: num
if there is a lot of food on the field, then you need a limited an array for the amount of food on the field.
1 Create the field
2 Create the player
We start a timer that should draw a picture for us every frame and execute the following code (in fact, it’s not necessary, each object can have its own timer, the main timer is done for smoothness and stable FPS, in js this is achieved through requestAnimationFrame (callback)
Checking for collision of the player with food or obstacles
Checking if we have gone beyond the field ( we know the beginning of the field is 0 and we know the width of the field 300 from 0 to 300 to the left and to the right we can run, we know the top 0 and we know the height of the field 300, from zero, we can run up to 300 top down in.
Any game starts with a global timer =)
Well, in order not to read this dregs that I wrote, you can read the article
https://habr.com/en/post/334434/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question