Categories
"Hey! White?" Lesson plans

It's not what you think:A program website

This lesson we try to develop a simple command-line games,To complete the experience a so-called "development process"。

This game is set:

This is a board game,We guess the location of enemy ships,As long as the number of hits you can send them to sink。

We give these ships the label affixed to point it ...... such a variety of sites?So,This has become a site of attack Behind his program ......。

Goal of the game

We want to attack the player with the least number of sites,It crushed。Then we scored based on the number of players guessing。

Roughly design

We draw a grid 7 * 7 to represent the board,Then arrange the three sites immediately on the grid,Each site accounted for three consecutive grid,And then ask the players to guess the coordinates of the site。

Because we do not contact pattern design,So we ask the user to enter the coordinates of this example A5,We use the letters on behalf of the ordinate,Figures represent the abscissa。Then we set three states,They are "missed"、"Hit!" And "kill it!"

When the players get rid of all sites on the chessboard,We calculate the scores of players。

game design
game design

Flowchart design game

We need classes and methods to get this game,But what methods which have specific class? Prior to this, I am afraid we have to straighten out the flow of questions about the game:

Game flow chart
Game flow chart

Ok,I'm blind Canoeing something is too hard to read the,But that's okay,Please understand the spirit。

The first version

It seems that we can use two classes Game and WebSite。First of all,Let's take a simple point,We only use one-dimensional map,That is to guess the location of the site in a strip inside - which makes it easier to understand and implement,Now we try to write this pseudo-code program。

What is the pseudo code?

Pseudo code is not the code,It is the code for the model you use more natural language description out,It used to test the most simple logic implementation - in this process we not only focus on the design itself outside,Further focus on the logical framework - but avoid the trouble programming language syntax itself,Let more natural expression and quickly。

Here we posted a handwritten version of the pseudo-code chestnuts to you:

Fake code
Fake code

Here we come to a class auxiliary body for the game:

At last,While we try to say away from the main file,But this time in order to facilitate,We still run the game directly written on the entrance in:

Okay, I admit WebSite class is not completely written out,Because the screen you want to capture,Space and other issues that I just wrote a self-test method,But that's okay,The main is to make you understand the process to write pseudo code。

Write real code pseudocode

All right,Repeatedly calculating a logical process pseudocode,After determining no problem,You can use real code to implement it:

Game execution process
Game execution process

Since there is no GUI interface,So it does not look how tall on ...... but we go through this simple version again the complete development process。

remember:

In practice, in development,Pseudo code you write is what,Then take the code written in what - I believe you for hitting definitely worth attention - but you can still find a small notebook to write down is wonderful。If you really smoothly increases the other and is not expected to function in your code,That ultimately out of the code may have a weird bug。

So,Step by step - the first to write pseudo code,To achieve the original purpose,Then the next step - a new feature to add more ...... so make your code robust lot。

Original article written by Gerber drop-off:R0uter's Blog » It's not what you think:A program website

Reproduced Please keep the source and description link:https://www.logcg.com/archives/1113.html

By R0uter's Blog

The non-declaration,I have written articles are original,Reproduced, please indicate the link on this page and my name。

1 reply on “It's not what you think:A program website”

Leave a Reply

Your email address will not be published. Required fields are marked *