: yes but what type of source code is needed
:
Before writing any code, you'll need to think about several things first. Some of those are:
- is the game real-time or turn-based?
- what are the characteristics of the players on the field?
- is the game multithreaded or single threaded? If multithreaded, which threads do I need?
- is the field completely visible on the screen or is it side- or up/down scrolling; or perhaps 3D?
- is the game played by mouse clicks, keyboard or both?
- etc.
The answers to these questions will determine the code. For example: a single threaded, turn-based game code has this as basis:
while (playingtime < 90 minutes) {
for (int playerIndex = 0; playerIndex < 22; playerIndex++) {
players[playerIndex].move();
ball.update();
field.update();
}
}
A real-time, 2-threaded game code has these two htreads:
public void run() {
screenThread.start();
while (playingtime < 90 minutes) {
for (int playerIndex = 0; playerIndex < 22; playerIndex++) {
if (playerIndex == activePlayer) {
players[playerIndex].move(getUserInput());
} else {
players[playerIndex].move(getAIInput());
}
ball.update();
}
}
screenThread.terminated = true;
}
public void run() {
while (!screenThread.terminated) {
field.update();
}
}
As you can imagine, a 3 or more multithreaded engine becomes increasingly difficult to time and needs more and more synchronization.
As you can see above I placed the players in an array of Player objects. These objects can hold the physical characteristics of the players, the appearance on the field, depending on other choices: the chance of making a successful pass, a successful goal, running speed, stability, etc.
The code of for a soccer game engine (minus the AI) can quickly increase to thousands of lines. As you can see the question of "what type of source code is needed" is very hard to answer, because it depends on a whole lot of factors and the precise specification of the game itself.