C#实现扫雷游戏中左右键同时点击

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
private MouseButtons Button;
private long Ticks;
private long TicksDelay = 100000L;

private void btn_Click(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (DateTime.Now.Ticks - Ticks < TicksDelay && Button == MouseButtons.Right)
{
//左右键"同时"(先左后右)

}
else
{
//左键

}
}
else if (e.Button == MouseButtons.Right)
{
if (DateTime.Now.Ticks - Ticks < TicksDelay && Button == MouseButtons.Left)
{
//左右键"同时"(先右后左)

}
else
{
//右键

}
}
Button = e.Button;
Ticks = DateTime.Now.Ticks;

}

C#定义变量左右值及桶模拟

上图显示了具有两个分支的变量i,这两个分支分别名为lvalue和rvalue.

变量的lvalue是指存储变量的内存地址。变量lvalue总是被解释为内存地址,是location value 的简写。

变量rvalue是指当前存储在变量中的实际值,代表register value。当定义一个变量时,lvalue先被赋值,值是分配的地址号。当对变量赋值时,rvalue被赋值,值就是被赋予的实际值。同时,lvalue与rvalue可以理解成变量的左右值,即left value和right value。

举例来说,语句

阅读更多

图解C#类的内存分配

对象的创建

格式:

clsPerson myFriend = new clsPerson();

或者

clsPerson myFriend;
myFriend = new clsPerson();
阅读更多

类与对象的理解

假如你和多年未见面的朋友安排见面,时间很久你已经记不清他的样子,因此您会询问他一些问题,同时描述自己:180cm,短发,黑色西装等等。


Person类: 属性列表 对象: 我 朋友


name Jack Lee

阅读更多

C#数据结构程序举例

