Ballin

Check-in [c245ec7155]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:copied code from end of spring 2010
Timelines: family | trunk
Files: files | file ages | folders
SHA1:c245ec71555fc6b8ef23e16a2ce02be5be29f7c2
User & Date: donnyjward@gmail.com 2010-06-01 07:36:30
Context
2010-06-01
07:36
copied code from end of spring 2010 Leaf check-in: c245ec7155 user: donnyjward@gmail.com tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace

Added Makefile.

























































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
#SOURCES=main.c input.c p_bman.c map.c
#OBJECTS=main.o input.o p_bman.o map.o

all: bomberman

#bomberman: $(OBJECTS)

#$(OBJECTS): 
bomberman: main.o input.o p_bman.o map.o enemy.o
	gcc main.o input.o p_bman.o map.o enemy.o -lcurses -lpthread -o bomberman

main.o: main.c
	gcc -c main.c

input.o: input.c
	gcc -c input.c
p_bman.o: p_bman.c
	gcc -c p_bman.c
map.o: map.c
	gcc -c map.c
enemy.o: enemy.c
	gcc -c enemy.c


clean:
	-rm *.o bomberman


Added enemy.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
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
#include "enemy.h"
#include "p_bman.h"
#include "map.h"
#include <math.h> //for absolute value abs()
#include <string.h>
#include <pthread.h>
#include <float.h> //for float lol

#define LIST_SIZE 1000 //100 wasnt big enough
#define MOVE_COST 10

extern pthread_mutex_t mymutex;

extern map * maps;
extern space * spaces;
extern bomberman* b;
extern lvlOver;

enemy * enemys[MAX_ENEMIES]; //array of pointers to enemies. an actor is an individual enemy
int num_enemys_total;
int num_enemys_alive;

extern bomberman * b;

space * openlist[LIST_SIZE]; //array of pointers to spaces
space * closedlist[LIST_SIZE];
int openlist_count = 0; //start empty
int closedlist_count = 0;

int debugcounter = 1;

#define FREQ_CONST 0.4;
extern float AI_FREQ; //freqency that ai will tick
extern float AI_MOD; //frequency modifier (since in e_think there will be slight delays) those delays will be added up and subtracted from ai_freq

void e_alloc(enemy ** e)
{
	int i;

	//allocate space for structure enemy
	enemy *temp = ((enemy *)malloc(sizeof(enemy)));
	*e = temp;
	//set default values
	(*e)->alive = 1;
	(*e)->fire = 1;
	(*e)->bomb = 1;
	(*e)->bombs_set = 0;
	(*e)->cpu = 1;
	(*e)->wins = 0;
	(*e)->symbol = '@'; //what is displayed for this character
	
	(*e)->spiky = 1; //if it is spiky then anybody it touches dies
	(*e)->thinkstate = idle;
	(*e)->clicks = 0;

	(*e)->steps = 0;
	(*e)->path_length = 0;

	for (i = 0; i < MAX_STEPS; i++)
		(*e)->path[i] = -1;

	(*e)->target = NULL;
}

void e_list_init()
{
	int i;
	for (i = 0; i < LIST_SIZE; i++)
	{
		openlist[i] = NULL;
		closedlist[i] = NULL;
	}
	openlist_count = 0;
	closedlist_count = 0;
}

void e_setpos(enemy * actor, int index)
{
	actor->pp = index;
}

int e_getpos(enemy * actor)
{
	return actor->pp;
}

enemy * e_getenemyatpos(int pos)
{
	enemy * temp = NULL;
	int i;

	for (i = 0; i < num_enemys_total; i++)
	{
		if ( enemys[i]->pp == pos ) //this actor is at this position
			return enemys[i]; //a pointer to the enemy
	}

	return temp;
}

//flag this enemy as dead
void e_kill(enemy * actor)
{
	int pos = e_getpos(actor);

	//num_enemys--;
	//free(actor);
	//num_enemys_alive--;
	actor->alive = 0;

	//erase him from the space hes on.
	spaces[pos].is_enemy = 0;
	spaces[pos].icon = none;
}

void e_clear()
{
	int i;

	for (i = 0; i < num_enemys_total; i++)
	{
		enemys[i]->alive = 0;
		free(enemys[i]);
	}

	num_enemys_total = 0;
	num_enemys_alive = 0;
}
		

//int e_alldead(enemy * e[], int e_index)
//{
//	int i;
/* if an enemy is dead the index goes down. so if all are dead the index is 0. this for loop is redundant.
	for (i = 0; i < e_index; i++)
	{
		if (e[i]->alive = 1) //if this enemy is alive.
*/
/*	
void e_think()
{
	//current behavior: move toward the player, most of the time at least, until a better algorithm is implemented
	int i, j;

	int b_pos = bm_getpos(b);
	int e_pos;
	int dist;
	int dir;
	int trymove;

	for (i = 0; i < num_enemys_total; i++) //cycle through enemys
	{
		if (!(enemys[i]->alive))
		{
			//cant think if im dead
		}
		else
		{
			e_pos = e_getpos(enemys[i]);
			dist = abs(b_pos - e_pos);

			if (b_pos < e_pos) //going to move up or left
			{
				if ( dist > maps->sizex ) //pretty far away, move up
				{
					//move up
					dir = dir_up;
				}
				else //just move left for now
				{
					//move left
					dir = dir_left;
				}
			}
			else //going to move down or right
			{
				if ( dist > maps->sizex ) //pretty far, move down
				{
					//move down
					dir = dir_down;
				}
				else //just move right for now
				{
					//move right
					dir = dir_right;
				}
			}

			//i know where im going, now see if i can actually move there
			trymove = e_trymove(enemys[i], dir);
			
			if (!trymove) //couldnt move where i wanted to, just try to move somwhere now, anywhere
			{
				for (j = 0; j < 4; j++)
				{
					trymove = e_trymove(enemys[i], j); //just try to move anydirection
					if (trymove) //suceessfully moved
						break;
				}
			}
		}
	}

}*/

void e_think() //this function will be called often. so dont do everything everytime (like calculate a new path) or that will slow down the program
{
	int i;
	int steps;
	int loc;
	enemy * e;

	AI_MOD = 0;

	pthread_mutex_lock(&mymutex);
	for (i = 0; i < num_enemys_total; i++) //cycle through enemys
	{
		
		e = enemys[i];
		steps = e->steps;
		loc = bm_getpos();
		if (!(e->alive))
		{
			//cant think if im dead
		}
		else
		{
/*
	the thoughts are in the past tense; they represent what happened last time e_think ran its course
idle - just do nothing for a few clicks
moving - keep moving on path, every once in awhile either recalculate path or become idle if very far away
set_bomb - only happens after setting a bomb, calculate a path and start moving immediately
done - killed player, do nothing
*/

			switch (e->thinkstate)
			{
				case idle:
					
					if (e->clicks < 1)
					{
						 //wait longer
					}	
					else //waited long enough
					{
						e->clicks = 0;
						if ( e_getpath(e, loc) )//calc a path to player
						{
							
							//spaces[0].icon = 'Z';
							//strcpy(debugmsg, "Path found\n");
							e->thinkstate = moving;
							if ( e_jumpto(e, e->path[steps]) ) //start moving on the path
							{
								//on successful move increase step counter
								//e->path[steps]++; //done inside of e_jumpto already
								//spaces[0].icon = 'z';
							}
							else
							{
								//spaces[0].icon = 'X';
							}
						}
						else
						{
							//strcpy(debugmsg, "No Path found\n");
							//no path could be find, sit around for a few moments
							//spaces[0].icon = 'Y';
							e->thinkstate = idle;
							e->clicks = 0;
						}
					}
					break;
				case moving:
					if ( steps >= (e->path_length/3) ) //been going on this path for awhile, recalculate
					{
						if ( !e_getpath(e, loc) ) //calc new path, if no path found, wait for a few moments
						{
							e->thinkstate = idle;
							e->clicks = 0;
						}
					}
					//try to move to next step in path. if blocked, calculate a new path and move

					steps = e->steps; //this was the cause of the ai teleportation bug? outdated data
					if ( e_jumpto(e, e->path[steps]) )
					{
						//do nothing, already moved
					}
					else
					{
						//couldnt move for some reason, sit around for a few moments
						e->thinkstate = idle;
						e->clicks = 0;
					}
					break;
				case done:
					break;
			}	
		}

		e->clicks++;

		//this is so all the ai dont move at the exact same time (so the game looks better)
		pthread_mutex_unlock(&mymutex);
		usleep(10000); //should be 0.1 sec
		pthread_mutex_lock(&mymutex);
	}
	AI_MOD = (0.01 * i);
	AI_FREQ = FREQ_CONST-AI_MOD;
	pthread_mutex_unlock(&mymutex);
//	spaces[21].icon = (char)(i+48);
}

int e_jumpto(enemy * actor, int pos)
{
	int success = 0;
	int pos_orig = actor->pp;

	int hard = mp_checkspace(pos, has_hard);
	int soft = mp_checkspace(pos, has_soft);
	int bomb = mp_checkspace(pos, has_bomb);
	//int enemy = mp_checkspace(pos, has_enemy);
	int enemy = 0;
	int bman = mp_checkspace(pos, has_bman);
	int flames = mp_checkspace(pos, has_xplode);
	int i;

	actor->pp = pos;
	
	if( 1 == 0 )//(!hard) || (!soft) || (!bomb) || (!enemy) ) ISNT WORKING FOR SOME REASON, BUT DOESNT MATTER, PATH WAS ALREADY DEEMED WALKABLE
	{
		//spaces[5].icon = 'V';
		actor->pp = pos_orig;
	}
	else if (bman) //player here, let him live until i am threaded
	{
		for (i = 0; i < num_enemys_total; i++)
		{
			if ( enemys[i]->alive )
				enemys[i]->thinkstate = done; //stops doing anything
		}
		success = 1; //lol
		bm_kill();
	}
	else if (flames) //just walked into flames, die
	{
		//spaces[5].icon = 'W';
		success = 1; //jot this down as successful move, or else i will have an undead enemy
		e_kill(actor);
	}
	else if(actor->alive != 0)
	{ //i can and will move now
		//move symbol to next space, clear old space, and also update is_enemy values
		spaces[actor->pp].icon = actor->symbol;
		spaces[actor->pp].is_enemy = 1;
		//spaces[actor->pp].is_soft = 1;
		if(spaces[pos_orig].is_bomb == 1)
			spaces[pos_orig].icon = BOMB;
		else
			spaces[pos_orig].icon = none;
		spaces[pos_orig].is_enemy = 0; 
		//spaces[actor->pp-1].is_soft = 0;

		actor->steps = actor->steps + 1;
		success = 1;

		//spaces[20].icon = (char)(actor->steps);
		//if (actor->steps == actor->path_length) //reached end of the path
		//	actor->thinkstate = idle;
	}

	return success;
}

