This is "using C # To develop smartphone software: Push box" Series Article . This article introduces the common/step. Cs SOURCE Program File. 1 Namespace Skyiv. Ben. pushbox. Common
2 {
3 Enum Direction {None, east, south, west, north} // Direction: East-South-West-North
4 Public Enum Action {None, create, edit, delete} // DESIGN: no creation, editing, and deletion
5
6 /**/ /// <Summary>
7///Steps
8/// </Summary>
9 Struct Step
10 {
11 Direction direct; // Forward Direction
12 Bool Isbox; // Push the box forward together?
13 Bool Isstop; // Whether to stop when "undo" is enabled
14
15 Public Direction direct {Get {ReturnDirect ;}}
16 Public Bool Isbox {Get {ReturnIsbox ;}}
17 Public Bool Isstop {Get {ReturnIsstop ;}}
18
19 Public Step (Direction direct, Bool Isbox, Bool Isstop)
20 {
21 This . Direct = Direct;
22 This . Isbox = Isbox;
23 This . Isstop = Isstop;
24 }
25
26 // Isbox isstop none east south west north
27 // A B C D E
28 // X f g h I j
29 // X k l m n o
30 // X P Q R S T
31
32 Public Static Implicit Operator Char (Step by step)
33 {
34 Char C = " ABCDE " [Step. Direct - Direction. None];
35 If (Step. isbox) c = ( Char ) (C + 5 );
36 If (Step. isstop) c = ( Char ) (C + 10 );
37 Return C;
38 }
39
40 Public Static Implicit Operator STEP ( Char C)
41 {
42 Int N = C - ' A ' ;
43 Return New STEP (Direction) (N % 5 ), (N % 10 > = 5 ), (N > = 10 ));
44 }
45 }
46 }
47
This source program file contains two enumerations (Direction and action) and a structure (STEP) definition.
Enumerative direction is used to indicate the movement direction of the worker and the box. It contains five members: None, east, south, west, and north.
Enumeration actions are used to indicate the actions selected in the "design" dialog box, including four members: None, create, edit, and delete.
The structure step is used to record the steps. The elements of the record are: forward direction, whether to push the box together, and whether to stay when "undo.
Let's take a look at the two images:
In the picture on the left, if you click the position of the Red Circle, the worker will go through steps 1 and 2 to reach the position. Then click the position of the green circle, so the box is pushed to this position, the worker goes through steps 3, 4, 5, and 6 to reach a cell on the right of the box, as shown in the right figure. These six steps are pushed into the stack as six instances of the structure step in the program, if you click "back" or "undo" (as shown in the Red Circle in the right figure), the instances of these steps will pop up from the stack. The following table lists the values of the six step instances:
|
Step 2 |
Step 2 |
Step 2 |
Step 2 |
Step 2 |
Step 2 |
Direct |
West |
South |
West |
West |
West |
West |
Isbox |
False |
False |
False |
True |
True |
True |
Isstop |
True |
False |
True |
False |
False |
False |
Operator char |
N |
C |
N |
I |
I |
I |
If the user clicks the "back" button, the worker will return after each click (to step. direct) step, if step. if the isbox value is true, the box also needs to move back. If the user clicks the "undo" button, the worker will always go back to the place where step. isstop is true. That is to say, if the user clicks the "back" button in the right figure, the worker will take the box one step back (step 1 ). If you click the "undo" button again, the worker will continue to step 3 (step 1, step 2, step 2) to reach the red circle on the left, the first two steps are taken back with the box. If you click "undo" again, the worker will continue to step two (step 1 and step 2) and return to the location of the worker on the left.
The conversion operator char of the structure step is used to save the customs clearance steps to the configuration file (pushbox. cfg) and the Customs Clearance step file (steps/*. Bxs. The conversion operator step of the structure step is used to "play back" the step of pushing the box from the configuration file or the customs clearance step file.
Previous Article: Using C # To develop smartphone software: Push box (6)
Next article: Using C # To develop smartphone software: Push box (8)
Returned directory