473,378 Members | 1,462 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

A good way of programming?

I am programming an easy game (not with a commercial purpose, just with
learning purpose), but I doubt whether the following way of programming is
proper or advisable.

The main form (BugEaterForm) that has a module, has the following objects:
- Snake, for drawing and being controlled;
- Player, with player information, such as name, score, number of lives;
- PlayField, containing the matrix on which you are playing;
- BugEaterForm.

But I think I don't have a neat way of realizing the communication with each
other.

For example, if the snake must be moved, or it eats a candy or it is dying.
The trick is passing the classes as a parameter in the constructor of the
other class.

For example:

currentplayer = new Player(gnf, playPanel, timeleftPanel, playField,
timerSnake, timerBonus, "Hans Kamp", scoreLabel, livesLabel);

all this stuff must be passed, because the player and objects that are
dependent of the player must have the ability to do something with the
controls and other variables in the above constructor.

The constructor Player is defined as:

public Player(GetNameForm gnf, Panel pp, Panel tlp, PlayField pf, Timer s,
Timer b, string playerName, Label sl, Label ll)
{
...
playerSnake = new Snake(pp, pf, this, s, b);
...
}

The constructor Snake has 5 parameters. It is defined as:

public Snake(Panel playP, PlayField pf, Player p, Timer s, Timer b)
{
...
playfield.setCell(panel, snakeHead.X, snakeHead.Y, Field.SnakeHead);
}

And setCell needs access to the object PlayField (by playfield) so that the
snake can be drawn initially. But the snake has to do several things, for
example:

- repositioning. It needs access to PlayField;
- completing a level. It needs access to timers on the main Form (stopping
and starting a timer), access to a player (adding bonus to the score,
incrementing the live and level with one, and setting the bonus points to
4000), access to the playfield (redrawing the field);
- removing the snake. It needs access to playField;
- dying. It needs access to the timers, to the player, to playField;
- moving. It needs access to the playField;
- processing keys (being controlled by the user).

The player has the following tasks:
- drawing the time left bar. It needs access to the timeLeftPanel;
- displaying the number of lives. It needs access to the livesLabel of the
form;
- displaying the score. It needs access to the scoreLabel of the form.

The playField has the following tasks:
- drawing a cell (it needs access to the playPanel);
- setting a cell;
- getting a cell;
- redrawing a new level play field (it needs access to the playPanel);
- drawing walls (access to the panel);
- drawing candies (access to the pane).

For the whole source code (related to the above text), see

www.hanskamp.com/csharp/WinForm.cs

What do you think? What is the best way of organizing the communication
between the objects?

Hans Kamp.
Nov 15 '05 #1
2 1849
Hans, Game Engine design is a big topic, but let me offer up a few things.
(BTW, I wasn't offering commercial services in my previous post. Games4 and
BrainFreeze are both going to be community companies and not a massive money
making machines.)

First, modularize everything so that it is independent of the other pieces.
What do I mean by this? Well first off, create the game so that it can play
by itself without showing off any graphics. This generally means creating
an object that can be set-up to play the game using different parameters,
providing methods to step forward through each tick of the game (every game
has a logical timeslice), and finally some end state variable that lets
callers of the engine know when it is complete.

With the *engine* done you need to abstract the process of input. Generally
you can use a Queue of action objects. In your game runner (the engine
host), whether it be WinForms, console, web page, whatever, you can then map
user input to these generic actions and then put them into the games queue.
This has an added benefit. Your game also achieves a natural AI interface
(an interface through which AI can provide typed input to the game in order
to play). Each AI player can simply use the same interfaces as a real
player. You also gain the ability to easily take network messages right off
the sockets and plop them down into the engine for remote play.

The last process is going to be deciding what data is available. This is
important, you'll need to relese enough data for the graphics engine to
actually render itself. Sometimes the graphics engine is completely
separate and sometimes it is heavily integrated with the game engine host
since it will be responsible for providing input UI. Between calls to
Advance() or NextTick() or whatever you called the game engine advancedment
method, you can render your scene by getting the state of the engine.

By modularizing in this fasion you can work on little pieces of your game.
In the end you can actually upgrade only the portions that you want to. If
you are slick with the way modules work together you can even interface the
entire thing and do dynamic binding in a config file so you can swap modules
out. The best place for this is AI so that users can change the AI classes
they are playing against.
--
Justin Rogers
DigiTec Web Consultants, LLC.

"Hans Kamp" <in**@hanskamp.com> wrote in message
news:bi**********@news1.tilbu1.nb.home.nl...
I am programming an easy game (not with a commercial purpose, just with
learning purpose), but I doubt whether the following way of programming is
proper or advisable.