int e_trymove(enemy * actor, int dir)
{
	int success = 0;
	if(actor->alive != 0){
		
	
	if(dir == dir_right)
	{
		actor->pp++;
	
		if(mp_checkspace(actor->pp, has_hard) == 1)
			actor->pp--;
		else if(mp_checkspace(actor->pp, has_soft) == 1)
			actor->pp--;
		else if (mp_checkspace(actor->pp, has_bomb) == 1) //cant move thru bombs
			actor->pp--;
		else if (mp_checkspace(actor->pp, has_enemy) == 1) //cant move thru enemys
			actor->pp--;
		else if (mp_checkspace (actor->pp, has_xplode) == 1){ //bomb explosion, dead
			e_kill(actor);
			spaces[actor->pp-1].icon = none;
			spaces[actor->pp-1].is_enemy = 0;
			spaces[actor->pp].icon = XPLODE;
		}	
		else{ //i can and will move now
			//move symbol to next space, clear old space, and also update is_enemy values
			spaces[actor->pp].icon = actor->symbol;
			spaces[actor->pp].is_enemy = 1;
			if(spaces[actor->pp].is_bman == 1)
				bm_kill(b);
			spaces[actor->pp-1].icon = none;
			spaces[actor->pp-1].is_enemy = 0; 

			success = 1;
		}
	}
	else if(dir == dir_left)
	{
		actor->pp--;
		if(mp_checkspace(actor->pp, has_hard) == 1)
			actor->pp++; //undo decrement due to wall present
		else if(mp_checkspace(actor->pp, has_soft) == 1)
			actor->pp++; //undo decrement due to soft wall
		else if (mp_checkspace(actor->pp, has_bomb) == 1) //cant move thru bombs
			actor->pp++;
		else if (mp_checkspace(actor->pp, has_enemy) == 1) //cant move thru enemys
			actor->pp++;

		else if (mp_checkspace (actor->pp, has_xplode) == 1){ //bomb explosion, dead
			e_kill(actor);
			spaces[actor->pp+1].icon = none;
			spaces[actor->pp+1].is_enemy = 0;
			spaces[actor->pp].icon = XPLODE;
		}
		else{
			spaces[actor->pp].icon = actor->symbol;
			spaces[actor->pp].is_enemy = 1;
			if(spaces[actor->pp].is_bman == 1)
				bm_kill(b);
			spaces[actor->pp+1].icon = none;
			spaces[actor->pp+1].is_enemy = 0; 

			success = 1;
		}
	}
	else if(dir == dir_down)
	{
	
		actor->pp += maps->sizey;
		if(mp_checkspace(actor->pp, has_hard) == 1)
			actor->pp -= maps->sizey; //undo increment due to wall present
		else if(mp_checkspace(actor->pp, has_soft) == 1)
			actor->pp -= maps->sizey; //undo increment due to soft wall
		else if (mp_checkspace(actor->pp, has_bomb) == 1) //cant move thru bombs
			actor->pp -= maps->sizey;
		else if (mp_checkspace(actor->pp, has_enemy) == 1) //cant move thru enemys
			actor->pp -= maps->sizey;
		else if (mp_checkspace (actor->pp, has_xplode) == 1){ //bomb explosion, dead
			e_kill(actor);
			spaces[actor->pp-maps->sizey].icon = none;
			spaces[actor->pp-maps->sizey].is_enemy = 0;
			spaces[actor->pp].icon = XPLODE;
		}
		else{
			spaces[actor->pp].icon = actor->symbol;
			spaces[actor->pp].is_enemy = 1;
			if(spaces[actor->pp].is_bman == 1)
				bm_kill(b);
			spaces[actor->pp-maps->sizey].icon = none;
			spaces[actor->pp-maps->sizey].is_enemy = 0; 

			success = 1;
		}
	}
	else if(dir == dir_up)
	{
		actor->pp -= maps->sizey;
		if(mp_checkspace(actor->pp, has_hard) == 1)
			actor->pp += maps->sizey; //undo decrement due to wall present
		else if(mp_checkspace(actor->pp, has_soft) == 1)
			actor->pp += maps->sizey; //undo decrement due to wall present
		else if (mp_checkspace(actor->pp, has_bomb) == 1) //cant move thru bombs
			actor->pp += maps->sizey;
		else if (mp_checkspace(actor->pp, has_enemy) == 1) //cant move thru enemys
			actor->pp += maps->sizey;
		else if (mp_checkspace (actor->pp, has_xplode) == 1){ //bomb explosion, dead
			e_kill(actor);
			spaces[actor->pp+maps->sizey].icon = none;
			spaces[actor->pp+maps->sizey].is_enemy = 0;
			spaces[actor->pp].icon = XPLODE;
		}

		else
		{
			spaces[actor->pp].icon = actor->symbol;
			spaces[actor->pp].is_enemy = 1;
			if(spaces[actor->pp].is_bman == 1)
				bm_kill(b);
			spaces[actor->pp+maps->sizey].icon = none;
			spaces[actor->pp+maps->sizey].is_enemy = 0; 

			success = 1;
		}
	}
	return success;
	}
}

void e_list_print(space * list[], int size)
{
	int i;
	printf("in print, size = %d\n", size);

	if (size == 0)
		printf("The list is empty!\n");
	else
	{
		for (i = 0; i < size; i++)
		{
			printf("list[%d]->f = %d (s[%d])\n", i, list[i]->f, list[i]->f);
		}
	}
}

void e_list_add(space * list[], space * s, int * count)
{
	int i = 0;

	while (list[i] != NULL) //go to end of list where nothing is there
	{
		if (i >= LIST_SIZE)
			return;
		i++;
	}

	list[i] = s;
	(*count)++;
}

void e_list_remove(space * list[], space * s, int * count)
{
	int i = 0;

	while (list[i] != s) //go through list until end reached or s found
	{
		if (i >= LIST_SIZE)
			return;
		i++;
	}

	//s found, bump up each element and decrement count
	(*count)--; //lesson learned, *count-- decrements pointer, not what it points to!!!!

	while (list[i] != NULL)
	{
		list[i] = list[i+1]; //go through rest of list and bump up every element

		
		i++;
		if (i >= LIST_SIZE-1) //if list is full, replace last element with null
		{
			list[i] = NULL;
		}
	}
	//printf("In e_list_remove, exiting, *count = %d\n", *count);
}

int e_list_find(space * list[], space * s)
{
	int i = 0;

	while (i < LIST_SIZE)
	{
		if (list[i] == s) //found it
			return 1;
		i++;
	}

	return 0; //went thru whole list and found nothing
}

void e_list_sort(space * list[], int size)
{
	int i, j, min;

	for (i = 0; i < size - 1; i++)
	{
		min = i;
		for (j = i+1; j < size; j++)
		{
			if ( list[j]->f < list[min]->f ) //compare f scores and put smallest in front of list
				min = j;
		}
		e_list_swap(&(list[i]), &(list[min]));
	}
}

void e_list_swap(space ** s1, space ** s2)
{
	space * temp;
	temp = *s1;
	*s1 = *s2;
	*s2 = temp;
}

int e_getpath(enemy * actor, int pos_end)
{	
	int t;
	int done = 0; //1 on finish(found path), 2 on finished(no path possible)
	int i, x1, y1, x2, y2, temp_int;
	int pos;
	int pos_rel; //relativeposition of space
	//int pos_end = bm_getpos(b); //target position (most likely bomberman pos)
	space * current = &(spaces[e_getpos(actor)]); //the current square. begins as starting square
	current->parent = NULL; //the starting space on the path will have null parent (used for retracing path back to beginning)
	space * target = &(spaces[pos_end]); //target square
	space * s; //pointer to space
	int pathsize; //used to calculate the size of the path (how many steps)
	int spacesize;

	//clear all relevant data for bug free pathfinding
	spacesize = maps->sizex*maps->sizey;
	mp_s_clearparents(spacesize); //clear parent of every space for proper pathfinding
	e_list_init(); //clears list and resets values to 0
	for (i = 0; i < MAX_STEPS; i++)
		actor->path[i] = -1;
	actor->steps = 0; //reset since were on a new path
	actor->path_length = 0;

	e_list_add(openlist, current, &openlist_count); //add the starting space to open list
//spaces[0].icon = '4';
	while ( openlist_count ) //stop when the list is empty
	{
	//	usleep(200000);
		//spaces[0].icon = '5';
		e_list_sort(openlist, openlist_count); //sort the current list lowest f score 1st
		//switch this lowest f score space to the closed list
		current = openlist[0];
		pos = current->pos; //dont forget this
	//current->icon = 'Z';
		e_list_remove(openlist, current, &openlist_count);
		e_list_add(closedlist, current, &closedlist_count);//e_list_add(openlist, current, &closedlist_count);

		if (current == target) //target added to closed list, path found
		{

			//now rebuild the path backwards to get a list pointing from the beginning to end
			pathsize = 0;
			s = current; //just to count how long the path is
			while ( s->parent != NULL ) //go thru path backwards to find out how long it is
			{		
//	debugcounter++;
//	spaces[0].icon = debugcounter;
//	usleep(250000);
				s = s->parent;
				pathsize++;

//mark path for debuggin purposes
			//	if (pathsize != 0 && s->parent != NULL)
			//		s->icon = (char)(pathsize+48);
			}
			t = pathsize-1; //TEMPORARY
			for (i = pathsize-1; i >= 0; i--) //start at endn of list and put in the path backwards to get a forwards list
			{
				//spaces[current->pos].icon = (char)(t+48);
				//spaces[current->pos].icon = '$';
				actor->path[i] = current->pos;
				current = current->parent;

				t--;
			}
			actor->path_length = pathsize;
			


			return 1;
		}
		//scan the 4 adjacent squares to this current node
		for (i = 0; i < 4; i++) //search left, right, above, then below node
		{
			//usleep(200000);
			pos_rel = mp_getrelative(pos, i);
			s = &(spaces[pos_rel]);
			if ( !mp_walkable(pos_rel) || e_list_find(closedlist, s) )
			{
				//if not walkable space or on closed list, ignore it
			}
			else
			{
				if ( !e_list_find(openlist, s) ) //if not on open list,
				{ //then add it to open list, make current square the parent of this square, and calculate its f score
					e_list_add(openlist, s, &openlist_count);
					s->parent = current;

		//			s->icon = 'z';

					//pos_rel is already the pos of this space
					mp_getcoords(pos_rel, &x1, &y1); //sets x and y to the coords of this space
					mp_getcoords(pos_end, &x2, &y2); //sets x and y to the coords of target

					s->g = s->parent->g + MOVE_COST; //add movecost to g of parent square
					s->h = MOVE_COST*(abs(x1-x2) + abs(y1-y2)); //number of moves to get to end
					s->f = s->g + s->h; //f = g+h
				}
				else //already on the open list wtf?
				{ //see if this node's g cost would b smaller if it went thru the current node instead of whatever its parent node is.
					temp_int = current->g + MOVE_COST;
					if (s->g > temp_int) //then this path is better, change its parent to current node and recalc its f, g cost
					{
						s->parent = current;
						s->g = temp_int;
						s->f = s->g + s->h;
					}
				}
			}

		}

	}
	return 0; //fail
}

Added enemy.h.

























































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
#ifndef __ENEMY_H__
#define __ENEMY_H__


#define MAX_ENEMIES 9
#define MAX_STEPS 50 //the amount of steps that can be stored in one actor's memory

//struct bomberman;
//struct map;
//struct space;
/*
below i use a function that takes arrays of structs. before you can use an array, the struct must be defined 
so the compiler knows how much space to set aside for it. thats why map.h must be included here, and simply
declaring map and space above doesnt work
*/
#include "map.h"
#include <stdio.h> //for printf, only used by debugging funcs

enum thoughts
{
	moving,
	set_bomb,
	idle,
	done,
};

typedef struct enemy
{
	int alive; //similar to bool alive = false
	int fire; //blast radius of bombs
	int bomb; //# of bombs that can be live at once
	int bombs_set; //# of bombs currently live
	//int skull; //the type determines which skull powerdown the bomber has. use enum
	int cpu; //bool: whether or not to use ai control
	int wins;

	char symbol; //what is displayed for this character
	int pp; //enemy position
	
	int spiky; //if it is spiky then anybody it touches dies
	int thinkstate;
	int clicks; //used to delay decisions while thinking

	int steps; //how many steps taken on current path so far
	int path_length; //how many steps the path is
//	space * path[MAX_STEPS]; //array of pointers to spaces. list of consecutive spaces to get where i want to go.
	int path[MAX_STEPS]; //array of loc's of spaces on the path. in order
	space * target; //destination of path (last space on path)
	
} enemy;