链表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace list
{
class Program
{
static void Main(string[] args)
{
LinkedList<int> LinkList;
List<LinkedListNode<int>> Lnode;
LinkList = new LinkedList<int>();
Lnode = new List<LinkedListNode<int>>();
Lnode.Add(new LinkedListNode<int>(3));
Lnode.Add(new LinkedListNode<int>(1));
Lnode.Add(new LinkedListNode<int>(2));
LinkList.AddFirst(Lnode[2]);
LinkList.AddBefore(Lnode[2],Lnode[1]);
LinkList.AddAfter(Lnode[2],Lnode[0]);

foreach (int doc in LinkList)
{
Console.WriteLine(doc);
}

}
}
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using System;
using System.Collections;
using System.Linq;
using System.Text;

namespace stack
{
class Program
{
static void Main(string[] args)
{
Stack st = new Stack();
st.Push('A');
st.Push('B');
Console.WriteLine(st.Pop());
st.Push('C');
Console.WriteLine(st.Pop());
Console.WriteLine(st.Count);
Console.WriteLine(st.Pop());
st.Push('D');
Console.WriteLine(st.Pop());
}
}
}

队列

阅读更多

Freescale芯片智能小车程序分析

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
#include <hidef.h>
#include <MC9S12XS128.h>
#pragma LINK_INFO DERIVATIVE "mc9s12xs128"
#define PITTIME 5000 //50MS定时中断
#define speed_set1 3200
#define speed_set2 2000
#define NB 150 //直道最小速度
#define NS 250 //直道中小速度
#define Z 350 //中速
#define PS 500 //中高速
#define PB 600 //高速
#define NB1 275 //弯道最小速度
#define Z1 325 //中速
#define PS1 350 //中高速
#define PB1 375 //高速
int speed_data[5][7] = //直道速度表

{

{ NB, NB, NS, Z, PS, Z, NS },

{ NB, NS, Z, PS, PB, PB, Z },

{ NS, Z, PS, PB, PS, Z, NS },

{ Z, PS, PB, PS, Z, NS, NB },

{ NS, Z, NS, Z, NS, NB, NB }

};



int speed_data0[5][7] = //弯道速度表

{

{ NB1, NB1, NS1, Z1, PS1, Z1, NS1 },

{ NB1, NS1, Z1, PS1, PB1, PB1, Z1 },

{ NS1, Z1, PS1, PB1, PS1, Z1, NS1 },

{ Z1, PS1, PB1, PS1, Z1, NS1, NB1 },

{ NS1, Z1, NS1, Z1, NS1, NB1, NB1 }

};





int ad_data[10][11];

int ad_data1[11];

int pd_data[11];



int ad_min[11] = { 40, 20, 20, 30, 50, 50, 50, 50, 60, 50, 50 }; //新

int ad_mid[11];

int state;

int start_flag = 1; //启停标志

int straight_flag = 1; //直弯标志

int count = 0;

int B_cnt;

int B_cnt_last;

int count1 = 0; //赛道特殊状况检测次数

int count3 = 0; //直弯检测累计

int count4 = 0;

int state_first = 0; //赛道状态传递

int state_last = 0;

int state_now;

int state_e = 0;

int state_e_last;

int u;

int v = 200;

int steer_e; //舵机增量

float Kp = 2; //舵机K

float Kp_data[11] = { 0.6, 0.65, 0.82, 0.83, 0.84, 0.90, 0.95, 1.1, 1.35, 1.47, 1.59 };



float Kp_data2[11] = { 0 };

float Kd = 0.5; //舵机D

float Kp_s = 0.008; //速度K



float Ki_s = 0; //速度I

float Kd_s = 0; //速递D

int steer = 2600;

int speed; //光电编码器测速值

int speed_e_first = 0;

int speed_e_last = 0;

int speed_e;

int speed_set; //速度设定值

int motor_e;

int motor_pwm;









//初始化//



void PLL_Init(void) //PLLClK=2*OSCCLK*(SYNR+1/REFDV+1)

{

//锁相环=2*16=32MHz

REFDV = 1; //总线时钟=32/2=16MHz

SYNR = 1;

while (!(CRGFLG & 0x08));

CLKSEL = 0X08; //时钟选择,等待模式下锁相环停止工作

}



void PWM_Init(void)

{

PWME = 0x00;

PWMCTL = 0x70; //级联方式

PWMPOL = 0xff;

PWMCAE = 0xff; //对齐方式左对齐

PWMCLK = 0x30; //PWM时钟选择,23通道CLOCKSB

PWMPRCLK = 0x11; //PWM预分频,时钟源A=时钟源B=8MHz

PWMSCLA = 5;

PWMSCLB = 5;

PWMPER01 = 1000;

PWMDTY01 = 0;

PWMPER45 = 1000;

PWMDTY45 = 200;

PWMPER23 = 16000;

PWMDTY23 = 0;

PWME = 0x3f;

}



void AD_Init(void)

{

ATD0CTL0 = 0x0A;

ATD0CTL1 = 0x00; //7:1-外部触发,65:00-8位精度,4:放电,3210:ch

ATD0CTL2 = 0x40; //禁止外部触发, 中断禁止

ATD0CTL3 = 0xD8; //右对齐无符号,每次转换11个序列, No FIFO, Freeze模式下继续转

ATD0CTL4 = 0x01; //765:采样时间为4个AD时钟周期,ATDClock=[BusClock*0.5]/[PRS+1]

ATD0CTL5 = 0x30; //6:0特殊通道禁止,5:1连续转换 ,4:1多通道轮流采样

ATD0DIEN = 0x00; //禁止数字输入

}



void PIT_Init(void)

{

PITCFLMT_PITE = 0; //PIT关

PITCE_PCE0 = 1; //定时器通道0使能

PITMTLD0 = 160 - 1; //8位定时器初值设定。160分频,在16MHzBusClock下,为0.1MHz。即 10us.

PITLD0 = PITTIME - 1; //16位定时器初值设定。PITTIME*0.01MS 50ms定时

PITINTE_PINTE0 = 1; //定时器中断通道0中断使能

PITCFLMT_PITE = 1; //PIT使能

}



void PACA_Init(void) //初始化脉冲累加器A

{

TCTL3 = 0X40; //下降沿捕捉脉冲

PACTL = 0x40; //脉冲累加使能

PACNT = 0X0000;

}



//功能函数//



void delay_ms(int ms) //延时函数

{

int i, j;

for (i = 0; i < ms; i++)

for (j = 0; j < 2770; j++); //16MHz--2ms

}



int abs(int num) //绝对值

{

if (num<0)

return -num;

else

return num;

}

void Reverse(int* arr, int b, int e) //数组元素对换

{

for (; b < e; b++, e--)

{

int temp = arr[e];

arr[e] = arr[b];

arr[b] = temp;

}

}

void RightShift(int* arr, int N, int K) //数组循环移位

{

K %= N;

Reverse(arr, 0, N - K - 1);

Reverse(arr, N - K, N - 1);

Reverse(arr, 0, N - 1);

}



//单片机处理/

void ATD_data(void) //AD采集

{



int i;



for (i = 0; i<10; i++)

{

while (!ATD0STAT0_SCF);



ad_data[i][0] = ATD0DR0L;

ad_data[i][1] = ATD0DR1L;

ad_data[i][2] = ATD0DR2L;

ad_data[i][3] = ATD0DR3L;

ad_data[i][4] = ATD0DR4L;

ad_data[i][5] = ATD0DR5L;

ad_data[i][6] = ATD0DR6L;

ad_data[i][7] = ATD0DR7L;

ad_data[i][8] = ATD0DR8L;

ad_data[i][9] = ATD0DR9L;

ad_data[i][10] = ATD0DR10L;

ATD0CTL5 = 0x30;

}

}



void PD_data(void) //AD数据处理

{

int i, j, k, temp;

for (i = 0; i<10; i++) //每个传感器采样10次的数据进行排序

{

for (j = 0; j<11; j++)

for (k = j + 1; k<10; k++)

{

if (ad_data[j][i]>ad_data[k][i])

{

temp = ad_data[j][i];

ad_data[j][i] = ad_data[k][i];

ad_data[k][i] = temp;

}

}

}

for (j = 0; j<11; j++) //对中间的两个值求平均作为本次采集的结果

ad_data1[j] = (ad_data[4][j] + ad_data[5][j]) / 2;

}



void STATE_data(void) //位置判断

{

int i;



B_cnt_last = B_cnt; //B_cnt为当前检测到黑线传感器的个数

B_cnt = 0;

for (i = 0; i<11; i++) //对采集的数据进行二值化处理

{

ad_mid[i] = ad_min[i] + 60;

(ad_data1[i]<ad_mid[i]) ? (pd_data[i] = 1) : (pd_data[i] = 0);

}



for (i = 0; i<11; i++) //位置计算,判断采集黑线传感器的个数

{

if (pd_data[i] == 1)

B_cnt++;

}

if (B_cnt == 1)

for (i = 0; i<11; i++) //判断黑线的位置

{

if (pd_data[i] == 1)

state = 2 * i - 10;

}

if (B_cnt == 2)

for (i = 0; i<10; i++)

{

if (pd_data[i] == 1 && pd_data[i + 1] == 1)

state = 2 * i + 1 - 10;

}

if (B_cnt>5 && B_cnt_last<6) //特殊状况,十字,起跑线

count1++;



}





void START_judge(void) //起跑线识别

{

int i, knum, SATurn;

int kA[4] = { 0 };

if (count1>2)

for (i = 0, knum = 0, SATurn = 0; i<10; i++)

if (pd_data[i] ^ pd_data[i + 1])

{

SATurn++;

kA[knum] = i;

knum++;

}

if (SATurn == 4)

if ((kA[1] - kA[0]) <= 2 && (kA[1] - kA[0]) >= 1 && //起跑线左白区域

(kA[2] - kA[1]) <= 2 && (kA[2] - kA[1]) >= 1 && //起跑线中黑区域

(kA[3] - kA[2]) <= 2 && (kA[3] - kA[2]) >= 1 && //起跑线右白区域

(B_cnt <= 9 && B_cnt >= 7)) //状态1传感器总数



start_flag = 0;



}





void STATE_judge(void) //滤波&&直弯判断

{

state_last = state_now;

state_now = state;

if (abs(state_now - state_last)>2)

{

state_now = state_last;

}

if (count3<40)

count3++;

if (abs(state_now)<5)

count4++;

if (count3 == 40 && count4>35)

{

straight_flag = 1;

count3 = 0;

count4 = 0;

}

if (count3 == 40 && count4<30)

{

straight_flag = 0;

count3 = 0;

count4 = 0;

}



Kp = Kp_data[abs(state_now)];



}





void STATE_e(void) //误差变化计算

{

if (count == 0)

{

state_first = state_now;

}

count++;



if (count>5)

{

state_e_last = state_e;

state_e = state_now - state_first;

count = 0;

}

}





void STEER_pd(void) //舵机PD控制

{

/* if(abs(state_now)<4) //速度对转角的影响,速度大时,直道K值取小

Kp-=speed/speed_set1;

if(abs(state_now)>4) //弯道K值随速度增大

Kp+=speed/speed_set2; */

//Kp=Kp_data[abs(state_now)];

steer = (int)(2550 + Kp*state_now * 70 + Kd*(state_e - state_e_last) * 70);

// steer+=(int)(Kp*(state_now-state_last)*80+Kd*(state_e-state_e_last)*80);





if (steer > 3400)

{

steer = 3400;

}

if (steer < 1700)

{

steer = 1700;

}



PWMDTY23 = steer;

}



void SPEED_set(void)

{

int i, j;

if (state_e>4)

i = 4;

else if (state_e<-4)

i = 0;

else

{

i = (state_e + 4) / 2;

j = (state_now + 10) / 3;

}

if (straight_flag == 1)

speed_set = speed_data[i][j];

if (straight_flag == 0)

speed_set = speed_data0[i][j];

// speed_e_first=speed_e_last;

speed_e_last = speed_e;

speed_e = speed_set - speed;





}







void SPEED_pd(void)

{

if (start_flag == 0)

{

delay_ms(50);

PWMDTY01 = 200;

}

else

{

if (speed_set - speed>300)

{

motor_pwm = 700;

}

else if (speed_set - speed<-300)

{

motor_pwm = 0;

}

else

{

motor_e = (int)(Kp_s*speed_e + Kd_s*(speed_e - speed_e_last));

//motor_e = (int)(Kp_s*(speed_e-speed_e_last)+Ki_s*speed_e+

// Kd_s*(speed_e-2*speed_e_last+speed_e_first));

motor_pwm = motor_e + v;

v = motor_pwm;

}

PWMDTY01 = motor_pwm;

}



}



/* 定时中断 */

\#pragma CODE_SEG __NEAR_SEG NON_BANKED

void interrupt 66 PIT0(void)

{

PITTF_PTF0 = 1; //清中断标志位

speed = PACNT;

PACNT = 0x0000;

}









/********************************/

/* 主函数 */

/********************************/

void main(void)

{

PLL_Init();

PWM_Init();

AD_Init();

PIT_Init();

PACA_Init();

EnableInterrupts;

for (;;)

{

ATD_data();

PD_data();

STATE_data();

START_judge();

STATE_judge();

STATE_e();

SPEED_set();

STEER_pd();

SPEED_pd();

}

}

这份源代码的不足和错误还是比较多, for(i=0;i<10;i++) //每个传感器采样10次的数据进行排序

排序采用了冒泡排序,效率大打折扣,而且采用排序的方法处理数据稳定但并不是特别好。更改排序算法效果也不明显。

for(j=0;j<11;j++) //对中间的两个值求平均作为本次采集的结果

ad_data1[j]=(ad_data[4][j]+ad_data[5][j])/2;

阅读更多

离散事件模拟

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/* by SonicRang */

#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <windows.h>

using namespace std;

#define WINDOW 5 //定义服务窗口个数

/* 定义各窗口服务队列 */

typedef struct qnode
{
int arrivetime; //到达时刻
int duration; //处理时长
struct qnode *next;
}Qnode, *Queptr;


typedef struct
{
Qnode *front, *rear;
int length;
}LinkQueue;

/* 定义结束 */

/* 定义一天内所有事件链表 */
typedef struct enode
{
int occurTime, NType; //事件发生时刻,事件类型(0:未发生 非0:已完成)
struct enode *next;
}Enode, *Eptr;

typedef struct
{
Enode *front, *rear;
int eventNum; //事件数
}EventList;

/* 定义结束 */


/* 定义全局变量 */

EventList *eventlist; //事件链表
LinkQueue q[WINDOW + 1]; //窗口队列
Eptr pe, ev; //事件节点

int seed = 300;
int closetime; //银行工作时长
int totaltime; //总时间
int customerNum; //客流量

/* 定义结束 */



/* 插入客户事件到事件链表 */

void InsertEvent(EventList *eventlist, int Time, int Type)
{
Eptr p, q, location;
p = new Enode;
p->occurTime = Time;
p->NType = Type;
eventlist->eventNum++;
q = eventlist->front;
location = NULL;


while (q && (Time > q->occurTime)) //找到插入位置
{
location = q;
q = q->next;
}


if (location == NULL) //找到了空队列插入到队头
{
p->next = eventlist->front;
eventlist->front = p;
}
else //找到了非空队列插入到队尾
{
p->next = q;
location->next = p;
}


if (eventlist->eventNum == 1) //初始化队尾
{
eventlist->rear = p;
}
}

/* 插入完成 */



/* 删除事件链表中的事件 */
void DeletEvent(EventList *ev, Eptr &data)
{
Eptr p;
p = ev->front;
ev->front = p->next;
if (--ev->eventNum<1)
{
ev->rear = ev->front;
}
data = p;
}

/* 删除完成 */



/* 当前客户插入窗口队列 */
void EnQueue(LinkQueue *q, int t1, int t2)
{
Queptr p;
p = new Qnode;
p->arrivetime = t1;
p->duration = t2;
q->length++;
if (q->length == 1) //只有一个元素的队列处理
{
p->next = NULL;
q->front = q->rear = p;
}
else
{
p->next = q->rear->next;
}
q->rear->next = p;
q->rear = p; //重连接队列
}
/* c插入完成 */


/* 当前客户出窗口队列进行处理 */
void DeQueue(LinkQueue *q, Queptr f)
{
Queptr p;
if (q->length>0)
{
f->arrivetime = q->front->arrivetime;
f->duration = q->front->duration;
p = q->front;
q->front = q->front->next;
q->length--;
if (q->length == 0)
q->rear = NULL;
delete (p);
}
}
/* 处理结束 */



/* 找最短队列 */
int Minlength()
{
int min, j, i;
min = q[1].length;
j = 1;
for (i = 2; i <= WINDOW; i++)
if (q[i].length < min)
{
min = q[i].length;
j = i;
}
return j;
}
/* 查询完成 */


/* 初始化银行 */
void Open()
{
int i;
eventlist = new EventList;
pe = new Enode;
pe->occurTime = 0; //初始化发生事件事件
pe->NType = 0;
pe->next = NULL;
eventlist->front = pe; //插入第一个客户到事件表
eventlist->rear = pe;
eventlist->eventNum = 1;


for (i = 1; i < WINDOW + 1; i++) //初始化服务窗口队列为空
{
q[i].front = q[i].rear = NULL;
q[i].length = 0;
}
}
/* 初始化结束 */


/* 客户到达 */
void CustomerArrived()
{
int durtime, intertime, min;
customerNum++; //客流量增加

srand((unsigned)time(NULL));

Sleep(1000);
durtime = 5 + rand() % 31; //产生随机数(当前客户所需的服务时间和下一个用户到达的时间间隔)
intertime = 5 + rand() % 11;


if ((ev->occurTime + intertime) < closetime)
InsertEvent(eventlist, ev->occurTime + intertime, 0); //下一个客户到事件加入事件表

min = Minlength(); //找最短队列
EnQueue(&q[min], ev->occurTime, durtime); //客户加入窗口


cout << "客户于<" << ev->occurTime << ">时刻进入" << min << "号窗口," << "处理了" << durtime << "分钟" << endl;

if (q[min].length == 1)
InsertEvent(eventlist, ev->occurTime + durtime, min); //唯一客户加入离开事件
}
/* 函数结束 */



/* 客户离开 */
void CustomerLeave()
{
int i;
i = ev->NType; //第i号窗的客户离开
Queptr data;
data = new Qnode;
DeQueue(&q[i], data); //删除i号窗口的排头客户

cout << i << "号窗口客户离开" << endl;

totaltime += ev->occurTime - data->arrivetime; //总时间累积

if (q[i].length != 0) //插入离开事件
InsertEvent(eventlist, ev->occurTime + q[i].front->duration, i);
}
/* 函数结束 */



/* 主函数 */
void main()
{
cout << "**************银行模拟系统**************" << endl;
cout << "请输入银行营业时长(分钟):" << endl;
cin >> closetime;

Open(); //初始化银行

while (eventlist->eventNum > 0) //事件非空开始执行
{
DeletEvent(eventlist, ev); //取事件表中的第一个事件节点

if (ev->NType == 0) //处理客户到达事件
CustomerArrived();

else
CustomerLeave(); //处理离开事件
}

cout << "今日客流量:" << customerNum << endl;
cout << "平均处理时间:" << totaltime / customerNum << "分钟" << endl;
system("pause");
}

c#制作视频音频歌词相关技术代码记录

开发类似千千静听或者KMplayer等音频视频播放器播放字幕或者歌词的技术

从两方面着手,一是时间轴,二是帧(对于视频)。

方法一的实现比较简单,只需要内置一个定时器,在媒体播放时开始计时,然后读指定的脚本即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;


namespace MediaPlayer
{
public partial class Form6 : Form
{
private AxWMPLib.AxWindowsMediaPlayer axWindowsMediaPlayer2 = new AxWMPLib.AxWindowsMediaPlayer();
PictureBox pictureBox2 = new PictureBox();
private int t = 0;
private int count = 0;
private string filename;
private string[] info = new string[100];



public Form6(ref AxWMPLib.AxWindowsMediaPlayer axWindowsMediaPlayer1, ref PictureBox pictureBox1)
{
InitializeComponent();
this.Text = "视频分析";
timer1.Enabled = false;
axWindowsMediaPlayer2 = axWindowsMediaPlayer1;
pictureBox2 = pictureBox1;
}


private void timer1_Tick(object sender, EventArgs e)
{
t++;
label2.Text = t.ToString();


if (!info[count].Equals("end#"))
{
if (t == Int32.Parse(info[count].Substring(0, info[count].IndexOf(']'))))
{
richTextBox1.Text = info[count].Substring(info[count].IndexOf(']') + 1);

count++;
}
}


}

private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
filename = openFileDialog1.FileName;
try
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader(filename))
{
String line;
int i = 0;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
info[i] = line;
i++;
}
sr.Close();
}
}
catch (Exception a)
{
// Let the user know what went wrong.
MessageBox.Show("读取错误");


MessageBox.Show(a.Message);
}
}

