Stored data for games

From Arianne
Jump to: navigation, search

Data storage in applications

In this section we introduce data storage for applications. We use various games as example applications.

  • what data needs to be stored
  • methods for storing data
  • some points to take care of when storing data
  • introduction to databases
  • effective data storage with databases (normalization)

The first example is a game played locally on a home computer. High scores can be recorded at the end of each game by putting in a name. The data that needs to be stored is simple and it is stored locally.

The next example is an online game with a scoreboard. The data that needs to be stored is simple but it is stored on a remote server

The last example is a online game with a scoreboard, where users can create an account which they login to, rather than typing a name. The data stored is complex and it is stored remotely. We add consider different examples of data to store such as historic high scores and login history.

Downloaded local game with score board

A very simple example of data storage in a game is the high score board for a game like tetris which you may have downloaded onto your computer. My favourite game when I was younger was Tetris, and I found a text file (like you would open with NotePad, say) which stored the high score table in a fairly readable form. That was the only piece of information the game ever remembered, you could type in your name when you got a high score and it would write the name you typed, and the score, to that text file. It would look like

name    | score
KT      | 10009292
KT      | 9698229
KT      | 7466343
Brother | 29254


This game was self contained, and did not connect to other users, so the 'world' of the game was small - just me and whoever else used the computer. It made sense that the data could be stored on the computer. And it was not complicated data, so a text file is fine.

Some points for thought:

If you had this game, and got a new computer, could you keep your high score from the old computer? How?

Ans: copy the text file onto the new computer in the correct place

If you played the game after your Brother had been on the computer and saw that he suddenly had a high score beating yours, of 9999999999, say, what would you think had happened? (your Brother is bad at tetris)

Ans: your brother edited the text file

If you are a game designer, how could you protect against editing of this high score file?

Ans: - make it harder to find (hidden file) - Better: encode the contents (very simply, map every letter and number to a different letter and number according to a rule only you know. you tell the program itself the rule so it can write the file using the rule and read the file using the rule)

Online game with a high score board, no user accounts

Lets imagine that this tetris game was an online game, so that you could play it but also compare your high score to other users. We are not going to talk about how the communication between your game client and the server with the game on it, works - that's another topic called 'client server communication'. It is enough to say that you can launch the game but when you play, the game is actually stored on another computer and your client is showing you what is happening, as well as sending your commands to the remote computer.

At the end of the game, you again got a high score! You're asked to enter a name for yourself and your score is stored on a file on the remote computer. When you look at the high score board you can see your scores and also a bunch of other users.

Online with a high score board and user accounts