void e_alloc(enemy ** e);
//void e_findclosest(enemy * actor, map * m);
void e_list_init();
void e_setpos(enemy * actor, int index); //set position of an enemy to index
int e_getpos(enemy * actor); //get space index that the enemy is standing on
enemy * e_getenemyatpos(int pos); //return a pointer to the enemy at a specific space
void e_kill(enemy * actor);
void e_clear(); //clear enemy array. use at the end of a round to reset. same as killing all enemies
//int e_alldead(int e_index); //check if all enemys are dead

void e_think(); //periodic function that makes all the decisions for enemy
int e_jumpto(enemy * actor, int pos); //try to jump to a specific space with no regard for human life
int e_trymove(enemy * actor, int dir); //try to move in a direction. returns 1 on success, 0 on fail


void e_list_add(space * list[], space * s, int * count); //add a space to the end of an open or closed list
void e_list_remove(space * list[], space * s, int * count); //remove a space
int e_list_find(space * list[], space * s); //search for a specific space. 1 on success, 0 on fail
void e_list_sort(space * list[], int size); //sort list from smallest to largest f scores
void e_list_swap(space ** s1, space ** s2);
int e_getpath(enemy * actor, int pos);

//enemy * g_enemy;

#endif

Added input.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
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
/*
==================================================
input.c (formerly move.c)
By: Julio Pescador
Edited By: Donny Ward

Description:

Currently creates and displays the gamespace and monitors keyboard input to update the screen. Map functionality needs to be
transferred to map.c file for more flexibility. ~check
==================================================
*/

#include <curses.h>
#include <string.h>
#include <stdlib.h>
#include "map.h"
#include "enemy.h"
#include "p_bman.h"

/*
push arrow keys to move
spacebar to set bombs
push k to kill yourself (ends match)
w = win button
*/

extern map * maps;
extern enemy * enemys[MAX_ENEMIES];
extern space * spaces;
extern bomberman* b;


extern int num_enemys_total;
extern int num_enemys_alive;
extern int data;

int spacesize;
char player;
int lvlOver;
int success = 1;

//move is a macro so i had to change the function name from move to m_move
void new_game()
{
	
	//map* initialize; 

	//int num_enemys_total; // number of enemies alive
	//enemy * actor[MAX_ENEMIES]; //array of pointers to enemies

	mp_alloc(&maps); //allocate some space for the MAP

	//bomberman* p[1]; //create bomberman player(s)
	bm_alloc(&b); //allocate space for structure bomberman

	//int spacesize;

	/*echo(); //so you can see what you are typing
	printw("Please type in your name:");
	char* name;
	name = malloc(sizeof(char));
	getstr(name);
	bm_setname(p[0], name);
	*/
	clear();
	mp_readMapsInfo(); //read in array of txt file from maps.txt
	mp_readMap(); //read in map level1.txt, level2.txt, etc

//	space sMap[maps->sizex*maps->sizey];
	spacesize = maps->sizex*maps->sizey;
	mp_s_alloc(&spaces, spacesize);

	mp_create();
	
	player = mp_getSymbol(); //get player symbol
	bm_setsymbol(player); //set player symbol
	mp_startPosition(b); //place player starting position
	
	//mp_print(); //print out map
	
	/*beginning of do while  loop. Loop takes in input from user. 
	right now just arrow keys. player moves in the map based on wat 
	direction the character wishes to travel*/

	/*pthread_t print;
	void *status;

	if(pthread_create(&print, NULL, mp_print, NULL) != 0)
	{
		perror("pthread_create");
		exit(1);
	}
	if(pthread_join(print, &status) != 0){
		perror("pthread_join");
		exit(1);
	}*/

	
}

int next_lvl()
{
	int success;
	free(maps->buffer);
	maps->iterate++;
	success = mp_readMap();

	if(success == 1){
	spacesize = maps->sizex*maps->sizey;
	mp_s_alloc(&spaces, spacesize);

	mp_create();
	
	player = mp_getSymbol(); //get player symbol
	bm_setsymbol(player); //set player symbol
	mp_startPosition(b); //place player starting position
	}

	return success;
	//mp_print();
}

int m_move()
{
	//int getInput; //variable used to get character from user input	

        //do{

		if(success)
	        	success = mp_playerInput(b); //must find out how to make enemy a global variable
		if ( !bm_isalive()) //if the player dies
		{
			clear();
			lvlOver = 1;
			return 0;
			//break; //go back to main menu
		}

		else if ( !num_enemys_alive ) //if all enemies are dead. MUST be else if. if you die with the last enemy then i win u lose
		{
			//next stage
			//break;
			lvlOver = 1;
			clear();
			return 1;
		}	
		//clear();
		//mp_print();
		//data = 1;

	
	//}while(getInput != 27); //keep running loop based on users input until user types in esc key on keyboard
	       
	//getch();
	/*else if(getInput == 'q'){
		lvlOver = 1;
		clear();
		return 2;
	}*/
}

Added item.c.































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include "item.h"

void item_kill(struct * item) //kill an item, if it gets smashed by a block or blown up
{
	//special effects
	//...
	//...

	item_remove(item);
}

void item_remove(struct * item) //erase item, make it disapear
{
	//
}

Added item.h.









































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
struct item
{
	enum itemtype
	{
		fire, //increase blast radius by 1
		bomb, //increase # of bombs at once by 1
		glove, //pick up bombs/players and throw them
		kick, //kick a bomb so it slides till it hits something
		skull, //diseases for the player
		punch, //like kick except the bomb goes airborne and thus can fly over blocks
	};

	int x;
	int y;

	itemtype type; //defines what this item is/does
};

void item_kill(struct * item); //kill an item, if it gets smashed by a block or blown up
void item_remove(struct * item); //erase item, make it disapear

Added levels/battleroyal.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
|B                  |
|                   |
|                   |
|                   |
|                   |
|                @  |
|                   |
|                   |
|                   |
|            @      |
|   @               |
|                   |
|               @   |
|                   |
|       @           |
|                   |
|          @        |
|                   |
| @                @|
---------------------

Added levels/lvl1.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
|B                  |
| X X X X X X X X X |
|                   |
| X X X X X X X X X |
|                   |
| X X X X X X X X X |
|              @    |
| X X X X X X X X X |
|                   |
| X X X X X X X X X |
|         @         |
| X X X X X X X X X |
|    @              |
| X X X X X X X X X |
|                @  |
| X X X X X X X X X |
|  @                |
| X X X@X X X X X X |
|                  @|
---------------------

Added levels/lvl10.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
|B                  |
| # # # # # # # # # |
|                   |
| # # # # # # # # # |
|                   |
| # # # # # # # # # |
|                   |
| # # # # # # # # # |
|              @    |
| # # # # # # # # # |
|          @        |
| # # # # # # # # # |
|     @             |
| # # # # # # # # # |
|                   |
| # # # # # # # # # |
|  @       @        |
| # # # # # # # # # |
|          @       @|
---------------------

Added levels/lvl11.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
| X       B       X |
| X XXX X#X#X XXX X |
| X   X   X   X   X |
| XXX X X X X X XXX |
| #               # |
| XXXXX X X X XXXXX |
|                   |
| X XXXXX X XXXXX X |
| X               X |
| X X XXXX#XXXX X X |
| X               X |
| X XXXXX X XXXXX X |
|  @             @  |
| XXXXX X X X XXXXX |
| #       X       # |
| XXX X X X X X XXX |
| X @ X       X @ X |
| X XXX X#X#X XXX X |
| X       @       X |
---------------------

Added levels/lvl12.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
|B                  |
| XXXXX XXXXXXXXXXX |
| X X     X   X   X |
| # XXXXX X X X X # |
| X     X X  @  X X |
| X X X X X#X XXX X |
| X     X         X |
| X XXX XXXXX X X X |
| #   X         X X |
| X X X X X X XXX X |
| X X X   X  @X     |
| XXX XXX#X X X X X |
|         X   X   X |
| X XXXXXXX X XXX X |
| X X  @    X     X |
| # X#XXXXX#XXXXX # |
| X   X         X X |
| XXXXX XXXXXXXXX X |
|      @           @|
---------------------

Added levels/lvl13.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
|       X B X       |
| X#XXXXX   XXXXX#X |
| X       X       X |
| X XXX XX#XX XXX X |
| X X           X X |
| X XXX X # X XXX X |
| #     X   X     # |
|XX XXX X X X XXX XX|
|   X   X   X   X   |
|   X XX# # #XX X   |
|   X   X   X   X   |
|XX XXX X X X XXX XX|
| #     X   X     # |
| X XXX X # X XXX X |
| X X           X X |
| X XXX XX#XX XXX X |
|@X       X       X@|
| X#XXXXX   XXXXX#X |
|    @  X @ X  @    |
---------------------

Added levels/lvl14.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
| X  B    X    X    |
| X X XXX X X X X XX|
|   X       X      X|
|#X X XXX XXX X XXX |
|       X X     X   |
|XXXX X X X X X XXX |
|   X      #        |
|XX XXX X X X X XXX |
|  @       X  X @  #|
| X X XXX X X X X X |
| #     X     X  X  |
| X X X X X XXX X X |
| X     X    @    X |
| X X XXX XXX XXX X |
|XX   X   X     X XX|
|#X XXX X X X X X X |
|   #     X    X    |
|XXXX X X X X X X X |
|    #X XXX   X  @X |
---------------------

Added levels/lvl15.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
|B # #  X       X   |
|##X # #X XXXX   X##|
| X  XX      X   X  |
| #  X   X#   XX    |
| # X  XX  X      X |
| XXX      X   XX## |
|##  #X    XXX      |
|X  XX        X  XX |
|       XXX X   XX  |
| XXX  X  X  X XX   |
|   X  X   # X      |
|   X XX# #   XXX#  |
| ##     #X      # @|
|XX  XXX  X   X  XX |
|    X X  XXXX  X   |
|XXX##          X   |
|@X      X    X  @X |
|#X##  X XXX   X  ##|
| @ #X X   X   XXX @|
---------------------

Added levels/lvl16.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
|X##X##X##X##X##X##X|
|#B #  #  #  #  #  #|
|#  #  #  #  #  #  #|
|X##X##X##X##X##X##X|
|#  #  #  #  #  #  #|
|#  #  #  #  #  #  #|
|X##X##X##X##X##X##X|
|#  #  #  #  #  #  #|
|#  #  #  #  #  #  #|
|X##X##X##X##X##X##X|
|#  #  #  #  #  #  #|
|#  #  #  #  #  #  #|
|X##X##X##X##X##X##X|
|#  #  #  #  #  #@ #|
|#  #  #  #  #  # @#|
|X##X##X##X##X##X##X|
|#  #  #  #  #@ #@@#|
|#  #  #  #  # @#@@#|
|X##X##X##X##X##X##X|
---------------------

Added levels/lvl17.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
|B #  X      X  X   |
|#X XX  XXX  XX X   |
| X      X       X  |
|XX  XXX    XX    X |
| ##   X  X  X #X   |
|XX XX  X    XX X  X|
|#  X    ##X   XX  X|
|#X # XX   X    X  X|
|X X  X  @    XX  XX|
|     XX    X X#  @ |
|   X   #  XX #  X  |
| X XXX##X   X  X ##|
|#X      X   X  X   |
| XX XX    X  ##    |
| @ #  XX## X    X  |
|   X     ##  XXX # |
|X  X##  @ #       #|
| XXX ##X  X    X## |
| #    #XX X   X  @ |
---------------------

Added levels/lvl18.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
|     #       #     |
|    X X     X X    |
|   X   X   X   X   |
|  X     X X     X  |
| #   B   #    @  # |
|  X     X X     X  |
|   X   X   X   X   |
|    X X     X X    |
|     #       #     |
|    X X     X X    |
|   X   X   X   X   |
|  X     X X     X  |
| #   @   #   @   # |
|  X     X X     X  |
|   X   X   X   X   |
|    X X     X X    |
|     #       #     |
|    X X     X X    |
|                   |
---------------------