The main form (BugEaterForm) that has a module, has the following objects:
- Snake, for drawing and being controlled;
- Player, with player information, such as name, score, number of lives;
- PlayField, containing the matrix on which you are playing;
- BugEaterForm.

But I think I don't have a neat way of realizing the communication with each other.

For example, if the snake must be moved, or it eats a candy or it is dying. The trick is passing the classes as a parameter in the constructor of the
other class.

For example:

currentplayer = new Player(gnf, playPanel, timeleftPanel, playField,
timerSnake, timerBonus, "Hans Kamp", scoreLabel, livesLabel);

all this stuff must be passed, because the player and objects that are
dependent of the player must have the ability to do something with the
controls and other variables in the above constructor.

The constructor Player is defined as:

public Player(GetNameForm gnf, Panel pp, Panel tlp, PlayField pf, Timer s,
Timer b, string playerName, Label sl, Label ll)
{
...
playerSnake = new Snake(pp, pf, this, s, b);
...
}

The constructor Snake has 5 parameters. It is defined as:

public Snake(Panel playP, PlayField pf, Player p, Timer s, Timer b)
{
...
playfield.setCell(panel, snakeHead.X, snakeHead.Y, Field.SnakeHead);
}

And setCell needs access to the object PlayField (by playfield) so that the snake can be drawn initially. But the snake has to do several things, for
example:

- repositioning. It needs access to PlayField;
- completing a level. It needs access to timers on the main Form (stopping
and starting a timer), access to a player (adding bonus to the score,
incrementing the live and level with one, and setting the bonus points to
4000), access to the playfield (redrawing the field);
- removing the snake. It needs access to playField;
- dying. It needs access to the timers, to the player, to playField;
- moving. It needs access to the playField;
- processing keys (being controlled by the user).

The player has the following tasks:
- drawing the time left bar. It needs access to the timeLeftPanel;
- displaying the number of lives. It needs access to the livesLabel of the
form;
- displaying the score. It needs access to the scoreLabel of the form.

The playField has the following tasks:
- drawing a cell (it needs access to the playPanel);
- setting a cell;
- getting a cell;
- redrawing a new level play field (it needs access to the playPanel);
- drawing walls (access to the panel);
- drawing candies (access to the pane).

For the whole source code (related to the above text), see

www.hanskamp.com/csharp/WinForm.cs

What do you think? What is the best way of organizing the communication
between the objects?

Hans Kamp.

Nov 15 '05 #2
A better attempt in http://www.hanskamp.com/csharp/BugEater2.zip.

Hans Kamp.
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: matty | last post by:
Go away for a few days and you miss it all... A few opinions... Programming is a craft more than an art (software engineering, not black magic) and as such, is about writing code that works,...
4
by: Kanthi Kiran Narisetti | last post by:
Hi ALL, I am new to programming and python. In my quest to get good at programming, even when I am able to get through the python tutorials I feel for lack of exercises & examples that...
20
by: Clark | last post by:
Hi all. I'm looking for good C source code to study and be able to advance my C programming skills. Do you recomend any open source project in particular that in your opinion has good writen C...
12
by: G. | last post by:
Hi all, During my degree, BEng (Hons) Electronics and Communications Engineering, we did C programming every year, but I never kept it up, as I had no interest and didn't see the point. But now...
39
by: Suresh | last post by:
Hi, I am new to C and curious to know some basic questions about C. Why C is good? In what way its better than any other languages? If it is no longer a choice of programming language...why...
3
by: beachboy | last post by:
hi all, would you pls advise any good books for learning C# (web related back-end programming) with java background? thanks for your suggestion. beachboy
15
by: Alex L Pavluck | last post by:
I am new to programming other than SAS. I read that C# is a good starting language and I have started to create some simple programs with C# 2005 express edition. Can someone let me know if this...
2
by: ppuniversal | last post by:
Hello, Can someone tell a good Tutorial on Network Programming in C++, except Beej's Guide and Vijay Mukhi's tutorials. I want to make a Client Server application in C++ which will involve...
206
by: WaterWalk | last post by:
I've just read an article "Building Robust System" by Gerald Jay Sussman. The article is here: http://swiss.csail.mit.edu/classes/symbolic/spring07/readings/robust-systems.pdf In it there is a...
13
by: 1jasong | last post by:
Hello I am new to programming and want to know what is a good free compiler is. I am asking this because there are so many of them and I just want to start programming also a good website for...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.