private void openFileDialog2_FileOk(object sender, CancelEventArgs e)
{
axWindowsMediaPlayer2.URL = openFileDialog2.FileName;
pictureBox2.Visible = false;
timer1.Enabled = true;
}


private void button2_Click(object sender, EventArgs e)
{
openFileDialog2.ShowDialog();
}

}
}

方法二需要利用DirectX开发,或者flash播放的技术拆解成帧然后播放

阅读更多

线索树

最近懒了,贴篇源码补补空闲……

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using namespace std;
typedef struct bithrnode
{
char data;
struct bithrnode *lchild;
struct bithrnode *rchild;
int ltag, rtag;
}BiThrNode, *BiThrTree;

BiThrTree pre;

void InitBTree(BiThrTree &BT);
void CreatBTree(BiThrTree &BT);
void AddThread(BiThrTree p);
void ThreadTree(BiThrTree BT, BiThrTree &head);
BiThrTree InorderNext(BiThrTree p);
void ThInorder(BiThrTree head);

void InitBTree(BiThrTree &BT)
{
BT = NULL;
}


void CreatBTree(BiThrTree &BT)
{
char ch;
ch = getchar();
if (ch == ' ')
BT = NULL;
else
{
BT = new BiThrNode;
BT->data = ch;
BT->ltag = 0;
BT->rchild = 0;
CreatBTree(BT->lchild);
CreatBTree(BT->rchild);
}
}