Added levels/lvl19.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
| XXXXXXX X XXXXXXX |
| XB # X# X #X #  X |
| XXXX  X   X  XXXX |
| #   # # X # #   # |
| XXXXXXX X XXXXXXX |
| X # # X X X # # X |
| X X X X X X X X X |
| X XXXXX X XXXXX X |
| X #    # #    # X |
| # X X X X X X X # |
| X #    # #    # X |
| X XXXXX X XXXXX X |
| X X@X X X X X@X X |
| X # # X X X # # X |
| XXXXXXX X XXXXXXX |
| # @ # # X # # @ # |
| XXXX  X   X  XXXX |
| X @# X# X #X #@ X |
| XXXXXXX X XXXXXxX |
---------------------

Added levels/lvl2.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
|                   |
| X X X X X X X X X |
| B X   X   X   X   |
| X X X X X X X X X |
| X   X   X   X   X |
| X X X X X X X X X |
|   X   X   X   X   |
| X X X X X X X X X |
| X   X @ X   X   X |
| X X X X X X X X X |
|   X   X   X @ X   |
| X X X X X X X X X |
| X@  X   X   X   X |
| X X X X X X X X X |
|   X   X @ X   X @ |
| X X X X X X X X X |
| X   X @ X   X   X |
| X X X X X X X X X |
|    @         @    |
---------------------

Added levels/lvl20.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
|B         XXXXXXXX |
| XX#XXXXX X      X |
| X# #  #X X XXXX X |
|#X X XX X # X  X X |
| XXXXXX X X X XX # |
|#    @  # X X    X |
| XXXXXXXX X XXXXXX |
| X        X     X  |
| X  XXXXXXXXXXX X  |
| X  #   @   # X X  |
| X  X XXXXXX# X #  |
| X  X X # #  #X X  |
| X  X XXXXXXXXX XXX|
|    X   @  X       |
| X  X#XXXX X XXXXX |
| X  X X  # X X # X |
|##@   X  X # XXX X |
| XXXXXXXXX X  # @X |
|  #    #   XXXXXXX |
---------------------

Added levels/lvl21.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
|B  X       XXXXX   |
|X  X X#XX     X   X|
| X XXX  X X X    X |
|X       XX # XXX ##|
|  XXX#X        #   |
|  #   X    XXX X XX|
|  XXX X  XXX X X X |
|    X XXXX   X X # |
|XX  X      XXX XXX |
| X##X  XXX X    @  |
|       X XXX X##XX |
|@  XXXXX     X   X |
|   #   @  XXXX XXX |
|   X XXX  X  @ X   |
|XX#X X X  X XX#X   |
|  @  X XXXX X      |
| X#XXX      #  XXX |
| #     X#XX XXXX # |
| XXXXXX  X      X @|
---------------------

Added levels/lvl22.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
|XXXXXXXXXXXXXXXXXXX|
|XB  X   # #   X   X|
|XXX##   X X   ##XXX|
|X       X X       X|
|X#XXXXXXX XXXXXXX#X|
|X     #     #     X|
|X     X     X     X|
|X     X     X     X|
|X#XXXXX     XXXXX#X|
|X        X        X|
|X#XXXXX     XXXXX#X|
|X     X     X     X|
|X     X     X     X|
|X     #     #     X|
|X#XXXXXXX XXXXXXX#X|
|X     @ X X  @    X|
|XXX##   X@X   ##XXX|
|X@  X   # #   X  @X|
|XXXXXXXXXXXXXXXXXXX|
---------------------

Added levels/lvl23.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
|XXXXXXXXXXXXXXXXXXX|
|X          B      X|
|XXXXXXXX XXXXXXX XX|
|       X X     X X |
|XXXXXXXX XXXXXXX XX|
|X                 X|
|XXXX XXXXXXXXX XXXX|
|   X X       X X   |
|XXXX XXXXXXXXX XXXX|
|X                 X|
|XX XXXXXXX XXXXXXXX|
| X X     X X       |
|XX XXXXXXX XXXXXXXX|
|X   @        @    X|
|XXXXXXXX XXXXXXXXXX|
|       X X         |
|XXXXXXXX XXXXXXXXXX|
|X   @     @       X|
|XXXXXXXXXXXXXXXXXXX|
---------------------

Added levels/lvl24.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
|X##      B      ##X|
|X##X  X     X  X##X|
|X##X  #XXXXX#  X##X|
|X###X         X###X|
|X###X  XXXXX  X###X|
|X####X   X   X####X|
|XX####   X   ####XX|
|X#@##X       X###@X|
|X###X  X   X  X###X|
|X###  XXX XXX  ###X|
|X###X  X   X  X###X|
|X@###X       X####X|
|XX####   X   ####XX|
|X####X@  X  @X####X|
|X###X  XXXXX  X##@X|
|X###X         X###X|
|X##X  #XXXXX#  X##X|
|X##X  X     X  X##X|
|X##      @      ##X|
---------------------

Added levels/lvl25.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
| XX###XX    XX###XX|
| X     X    X     X|
|XX BX  XX##XX  X  X|
| X     X    X     X|
| XX###XX    XX###XX|
|                   |
|XX    XX###XX    XX|
| X    X     X    X |
| XX##XX  X  XX##XX |
| X    X     X    X |
|XX    XX###XX    XX|
|                   |
| XX###XX    XX###XX|
| X     X    X     X|
|XX @X  XX##XX  X@ X|
| X     X    X     X|
| XX###XX    XX###XX|
|  @       @     @  |
|XX   XX    XX    XX|
---------------------

Added levels/lvl3.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
|                   |
| X X X X X X X X X |
|   X X     X X     |
| X X X X X X X X X |
| X  B  X X   X X   |
| X X X X X X X X X |
|   X X     X X  @  |
| X X X X X X X X X |
|       X X     X X |
| X X X X X X X X X |
| X X     X X @     |
| X X X X X X X X X |
|     X X     X X @ |
| X X X X X X X X X |
|   X X  @  X X     |
| X X X X X X X X X |
| X X @ X X  @  X X |
| X X X X X X X X X |
|                   |
---------------------

Added levels/lvl4.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
|                   |
| X X X X X X X X X |
| B  #   #   #   #  |
| X X X X X X X X X |
|  #   #   #   #    |
| X X X X X X X X X |
|    #   #   #   #  |
| X X X X X X X X X |
|  #   #   #   #    |
| X X X X X X X X X |
|    #   # @ #   #  |
| X X X X X X X X X |
|  # @ #   # @ #    |
| X X X X X X X X X |
|    #   # @ #   #  |
| X X X X X X X X X |
|  # @ #   #   #  @ |
| X X X X X X X X X |
|                   |
---------------------

Added levels/lvl5.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
|                   |
| X X X ##### X X X |
|       #####   X   |
| X X X ##### X X X |
| B X   #####  @    |
| X X X ##### X X X |
|       #####    @  |
| X X X ##### X X X |
|                   |
| X X X ##### X X X |
|   X   #####       |
| X X X ##### X X X |
|       #####   X @ |
| X X@X ##### X X X |
|       #####    @  |
| X X X ##### X X X |
|   X   #####   X   |
| X X X ##### X X X |
|    @              |
---------------------

Added levels/lvl6.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
|  B X              |
| X XXX#X X XXXXX#X |
| # #   X   X     X |
| X X X X X X XXX X |
|   X     # X X@# XX|
|XX X XXX X XXX X X |
|       # X     X X |
| X X X X X X XXX X |
| X #               |
| XXXXX X X X XXXXX |
|   @   #     X     |
| X X#XXX XXX X X X |
| X          @#   # |
| X X XXX X#X X X X |
| X # X X X   X   X |
|XX XXX X X X X X X |
| X   @ X         X |
| X#XXXXX X XXX#XXX |
|  @          X  @  |
---------------------

Added levels/lvl7.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
|B                  |
| XXXXXXXX XXXXXXXX |
| X               X |
| X XXXXXXXXXXXXX X |
| X X           X X |
| X X XXXX XXXX X X |
| X X X@  @  @X X X |
| X X X XX#XX X X X |
| X X X #X@X# X X X |
|   X   XX#XX   X   |
| X X X #X@X# X X X |
| X X X XX#XX X X X |
| X   X@  @  @X   X |
| X X XXXX XXXX X X |
| X X           X X |
| X XXXXXXXXXXXXX X |
| X               X |
| XXXXXXXX XXXXXXXX |
|                   |
---------------------

Added levels/lvl8.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
|XXXXXXXXXXXXXXXXXXX|
|X        B        X|
|XXXX XXXX XXXX XXXX|
|X                 X|
|XXXX XXXX XXXX XXXX|
|X                 X|
|XXXX XXXX XXXX XXXX|
|X                 X|
|XXXX XXXX XXXX XXXX|
|X                 X|
|XXXX XXXX XXXX XXXX|
|X                 X|
|XXXX XXXX XXXX XXXX|
|X                 X|
|XXXX XXXX XXXX XXXX|
|X   @    @    @   X|
|XXXX XXXX XXXX XXXX|
|X   @    @    @   X|
|XXXXXXXXX XXXXXXXXX|
---------------------

Added levels/lvl9.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
|XXXXXXXXX XXXXXXXXX|
|XXXXXXXX   XXXXXXXX|
|XXXXXXX  X  XXXXXXX|
|XXXXXX   #@  XXXXXX|
|XXXXX  X # X  XXXXX|
|XXXX   # X #   XXXX|
|XXX  X # X # X  XXX|
|XX   X # # # X   XX|
|X  X # X # X # X  X|
|XB X # X@X X # X @X|
|X  X # X # X # X  X|
|XX   X # # # X   XX|
|XXX  X # X # X  XXX|
|XXXX   # X #   XXXX|
|XXXXX  X # X  XXXXX|
|XXXXXX   #@  XXXXXX|
|XXXXXXX  X  XXXXXXX|
|XXXXXXXX   XXXXXXXX|
|XXXXXXXXX XXXXXXXXX|
---------------------

Added lvl1.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
|B                  |
| X X X X X X X X X |
|                   |
| X X X X X X X X X |
|                   |
| X X X X X X X X X |
|                   |
| X X X X X X X X X |
|                   |
| X X X X X X X X X |
|                   |
| X X X X X X X X X |
|                   |
| X X X X X X X X X |
|                @  |
| X X X X X X X X X |
|                   |
| X X X X X X X X X |
|                   |
---------------------

Added lvl2.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
|                   |
| X X X X X X X X X |
| B X   X   X   X   |
| X X X X X X X X X |
| X   X   X   X   X |
| X X X X X X X X X |
|   X   X   X   X   |
| X X X X X X X X X |
| X   X @ X   X   X |
| X X X X X X X X X |
|   X   X   X @ X   |
| X X X X X X X X X |
| X@  X   X   X   X |
| X X X X X X X X X |
|   X   X @ X   X @ |
| X X X X X X X X X |
| X   X @ X   X   X |
| X X X X X X X X X |
|    @              |
---------------------

Added lvl3.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
|                   |
| X X X X X X X X X |
|   X X     X X     |
| X X X X X X X X X |
| X  B  X X   X X   |
| X X X X X X X X X |
|   X X     X X  @  |
| X X X X X X X X X |
|       X X     X X |
| X X X X X X X X X |
| X X     X X @     |
| X X X X X X X X X |
|     X X     X X @ |
| X X X X X X X X X |
|   X X  @  X X     |
| X X X X X X X X X |
| X X @ X X  @  X X |
| X X X X X X X X X |
|                   |
---------------------

Added lvl4.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
|  ##########   ####|
|BX#X#X#X#X#X#X#X#X#|
|#####   ##### ## ##|
|#X#X#X#X X#X X#X#X#|
|### ###### #### ###|
|#X#X X X#X#X X X X#|
|### #  ## ###  ### |
| X X X#X X X X X#X#|
| ##   ##  #   # #  |
| X X X#X X X X X X |
|####### # @ #   #  |
| X X X X X X X X X |
|  # @ #   # @ #####|
| X X X X X X X X X |
|#####   # @ ## #  #|
| X X X X X X X X X |
|#   @ ###### ######|
| X X X X X X X X X |
|###  ##########  @#|
---------------------

