game project

hello every one;
while I was learning c++ I thought it was something boring that I cannot build
any games;
so I started to build one;
its small and not funny at all
that is why I am writing this ,so that we build it again together like adding music or colors;
it will be very good idea for us(beginners)and we will have fun too;
here is the code for the tiny game
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
#include<iostream>
#include<cstring>
char screen[80][25];
using namespace std;
class static_obg{
private:char shape[4];int location[4][2];
public:void put_in_screen()
	{
	int a,b;
	for(int C=0;C<4;C++)
	 {a=location[C][0]; b=location[C][1]; screen[a][b]=shape[C];}
	}
	   static_obg()
	   {
		   strcpy(shape,"WALL");
		int  temporary[4][2]={{40,0},{40,1},{40,2},{40,3}};
	    for(int u=0;u<4;u++)
		{
		for(int e=0;e<2;e++)
		{location[u][e]=temporary[u][e];}
		}
	   }
friend class object;
};

static_obg wall;
class object{
private:
	char shape[2];
	int location[2][2];
public:
	void but_shape()
	{
	for(int u=0;u<2;u++)
	{ 
      cout<<"enter the a block:"; 
	  cin>>shape[u];

	  cout<<"now enter the location of this block(80,25):";
	  cin>>location[u][0]>>location[u][1];}
	}
	void put_in_screen()
	{
	int a,b;
	for(int C=0;C<2;C++)
	 {
	 a=location[C][0];
	 b=location[C][1];
	 screen[a][b]=shape[C];
	 }
	}
	void move()
	{
	char q;
	cin>>q;
	switch (q)
	{case'w':if(test_avialbility('w')){for(int u=0;u<2;u++)((location[u][1])=(location[u][1])-1);};
	              break;
	case's':if(test_avialbility('s')){for(int u=0;u<2;u++)((location[u][1])=(location[u][1])+1);};
			      break;
	case'd':if(test_avialbility('d')){for(int u=0;u<2;u++)((location[u][0])=(location[u][0])+1);};
			      break;
	case'a':if(test_avialbility('a')){for(int u=0;u<2;u++)((location[u][0])=(location[u][0])-1);};
			      break;
	    }
}
	bool test_avialbility(char action)
{
	int flex1=0,flex2=0;
	switch(action){
	case'w':flex2=-1; break;
	case's':flex2= 1; break;
	case'a':flex1=-1; break;
	case'd':flex1= 1; break;
	}

int k,b;   for(int C=0;C<2;C++){
k=location[C][0];
b=location[C][1];   
for(int p=0;p<4;p++){if ((wall.static_obg::location[p][0]==(k+flex1))&&(wall.static_obg::location[p][1]==(b+flex2))){return false;}}}return true;}
};
object a;

void main(){

	
	
	
	a.but_shape();
	for(;;)
	{
	for(int w=0;w<80;w++)
	{for(int q=0;q<25;q++)
	screen[w][q]=' ';}; 
	a.put_in_screen();
	wall.put_in_screen();
	for(int w=0;w<25;w++)
	{for(int q=0;q<80;q++)
	cout<<screen[q][w];}
	a.move();
	system("CLS");
	}
}

the game is simple first enter a character then its location
then the second one
after that you can move by(w a s d)//enjoy
Last edited on
Topic archived. No new replies allowed.