C # 44 Waterloo battle

Source: Internet
Author: User

Tell students that information about the movement of the player and the computer can be stored in a 3x3 array called a. Each element in the 3x3 array will represent the squares in the battlefield, as shown in.

A[0, 0]

A[0, 1]

A[0, 2]

A[1, 0]

A[1, 1]

A[1, 2]

a[2, 0]

A[2, 1]

A[2, 2]

For each array element's cell


Initially, the value 0 is stored in all array elements. When the player puts the bomb in the cell, the value in the array element corresponding to this cell is changed to 1. When a computer puts a bomb in a cell, the value in the array element corresponding to this cell is changed to-1.

If any of the following is true, the computer will win the game:

N a[0,0] + a[0, 1] + a[0, 2] = 3

N a[1,0] + a[1, 1] + a[1, 2] = 3

N a[2,0] + a[2, 1] + a[2, 2] = 3

N a[0,0] + a[1, 0] + a[2, 0] = 3

N a[0,1] + a[1, 1] + a[2, 1] = 3

N a[0,2] + a[1, 2] + a[2, 2] = 3

N a[0,0] + a[1, 1] + a[2, 2] = 3

N a[0,2] + a[1, 1] + a[2, 0] = 3

If any of the following is true, the player will win the game:

N a[0,0] + a[0, 1] + a[0, 2] = 3

N a[1,0] + a[1, 1] + a[1, 2] = 3

N a[2,0] + a[2, 1] + a[2, 2] = 3

N a[0,0] + a[1, 0] + a[2, 0] = 3

N a[0,1] + a[1, 1] + a[2, 1] = 3

N a[0,2] + a[1, 2] + a[2, 2] = 3

N A[0, 0]+ a[1, 1] + a[2, 2] = 3

N a[0,2] + a[1, 1] + a[2, 0] = 3

The computer will act as another player in the game. Students need to write the logic of computer action. The computer will challenge the player to make it difficult before they win the game.

When you write code for a computer's movement, you must consider the following points:

N first the computer should check if it can win the game by burying the bomb in any available cell. For this you can check that the sum of the cells of any row, column, and Diagonal is-2. If this condition is true for any row, column, or diagonal, this means that the row, column, or diagonal already contains two bombs placed by the computer, and also contains blank cells. The computer can fill this blank cell to win the game.

N If the computer does not win the game by placing the bombs in any blank cell, the computer should check these to prevent the player from winning the game. For this you can check that the sum of the cells of any row, column, and diagonal is 2. If this condition is true for any row, column, or diagonal, this means that the row, column, or diagonal already contains two bombs placed by the player and contains blank cells. Players can fill this blank cell to win the game. Therefore, the computer should fill up this cell to prevent the player from winning the game.

N If none of the above two conditions are true, the computer can randomly select a cell and place a bomb there.

In order to generate random numbers, the following code is used:

Random ran= new Random ();

Num =ran.    Next (0,2); 0 is included in Therange, 2 is excluded



The following is the interface design for the original screen of the Waterloo campaign.




The following is the interface design of the game board.


The following is the interface design of the Integrator board.




This group will use 12 hours (per student) to complete the project. During this time, they need to:

n analyze use case studies and identify these requirements

N Design the game's interface

n basic logic used to develop the game

n logic to implement development

N Development Game

n develop and integrate a help system into a project

N Package a complete solution





C # 44 Waterloo battle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.