Added lvl5.txt.











































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
---------------------
|#                 #|
| X X X ##### X X X |
|       #####   X   |
| X X X ##### X X X |
| B X   #####  @    |
| X X X ##### X X X |
|       #####    @  |
| X X X ##### X X X |
|       #####       |
| X X X ##### X X X |
|   X   #####       |
| X X X ##### X X X |
|       #####   X @ |
| X X@X ##### X X X |
|       #####    @  |
| X X X ##### X X X |
|   X   #####   X   |
| X X X ##### X X X |
|#   @             #|
---------------------

Added main.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
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
/*
==================================================
main.c
By: Donny Ward


Description:

Main file that starts first, runs everything else. Displays a menu and allows the user to pick an option.

Currently uses move.c to start the game. If move.c is edited significantly please make note of it.
==================================================
*/


#include <stdio.h>
#include <stdlib.h>
#include <curses.h>
#include <signal.h>
#include <pthread.h>
#include "map.h"
#include <float.h> //for float lol


//int move();
void* th_print();
void* th_move();
void* th_ai();
void* th_end_in();
void main_menuup(int * o); //move up 1 in the menu
void main_menudown(int * o); //move down 1 in the menu
void main_framenew(); //draw menu with new game selected
void main_frameload(); //draw menu with load game selected
void main_frameexit(); //draw menu with frame exit selected
void main_frameLevel(int n); //display screen telling you level number
void main_framelose(); //displays a screen telling you that you died
int main_framewin();
void main_threadwin();
void main_framewin1();
void main_framewin2();
void main_printerror(char e[]); //print error messages

extern space * spaces;
extern int lvlOver;
int gameresult;
int input_end;

#define FREQ_CONST 0.4
float AI_FREQ = FREQ_CONST; //frequency that ai will tick
float AI_MOD;

enum optiontype
{
	newgame = 0,
	loadgame,
	exittowindows, //exit is used already
};

//int data;
//thread_mutex_t  data_mutex  =  PTHREAD_MUTEX_INITIALIZER;
//pthread_cond_t  data_cond  =  PTHREAD_COND_INITIALIZER;

pthread_mutex_t mymutex;

int main (int argc, char * argv[])
{
	WINDOW * mainwin;
	
	mainwin = initscr();
	raw();
	keypad(stdscr, TRUE);
	noecho();
		
	clear();
	int finish = 0;
	char c;
	int input;
	//int gameresult;
	int numLvl = 1;
	int progress;


	int option = newgame;

	pthread_mutex_init(&mymutex, NULL);
	//initscr();

	while (!finish)
	{	
//		main_framenew();
//		option = newgame;

		if (option == newgame)
			main_framenew();
		else if (option == loadgame)
			main_frameload();
		else if (option == exittowindows)
			main_frameexit();

		refresh();

		input = getch();

		while (input != 10) //return key or enter key
		{
			if (input == KEY_UP)
				main_menuup(&option);
			else if (input == KEY_DOWN)
				main_menudown(&option);

			input = getch();
		}

		switch (option)
		{
			case newgame: //then let the games begin
				input_end = 0;				
				lvlOver = 0;
				numLvl = 1;				
				//clear();
				main_frameLevel(numLvl);
				new_game();
				pthread_t print, move, ai;

				pthread_create(&print, NULL, th_print, NULL);
				pthread_create(&move, NULL, th_move, NULL);
				pthread_create(&ai, NULL, th_ai, NULL);
				
				pthread_join(print, NULL);
				pthread_join(move, NULL);
				pthread_join(ai, NULL);

				//gameresult = m_move();
				e_clear(); //clear enemys
				mp_s_clear(); //clear spaces 'array'

				if (gameresult == 0) //player died
				{//show 'you died' screen before going back to main menu
					main_framelose();
				}
				else if (gameresult == 1) //player won
				{//go to next level
					//display brief victory animated screen (will require thread)
					//main_threadwin();
					//integrate julio's level progression code here
					//gameresult = m_move();
					do
					{
						//if(gameresult == 2)
						//	break;
						if(gameresult == 1){
							lvlOver = 0;
							progress = next_lvl();
							if(progress == 1){
							numLvl++;
							main_frameLevel(numLvl);
							pthread_create(&print, NULL, th_print, NULL);
							pthread_create(&move, NULL, th_move, NULL);
							pthread_create(&ai, NULL, th_ai, NULL);

							pthread_join(print, NULL);
							pthread_join(move, NULL);
							pthread_join(ai, NULL);
							
							e_clear(); //clear enemys
							//gameresult = m_move();
								if(gameresult == 0){
									main_framelose();
									break;
								}
							}

							else{
								clear();
								lvlOver = 1;
								gameresult = 2;
								break;
							}
						}
					}while(gameresult != 0 || gameresult != 2);
	
				}
				if (gameresult == 2) //player wins
				{

					pthread_t endin;
					pthread_create(&endin, NULL, th_end_in, NULL);
					main_threadwin();
					//input_end = 0;
				}

				noecho();
				break;
			case loadgame:
				main_printerror("Load game doesn't work yet!");
				clear();
				break;
			case exittowindows:
				finish = 1;
				break;
			default:
				break;
		}

//		getchar();
/*
		if (m_move() == 0)
		{
			printf("Game exited. Play again? (Y/N): ");
			scanf("%c", &c);

			if (c == 'n' || c == 'N')
				finish = 1;
			else if (c != 'y' && c != 'Y')
				printf("I'll take that as a yes.\n\n");
		}
*/
	//if(gameresult == 0)
	//	main_framelose();
	}
	
	printw("[Bomberman] : Exiting game...\n");
	refresh();
	usleep(500000);
	//clear();
	endwin(); //exits window
	return 0;
}

void* th_print()
{
	while(!lvlOver){
		/*pthread_mutex_lock(&data_mutex);
		while(!data)
			pthread_cond_wait(&data_cond, &data_mutex);		
		mp_print();
		data = 0;
		pthread_mutex_unlock(&data_mutex);
		usleep(100);*/
		usleep(20000);
		mp_print();
		//usleep(20000);
	}
	pthread_exit(NULL);
}

void* th_move()
{
	while(!lvlOver){
	/*pthread_mutex_lock(&data_mutex);
	//m_move();
	gameresult = m_move();
	pthread_cond_signal(&data_cond);
	pthread_mutex_unlock(&data_mutex);
	usleep(1000);*/
	usleep(20000);
	gameresult = m_move();
//	usleep(20000);
	}

	pthread_exit(NULL);
}

void* th_ai()
{
	int time; 
	while(!lvlOver){
	time = AI_FREQ * 1000000;
	usleep(time);
	spaces[20].icon = '[';
	e_think();
//spaces[20].icon = ']'; //for debugging response
//	usleep(900000);
	}
	pthread_exit(NULL);
}

void* th_end_in()
{
	//clear();
	cbreak();
	while(!input_end){
		usleep(20000);
		main_framewin();
	}
	pthread_exit(NULL);
}

void main_menuup(int * o)
{
	clear();

	if (*o == newgame) //then jump to end of list
	{
		main_frameexit();
		*o = exittowindows;
	}
	else
	{
		if (*o == loadgame)
		{
			main_framenew();
			*o = newgame;
		}
		else if (*o == exittowindows)
		{
			main_frameload();
			*o = loadgame;
		}
	}

	refresh();
}

void main_menudown(int * o)
{
	clear();

	if (*o == exittowindows) //then jump to top of list
	{
		main_framenew();
		*o = newgame;
	}
	else
	{
		if (*o == newgame)
		{
			main_frameload();
			*o = loadgame;
		}
		else if (*o == loadgame)
		{
			main_frameexit();
			*o = exittowindows;
		}
	}

	refresh();
}

//have to use printw instead of printf
void main_framenew()
{
	//50 spaces across
	printw(
	"==================================================\n"
	"\n"
	"\n"
	"\n"
	"                    BOMBERMAN!\n"
	"\n"
	"\n"
	"\n"
	"\n"
	"                 *** NEW GAME ***\n"
	"\n"
	"                     LOAD GAME\n"
	"\n"
	"                  EXIT TO WINDOWS\n"
	"\n"
	"--Up and down arrows to navigate--\n"
	"--Enter to make selection--\n"
	"==================================================\n"
	);
}

void main_frameload()
{
	//50 spaces across
	printw(
	"==================================================\n"
	"\n"
	"\n"
	"\n"
	"                    BOMBERMAN!\n"
	"\n"
	"\n"
	"\n"
	"\n"
	"                     NEW GAME    \n"
	"\n"
	"                 *** LOAD GAME ***\n"
	"\n"
	"                  EXIT TO WINDOWS\n"
	"\n"
	"--Up and down arrows to navigate--\n"
	"--Enter to make selection--\n"
	"==================================================\n"
	);
}

void main_frameexit()
{
	//50 spaces across
	printw(
	"==================================================\n"
	"\n"
	"\n"
	"\n"
	"                    BOMBERMAN!\n"
	"\n"
	"\n"
	"\n"
	"\n"
	"                     NEW GAME\n"
	"\n"
	"                     LOAD GAME\n"
	"\n"
	"              *** EXIT TO WINDOWS ***\n"
	"\n"
	"--Up and down arrows to navigate--\n"
	"--Enter to make selection--\n"
	"==================================================\n"
	);
}

void main_frameLevel(int n)
{
	clear();
	printw(
	"==================================================\n"
	"\n"
	"\n"
	"\n"
	"\n"
	"\n"
	"\n"
	"\n"
	"		     Level %d\n"
	"\n"
	"\n"
	"\n"
	"\n"
	"\n"
	"\n"
	"\n"
	"\n"
	"==================================================\n"
	,n);
	refresh();
	sleep(1);
	//getch();
	clear();
}

void main_framelose()
{
	clear();
	printw(
	"==================================================\n"
	"\n"
	"\n"
	"\n"
	"\n"
	"\n"
	"                    YOU LOSE...\n"
	"\n"
	"\n"
	"\n"
	"                      O    O\n"
	"                        **\n"
	"                      *    *\n"
	"                     *      *\n"
	"\n"
	"\n"
	"\n"
	"==================================================\n"
	);
	refresh();
	sleep(1);
	clear();
}

int main_framewin()
{
	//clear();
	//cbreak();
	int input;
	input = getch();
	if(input == 10)
		input_end = 1;

	/*while (input != 10) //return key or enter key
	{
		//wait for user to hit enter
		input = getch();
	}*/
	

}

void main_threadwin()
{
	//alternate between the 2 win screens until termin8ed
	//clear();
	//cbreak();
	while (!input_end)
	{
		main_framewin1();
		usleep(500000);
		clear();
		main_framewin2();
		usleep(500000);
		clear();
	}
}

void main_framewin1()
{
	printw(
	"==================================================\n"
	"\n"
	"\n"
	"\n"
	"\n"
	"\n"
	"                      YOU WIN!\n"
	"\n"
	"\n"
	"                         o\n"
	"                        /|\\ \n"
	"                        / \\ \n"
	"\n"
	"\n"
	"\n"
	"\n"
	"--Press Enter to continue--\n"
	"==================================================\n"
	);
	refresh();
}

void main_framewin2()
{
	printw(
	"==================================================\n"
	"\n"
	"\n"
	"\n"
	"\n"
	"\n"
	"                      YOU WIN!\n"
	"\n"
	"\n"
	"                       \\ o /\n"
	"                         |\n"
	"                        / \\  \n"
	"\n"
	"\n"
	"\n"
	"\n"
	"--Press Enter to continue--\n"
	"==================================================\n"
	);
	refresh();
}


