After a while from the previous article, the people who are about to graduate are too busy. In addition, the network speed is not very good, if you want to write an article smoothly, you have to wait until the network speed is good at night to write a few times, life is such a cup. It's hard to catch this moment. There are no busy things, and the network speed is too high. Let's continue to finish the unfinished chapters in this series!
This chapter describes the realization of prizes in the game.
Almost all games have prize systems. When a role beats a monster, opens a box, or destroys an item, it is likely to receive a prize of a certain attribute. This greatly enhances the playability of the game, to make the game more interesting, prize settings are essential!
The following is a prize Category I have defined:
Prize
/// <Summary> <br/> // prize type <br/> /// </Summary> <br/> Public Enum prizetype <br/> {<br /> addlife, // Add life <br/> addmoney, // Add wealth <br/> addspeed, // increase speed <br/> addbomb, // Add bomb <br/> addpower, // enhance the bomb power <br/> nextlevel, // next level <br/> ranpos // transfer to random location <br/>}</P> <p> // <summary> <br/> // /prize <br/> /// </Summary> <br/> Public Class prize: baseentity <br/>{< br/> Public prizetype; <br/> Public bool ispick = false; // whether it has been picked up </P> <p> Public Prize () {}</P> <p> Public Prize (prizetype type) <br/>{< br/> This. prizetype = type; <br/>}</P> <p> Public override void draw (Graphics g) <br/>{< br/> string code = ""; <br/> switch (prizetype) <br/> {<br/> case prizetype. addlife: <br/> code = "life"; <br/> break; <br/> case prizetype. addmoney: <br/> code = "gold"; <br/> break; <br/> case prizetype. addspeed: <br/> code = "Speed"; <br/> break; <br/> case prizetype. addbomb: <br/> code = "Bullet"; <br/> break; <br/> case prizetype. addpower: <br/> code = "fire"; <br/> break; <br/> case prizetype. nextlevel: <br/> code = "N"; <br/> break; <br/> case prizetype. ranpos: <br/> code = ""; <br/> break; <br/>}< br/> G. drawrectangle (new pen (color. yellow, 1), poi. x, poi. y, utility. gridsize-1, utility. gridsize-1); <br/> G. drawstring (Code, new font ("", 15f), new solidbrush (color. yellow), poi. X + 4, poi. Y + 8); <br/>}< br/>}
I'm a little lazy here, And the prizes are presented in text format. It will be better if you replace it with vivid image materials! Next, you only need to instance n prizes and randomly distribute them to soilwall, which can be burned out on the map. When the main character destroys these prizes, there is a chance to get the prize. In order to better demonstrate the distribution of prizes on the map, I will reverse the order of prize painting and prize painting here, draw a wall first, and then draw a prize (in fact, draw a prize first and then draw a wall, in this way, the prize location is hidden ). Processing game rendering and game logic inGamemanagerIn this class, the following code draws the prize part and:
Gamemanager---> Initprize
Public class gamemanager <br/>{< br/> private random = new random (); <br/> // omitted <br/> private list <prize> prizes = new list <prize> (); <br/> // </P> <p> // <summary> <br/> // initialize the game <br/> /// </Summary> <br/> Public void initgame () <br/>{< br/> int Cols = utility. mapcols; <br/> int rows = utility. maprows; <br/> map = new map (cols, rows ); </P> <p> // omitted </P> <p> // initialize the prize <br/> This. prizes. clear (); <B R/> for (INT I = 0; I <(7 + level/3); I ++) <br/>{< br/> int rcol = random. next (2, cols); <br/> int rrow = random. next (2, rows); <br/> If (map. grids [rcol, rrow] = gridtype. soil) <br/>{< br/> prize = NULL; <br/> int r = random. next (0,100); <br/> switch (r) <br/>{< br/> case 1: <br/> case 2: <br/> case 3: <br/> prize = new prize (prizetype. addmoney); <br/> break; <br/> case 10: <br/> Ca Se 11: <br/> case 12: <br/> prize = new prize (prizetype. addbomb); <br/> break; <br/> case 20: <br/> prize = new prize (prizetype. addpower); <br/> break; <br/> case 30: <br/> case 31: <br/> prize = new prize (prizetype. addspeed); <br/> break; <br/> case 40: <br/> prize = new prize (prizetype. ranpos); <br/> break; <br/> case 0: <br/> prize = new prize (prizetype. addlife); <br/> break; <br/> case 50: <br /> Prize = new prize (prizetype. nextlevel); <br/> break; <br/>}< br/> If (prize! = NULL) <br/>{< br/> prize. poi. X = rcol * utility. gridsize; <br/> prize. poi. y = rrow * utility. gridsize; <br/> prizes. add (prize); <br/>}< br/> else <br/> I = I> 0? I-= 1: I; <br/>}< br/> else <br/>{< br/> I = I> 0? I-= 1: I; <br/>}< br/> // <br/>}</P> <p> Public void draw (Graphics g) <br/>{< br/> map. draw (g); </P> <p> for (INT I = 0; I <soilwils. count; I ++) <br/>{< br/> soilwils [I]. draw (g); <br/>}< br/> for (INT I = 0; I <prizes. count; I ++) <br/>{< br/> prizes [I]. draw (g); <br/>}< br/> // omitted <br/>}
The switch branch above is just a rough solution to the probability problem of different prize attributes. It is not very accurate and will be renewed. Below is:
When it comes to implementation, you just need to adjust the sequence of drawing shards and prizes. Otherwise, the consequences will be very serious and the players will despise it. We suggest you replace all the prizes with image materials of specific significance. text shows instantly weaken the game's worth a lot. I can't afford to hurt it!