void ThreadTree(BiThrTree BT, BiThrTree &head)
{
head = new BiThrNode;
head->data = NULL;
head->ltag = 0;
head->rtag = 0;
head->rchild = head;
if (BT == NULL)
head->lchild = head;
else
{
pre = head;
head->lchild = BT;
AddThread(BT);
pre->rchild = head;
pre->rtag = 1;
head->rchild = pre;
head->rtag = 1;
}
}


void AddThread(BiThrTree p)
{
if (p != NULL)
{
AddThread(p->lchild);
if (p->lchild == NULL)
{
p->ltag = 1;
p->lchild = pre;
}
if (pre->rchild == NULL)
{
pre->rtag = 1;
pre->rchild = p;
}
pre = p;
AddThread(p->rchild);
}
}


BiThrTree InorderNext(BiThrTree p)
{
if (p->rtag == 1)
return p->rchild;
else
{
p = p->rchild;
while (p->ltag == 0)
p = p->lchild;
return p;
}
}


void ThInorder(BiThrTree head)
{
BiThrTree HT;
HT = head->lchild;
while (HT != head)
if (HT != NULL)
{
while (HT->ltag == 0)
HT = HT->lchild;
while (HT != head)
{
cout << HT->data << ' ';
HT = InorderNext(HT);
}
}
}
void main()
{
BiThrTree T, head;
InitBTree(T);
cout << "InitTree completed!" << endl;
cout << "Create Tree:" << endl;
CreatBTree(T);
ThreadTree(T, head);
cout << "The ThreadTree is Inordered:" << endl;
ThInorder(head);
system("pause");
}

C#调用IE浏览器设置

1
2
3
4
using  System.Diagnostics;   
ProcessStartInfo Info=new ProcessStartInfo();
Info.FileName = "inetcpl.cpl ";
Process.Start(Info);