void main_printerror(char e[])
{
	printw("ERROR: %s\n", e);
/*
	printw(
	"==================================================\n"
	"\n"
	"\n"
	"\n"
	"\n"
	"\n"
	"\n"
	);

	printw("ERROR: %s\n", e);

	printw(
	"\n"
	"              Press Enter to continue\n"
	"\n"
	"\n"
	"\n"
	"\n"
	"\n"
	"\n"
	"\n"
	"==================================================\n"
	);

	getch();
*/
	refresh();
}

Added map.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
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
851
/*************************************************
map.c

By: Donny Ward
Edited By: Julio Pescador

TO EVERYONE:

I made functions mp_checkspace and mp_checkrelative. use these
functions to check if a space has something.

//check if a specific space has property
int mp_checkspace(map * m, int row, int col, int property);

//check if a space relative to the one specified has property. multiplier to check subsequent spaces
int mp_checkrelative(map * m, int row, int col, int dir, int multiplier, int property); 

m = the map pointer to the  map
row, col = the row and column that the space belongs to
property = integer value that determines what the function will check for. use these enum values for property:
	
	has_bomb
	has_bman
	has_soft
	has_item
	has_hard

	the function will check the space to see if it has whatever you are looking for and return 1
	if it is there, and 0 if it is not there.


mp_checkrelative is used to let you easily check a status of a space relative to the one that you know about (ex: origin of a bomb blast)
multiplier is used to check spaces x times beyond the first one in that direction. valid dir values are:

	dir_left
	dir_right
	dir_up
	dir_down

example: if you have an explosion starting at row 2 column 2, and you want to see if theres anything in the way at the space right below this one:
	if ( mp_checkrelative(m, 2, 2, dir_down, 1, has_soft) == 1 )
	if ( mp_checkrelative(m, 2, 2, dir_down, 1, has_bomb) == 1 )

	so if there is a soft block in that location you blow it up. if theres a bomb in that location you blow it up prematurely and set off its own explosions

	if there was nothing there and you want the explosion to continue to the block beyond it, you would check that block by changing the multiplier to 2.

	if ( mp_checkrelative(m, 2, 2, dir_down, 2, has_soft) == 1 )

	etc.


these functions are invaluable for collision detection for players, bombs, actors, and everything in between.
examples of practicale use are:

-making a bomb explosion recursively check adjacent sectors in a straight line to see how far the bomb blast should go

thats all i could think of for now.


whenever a space on the map changes it must be updated. maps->map[row][col] is the space structure at (col, row). so a bomb destroys
something (be it a player or item or whatever) on a space, that space must be updated to reflect this. the current values held are:

	int is_bomb; //is there a bomb on this space?
	int is_bman; //is there a bomberman on this space?
	int is_soft; //is there a soft block on this space?
	int is_item; //is there an item on this space?
	int is_hard; //is there a hard block on this space?	

set to 1 if true and 0 if false

-Donny

note: i didnt finish checkrelative yet, only checkspace works

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


#include "map.h"
#include "p_bman.h"
#include "enemy.h"

#include <curses.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <time.h>
#include <pthread.h>

extern pthread_mutex_t mymutex;

map * maps; //global map variable
space * spaces; //refer to a specific space member with spaces[i]. not spaces[i]-> because [i] gets the struct at that point, not a pointer to it

extern enemy * enemys[MAX_ENEMIES];
extern bomberman* b;
extern int num_enemys_total;
extern int num_enemys_alive;
extern lvlOver;

void mp_s_alloc(space ** s, int size)
{
	int i;

	space * temp = (space *)malloc(sizeof(space) * size);
	*s = temp;

	for (i = 0; i < size; i++) //initialize every space to a clean slate
	{
		(*s)[i].icon = '~'; //the character that will be displayed on the map for this space
		(*s)[i].is_bomb = 0; //is there a bomb on this space?
		(*s)[i].is_bman = 0; //is there a bomberman on this space?
		(*s)[i].is_soft = 0; //is there a soft block on this space?
		(*s)[i].is_item = 0; //is there an item on this space?
		(*s)[i].is_hard = 0; //is there a hard block on this space?
		(*s)[i].is_enemy = 0; //is there an enemy on this space?
		(*s)[i].is_dead = 0;

		(*s)[i].f = 0; //f score. f = g + h
		(*s)[i].g = 0; //the movement cost to move from starting point to this space
		(*s)[i].h = 0; //'heuristic'. estimated movement cost to move from here to destination
		//(*s)[i].open; //is this space on the open list? 1 or 0
		//(*s)[i].closed; //is this space on the closed list? 1 or 0
		(*s)[i].parent = NULL; //points to the parent of this space
	}
}

void mp_s_clearparents(int size)
{
	int i;

	for (i = 0; i < size; i++)
		spaces[i].parent = NULL;
}

void mp_s_clear()
{
	free(spaces);
}

/*********************************
allocates space for map structure
**********************************/
void mp_alloc(map ** m)
{
	map *temp = ((map *)malloc(sizeof(map)));
	//*maps = ((map *)malloc(sizeof(map)));
	*m = temp;
	(*m)->iterate = 0;
	(*m)->sizex = 0;
	(*m)->sizey = 0;
}

/****************************************************************************
  This function reads in a file: maps.txt and stores the txts into an array
  called arrayMaps
*****************************************************************************/
void mp_readMapsInfo()
{
	memset(&(maps->arrayMaps[0]), 0, sizeof(maps->arrayMaps));	
	FILE * pFile;
	int c;
	pFile = fopen("maps.txt", "r");
	if(pFile == NULL)
		printw("Error opening file");
	else{
		c = getc(pFile);
		while(c != EOF)		
		{
			maps->arrayMaps[maps->iterate] = c;
			maps->iterate++;

			c = getc(pFile);
		}
		fclose (pFile);
	}

	maps->iterate = 0;
}

/*********************************************************************************
  this function uses the arrayMaps array from the previous function and will
  call each txt in that array one at a time. 
  note: havent coded the part when it goes from lvl1.txt to lvl2.txt
  Right now it just reads in the first txt from the array and places the characters 
  in char* mapLvl
*********************************************************************************/
int mp_readMap()
{
	//char * buffer;
	int spacesize;

	int count = 0;
	if(maps->arrayMaps[maps->iterate] != 0){
	memset(&(maps->fMapLvl[0]), 0, sizeof(maps->fMapLvl));
	while(maps->arrayMaps[maps->iterate] != '\n')
	{
		maps->fMapLvl[count] = maps->arrayMaps[maps->iterate];
		maps->iterate++;
		count++;
	}
	//printw("%s", maps->fMapLvl); //debug
	

	char* temp = maps->fMapLvl;
	
	int row = 0, col = 0;
	int doOnce = 1;
	//printw("%s", temp); //debug
	FILE * pFile;
	char c;
	pFile = fopen(temp, "r");
	if (pFile==NULL) 
		printw ("Error opening file");
	else
	{
		c = getc(pFile);
		while(c != EOF)
		{
			col++;
			if(c == '\n')
			{
				maps->sizey = col-1;
				col= 0;
				row++;	
			}
			c = getc(pFile);
		}
		maps->sizex = row;
		//printw("row: %d", row);
		fclose(pFile);
		
	}

//	char buffer[maps->sizex * maps->sizey];
//	memset(&(buffer[0]), 0, sizeof(buffer));
	count = 0;


	//following 2 lines from donny. this fixes the problem of corrupt map displaying. more info at the end of this function.
	spacesize = maps->sizex * maps->sizey;
	maps->buffer = (char *)malloc(sizeof(char) * spacesize); 

	pFile = fopen(temp, "r");
	if (pFile==NULL) 
		printw ("Error opening file");
	else
	{
		c = getc(pFile);
		while(c != EOF)
		{
			if(c != '\n'){
				maps->buffer[count] = c;
				count++;
			}
			c = getc(pFile);
			
		}
		fclose(pFile);
		
	}
/*
Dangling pointers arise when an object is deleted or deallocated, without modifying the value of the pointer, so that the pointer still points to the memory location of the deallocated memory. As the system may reallocate the previously freed memory to another process, if the original program then dereferences the (now) dangling pointer, unpredictable behavior may result, as the memory may now contain completely different data. This is especially the case if the program writes data to memory pointed by a dangling pointer, a silent corruption of unrelated data may result, leading to subtle bugs that can be extremely difficult to find
*/
	maps->mapLvl = maps->buffer; //when this function goes out of scope, (julio's) buffer was released from memory. maps->mapLvl was dangling pointer
	return 1;
}
/*
This bug has been present for a long time now, but it only showed itself when the space structure was changed to allocate memory
dynamically during runtime. The reason for this is that, by chance, when sMap was just a space array, the program ran in it's entirety without
overwriting the contents of buffer. mapLvl pointed to buffer, and the program never touched this location of memory again so it remained uncorrupted.
When sMap was changed to a pointer with dynamic memory allocation, the program at runtime used the location of memory that mapLvl pointed to to
allocate space for sMap. This resulted in the buffer data at that location becoming corrupted, and thus corrupting mapLvl (which was pointing to
memory that was released back to the system). This is now fixed by manually allocating memory for buffer. Now later on we just have to make sure to
manually free() this memory.
*/
else
	return 0;

}
/*************************************************************************
  This function takes the char* mapLvl and places the characters in the space
  structure: s[ROW*COL]. With the space structure declared this way, each space
  in the map has its own space struct data. Space structure is declared as
  s[ROW*COL] rather than s[ROW][COL] because i couldn't get the latter to work
  so i ended up using the 1d approach instead. so a position at s[0][0] is 
  equivalent to s[0] and s[0][1] is equivalent to s[0+COL]. Think back to the
  magic squares lab if you coded the array as a 1d array rather than 
  multi-dimensional.


**************************************************************************/
void mp_create()
{	
	int i;
	int spacesize;
/*	int count = 0;
	int count1 = 1;
	char* temp = maps->mapLvl;
	int row = 0, col = 0;
	while(count != maps->sizex * maps->sizey)
	{
		/*stuff below that is commented out in this
		while loop, couldn't get to work for s[][].
		so used s[] method instead.*/
//		spaces[count].icon = *(temp);
		/*if(count1 == maps->sizey){
			row++;
			col = 0;
			count1 = 0;
		}
		else
			col++;
		*/
//		temp++;
		//count1++;
//		count++;
//	}

	char * t;
	spacesize = maps->sizex * maps->sizey;
	for (i = 0; i < spacesize; i++)
	{
		t = maps->mapLvl;
		//t[i] is the char for a specific spot on the map

		if ( t[i] != none && t[i] != BARRICADE && t[i] != soft && t[i] != HWALL && t[i] != VWALL && t[i] != BMAN && t[i] != mob && t[i] != BOMB && t[i] != XPLODE )
		{
			clear();
			//printw("maps->sizex = %d, maps->sizey = %d\n", maps->sizex, maps->sizey);
			//printw("maps->sizex = %d, maps->sizey = %d\n", maps->sizex, maps->sizey);
			refresh();
			spaces[i].icon = '$';
		}
		else
		{
			spaces[i].icon = t[i];
		}
	}

	//This for loop checks each space if there is hard block,
	//soft block, player, etc. present in space

	int e_index = 0;
	for(i = 0; i < maps->sizex*maps->sizey; i++)
	{
		spaces[i].pos = i; //the space must know where it is

		//no longer need to set values to 0. all default to 0 when alloc'd.
		if(spaces[i].icon == HWALL)
		{
			spaces[i].is_hard = 1;
		}	
		else if(spaces[i].icon == VWALL)
		{
			spaces[i].is_hard = 1;
		}
		else if(spaces[i].icon == BARRICADE)
		{
			spaces[i].is_hard = 1;
		}
		else if(spaces[i].icon == soft)
		{
			spaces[i].is_soft = 1;
		}
		else if(spaces[i].icon == BMAN)
		{
			spaces[i].is_bman = 1;
		}
		else if(spaces[i].icon == none)
		{
			//nothing
		}
		else if (spaces[i].icon == mob) //a enemy starts in this spot
		{
			if (e_index >= MAX_ENEMIES) //cant hold anymore enemies
			{
				spaces[i].icon = none; //just pretend nothing was here
			}
			else
			{
				spaces[i].is_enemy = 1;

				e_alloc(&enemys[e_index]); //allocate space for this actor
				e_setpos(enemys[e_index], i); //write in the location to the actor's memory
				e_index++;
			}
		}			

	}//end of for loop
	num_enemys_total = e_index; //keep track of total # of enemies in round
	num_enemys_alive = num_enemys_total;
}


//prints out map
void mp_print()
{	
	clear();
	int count = 0;
	int count1 = 1;
	num_enemys_alive = 0;

	pthread_mutex_lock(&mymutex);
	while(count != maps->sizex * maps->sizey)
	{	
		printw("%c", spaces[count].icon);
		if(count1 == maps->sizey){
			printw("\n");
			count1 = 0;
		}
		if(spaces[count].is_enemy == 1)
			num_enemys_alive++;
		count1++;
		count++;
	}
	printw(
	"Press arrow keys to move\n"
	"Press spacebar key to drop bomb\n"
	"num_enemys_alive: %d\n", num_enemys_alive
	);
	refresh();	
	pthread_mutex_unlock(&mymutex);
}

//finds starting position usingthe s[] structure based if is_bman is 
//true in any of the indexes
void mp_startPosition(bomberman* b)
{
	int i;
	for(i = 0; i < maps->sizex*maps->sizey; i++)
	{
			if(spaces[i].is_bman == 1)
			{
				b->pp = i;
				//b->ppc = j;
			}
	}
	//printw("%d", b->pp);	
}

//this function gets the symbol from the s[] structure if
//BMAN character is present in any of the indexes
char mp_getSymbol()
{
	int i;
	char symbol;
	for(i = 0; i < maps->sizex*maps->sizey; i++)
	{
		if(spaces[i].icon == BMAN)
		{
			symbol = BMAN;
		}
	}
	return symbol;
}


/*****************************************************************
In this function mp_playerInput b->ppr and b->ppc have been changed 
to just b->pp since the s[] structure is 1d and not a multi array 
otherwise if were using s[][] then we would be using b->ppr and b->ppc
******************************************************************/
int mp_playerInput(bomberman* b)
{
	int i;

	//if(spaces[b->pp].is_bman != 0){
	if(b->alive != 0)
	{
		maps->input = getch();

		//int check; //bool check
		pthread_mutex_lock(&mymutex);
		if(maps->input == KEY_RIGHT)
		{
			b->pp++;
			//printw("%d", spaces[b->pp].is_hard);
		
			if(mp_checkspace(b->pp, has_hard) == 1)
				b->pp--;
			else if(mp_checkspace(b->pp, has_soft) == 1)
				b->pp--;
			else if (mp_checkspace (b->pp, has_enemy) == 1) //enemy here, die die die
				bm_kill();
			else if (mp_checkspace (b->pp, has_xplode) == 1) //bomb explosion, dead
				bm_kill();
			else if (b->alive != 0){
				//move symbol to next space, clear old space, and also update is_bman values
				spaces[b->pp].icon = b->symbol;
				spaces[b->pp].is_bman = 1;
				if(spaces[b->pp-1].is_bomb == 1)
					spaces[b->pp-1].icon = BOMB;
				else
					spaces[b->pp-1].icon = none;
				spaces[b->pp-1].is_bman = 0; 
				spaces[b->pp-1].is_soft = 0;
			}
		}
		else if(maps->input == KEY_LEFT)
		{
			b->pp--;
			if(mp_checkspace(b->pp, has_hard) == 1)
				b->pp++; //undo decrement due to wall present
			else if(mp_checkspace(b->pp, has_soft) == 1)
				b->pp++; //undo decrement due to soft wall
			else if (mp_checkspace (b->pp, has_enemy) == 1) //enemy here, die die die
				bm_kill(b);
			else if (mp_checkspace (b->pp, has_xplode) == 1) //bomb explosion, dead
				bm_kill(b);
			else if (b->alive != 0){
				spaces[b->pp].icon = b->symbol;
				spaces[b->pp].is_bman = 1;
				if(spaces[b->pp+1].is_bomb == 1)
					spaces[b->pp+1].icon = BOMB;
				else
					spaces[b->pp+1].icon = none;
				spaces[b->pp+1].is_bman = 0; 
				spaces[b->pp+1].is_soft = 0;
			}
		}
		else if(maps->input == KEY_DOWN)
		{
		
			b->pp += maps->sizey;
			if(mp_checkspace(b->pp, has_hard) == 1)
				b->pp -= maps->sizey; //undo increment due to wall present
			else if(mp_checkspace(b->pp, has_soft) == 1)
				b->pp -= maps->sizey; //undo increment due to soft wall
			else if (mp_checkspace (b->pp, has_enemy) == 1) //enemy here, die die die
				bm_kill(b);
			else if (mp_checkspace (b->pp, has_xplode) == 1) //bomb explosion, dead
				bm_kill(b);
			else if(b->alive != 0){
				spaces[b->pp].icon = b->symbol;
				spaces[b->pp].is_bman = 1;
				if(spaces[b->pp-maps->sizey].is_bomb == 1)
					spaces[b->pp-maps->sizey].icon = BOMB;
				else				
					spaces[b->pp-maps->sizey].icon = none;
				spaces[b->pp-maps->sizey].is_bman = 0;
				spaces[b->pp-maps->sizey].is_soft = 0; 
			}
		}
		else if(maps->input == KEY_UP)
		{
			b->pp -= maps->sizey;
			if(mp_checkspace(b->pp, has_hard) == 1)
				b->pp += maps->sizey; //undo decrement due to wall present
			else if(mp_checkspace(b->pp, has_soft) == 1)
				b->pp += maps->sizey; //undo decrement due to wall present
			else if (mp_checkspace (b->pp, has_enemy) == 1) //enemy here, die die die
				bm_kill(b);
			else if (mp_checkspace (b->pp, has_xplode) == 1) //bomb explosion, dead
				bm_kill(b);
			else if (b->alive != 0){
				spaces[b->pp].icon = b->symbol;
				spaces[b->pp].is_bman = 1;
				if(spaces[b->pp+maps->sizey].is_bomb == 1)
					spaces[b->pp+maps->sizey].icon = BOMB;
				else
					spaces[b->pp+maps->sizey].icon = none;
				spaces[b->pp+maps->sizey].is_bman = 0;
				spaces[b->pp+maps->sizey].is_soft = 0;
			}
		}
		else if (maps->input == 'k') //kill the player. 107 = ascii for 'k'
		{
			bm_kill(b);
		}
		else if (maps->input == 'w') //i win button. kills all enemies
		{
			//num_enemys = 0;
			e_clear();
	/*
			for (i = *num_enemys-1; *num_enemys > 0; i--)
			{
				e_kill(enemys[i], num_enemys);
			}
	*/
		}
		else if(maps->input == 32)//insert ncurses spacekey) 
	 	{ 
			if(b->b_active==0)
			{
				int bs;
				pthread_t bombs;
				pthread_create(&bombs, NULL, mp_bomb, NULL);//(void *) b);
				//pthread_join(bombs, NULL);
			//	mp_bomb(b);
			}
		} 
		pthread_mutex_unlock(&mymutex);
		return 1;
	}
	else
	{
		pthread_mutex_unlock(&mymutex);
		return 0;		
	}
}

void* mp_bomb()//void* ptr) //use to be bomberman b
{ 
//	b= (bomberman) bom;
	//printw("%c", s[b->pp].icon);
	 //bomberman * b;//comment out
	 //b= (bomberman*) ptr;//comment out
	spaces[b->pp].icon = BOMB;//neway places icon, changes bomb placed variable etc 
	spaces[b->pp].is_bomb = 1;//julio whhat fun draws bomb icon?  
	b->b_active = 1; 
	b->bpp=b->pp;
	usleep(2500000);
	mp_explode(b);
	
	clock_t endwait;
//	endwait = clock () + 1.5 * CLOCKS_PER_SEC ;
//	while (clock() < endwait) {}
	usleep(750000); //0.75 sec
	mp_cleanXplode(b);
	b-> b_active =0;
	pthread_exit(NULL);
	
	// make sleep
	// then call xplode
	// then exit

} 

void mp_hurry()
{
	//do nothing
}

/*
PROPERTIES:
	has_bomb,
	has_bman,
	has_soft,
	has_item,
	has_hard,
*/
int mp_checkspace(int playerPosition, int property) //check if a specific space has property
{
	switch (property)
	{
		case has_bomb:
			return (spaces[playerPosition].is_bomb); //map is the name of the array of space structs
			break;
		case has_bman:
			return (spaces[playerPosition].is_bman);
			break;
		case has_soft:
			return (spaces[playerPosition].is_soft);
			break;
		case has_item:
			return (spaces[playerPosition].is_item);
			break;
		case has_hard:
			return (spaces[playerPosition].is_hard);
			break;
		case has_enemy:
			return (spaces[playerPosition].is_enemy);
			break;
		case has_xplode:
			return (spaces[playerPosition].is_dead);
			break;
		default:
			return 0;
	}
}

int mp_walkable(int pos)
{
	int bomb = mp_checkspace(pos, has_bomb);
	//int enemy = mp_checkspace(pos, has_enemy);
	int hard = mp_checkspace(pos, has_hard);
	int soft = mp_checkspace(pos, has_soft);

	if ( !bomb && !hard && !soft ) //no hard/soft blocks, and no bombs here
		return 1;
	else
		return 0;
}

int mp_getrelative(int pos, int dir)
{
	if (dir == dir_up)
	{
		pos -= maps->sizey;
	}
	else if (dir == dir_down)
	{
		pos += maps->sizey;
	}
	else if (dir == dir_left)
	{
		pos -= 1;
	}
	else if (dir == dir_right)
	{
		pos += 1;
	}

	return pos;
}

void mp_getcoords(int pos, int * x, int * y)
{
//sizex and sizey are backwards
//do the math on paper, this checks out
//top left space is pos 0, left to right, top to bottom
//top left space is (0, 0), space to the right is (1, 0), space below first is (0, 1).
	*x = pos % maps->sizey;
	*y = pos / maps->sizey;
}

void mp_explode(bomberman *b)
{
	int i;
	spaces[b->bpp].icon = XPLODE;
	spaces[b->bpp].is_dead = 1;
	if(spaces[b->bpp].is_bman == 1)
		bm_kill(b);

	/*for(i = 0; i < num_enemys_total; i++){
		if(enemys[i]->pp == b->bpp-1){
			e_kill(enemys[i]);
			//spaces[b->bpp-1].is_enemy = 0;
			spaces[(b->bpp-1)].icon = XPLODE;
		}
				//if(spaces[b->bpp-1].is_enemy == 1)
	}*/	

	if(!(spaces[b->bpp-1].icon==BARRICADE||spaces[b->bpp-1].icon==HWALL||spaces[b->bpp-1].icon==VWALL))//checks left
		{
			spaces[(b->bpp-1)].icon = XPLODE;
			spaces[b->bpp-1].is_dead = 1;
			if(spaces[b->bpp-1].is_bman == 1)
				bm_kill(b);
			for(i = 0; i < num_enemys_total; i++){
				if(enemys[i]->pp == b->bpp-1){
					e_kill(enemys[i]);
					//spaces[b->bpp-1].is_enemy = 0;
					spaces[(b->bpp-1)].icon = XPLODE;
				}
				//if(spaces[b->bpp-1].is_enemy == 1)
			}
		}

	if(!(spaces[b->bpp+1].icon==BARRICADE||spaces[b->bpp+1].icon==HWALL||spaces[b->bpp+1].icon==VWALL))//checks right
		{
			spaces[(b->bpp+1)].icon= XPLODE;
			spaces[b->bpp+1].is_dead = 1;
			if(spaces[b->bpp+1].is_bman == 1)
				bm_kill(b);
			for(i = 0; i < num_enemys_total; i++){
				if(enemys[i]->pp == b->bpp+1){
					e_kill(enemys[i]);
					//spaces[b->bpp+1].is_enemy = 0;
					spaces[(b->bpp+1)].icon= XPLODE;
				}
				//if(spaces[b->bpp+1].is_enemy == 1)
			}
		}

	int up= b->bpp+maps->sizey;
	int down= b->bpp-maps->sizey;

	if(!(spaces[up].icon==BARRICADE||spaces[up].icon==HWALL||spaces[up].icon==VWALL))
		{
			spaces[(up)].icon= XPLODE;
			spaces[up].is_dead = 1;
			if(spaces[up].is_bman == 1)
				bm_kill(b);
			for(i = 0; i < num_enemys_total; i++){
				if(enemys[i]->pp == up){
					e_kill(enemys[i]);
					//spaces[up].is_enemy = 0;
					spaces[(up)].icon= XPLODE;
				}
				//if(spaces[up].is_enemy == 1)
			}
		}

	if(!(spaces[down].icon==BARRICADE||spaces[down].icon==HWALL||spaces[down].icon==VWALL))
		{
			spaces[down].icon= XPLODE;
			spaces[down].is_dead = 1;
			if(spaces[down].is_bman == 1)
				bm_kill(b);

			for(i = 0; i < num_enemys_total; i++){
				if(enemys[i]->pp == down){
					e_kill(enemys[i]);
					//spaces[down].is_enemy = 0;
					spaces[down].icon= XPLODE;
				}
			}
		}	
	//makes checks using b->bpp which is a placehodler for bombs location
		

}

void mp_cleanXplode(bomberman*b)
{
	spaces[b->bpp].icon = none;
	spaces[b->bpp].is_bomb = 0;
	spaces[b->bpp].is_dead = 0;
	
	if(!(spaces[b->bpp-1].icon==BARRICADE||spaces[b->bpp-1].icon==HWALL||spaces[b->bpp-1].icon==VWALL))//checks left
		{
			if(spaces[b->bpp-1].is_soft == 1)
				spaces[b->bpp-1].is_soft = 0;
			spaces[(b->bpp-1)].icon = none;
			spaces[b->bpp-1].is_dead = 0;
		}

	if(!(spaces[b->bpp+1].icon==BARRICADE||spaces[b->bpp+1].icon==HWALL||spaces[b->bpp+1].icon==VWALL))//checks right
		{
			if(spaces[b->bpp+1].is_soft == 1)
				spaces[b->bpp+1].is_soft = 0;
			spaces[(b->bpp+1)].icon = none;
			spaces[b->bpp+1].is_dead = 0;
		}
	
	int up= b->bpp+maps->sizey;
	int down= b->bpp-maps->sizey;

	if(!(spaces[up].icon==BARRICADE||spaces[up].icon==HWALL||spaces[up].icon==VWALL))
		{
			if(spaces[up].is_soft == 1)
				spaces[up].is_soft = 0;
			spaces[(up)].icon= none;
			spaces[up].is_dead = 0;
		}

	if(!(spaces[down].icon==BARRICADE||spaces[down].icon==HWALL||spaces[down].icon==VWALL))
		{
			if(spaces[down].is_soft == 1)
				spaces[down].is_soft = 0;
			spaces[down].icon= none;
			spaces[down].is_dead = 0;
		}	
	//makes checks using b->bpp which is a placehodler for bombs location
	

}
//#endif

Added map.h.





























































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
#ifndef __MAP_H__
#define __MAP_H__

//#include "p_bman.h"
//#include "enemy.h"
#include <stdlib.h>
//#define ROW 47
//#define COL 52
#define MAXSIZE 265
#define MAX 12

//struct enemy; //forward declaration
struct bomberman;

//typedef struct space //is this necessary?
//{
enum blocktype
{
	none = ' ',
	BARRICADE = 'X',
	soft = '#',
	HWALL = '-',
	VWALL = '|',
	BMAN = 'B',
	mob = '@',
	BOMB = 'O',
	XPLODE = '+',
};

enum spaceproperty
{
	has_bomb,
	has_bman,
	has_soft,
	has_item,
	has_hard,
	has_enemy,
	has_xplode,
};

enum directions
{
	dir_left = 0,
	dir_right = 1,
	dir_up = 2,
	dir_down = 3,

	//for pathfinding
	dir_northwest,
	dir_northeast,
	dir_southwest,
	dir_southeast,
};

/*	int ROW; //x position of this space on the map
	int COL; //y position of this space on map

	int block; //# determines type of block that is on this square (if any). use num
} space;
*/

/*
each space was previously represented by a character. the character of a space determined the properties
of that space (hard block, soft block, bomberman, etc). a space can have more then one property though. it can
have a bomberman as well as a bomb on it. it can have a soft block as well as an item hidden inside (forward thinking).
so now each space is represented by a structure.
*/
typedef struct space
{
	//in the future: store an array of pointers to objects that are on this space. 
	//so if you want to kill everyone on this space, it has a list of objects to kill available instead of having to
	//loop through every object that exists and compare its coords to see if it sits in this space
	char icon; //the character that will be displayed on the map for this space
	int is_bomb; //is there a bomb on this space?
	int is_bman; //is there a bomberman on this space?
	int is_soft; //is there a soft block on this space?
	int is_item; //is there an item on this space?
	int is_hard; //is there a hard block on this space?
	int is_enemy; //is there an enemy on this space?
	int is_dead; //enemy or bomberman dies!	

	//the following is for pathfinding purposes
	int pos; //1 dimensional array type position
	int f; //f score. f = g + h
	int g; //the movement cost to move from starting point to this space
	int h; //'heuristic'. estimated movement cost to move from here to destination
	int open; //is this space on the open list? 1 or 0
	int closed; //is this space on the closed list? 1 or 0
	struct space * parent; //points to the parent of this space
} space;
	

typedef struct map {
//note to self sizex and sizey are backwards. sizex is recording the size of the columns (number of rows as opposed to the length of each row)
//and sizey is recording the size of the rows
	int sizex; //row size of map which will be read from file
	int sizey; //column size of map which will be read from file
	char arrayMaps[MAXSIZE]; //load array of files from map.txt into here
	char fMapLvl[MAX]; //load from file map
	int iterate; //used to keep track of the map array loaded from maps.txt
        int input; //user input based on what is entered. ex: arrow keys, space bar, backspace, etc.
	char* mapLvl; //reads data from file txt
	char* buffer;
} map;

void mp_s_alloc(space ** s, int size);
void mp_s_clearparents(int size); //clear parent of every space for proper pathfinding
void mp_s_clear();
void mp_alloc(map ** m);
void mp_readMapsInfo();
int mp_readMap();
void mp_create();
void mp_print();
void mp_startPosition(struct bomberman* b);
char mp_getSymbol();
int mp_playerInput(struct bomberman* b);
void* mp_bomb();//void* ptr);// added this to do bomb calculations. needs to edit map explosion, edit bomb bool(checks if u can set), also need a bomberman bomb counter for keyspace; will call check relative . use to take bomberman struct
void mp_hurry(); //alters the map by adding blocks to the outer edges (smaller playing field)
int mp_checkspace(int playerPosition, int property); //check if a specific space has property

int mp_walkable(int pos); //1 if position is walkable, 0 if not
int mp_getrelative(int pos, int dir); //return the pos that is 'dir' from the given position
void mp_getcoords(int pos, int * x, int * y); //convert 1-dimensional position into x and y coords
void mp_explode(struct bomberman*b);//makes checks
void mp_cleanXplode(struct bomberman*b);
#endif

Added maps.txt.











>
>
>
>
>
1
2
3
4
5
lvl1.txt
lvl2.txt
lvl3.txt
lvl4.txt
lvl5.txt

Added p_bman.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
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
//unnecessary, only use for .h files
//#ifndef BOMBERMAN_C
//#define BOMBERMAN_C
#include<stdlib.h>
#include<string.h>

#include "p_bman.h"
#include <stdlib.h>
#include <string.h>

bomberman* b;

void bm_alloc(bomberman **b)
{
	//allocate space for structure bomberman
	bomberman *temp = ((bomberman *)malloc(sizeof(bomberman)));
	*b = temp;
	//set default values
	(*b)->alive = 1;
	(*b)->fire = 1;
	(*b)->bomb = 1;
	(*b)->bombs_set = 0;
	(*b)->cpu = 0;
	(*b)->wins = 0;
	(*b)->b_active = 0;
	(*b)->bomb_counter = 0;
}

/*void bm_setname(char usrn[10])
{
	strcpy(b->name, usrn);
	//printw("%s", b->name);
}*/

void bm_setsymbol(char sym)
{
	b->symbol = sym;
}

int bm_getpos()
{
	return b->pp;
}

int bm_isalive()
{
	return b->alive;
}

/****************work on this later*********************/
//void bm_itemup(struct bomberman * b, struct item * i)
//{
/*
		fire,
		bomb,
		glove,
		kick,
		skull,
		punch,
*/

/*	switch *i.type
	{
		case fire:
			*b.fire++;
			break;
		case bomb:
			*b.bomb++;
			break;
		case glove:
			//nothing yet
			break;
		case kick:
			//nothing yet
			break;
		case skull:
			//not yet
			break;
		case punch:
			//not yet
			break;
		default:
			printf("[bomberman.c] item has invalid type\n")
			break;
	}

	item_remove(i);
}

void bm_ouch(struct bomberman * b)
{
	//disable controls for a second
	//...



	if (*b.fire > 1)
		*b.fire--;
	if (*b.bomb > 1)
		*b.bomb--;
}*/

void bm_kill()
{
	b->alive = 0;
}

//#endif

Added p_bman.h.











































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
#ifndef __P_BMAN_H__
#define __P_BMAN_H__

typedef struct bomberman
{
	/**********************work on later***********************/
	/*enum skulltype
	{
		slow, //move very slowly
		fast, //move very quickly
		nobombs, //cant set any bombs
		diarrhea, //cant stop setting bombs (they are set automatically)
		reverse, //controls are inverted
		shortfuse, //bombs blow up quickly
		longfuse, //bombs take a long time to blow up
	};*/
	/*********************************************************/

	
	char name[10];
	int alive; //similar to bool alive = false
	int fire; //blast radius of bombs
	int bomb; //# of bombs that can be live at once
	int bombs_set; //# of bombs currently live
	int b_active;//checks if bomb is live
	//int skull; //the type determines which skull powerdown the bomber has. use enum
	int cpu; //bool: whether or not to use ai control	
	int wins;
        int bomb_counter;//"timed counter" explodes based on ticks
	char symbol; //what is displayed for this character
	int pp; //player position
	//int ppc; //player position based on column
	int bpp;//bomb position(need to access coordinates after player moves)
	
	
} bomberman;

void bm_alloc(bomberman ** b);
//void bm_setname(bomberman *b, char usrn[10]);
void bm_setsymbol(char sym);
int bm_getpos();
int bm_isalive(); //bool
/********************work on later*******************************/
/*
void bm_itemup(struct bomberman * b, struct item * i); //picks up item and applies properties to bomberman
void bm_ouch(struct bomberman * b); //stun the player and make him drop items
void bm_fireup(struct bomberman * b); //increase fire by 1, call this after stepping on square with +fire
void bm_bombup(struct bomberman * b); //increase bomb 
*/
/***************************************************************/
void bm_kill(); //to kill a player if he is caught in a bomb blast or gets smushed by a block

#endif